This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Don't override operator new if GDB is built with -fsanitize=address


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3ef9d661f45abfaca5d0c0bb2ea9ab60470f1bb7

commit 3ef9d661f45abfaca5d0c0bb2ea9ab60470f1bb7
Author: Yao Qi <yao.qi@linaro.org>
Date:   Tue Oct 25 11:13:00 2016 +0100

    Don't override operator new if GDB is built with -fsanitize=address
    
    Nowadays, if we build GDB with -fsanitize=address, we can get the asan
    error below,
    
    (gdb) quit
    =================================================================
    ==9723==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x60200003bf70
        #0 0x7f88f3837527 in operator delete(void*) (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x55527)
        #1 0xac8e13 in __gnu_cxx::new_allocator<void (*)()>::deallocate(void (**)(), unsigned long) /usr/include/c++/4.9/ext/new_allocator.h:110
        #2 0xac8cc2 in __gnu_cxx::__alloc_traits<std::allocator<void (*)()> >::deallocate(std::allocator<void (*)()>&, void (**)(), unsigned long) /usr/include/c++/4.9/ext/alloc_traits.h:185
    ....
    0x60200003bf70 is located 0 bytes inside of 8-byte region [0x60200003bf70,0x60200003bf78)
    allocated by thread T0 here:
        #0 0x7f88f38367ef in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x547ef)
        #1 0xbd2762 in operator new(unsigned long) /home/yao/SourceCode/gnu/gdb/git/gdb/common/new-op.c:42
        #2 0xac8edc in __gnu_cxx::new_allocator<void (*)()>::allocate(unsigned long, void const*) /usr/include/c++/4.9/ext/new_allocator.h:104
        #3 0xac8d81 in __gnu_cxx::__alloc_traits<std::allocator<void (*)()> >::allocate(std::allocator<void (*)()>&, unsigned long) /usr/include/c++/4.9/ext/alloc_traits.h:182
    
    The reason for this is that we override operator new but don't override
    operator delete.  This patch does the override if the code is NOT
    compiled with asan.
    
    gdb:
    
    2016-10-25  Yao Qi  <yao.qi@linaro.org>
    
    	PR gdb/20716
    	* common/new-op.c (__has_feature): New macro.
    	Don't override operator new if asan is used.

Diff:
---
 gdb/ChangeLog       | 6 ++++++
 gdb/common/new-op.c | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 43175ff..5541086 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2016-10-25  Yao Qi  <yao.qi@linaro.org>
+
+	PR gdb/20716
+	* common/new-op.c (__has_feature): New macro.
+	Don't override operator new if asan is used.
+
 2016-10-24  Luis Machado  <lgustavo@codesourcery.com>
 
 	* exec.c (exec_file_locate_attach): Prevent NULL pointer dereference
diff --git a/gdb/common/new-op.c b/gdb/common/new-op.c
index 5ba4d6e..f04c5cb 100644
--- a/gdb/common/new-op.c
+++ b/gdb/common/new-op.c
@@ -17,6 +17,12 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+/* GCC does not understand __has_feature.  */
+#if !defined(__has_feature)
+# define __has_feature(x) 0
+#endif
+
+#if !__has_feature(address_sanitizer) && !defined(__SANITIZE_ADDRESS__)
 #include "common-defs.h"
 #include "host-defs.h"
 #include <new>
@@ -83,3 +89,4 @@ operator new[] (std::size_t sz, const std::nothrow_t&)
 {
   return ::operator new (sz, std::nothrow);
 }
+#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]