How to resolve ELF relative addresses?

2026-07-25

Stack Overflow: View Question

Tags: gdb, elf, dwarf

Score: 0 | Views: 99

The asker is building their own debugger. They've parsed DWARF4 line-number information out of an ELF binary and produced a table of (address, source line) pairs. When they compare that table against gdb's disassembly, the addresses line up perfectly — but only when the binary is examined statically. As soon as the process is running, the "real" addresses inside the traced program don't match what their line table says, and they need to know how to bridge that gap.

This is the classic load bias problem, and it's more subtle than it looks. Modern Linux toolchains default to -fPIE -pie, which produces an ET_DYN ELF (a shared-object-flavored executable). The addresses baked into DWARF are relative to the file's own virtual address space — typically starting at 0 for PIE binaries — but the kernel's loader (or ld-linux.so) picks a randomized base address at exec time thanks to ASLR. So a DWARF entry that says "line 42 is at 0x1149" actually lives at base + 0x1149 in the running process.

For non-PIE ET_EXEC binaries the load address is fixed (usually 0x400000 on x86_64), which is why static inspection "just works" and why the discrepancy only bites once you attach to a live process.

How to fix it

Gotchas

The challenge: DWARF addresses are file-relative, but PIE + ASLR means the kernel silently slides the whole binary at exec time — a debugger has to compute and apply that load bias for every lookup.

All newsletters