[PATCH] ELF: give .note.GNU-stack proper section type

Jan Beulich jbeulich@suse.com
Mon Dec 15 10:40:54 GMT 2025


Like all .note and .note.* sections it should be SHT_NOTE, not
SHT_PROGBITS.
---
While the patches are largely independent (except for the underlying
topic), likely "ld/ELF: suppress note section rearrangement for
relocatable linking" wants committing ahead of the one here in order to
reduce the risk of (perceived) regressions.

The need to make the setting conditional in ldelf_after_open() raises an
interesting question: As per documentation -z {no,}execstack overrides any
setting in the incoming object file(s). This is contrary to
1) bfd_make_section_with_flags() failing when the requested section
   already exists,
2) all input sections' flags being folded together, i.e. fiddling with
   just the first input's settings isn't sufficient.
Is documentation simply wrong? And even if it is, shouldn't we at least
emit a warning if the command line option in fact isn't being honored?

--- a/gas/as.c
+++ b/gas/as.c
@@ -1505,7 +1505,7 @@ main (int argc, char ** argv)
       gnustack = subseg_new (".note.GNU-stack", 0);
       bfd_set_section_flags (gnustack,
 			     SEC_READONLY | (flag_execstack ? SEC_CODE : 0));
-
+      elf_section_type (gnustack) = SHT_NOTE;
     }
 #endif
 
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -1327,8 +1327,10 @@ ldelf_after_open (int use_libpath, int n
 	     effect.  Instead we create a .note.GNU-stack section in much the
 	     same way as the assembler does with its --[no]execstack option.  */
 	  flagword flags = SEC_READONLY | (link_info.execstack ? SEC_CODE : 0);
-	  (void) bfd_make_section_with_flags (link_info.input_bfds,
-					      ".note.GNU-stack", flags);
+	  s = bfd_make_section_with_flags (link_info.input_bfds,
+					   ".note.GNU-stack", flags);
+	  if (s)
+	    elf_section_type (s) = SHT_NOTE;
 	}
       return;
     }


More information about the Binutils mailing list