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

Jan Beulich jbeulich@suse.com
Mon Jan 19 16:02:47 GMT 2026


On 15.01.2026 23:56, H.J. Lu wrote:
> On Thu, Jan 15, 2026 at 8:27 PM Jan Beulich <jbeulich@suse.com> wrote:
>>
>> From: H.J. Lu <hjl.tools@gmail.com>
>>
>> PR ld/33780
>> Correct the section's special_sections[] entry as well, and further
>> constrain ld's setting of the section type.
>> ---
>> Requires either the patch at the bottom of
>> https://sourceware.org/pipermail/binutils/2026-January/147115.html
>> or (afaict, didn't check myself)
>> https://sourceware.org/pipermail/binutils/2026-January/147275.html
>> as a prereq.
>>
>> I can't help the impression that the table entry in bfd/elf.c can in fact
>> simply be deleted, as the subsequent one would now take care of all of the
>> .note.* sections.
>>
>> --- a/bfd/elf.c
>> +++ b/bfd/elf.c
>> @@ -3139,7 +3139,7 @@ static const struct bfd_elf_special_sect
>>  static const struct bfd_elf_special_section special_sections_n[] =
>>  {
>>    { STRING_COMMA_LEN (".noinit"),       -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
>> -  { STRING_COMMA_LEN (".note.GNU-stack"), 0, SHT_PROGBITS, 0 },
>> +  { STRING_COMMA_LEN (".note.GNU-stack"), 0, SHT_NOTE,     0 },
>>    { STRING_COMMA_LEN (".note"),                 -1, SHT_NOTE,     0 },
>>    { NULL,                   0,           0, 0,            0 }
>>  };
>> --- a/ld/ldelf.c
>> +++ b/ld/ldelf.c
>> @@ -1329,7 +1329,7 @@ ldelf_after_open (int use_libpath, int n
>>           flagword flags = SEC_READONLY | (link_info.execstack ? SEC_CODE : 0);
>>           s = bfd_make_section_with_flags (link_info.input_bfds,
>>                                            ".note.GNU-stack", flags);
>> -         if (s)
>> +         if (s && bfd_get_flavour (s->owner) == bfd_target_elf_flavour)
>>             elf_section_type (s) = SHT_NOTE;
>>         }
>>        return;
> 
> 1.  Please coordinate with GCC developers to change .note.GNU-stack to SHT_NOTE.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123698

> 2.  Please add a testcase to show why it should be changed to SHT_NOTE.

https://sourceware.org/pipermail/binutils/2026-January/147528.html

> 3.  Please add a testcase for PR ld/33780.

I'm very inclined to leave that to you (as the [original] patch author) or
somebody else. I simply don't think that each and every bugfix needs to be
accompanied by a new testcase. In the long run that simple won't scale.

Jan


More information about the Binutils mailing list