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;
