From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103338 invoked by alias); 25 Oct 2016 09:39:32 -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 103311 invoked by uid 89); 25 Oct 2016 09:39:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=2016-10-25 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Oct 2016 09:39:21 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4158F61E4C; Tue, 25 Oct 2016 09:39:20 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9P9dJCn030025; Tue, 25 Oct 2016 05:39:19 -0400 Subject: Re: [PATCH] Don't override operator new if GDB is built with -fsanitize=address To: Yao Qi , gdb-patches@sourceware.org References: <1477387295-24846-1-git-send-email-yao.qi@linaro.org> From: Pedro Alves Message-ID: <6afd5d0c-5e8e-1edb-5fa7-cd7c80d493df@redhat.com> Date: Tue, 25 Oct 2016 09:39:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1477387295-24846-1-git-send-email-yao.qi@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-10/txt/msg00687.txt.bz2 On 10/25/2016 10:21 AM, Yao Qi wrote: > 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. LGTM. Thanks, Pedro Alves