From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 4FD3D3835421 for ; Fri, 20 May 2022 05:54:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FD3D3835421 Received: by mail-pl1-x62a.google.com with SMTP id q18so6532008pln.12 for ; Thu, 19 May 2022 22:54:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=zQeUuEI7tOGh8nKlgxYvf3JgG50GWxfjQSB4cWZOU3k=; b=w1Uyvx1hCGH0Co37KHwyUw2LVwS4P3ubbg340shQ17QsnepCDvs0yRJ+8Ht4fAUey/ paksqtJLCrdQln1afNRpnCrBUvRG2fnMP28Ct4OQpeARhFoB0VBLb4/p2A7LlO6S/N22 MVm+5+U04NAx3pnYgyJiIKH+uzjlMVyKtNj8Q4qBgP2hT4dirsfYzJefxmWVzoMNpuM2 +KF0cesghP6iZ9Tjs4URsaBBDYRpFb600/S249+Qoq0rxxaJ/i6rhjYLobojINyGCrUb HQbxfgtxIv6xzjfTucwnUok0Ucw4GWahi+/zbQt3hDoglI2AoFvLLN0Jc68ed7kJu4DF groQ== X-Gm-Message-State: AOAM531krn/fCB2IKKJ6zZAZlXvbL00zwgLnOXVEhRRVPm0mfucDVic1 bcJamjlhxAbpVbU+r1YzTXx5KqUj744= X-Google-Smtp-Source: ABdhPJy0DDl+Yns18ezGGXbe3UjK4kOifCpBgq9CaE69zMwmH6/Z5hZzLFahnYMuoeES2GkJ7qmOIw== X-Received: by 2002:a17:902:ccc1:b0:15a:24df:a7cc with SMTP id z1-20020a170902ccc100b0015a24dfa7ccmr8321325ple.42.1653026066150; Thu, 19 May 2022 22:54:26 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id x16-20020a170902821000b0016188a3efb9sm4687759pln.89.2022.05.19.22.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 22:54:25 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 62A2611400DD; Fri, 20 May 2022 15:24:22 +0930 (ACST) Date: Fri, 20 May 2022 15:24:22 +0930 From: Alan Modra To: =?iso-8859-1?Q?Cl=E9ment?= Chigot Cc: binutils@sourceware.org Subject: Re: [PATCH] ld: harmonize the value of --enable-warn-execstack=no option Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-3037.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2022 05:54:31 -0000 On Tue, May 17, 2022 at 02:51:40PM +0200, Clément Chigot via Binutils wrote: > This patch sets the configure value of warn-execstack to 2 when > disabled as expected by bfd. > > ld/ChangeLog: > > * configure.ac: Update ac_default_ld_warn_execstack value when > --enable-warn-execstack=no is given. > * configure: Regenerate > * testsuite/ld-elf/elf.exp: Add --warn-execstack to ensure > the warning is always shown. Thanks for the patch, but I'm suspicious of the testsuite change and I think we need a little more here. I agree a change is needed to make ld/bfd values consistent but I'm going to jump the other way, changing link_info.warn_execstack. Making it consistent that way is nicer in that the flag becomes an "extended" boolean, ie. 0 => don't warn, 1 => always warn, 2 or 3 => conditional warning depending on link_info.execstack. Testing still in progress, I'll commit this shortly if I don't discover the need for a testsuite change. bfd/ * elflink.c (bfd_elf_size_dynamic_sections): Adjust warn_execstack test. include/ * bfdlink.h (warn_execstack): Swap 0 and 2 meaning. ld/ * configure.ac (DEFAULT_LD_WARN_EXECSTACK): Use values of 0, 1, 2 consistent with link_info.warn_execstack. * ld.texi: Typo fixes. * lexsup.c (parse_args): Adjust setting of link_info.warn_execstack. (elf_static_list_options): Adjust help message conditions. * configure: Regenerate. diff --git a/bfd/elflink.c b/bfd/elflink.c index 4d6fe663f68..96eb36aa5bf 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -7179,7 +7179,7 @@ warning: enabling an executable stack because of -z execstack command line optio { if (exec) { - if (info->warn_execstack != 2) + if (info->warn_execstack != 0) { /* PR 29072: Because an executable stack is a serious security risk, make sure that the user knows that it is diff --git a/include/bfdlink.h b/include/bfdlink.h index 27a8e11cc22..09a3ec01685 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -493,12 +493,9 @@ struct bfd_link_info unsigned int noexecstack: 1; /* Tri-state variable: - 0 => warn if the linker is creating an executable stack, but - execstack (above) is 0. - 1 => warn if the linker is creating an executable stack; ignores - the value of execstack. - 2 => do not warn. - 3 => not used. */ + 0 => do not warn when creating an executable stack. + 1 => always warn when creating an executable stack. + >1 => warn when creating an executable stack if execstack is 0. */ unsigned int warn_execstack: 2; /* TRUE if warnings should not be generated for TLS segments with eXecute diff --git a/ld/configure b/ld/configure index b4b0ce14ed9..16db825d5ab 100755 --- a/ld/configure +++ b/ld/configure @@ -15438,12 +15438,14 @@ fi -ac_default_ld_warn_execstack=unset +# By default warn when an executable stack is created due to object files +# requesting such, not when the user specifies -z execstack. +ac_default_ld_warn_execstack=2 # Check whether --enable-warn-execstack was given. if test "${enable_warn_execstack+set}" = set; then : enableval=$enable_warn_execstack; case "${enableval}" in yes) ac_default_ld_warn_execstack=1 ;; - no) ac_default_ld_warn_execstack=-1 ;; + no) ac_default_ld_warn_execstack=0 ;; esac fi @@ -16997,9 +16999,6 @@ _ACEOF -if test "${ac_default_ld_warn_execstack}" = unset; then - ac_default_ld_warn_execstack=0 -fi cat >>confdefs.h <<_ACEOF #define DEFAULT_LD_WARN_EXECSTACK $ac_default_ld_warn_execstack diff --git a/ld/configure.ac b/ld/configure.ac index 0b29e810dde..01121480c6d 100644 --- a/ld/configure.ac +++ b/ld/configure.ac @@ -204,13 +204,15 @@ AC_ARG_ENABLE(separate-code, esac]) -ac_default_ld_warn_execstack=unset +# By default warn when an executable stack is created due to object files +# requesting such, not when the user specifies -z execstack. +ac_default_ld_warn_execstack=2 AC_ARG_ENABLE(warn-execstack, AS_HELP_STRING([--enable-warn-execstack], [enable warnings when creating an executable stack]), [case "${enableval}" in yes) ac_default_ld_warn_execstack=1 ;; - no) ac_default_ld_warn_execstack=-1 ;; + no) ac_default_ld_warn_execstack=0 ;; esac]) ac_default_ld_warn_rwx_segments=unset @@ -531,9 +533,6 @@ AC_DEFINE_UNQUOTED(DEFAULT_LD_Z_SEPARATE_CODE, [Define to 1 if you want to enable -z separate-code in ELF linker by default.]) -if test "${ac_default_ld_warn_execstack}" = unset; then - ac_default_ld_warn_execstack=0 -fi AC_DEFINE_UNQUOTED(DEFAULT_LD_WARN_EXECSTACK, $ac_default_ld_warn_execstack, [Define to 1 if you want to enable --warn-execstack in ELF linker by default.]) diff --git a/ld/ld.texi b/ld/ld.texi index 8cad8478140..a2b162ce5b5 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -2654,7 +2654,7 @@ object file formats. For formats like COFF or ELF, the linker can not detect the use of global constructors. @kindex --warn-execstack -@cindex warnings, on exectuable stack +@cindex warnings, on executable stack @cindex executable stack, warnings on @item --warn-execstack @itemx --no-warn-execstack @@ -2667,7 +2667,7 @@ line option has been used, but this behaviour can be overridden by the On the other hand the linker will normally warn if the stack is made executable because one or more of the input files need an execuable stack and neither of the @command{-z execstack} or @command{-z -noexecstack} comman line options have been specified. This warning +noexecstack} command line options have been specified. This warning can be disabled via the @command{--no-warn-execstack} option. Note: ELF format input files specify that they need an executable diff --git a/ld/lexsup.c b/ld/lexsup.c index 78190472907..82c459adb51 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -927,7 +927,7 @@ parse_args (unsigned argc, char **argv) link_info.warn_execstack = 1; break; case OPTION_NO_WARN_EXECSTACK: - link_info.warn_execstack = 2; + link_info.warn_execstack = 0; break; case OPTION_WARN_RWX_SEGMENTS: link_info.no_warn_rwx_segments = 0; @@ -2169,14 +2169,14 @@ elf_static_list_options (FILE *file) -z execstack Mark executable as requiring executable stack\n")); fprintf (file, _("\ -z noexecstack Mark executable as not requiring executable stack\n")); -#if DEFAULT_LD_WARN_EXECSTACK > 0 +#if DEFAULT_LD_WARN_EXECSTACK == 1 fprintf (file, _("\ --warn-execstack Generate a warning if the stack is executable (default)\n")); #else fprintf (file, _("\ --warn-execstack Generate a warning if the stack is executable\n")); #endif -#if DEFAULT_LD_WARN_EXECSTACK < 0 +#if DEFAULT_LD_WARN_EXECSTACK == 0 fprintf (file, _("\ --no-warn-execstack Do not generate a warning if the stack is executable (default)\n")); #else -- Alan Modra Australia Development Lab, IBM