From patchwork Thu Dec 8 22:56:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 61713 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20B8B383D5DC for ; Thu, 8 Dec 2022 22:57:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20B8B383D5DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670540244; bh=JyCF77qZZzBIV7q62tahtc2/a/SmudCOw0uo7Y9ou1I=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=cVB/TphvzUztmafbIzNbiyzl6iR0Hnq4d/1bJSDudDNp48djQRB5VXO3HiF+W8Xwi dQdvgGaiiDvvY9ac0CvJ7ZeeWzViWdRvoXiTg2FP/9C8Fl55YpJZNnsF24Qr2WzPdL jKZO3W4kBQ237ZWcUr96jhfc+0QorQ895uicZQpc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6BCDC383E422 for ; Thu, 8 Dec 2022 22:56:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6BCDC383E422 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-365-VxodFdHsOYq7St0WS_4UOw-1; Thu, 08 Dec 2022 17:56:45 -0500 X-MC-Unique: VxodFdHsOYq7St0WS_4UOw-1 Received: by mail-qv1-f72.google.com with SMTP id c10-20020a05621401ea00b004c72d0e92bcso2792989qvu.12 for ; Thu, 08 Dec 2022 14:56:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JyCF77qZZzBIV7q62tahtc2/a/SmudCOw0uo7Y9ou1I=; b=qcE44FBzdwstnQBfp/RlTDoRiiZb1RbqjVg60CApYbgJdVBPw3bRzEXfz4zE+3Mb7E siMfVoXWWodlR0t3pauEqMbP00Eip1aHpjxnStUhhxgRdKGjyA3aXlFxBAz1vZHcMuMA m5E1NJYvhPjMgUCHH4GiKGgq6VA78vekdVXNjKr6ZygX9TFX1RqCpqbP4SFkmjh6Xkvc B3TCKzKD8O1zFPJyie5RwxVZlDGABUbEm9PvJcxvuhDD458AZvg2erJ16Df+Xy0sNgO0 C14pRRGY09e17p+xh4TlLUzHU2br53pDHtl7Fq6Q5lIn3ZXEuIuO7gwCoyAovTkd8Noj NCWA== X-Gm-Message-State: ANoB5pnrJVjHfuhfZha5VmfMndqjgL/6dPLV//s+tvUAReEs735c8Cch 5MICqAAx9j5aRNuUExUJZz3ueYgpX8KeBP2FbH4bash0SUPw1JAsp1wv3rIZiU3QQwFEzN2DjBl JtDNxq005oV7XkOKtyw== X-Received: by 2002:ac8:5490:0:b0:3a5:485e:7cc1 with SMTP id h16-20020ac85490000000b003a5485e7cc1mr4592080qtq.64.1670540204136; Thu, 08 Dec 2022 14:56:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ziyJkkOD3AtR03NNo3VYH/21QCEfJseS3jR1eHQQkq72CLsvse8kJUwQY0nqHqrKu2z9Nlw== X-Received: by 2002:ac8:5490:0:b0:3a5:485e:7cc1 with SMTP id h16-20020ac85490000000b003a5485e7cc1mr4592068qtq.64.1670540203885; Thu, 08 Dec 2022 14:56:43 -0800 (PST) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id s18-20020a05620a29d200b006f9ddaaf01esm21006448qkp.102.2022.12.08.14.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 14:56:43 -0800 (PST) Date: Thu, 8 Dec 2022 17:56:41 -0500 To: Jakub Jelinek Cc: Florian Weimer , Marek Polacek via Gcc-patches Subject: [PATCH v3] docs: Suggest options to improve ASAN stack traces Message-ID: References: <20221207203409.104322-1-polacek@redhat.com> <87fsdqjr15.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Thu, Dec 08, 2022 at 04:00:15PM +0100, Jakub Jelinek wrote: > On Thu, Dec 08, 2022 at 09:34:34AM -0500, Marek Polacek wrote: > > I got a complaint that while Clang docs suggest options that improve > > the quality of the backtraces ASAN prints (cf. > > ), our docs > > don't say anything to that effect. This patch amends that with a new > > paragraph. (It deliberately doesn't mention -fno-omit-frame-pointer.) > > > > gcc/ChangeLog: > > > > * doc/invoke.texi (-fsanitize=address): Suggest options to improve > > stack traces. > > --- > > gcc/doc/invoke.texi | 9 +++++++++ > > 1 file changed, 9 insertions(+) > > > > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > > index 726392409b6..1641efecf18 100644 > > --- a/gcc/doc/invoke.texi > > +++ b/gcc/doc/invoke.texi > > @@ -16510,6 +16510,15 @@ The option cannot be combined with @option{-fsanitize=thread} or > > @option{-fsanitize=hwaddress}. Note that the only target > > @option{-fsanitize=hwaddress} is currently supported on is AArch64. > > > > +To get more accurate stack traces, it is possible to use options such as > > +@option{-O} (which, for instance, prevents most function inlining), > > Still not sure about this part. For one, I wonder if we shouldn't > recommend -O0, -O1 or -Og instead of just one of them, and I'm also not sure > how much function inlining is prevented with -O1. Right, that's why I put "most" in there. But I think we should mention -O0 and -Og as well. > always_inline functions are certainly inlined even at -O0 or -Og (at least > when called directly), -O1 adds > { OPT_LEVELS_1_PLUS_NOT_DEBUG, OPT_finline_functions_called_once, NULL, 1 }, > to that, -O2 adds > { OPT_LEVELS_2_PLUS, OPT_findirect_inlining, NULL, 1 }, > { OPT_LEVELS_2_PLUS, OPT_finline_small_functions, NULL, 1 }, > { OPT_LEVELS_2_PLUS, OPT_fpartial_inlining, NULL, 1 }, > { OPT_LEVELS_2_PLUS, OPT_finline_functions, NULL, 1 }, > and -O3 further bumps some parameters: > { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_auto_, NULL, 30 }, > { OPT_LEVELS_3_PLUS, OPT__param_early_inlining_insns_, NULL, 14 }, > { OPT_LEVELS_3_PLUS, OPT__param_inline_heuristics_hint_percent_, NULL, 600 }, > { OPT_LEVELS_3_PLUS, OPT__param_inline_min_speedup_, NULL, 15 }, > { OPT_LEVELS_3_PLUS, OPT__param_max_inline_insns_single_, NULL, 200 }, > > > +@option{-fno-optimize-sibling-calls} (which prevents optimizing sibling > > -fno-optimize-sibling-calls is the default for -O0/-O1/-Og; dunno if we > want to reiterate it. Can't hurt. Here's an updated patch. -- >8 -- I got a complaint that while Clang docs suggest options that improve the quality of the backtraces ASAN prints (cf. ), our docs don't say anything to that effect. This patch amends that with a new paragraph. (It deliberately doesn't mention -fno-omit-frame-pointer.) gcc/ChangeLog: * doc/invoke.texi (-fsanitize=address): Suggest options to improve stack traces. --- gcc/doc/invoke.texi | 10 ++++++++++ 1 file changed, 10 insertions(+) base-commit: 3a9f6d5a8ee490adf9a18f93feaf86542642be7d diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 726392409b6..3f2512ce16a 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -16510,6 +16510,16 @@ The option cannot be combined with @option{-fsanitize=thread} or @option{-fsanitize=hwaddress}. Note that the only target @option{-fsanitize=hwaddress} is currently supported on is AArch64. +To get more accurate stack traces, it is possible to use options such as +@option{-O0}, @option{-O1}, or @option{-Og} (which, for instance, prevent +most function inlining), @option{-fno-optimize-sibling-calls} (which prevents +optimizing sibling and tail recursive calls; this option is implicit for +@option{-O0}, @option{-O1}, or @option{-Og}), or @option{-fno-ipa-icf} (which +disables Identical Code Folding for functions). Since multiple runs of the +program may yield backtraces with different addresses due to ASLR (Address +Space Layout Randomization), it may be desirable to turn ASLR off. On Linux, +this can be achieved with @samp{setarch `uname -m` -R ./prog}. + @item -fsanitize=kernel-address @opindex fsanitize=kernel-address Enable AddressSanitizer for Linux kernel.