why are there 2 ELF note formats and one of them is undocumented?

2026-07-01

Stack Overflow: View Question

Tags: linux, elf, dataformat

Score: -3 | Views: 66

The asker is parsing PT_NOTE segments and SHT_NOTE sections in real ELF binaries and finds that the format documented in elf(5) — a 12-byte header (namesz, descsz, type) followed by name and desc, each padded to a 4-byte boundary — doesn't match everything they see in the wild. They're asking why there appears to be a second, undocumented layout.

Why this is a real trap, not a mistake. The confusion isn't imaginary: the ELF gABI, glibc, binutils, and the Linux kernel have historically disagreed on the alignment rule for 64-bit notes. Three positions coexist in the ecosystem:

Approach. Trust the section/segment's sh_addralign/p_align field — that's the alignment the producer intended, and modern binutils sets it correctly (usually 4, occasionally 8). Then:

  1. Read the 12-byte header at the current offset.
  2. Advance namesz bytes for the name, then align to sh_addralign.
  3. Advance descsz bytes for the desc, then align again.
  4. Repeat until the segment/section ends.

For the well-known GNU notes (NT_GNU_BUILD_ID, NT_GNU_PROPERTY_TYPE_0, NT_GNU_ABI_TAG), and for core-dump notes (NT_PRSTATUS, NT_FILE, NT_PRPSINFO), the desc payload has its own structured layout — that's likely the "second format" the asker is seeing. It isn't a second note format; it's a typed payload inside the note.

Gotchas. The Linux kernel's fs/binfmt_elf.c historically padded to 4 bytes for core notes regardless of ELF class, so a strictly gABI-conformant parser will misread real Linux core files. Cross-check against readelf -n, which handles both conventions. And watch for NT_GNU_PROPERTY_TYPE_0: its outer alignment matches the section's, but its inner property array is aligned to sizeof(void*), which really does differ between ELF32 and ELF64.

The challenge: The "undocumented second format" is a mix of a genuine gABI-vs-Linux alignment schism and typed payload structures nested inside notes — three different layers of "format" that look like one to a byte-level parser.

All newsletters