[PATCH v2] elf: Don't set .note.GNU-stack type to SHT_NOTE

Michael Matz matz@suse.de
Tue Jan 13 16:07:15 GMT 2026


Hello,

On Tue, 13 Jan 2026, Jan Beulich wrote:

> > of such type (irrespective of name) are to conform to a certain format of 
> > contents.  In particular it _must_ contain a header, which .note.GNU-stack 
> > doesn't.
> 
> Sam question to you then: Where exactly is this said in the spec? What am
> I overlooking?

https://gabi.xinuos.com/elf/07-pheader.html#note-sections

> > First match wins, hence .note.GNU-stack must be special cased before a 
> > .note.* catchall, if anything needs to be done at all.
> 
> Well, something should be done imo. People simply using *(.note .note.*)
> in their linker scripts is legitimate, I'm inclined to say.

With the historic accident that exists, it isn't.  I agree that it should 
be, but it isn't.

> Those scripts may pre-date the introduction of .note.GNU-stack.

That may be, but it's increasingly unlikely.  .note.GNU-stack with the 
current warts was introduced around 2003.

> And that 
> "something" better wouldn't be "everyone needs to edit their linker 
> scripts".

I think "everyone" is an exaggeration.  Even "many" would be.  It's 
certainly fewer than those affected by suddenly generating invalid 
SHT_NOTE sections.

Didn't we go through all of this last year or two years ago?  I have a 
big dejavu that someone tried to make .note.GNU-stack SHT_NOTE before with 
exactly the same discussions and outcome that we have now here.

> >>> Readelf should at least issue a warning for an empty SHT_NOTE which
> >>> indicates a user error.
> >>
> >> I disagree; there's no "user error" there.
> > 
> > An empty SHT_NOTE section would be an error, if such was generated by a 
> > user it would indeed be a user error.  SHT_NOTE section must contain 12 
> > bytes at least: namesz, descsz and type, each 32bits.
> 
> See above - I'd be grateful if my misreading of the spec was corrected,
> as that was (naturally) part of the foundation of the original patch.
> 
> (As an aside, the spec I'm looking at also [still] mandates three 64-bit
> items for ELF64. I have no idea whether that was formally relaxed
> anywhere in the meantime.)

So you did find the section that mandates the header of 
SHT_NOTE sections, yet you are still convinved that a zero-length SHT_NOTE 
section is okay?  I'm confused.

(I won't go into a reiteration of all the ELFDATA64 vs ELFDATA32 vs 
SHT_NOTE sections and the related questions about how those sections 
should or should not be aligned.  For the discussion at hand it's enough 
to agree that there must be _some_ header in SHT_NOTE sections and that 
therefore zero-sized SHT_NOTE sections are invalid.)


Ciao,
Michael.


More information about the Binutils mailing list