[RFC] Disabling -z execstack per emulation

Michal Lach michal.lach@phoenix-rtos.com
Fri Mar 27 17:04:08 GMT 2026


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.

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