Skip to content

Commit ebf9c89

Browse files
committed
rtld: honor FreeBSD no-init notes
Accept FreeBSD note vendor sizing when parsing ELF notes so FreeBSD binaries carrying NT_FREEBSD_NOINIT_TAG set crt_no_init. This lets rtld run the main executable init arrays instead of leaving C++ globals uninitialized. AI-Assisted-by: Codex <noreply@openai.com> Signed-off-by: Lucas Holt <luke@foolishgames.com>
1 parent 07fa6c3 commit ebf9c89

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

libexec/rtld-elf/rtld.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,8 @@ digest_notes(Obj_Entry *obj, Elf_Addr note_start, Elf_Addr note_end)
17651765
note = (const Elf_Note *)((const char *)(note + 1) +
17661766
roundup2(note->n_namesz, sizeof(Elf32_Addr)) +
17671767
roundup2(note->n_descsz, sizeof(Elf32_Addr)))) {
1768-
if (note->n_namesz != sizeof(NOTE_MIDNIGHTBSD_VENDOR) ||
1768+
if ((note->n_namesz != sizeof(NOTE_MIDNIGHTBSD_VENDOR) &&
1769+
note->n_namesz != sizeof(NOTE_FREEBSD_VENDOR)) ||
17691770
note->n_descsz != sizeof(int32_t))
17701771
continue;
17711772
if (note->n_type != NT_FREEBSD_ABI_TAG &&
@@ -1797,7 +1798,7 @@ digest_notes(Obj_Entry *obj, Elf_Addr note_start, Elf_Addr note_end)
17971798
dbg("note fctl0 %#x", obj->fctl0);
17981799
break;
17991800
case NT_MIDNIGHTBSD_NOINIT_TAG:
1800-
/* MidnightBSD 'crt does not call init' note */
1801+
/* FreeBSD/MidnightBSD 'crt does not call init' note */
18011802
obj->crt_no_init = true;
18021803
dbg("note crt_no_init");
18031804
break;

0 commit comments

Comments
 (0)