[RFC] Disabling -z execstack per emulation

Message ID 87a4vtdx13.fsf@phoenix-rtos.com
State New
Headers
Series [RFC] Disabling -z execstack per emulation |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Michal Lach March 27, 2026, 5:04 p.m. UTC
  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, 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.

---
--
2.53.0

--
 - Michal Lach
  

Comments

Jan Beulich March 30, 2026, 6:14 a.m. UTC | #1
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
  
Michal Lach March 30, 2026, 11:06 a.m. UTC | #2
Jan Beulich <jbeulich@suse.com> writes:

Resending with binutils@ CC, sorry, did not reply-all.

> 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?

It was, 24 years ago, from 1.19 executable stacks are disabled by
default IIUC.

>> 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.

This would have to be paired with disabling execstack warnings
per-target in configure.tgt scripts, but it is already possible,
unlike what I described.

--
 - Michal Lach
  
Michal Lach March 31, 2026, 3:10 p.m. UTC | #3
Okay, so if there are no NAK's on this, I'll submit this patch tomorrow
and see how it does.

Michal Lach <michal.lach@phoenix-rtos.com> writes:
> Jan Beulich <jbeulich@suse.com> writes:
>
> Resending with binutils@ CC, sorry, did not reply-all.
>
>> 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?
>
> It was, 24 years ago, from 1.19 executable stacks are disabled by
> default IIUC.
>
>>> 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.
>
> This would have to be paired with disabling execstack warnings
> per-target in configure.tgt scripts, but it is already possible,
> unlike what I described.

--
 - Michal Lach
  

Patch

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;