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

Jan Beulich jbeulich@suse.com
Tue Jan 13 07:35:33 GMT 2026


On 13.01.2026 00:34, H.J. Lu wrote:
> On Mon, Jan 12, 2026 at 6:52 PM Jan Beulich <jbeulich@suse.com> wrote:
>> On 11.01.2026 01:57, H.J. Lu wrote:
>>> On Sat, Jan 10, 2026 at 5:35 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Sat, Jan 10, 2026, 5:28 PM Jan Beulich <jbeulich@suse.com> wrote:
>>>>> On 10.01.2026 04:50, H.J. Lu wrote:
>>>>>> .note.GNU-stack section doesn't conform to SHT_NOTE spec:
>>>>>>
>>>>>> https://gabi.xinuos.com/v42/elf/07-pheader.html#note-sections
>>>>>>
>>>>>> since it is an empty section with the corresponding fields.  It maps to
>>>>>> PT_GNU_STACK segment, not PT_NOTE segment.  It is inappropriate to set
>>>>>> its type to SHT_NOTE.
>>>>>
>>>>> Then it's also inappropriate to name it .note.*, as that way it will be
>>>>> covered by .note.* as commonly used
>>>>
>>>>
>>>> This was an overnight when it was introduced.
>>>> On the other hand, linker should check
>>>> section type, not section name, except
>>>> for special sections.
>>>>
>>>>> in linker scripts. I really wonder why
>>>>> no-one has cared to respond to the patch when it was still uncommitted ...
>>>
>>> Here is the v2 patch to add more tests.
>>
>> I continue to disagree; see my comments in the bug. But of course I'm happy
>> to learn ... Imo we should go with your originally propose patch plus the
>> correction of the table entry in bfd/elf.c, requiring as a prereq the patch
>> below (both yet to be properly tested for a wide range of targets).
> 
> 1. The meaning of the SHT_NOTE section is determined by the contents of
> the section, not by section names.

The meaning of .note.GNU-stack has been tied to its name, no matter what
the section type (and it was never meant to have any contents).

> 2. The sh_flags field of the SHT_NOTE section has no impact on the meaning of
> the section.

Generally not, but whichever type it has - .note.GNU-stack is special.

Also, what wording in the spec do you derive this from?

> 3. SHT_NOTE sections are mapped to the PT_NOTE segment.

Again, whichever type it has - .note.GNU-stack has been special.

> .note.GNU-stack section is none of the above.  From day one, .note.GNU-stack
> has been a SHT_PROGBITS section.   It is simply wrong to set it to SHT_NOTE.

Well, to me it simply was wrong (from day one) to make it SHT_PROGBITS
(or to name it the way it is named).

Furthermore, if we were to stick to SHT_PROGBITS (i.e. my change to be
reverted), what would be your alternative proposal to address the
linker script issue (which is what all of this started from)? There is
(imo clumsy / bogus; should never have been there if the spec had been
properly followed) handling of SHT_NOTE sections based on their
alignment. Are you envisioning something vaguely along those lines,
then effectively overriding what the linker script says?

Cc-ing Cary, who iirc used to maintain the ELF spec. Perhaps there are
other people to possibly seek any opinion from?

Also Cc-ing Fangrui, in an attempt to get llvm's perspective.

>> readelf: don't (silently) fail on empty SHT_NOTE sections
>>
>> Them simply containing no entries is not an error. Such sections simply
>> have nothing to dump. (Exiting with non-zero status but no error message
>> isn't quite appropriate anyway.)
> 
> 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.

Jan


More information about the Binutils mailing list