ELF32 Cross-ABI Auditing, VFP Hard-Float Traps & Missing PT_INTERP ENOENT

Inspect raw Elf32_Ehdr fields (ELFCLASS32, EM_ARM=40, EF_ARM_ABI_FLOAT_HARD=0x400) and trace why a missing /lib/ld-linux-armhf.so.3 makes execve() return ENOENT!

25 minfree previewLinux 6.12C11glibc 2.39→ module 6 lab
What you'll learn
  • Audit 52-byte Elf32_Ehdr headers and e_flags bitmasks (0x05000400 EABI5 hard-float vs 0x05000200 soft-float) before copying binaries to /srv/nfs/rootfs.
  • Diagnose why ./app: No such file or directory (ENOENT) occurs on an existing, executable ARM binary when PT_INTERP is absent from the target rootfs.
  • Verify DT_NEEDED shared-library presence and GLIBC_2.xx version ceilings against the target rootfs sysroot.

The Most Misleading Error Message in Embedded Linux Bring-Up

Picture this rite of passage: you cross-compile hello.c on your workstation, copy hello into /srv/nfs/rootfs/root/, verify ls -l ./hello shows -rwxr-xr-x 1 root root 9824, type ./hello on the ARMv7-A serial console, and the shell prints: -sh: ./hello: not found (or No such file or directory, errno = ENOENT = 2)! Engineers lose hours re-running chmod +x or blaming NFS caching on a file standing right in front of them.

Tracing Linux kernel fs/binfmt_elf.c explains every byte of what happened. First, if you accidentally compiled with host gcc (e_machine = EM_X86_64 = 62), elf_check_arch() rejects the header immediately with -ENOEXEC (Exec format error). Second, if you compiled with arm-linux-gnueabihf-gcc (EM_ARM = 40, EF_ARM_ABI_FLOAT_HARD = 0x400), elf_check_arch() passes, load_elf_binary() reads the PT_INTERP program header (/lib/ld-linux-armhf.so.3), calls open_exec() on that loader path inside your minimal BusyBox rootfs, gets -ENOENT because /lib was left empty, and returns -ENOENT to user space!

fig_m06_l01_a.svg — execve() returns ENOEXEC when e_machine != EM_ARM, and…

Figure 6.1a. execve() returns ENOEXEC when e_machine != EM_ARM, and returns ENOENT when PT_INTERP is missing in rootfs!

mental model: PT_INTERP inside a dynamically linked ELF executable works like a #! /bin/sh shebang line at the top of a script: if /bin/sh itself is missing from the rootfs, the kernel reports No such file or directory even though your script file is right there!

Where it stops working: Unlike text shebangs read as ASCII lines, PT_INTERP is a binary program-header table slice parsed only after fs/binfmt_elf.c validates e_machine (EM_ARM) and ELFCLASS32.

definition (PT_INTERP Program Header): An ELF program-header entry (p_type = 3) in dynamically linked executables storing the NUL-terminated filesystem path of the user-space runtime dynamic linker (such as /lib/ld-linux-armhf.so.3 on 32-bit ARM hard-float Linux) that the kernel maps and transfers initial control to before the application's own _start entry point runs.

ast_m06_l01.svg — Verify EM_ARM(40), e_flags 0x400 (hard-float),…step 1/4
  1. Step 1. Catching EM_X86_64 (62) or soft-float (0x200) on the host takes 5 milliseconds with readelf -h.
  2. Step 2. Note symlink chains: if ld-linux-armhf.so.3 -> ld-2.35.so, BOTH files must exist in rootfs/lib!
  3. Step 3. DT_NEEDED lists direct dependencies only (unlike ldd, it never executes foreign code).
  4. Step 4. Building against the SDK's target sysroot guarantees symbol versions never outrun target libc.so.6.

Figure 6.1b. Verify EM_ARM(40), e_flags 0x400 (hard-float), PT_INTERP in rootfs/lib, and matching sysroot glibc.

Inside the 52-Byte Elf32_Ehdr and VFPv3 Calling Convention

Every 32-bit ARM executable starts with a fixed 52-byte Elf32_Ehdr structure that you can parse directly in C without external libraries: bytes 0..3 hold 0x7F, 'E', 'L', 'F'; byte 4 (EI_CLASS) is 1 (ELFCLASS32); byte 5 (EI_DATA) is 1 (ELFDATA2LSB little-endian); uint16_t e_type at 0x10 is 2 (ET_EXEC) or 3 (ET_DYN PIE); uint16_t e_machine at 0x12 is 40 (EM_ARM); and uint32_t e_flags at 0x24 holds 0x05000400 (EF_ARM_EABI_VER5 | EF_ARM_ABI_FLOAT_HARD).

Why are armel (0x200 soft-float) and armhf (0x400 hard-float) mutually incompatible at the binary interface? Under AAPCS base (soft/softfp), double calc(double a, double b) passes a in integer core registers r0:r1 and b in r2:r3. Under AAPCS-VFP (hard, -mfloat-abi=hard -mfpu=neon-vfpv4 on Cortex-A7), a passes in hardware VFP register d0 and b in d1! If an armhf caller jumped into a softfp libm.so, sin(1.57) would read uninitialized junk from r0:r1 — which is why Debian/Linux assigns them completely separate PT_INTERP paths!

fig_m06_l01_b.svg — Byte offsets 0x00..0x27 of Elf32_Ehdr expose…

Figure 6.1b. Byte offsets 0x00..0x27 of Elf32_Ehdr expose architecture, endianness, EABI version, and VFP float ABI.

Build MistakeElf32_Ehdr / PT_INTERP StateTarget Shell ErrorExact Fix
Compiled with gcc instead of $(CROSS_COMPILE)gccELFCLASS64, e_machine = 62 (EM_X86_64)./app: Exec format error (ENOEXEC)Compile with arm-linux-gnueabihf-gcc (CC=$(CROSS_COMPILE)gcc)
Compiled with arm-linux-gnueabi-gcc (soft)e_flags & 0x200, PT_INTERP = /lib/ld-linux.so.3./app: No such file or directory (ENOENT)Switch to arm-linux-gnueabihf-gcc (-mfloat-abi=hard)
Minimal BusyBox rootfs missing /lib/ld-*.so*PT_INTERP = /lib/ld-linux-armhf.so.3 absent in /srv/nfs/rootfs./app: No such file or directory (ENOENT)Copy toolchain sysroot lib/ld-linux-armhf.so.3 + libc.so.6 (cp -a preserving symlinks!) or link -static
Host cross-gcc (glibc 2.39) vs target (glibc 2.35).gnu.version_r demands GLIBC_2.38libc.so.6: version 'GLIBC_2.38' not foundCompile against the target rootfs SDK --sysroot
learner@ksa: ~/gl-e00/m06-l01
learner@ksa:~/gl-e00/m06-l01$ bat -H 18 -H 38 elf32_armhf_contract.h File: elf32_armhf_contract.h    /* SPDX-License-Identifier: GPL-2.0 */    #ifndef KSA_ELF32_ARMHF_CONTRACT_H    #define KSA_ELF32_ARMHF_CONTRACT_H        #include <stdint.h>        #define KSA_ELFCLASS32              1U    #define KSA_ELFDATA2LSB             1U    #define KSA_ET_REL                  1U    #define KSA_ET_EXEC                 2U    #define KSA_ET_DYN                  3U    #define KSA_EM_ARM                  40U    #define KSA_EM_X86_64               62U    #define KSA_PT_INTERP               3U        #define KSA_EF_ARM_EABI_VER5        0x05000000U    #define KSA_EF_ARM_ABI_FLOAT_SOFT   0x00000200U  #define KSA_EF_ARM_ABI_FLOAT_HARD   0x00000400U    #define KSA_ARMHF_INTERP_PATH       "/lib/ld-linux-armhf.so.3"        struct ksa_elf32_ehdr {    	uint8_t  e_ident[16];    	uint16_t e_type;    	uint16_t e_machine;    	uint32_t e_version;    	uint32_t e_entry;    	uint32_t e_phoff;    	uint32_t e_shoff;    	uint32_t e_flags;    	uint16_t e_ehsize;    	uint16_t e_phentsize;    	uint16_t e_phnum;    	uint16_t e_shentsize;    	uint16_t e_shnum;    	uint16_t e_shstrndx;    };      _Static_assert(sizeof(struct ksa_elf32_ehdr) == 52U, "Elf32_Ehdr is exactly 52 bytes");        struct ksa_elf32_phdr {    	uint32_t p_type;    	uint32_t p_offset;    	uint32_t p_vaddr;    	uint32_t p_paddr;    	uint32_t p_filesz;    	uint32_t p_memsz;    	uint32_t p_flags;    	uint32_t p_align;    };        #endif /* KSA_ELF32_ARMHF_CONTRACT_H */
  1. EF_ARM_ABI_FLOAT_HARD (0x400) marks VFP register argument passing paired with /lib/ld-linux-armhf.so.3.
  2. 52-byte Elf32_Ehdr matches the SVR4 / ARM EABI specification identically on LP64 and ILP32 hosts.
elf(5) / readelf(1)(5) at a glance — GL-E00
elf(5) / readelf(1)(5)      GL-E00 Quick Reference      elf(5) / readelf(1)(5) SYNOPSIS       arm-linux-gnueabihf-readelf -h -l -d -V target_app file target_app DIAGNOSTIC COMMANDS       readelf -h app Verify Class: ELF32, Machine: ARM, Flags: Version5 EABI,       hard-float ABI. readelf -l app Inspect INTERP header -> [Requesting       program interpreter: /lib/ld-linux-armhf.so.3]. readelf -d app List       direct (NEEDED) shared libraries without running host ldd! cp -a       sysroot/lib/* Always use -a (archive/no-dereference) when populating       rootfs/lib symlinks! Kernel Systems Academy            Lesson 6.1            elf(5) / readelf(1)(5) GL-E00 quick reference · full manual page: man 5 elf(5) / readelf(1) 

Simulating fs/binfmt_elf.c Architecture and PT_INTERP Checks in C11

In verify.c, we synthesize three compact binary ELF images in memory — an EM_X86_64 accidental host build, a soft-float armel build (/lib/ld-linux.so.3), and a clean armhf (0x05000400) build (/lib/ld-linux-armhf.so.3) — and run them through an exact C11 model of fs/binfmt_elf.c's execve() validator against an armhf rootfs.

Watching -ENOEXEC (-8) vs -ENOENT (-2) emerge from 50 lines of C11 makes the No such file or directory mystery unforgettable.

learner@ksa: ~/gl-e00/m06-l01
learner@ksa:~/gl-e00/m06-l01$ bat -H 56 -H 63 verify.c File: verify.c    #define _POSIX_C_SOURCE 200809L    #include <errno.h>    #include <stdint.h>    #include <stdio.h>    #include <string.h>        struct mini_ehdr {    	uint8_t  ident[16];    	uint16_t type;    	uint16_t machine;    	uint32_t version, entry, phoff, shoff, flags;    	uint16_t ehsize, phentsize, phnum, shentsize, shnum, shstrndx;    };        struct mini_phdr {    	uint32_t type, offset, vaddr, paddr, filesz, memsz, flags, align;    };        static size_t build_test_elf(uint8_t *buf, uint8_t cls, uint16_t mach, uint32_t eflags, const char *interp)    {    	struct mini_ehdr eh = {0};    	struct mini_phdr ph = {0};    	size_t ilen = strlen(interp) + 1U;        	memcpy(eh.ident, "\x7f" "ELF", 4U);    	eh.ident[4] = cls;    	eh.ident[5] = 1U; /* LSB */    	eh.type = 2U;     /* ET_EXEC */    	eh.machine = mach;    	eh.version = 1U;    	eh.phoff = (uint32_t)sizeof(eh);    	eh.flags = eflags;    	eh.ehsize = (uint16_t)sizeof(eh);    	eh.phentsize = (uint16_t)sizeof(ph);    	eh.phnum = 1U;        	ph.type = 3U; /* PT_INTERP */    	ph.offset = (uint32_t)(sizeof(eh) + sizeof(ph));    	ph.filesz = (uint32_t)ilen;    	ph.memsz = (uint32_t)ilen;        	memcpy(buf, &eh, sizeof(eh));    	memcpy(buf + sizeof(eh), &ph, sizeof(ph));    	memcpy(buf + sizeof(eh) + sizeof(ph), interp, ilen);    	return sizeof(eh) + sizeof(ph) + ilen;    }        static int sim_arm_binfmt_elf(const uint8_t *img, size_t len, const char *rootfs_interp)    {    	struct mini_ehdr eh;    	struct mini_phdr ph;        	if (len < sizeof(eh) || memcmp(img, "\x7f" "ELF", 4U) != 0)    		return -ENOEXEC;    	memcpy(&eh, img, sizeof(eh));  	if (eh.ident[4] != 1U || eh.machine != 40U)    		return -ENOEXEC;    	if (eh.phnum >= 1U && eh.phoff + sizeof(ph) <= len) {    		memcpy(&ph, img + eh.phoff, sizeof(ph));    		if (ph.type == 3U && ph.offset + ph.filesz <= len) {    			const char *req = (const char *)(img + ph.offset);    			if (strcmp(req, rootfs_interp) != 0)  				return -ENOENT; /* open_exec(PT_INTERP) failed! */    		}    	}    	return ((eh.flags & 0x400U) != 0U) ? 0 : -EINVAL;    }        int main(void)    {    	uint8_t img_x64[160], img_soft[160], img_hf[160];    	size_t n1 = build_test_elf(img_x64, 2U, 62U, 0U, "/lib64/ld-linux-x86-64.so.2");    	size_t n2 = build_test_elf(img_soft, 1U, 40U, 0x05000200U, "/lib/ld-linux.so.3");    	size_t n3 = build_test_elf(img_hf, 1U, 40U, 0x05000400U, "/lib/ld-linux-armhf.so.3");        	int r_x64 = sim_arm_binfmt_elf(img_x64, n1, "/lib/ld-linux-armhf.so.3");    	int r_soft = sim_arm_binfmt_elf(img_soft, n2, "/lib/ld-linux-armhf.so.3");    	int r_hf = sim_arm_binfmt_elf(img_hf, n3, "/lib/ld-linux-armhf.so.3");        	if (r_x64 != -ENOEXEC || r_soft != -ENOENT || r_hf != 0)    		return 1;        	printf("BINFMT_ELF x86_64_rc=%d(ENOEXEC) armel_rc=%d(ENOENT_missing_interp) armhf_rc=%d(OK)\n",    	       r_x64, r_soft, r_hf);    	return 0;    }
  1. Wrong ELF class or e_machine != 40 (EM_ARM) fails elf_check_arch() immediately with -ENOEXEC (-8).
  2. Valid EM_ARM header whose PT_INTERP path is absent from rootfs returns -ENOENT (-2) from execve()!

Tracing Exact Return Codes (-ENOEXEC vs -ENOENT)

Notice how cleanly BINFMT_ELF separates -8 (-ENOEXEC, Exec format error) on the EM_X86_64 image from -2 (-ENOENT, No such file or directory) on the EM_ARM image requesting /lib/ld-linux.so.3 on an armhf-only rootfs.

Whenever a target shell reports not found or No such file or directory on a binary you know exists, run readelf -l binary | grep interpreter on your host — 99% of the time, either PT_INTERP or its symlink target (ld-2.xx.so) is missing in rootfs/lib/.

learner@ksa: ~/gl-e00/m06-l01
learner@ksa:~/gl-e00/m06-l01gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m06-l01./verifyBINFMT_ELF x86_64_rc=-8(ENOEXEC) armel_rc=-2(ENOENT_missing_interp) armhf_rc=0(OK)learner@ksa:~/gl-e00/m06-l01
strace — learner@ksa: ~/gl-e00/m06-l01
learner@ksa:~/gl-e00/m06-l01strace -e trace=write,exit_group ./verifywrite(1, "BINFMT_ELF x86_64_rc=-8(ENOEXEC)"..., 83) = 83exit_group(0)                           = ?+++ exited with 0 +++

Verification Checks

quiz · 1 of 3

On your ARMv7-A target console, ls -l /root/sensor_daemon shows -rwxr-xr-x 1 root root 18420, yet running /root/sensor_daemon prints -sh: /root/sensor_daemon: No such file or directory (ENOENT). What is the primary root cause?

quiz · 2 of 3

What distinguishes EF_ARM_ABI_FLOAT_HARD (0x400, armhf) from EF_ARM_ABI_FLOAT_SOFT (0x200, armel) at function call boundaries?

quiz · 3 of 3

Why should you inspect an ARM cross-binary's shared-library dependencies with arm-linux-gnueabihf-readelf -d app rather than host ldd app?

Key takeaways

  • A valid ARMv7-A Linux user-space binary carries ELF magic 0x7F 'E' 'L' 'F', EI_CLASS = ELFCLASS32 (1), e_machine = EM_ARM (40), and e_flags bit EF_ARM_ABI_FLOAT_HARD (0x400).
  • Executing an EM_ARM (40) binary on an x86_64 host fails elf_check_arch() with ENOEXEC (Exec format error), whereas executing an armhf binary on an ARM rootfs missing its PT_INTERP (/lib/ld-linux-armhf.so.3) makes execve() return ENOENT (No such file or directory).
  • Mixing soft-float (EF_ARM_ABI_FLOAT_SOFT = 0x200, r0..r3 float passing) with hard-float (0x400, VFPv3 s0..s15 / d0..d7 registers) breaks calling conventions and requests incompatible /lib/ld-linux.so.3 vs /lib/ld-linux-armhf.so.3 loaders.
  • DT_NEEDED entries and .gnu.version_r tags (GLIBC_2.xx) bind binaries to the sysroot's minimum glibc version; compiling with a newer host cross-toolchain than the target rootfs fails in ld.so at launch.
Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure