为何GDB与Objdump显示的指令地址一致?二进制加载地址不该随机吗?
Great question—this trips up a lot of folks new to reverse engineering, so let’s break down exactly what’s happening here:
Objdump displays static link-time virtual addresses
When you runobjdump -don a binary, the addresses you see are fixed virtual addresses (VAs) set during the compile/link phase. These are stored directly in the ELF file’s headers, representing where the linker expects sections like.text(your executable code) to reside if the program loads at its "default base address." They never change, since they’re baked into the binary itself.GDB disables ASLR by default
Address Space Layout Randomization (ASLR) is the security feature that randomizes a program’s loaded memory addresses on each run. But GDB turns this off automatically to simplify debugging—if code addresses shifted every time you launched the program, setting breakpoints or tracking memory would be a nightmare. With ASLR disabled, the program loads exactly at the link-time base address objdump shows, so the addresses line up perfectly.You can test this yourself in GDB:
- Run
show disable-randomization—it’ll almost certainly say "on" (meaning ASLR is disabled). - Toggle ASLR on with
set disable-randomization off, then start the program withrun. - Disassemble a function now, and you’ll see the runtime address no longer matches what objdump displayed—because the program loaded at a randomized base address.
- Run
What if ASLR is enabled system-wide but GDB doesn’t override it?
If you force GDB to keep ASLR enabled, the program’s actual loaded address will be offset from the link-time VA. GDB will then show you the runtime address of instructions, which won’t align with objdump’s static addresses anymore. The only reason they match in your case is GDB’s default behavior of disabling ASLR.
In short: Objdump shows fixed, pre-defined addresses from the binary, while GDB defaults to disabling ASLR so the program loads at those exact addresses—hence the perfect match. Toggle that GDB setting if you want to see ASLR in action!
内容的提问来源于stack exchange,提问作者Julien Séveno-Piltant

