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

H.J. Lu hjl.tools@gmail.com
Sun Jan 11 00:57:56 GMT 2026


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

Here is the v2 patch to add more tests.


-- 
H.J.

.note.GNU-stack section was introduced with the SHT_PROGBITS type.
Although its name starts with ".note.", but it doesn't conform to
SHT_NOTE specification:

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

since it is an empty section without the corresponding SHT_NOTE section
fields and maps to PT_GNU_STACK segment, not PT_NOTE segment.  Linkers
normally check section types when laying out the output, but they also
check section names for special sections, like .note.GNU-stack.  It is
inappropriate to set its type to SHT_NOTE.

Revert

commit c8db2c887b4129732341c4a1a51cdcd3191db271
Author: Jan Beulich <jbeulich@suse.com>
Date:   Fri Jan 9 08:39:38 2026 +0100

    ELF: give .note.GNU-stack proper section type

and add tests to verify that .note.GNU-stack section has the SHT_PROGBITS
type.

gas/

PR ld/33780
* as.c (main): Don't set .note.GNU-stack section type to SHT_NOTE.
* testsuite/gas/elf/elf.exp: Run section-GNU-stack.
* testsuite/gas/elf/section-GNU-stack.d: New file.
* testsuite/gas/elf/section-GNU-stack.s: Likewise.

ld/

PR ld/33780
* ldelf.c (ldelf_after_open): Don't set .note.GNU-stack section
type to SHT_NOTE.
* testsuite/ld-elf/pr33780a.d: New file.
* testsuite/ld-elf/pr33780b.d: Likewise.
* testsuite/ld-elf/pr33780c.d: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2-0001-elf-Don-t-set-.note.GNU-stack-type-to-SHT_NOTE.patch
Type: text/x-patch
Size: 6006 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20260111/dc5c95a4/attachment.bin>


More information about the Binutils mailing list