From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 69251 invoked by alias); 25 Oct 2016 09:21:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 69216 invoked by uid 89); 25 Oct 2016 09:21:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-spam-relays-external:209.85.192.194, H*RU:209.85.192.194, Hx-languages-length:2435, quit X-HELO: mail-pf0-f194.google.com Received: from mail-pf0-f194.google.com (HELO mail-pf0-f194.google.com) (209.85.192.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Oct 2016 09:21:44 +0000 Received: by mail-pf0-f194.google.com with SMTP id r16so19054502pfg.3 for ; Tue, 25 Oct 2016 02:21:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=Zyo9Bvu9Nbo6ugj5832VhbEV25V+Ml8pq7hoCKkMB8E=; b=PjJbTof4JH/DHQUssN/vuZnEbBezPy1rYrTd13jKd19QrWVsXPhIcq7SvQpAMrFC8y fb+b3oC2uV4Gfgp4zgUYcyJNddd/0omMjo4SFEk0fV0Tdmv8YZGXz3/FRuMa03KOKC8Z DNSzgqP0X02fVUh6mtS4WsCGP9oJc1Nn4hDIQK96kysmndy3i0un/36Lj8UMkwZPyiJj NDmaW4CVcSqmfgM2swciXarlTdBAFPCkFeoWKJt3TxwA9GQohRwTksi2QgDCfX+0G5ie iUVQoZ4FxdsUKCswx4dAP+yfEF329YTZk73UR9GjM0vAY9tPKIHLYb/WUqvepNU3OxHx BOYQ== X-Gm-Message-State: ABUngvfn4Rcj0N5s8vKSjH6ksDGxB9EA5G+GvL9TsSkRyf3pGqk4b9HnjLv5QH9NS+l0RQ== X-Received: by 10.98.61.85 with SMTP id k82mr37564836pfa.7.1477387303266; Tue, 25 Oct 2016 02:21:43 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc115.osuosl.org. [140.211.9.73]) by smtp.gmail.com with ESMTPSA id j63sm31475633pfj.70.2016.10.25.02.21.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 25 Oct 2016 02:21:42 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH] Don't override operator new if GDB is built with -fsanitize=address Date: Tue, 25 Oct 2016 09:21:00 -0000 Message-Id: <1477387295-24846-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2016-10/txt/msg00686.txt.bz2 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::deallocate(void (**)(), unsigned long) /usr/include/c++/4.9/ext/new_allocator.h:110 #2 0xac8cc2 in __gnu_cxx::__alloc_traits >::deallocate(std::allocator&, 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::allocate(unsigned long, void const*) /usr/include/c++/4.9/ext/new_allocator.h:104 #3 0xac8d81 in __gnu_cxx::__alloc_traits >::allocate(std::allocator&, 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 only if the code is NOT compiled with asan. gdb: 2016-10-25 Yao Qi PR gdb/20716 * common/new-op.c (__has_feature): New macro. Don't override operator new if asan is used. --- gdb/common/new-op.c | 7 +++++++ 1 file changed, 7 insertions(+) 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 . */ +/* 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 @@ -83,3 +89,4 @@ operator new[] (std::size_t sz, const std::nothrow_t&) { return ::operator new (sz, std::nothrow); } +#endif -- 1.9.1