2026-09-10
The asker is hand-crafting a minimal ELF64 executable in NASM, laying out the ELF header and a single PT_LOAD program header that maps a tiny amount of code at virtual address 0x1000. Producing an ELF that runs is a classic golf exercise (see a.out minimizers by Brian Raiter and others), but the Linux kernel loader has become significantly stricter over the years, and small deviations that were once tolerated now yield opaque failures like ENOEXEC, SIGKILL before _start, or a bare "cannot execute" message.
What makes it interesting is that the ELF spec permits a lot, but fs/binfmt_elf.c in the kernel enforces additional invariants that aren't obvious from reading the spec. A few common culprits for "single small segment" failures:
p_vaddr % p_align == p_offset % p_align. If your file offset for the segment isn't congruent to 0x1000 modulo the page size, the kernel refuses to mmap it. Many hand-golfed ELFs place the segment at file offset 0 and virtual address 0x1000 — that only works if p_align is 0x1000 and both offsets share a page-remainder of zero, which means the ELF header itself must live inside the mapped segment.PT_LOAD covering the ELF header: Related to the above — the de facto convention is that the first PT_LOAD starts at file offset 0 so the ELF header and program headers are mapped along with code.vm.mmap_min_addr is usually 65536. A segment at va = 0x1000 is below that threshold and will fail to map for an unprivileged process.p_filesz < sizeof(headers): If p_memsz or p_filesz underflows what you're actually reading, the loader silently bails.Diagnostic approach:
strace -f ./tiny 2>&1 | head — look for the execve return value. EINVAL almost always points to alignment; EACCES to mmap_min_addr.dmesg after the failed exec often prints "requested but not required" or "bad ELF" messages from load_elf_binary.readelf -l and check that VirtAddr and Offset match modulo Align.Without the actual error message the answer is speculative, but 9 times out of 10 for this pattern it's the p_offset ≡ p_vaddr (mod p_align) constraint biting.
load_elf_binary silently enforces additional invariants (page-congruent offsets, mmap_min_addr) that turn hand-crafted minimal ELFs into a puzzle of undocumented kernel quirks.
