[RFC] Disabling -z execstack per emulation

Jan Beulich jbeulich@suse.com
Mon Mar 30 06:14:16 GMT 2026


On 27.03.2026 18:04, Michal Lach wrote:
> Hi,
> 
> I was wondering about having an emulation parameter for elf.am
> based emulations to disable usage of -z execstack.
> 
> The rationale is that there are systems that do not allow for creation
> of executable stack mappings, such as OpenBSD,

And that also never was possible there?

> on which warnings about
> executable stacks will appear regardless; that is a bit misleading.
> 
> I'd like to ask for any thoughts on the matter described.
> 
> I'm attaching a patch with a draft of how I have this implemented
> right now.

That isn't quite enough, is it? You would also want to suppress ELF
note generation as well as recognition, I guess. Diagnostics emitted
when finding an execstack note (from an old or "foreign" toolchain)
may also want to have alternative wording there.

Jan

> ---
> diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
> index 37bdfff051c..1fd03b9b859 100644
> --- a/ld/emultempl/elf.em
> +++ b/ld/emultempl/elf.em
> @@ -900,7 +900,7 @@ gld${EMULATION_NAME}_handle_option (int optc)
>        break;
>      case OPTION_NO_ROSEGMENT:
>        link_info.one_rosegment = false;
> -      break;
> +      break;
>  EOF
> 
>  if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
> @@ -998,11 +998,25 @@ fragment <<EOF
>  	       'default'.   */
>  	    link_info.stacksize = -1;
>  	}
> +EOF
> +if test x"$DISALLOW_EXECSTACK" = xyes; then
> +fragment <<EOF
> +      else if (strcmp (optarg, "execstack") == 0)
> +	{
> +	  einfo (_("%P: -z execstack is disabled on this target"
> +                   ", treating this flag as a no-op\n"));
> +	}
> +EOF
> +else
> +fragment <<EOF
>        else if (strcmp (optarg, "execstack") == 0)
>  	{
>  	  link_info.execstack = true;
>  	  link_info.noexecstack = false;
>  	}
> +EOF
> +fi
> +fragment <<EOF
>        else if (strcmp (optarg, "noexecstack") == 0)
>  	{
>  	  link_info.noexecstack = true;
> --
> 2.53.0
> 
> --
>  - Michal Lach



More information about the Binutils mailing list