A binary isn’t a black box: it has a fingerprint, a table of contents, a symbol table, and a byte-by-byte layout. You just have to know which tool to ask.
Once a build finishes, you’re left with a file that runs—but explains nothing. You can read the source code with your own eyes, yet you can’t see what actually landed in machine code, how much space data takes up, where the linker wrote a string’s address, or which bytes correspond to which instruction. In this lesson, I build a hybrid C99 + NASM testbed and inspect it with six CLI utilities. This isn’t a textbook on the ELF specification—it’s the practical set of questions and commands I reach for every day.
Mental Model: Six Questions for One File
| Question | Tool | What it shows |
|---|---|---|
| What kind of file is this? | file |
word size, byte order, file type, architecture, linking mode |
| How big is it? | size, size -A |
total size by access permissions and per-section breakdown |
| How is it laid out? | readelf -h, -S, -l |
header, section table, memory map |
| Where are symbols and addresses? | nm, readelf -r |
symbol names and unresolved relocations |
| What bytes encode the instructions? | objdump -d |
disassembly in AT&T or Intel syntax |
| What’s in the file byte by byte? | xxd -g 1 |
raw hex dump |
None of these tools is the single “primary” one: file answers one question, readelf another, and objdump doesn’t replace nm. Below, I walk through this list on the same binary.
file, size, readelf, nm, objdump, and xxd. The lea and ret instructions, the 48 prefix, and relocation tables just serve as live specimens for the tools—we’ll cover them in detail across lessons 03–17.
Testbed: C99 Plus Assembly
The C99 side checks the first byte of a string returned by an assembly function:
/* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 */
/* probe.c — C99 check of the first byte of the string from asm_marker(). */
#include <stdint.h>
extern const char *asm_marker(void);
int main(void)
{
const char *marker = asm_marker();
if (marker[0] != 'a') {
return 1;
}
return 0;
}The assembly function returns the address of a string living in the read-only .rodata section:
; SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
; probe.asm — asm_marker function: returns the address of a string in .rodata.
default rel
section .rodata
marker: db "asm", 0
section .text
global asm_marker
; ------------------------------------------------------------------------------
; const char *asm_marker(void)
; Input: none
; Output: rax = address of string marker
; Clobbers: nothing except rax (flags untouched)
; ------------------------------------------------------------------------------
asm_marker:
lea rax, [marker]
ret
section .note.GNU-stack noalloc noexec nowrite progbitsThe build combines both object files into a single ELF executable:
$ nasm -f elf64 -g -F dwarf -o build/probe_asm.o probe.asm
$ gcc -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Werror -pedantic \
-g -O0 -no-pie -c -o build/probe.o probe.c
$ gcc -no-pie -o build/probe build/probe.o build/probe_asm.o
$ ./build/probe; echo $?
0That last command invokes gcc rather than ld directly, so it implicitly links CRT and libc. That’s why build/probe contains _start from crt1.o instead of just main; ld on its own links neither CRT nor libc.
An exit code of 0 means the string was found and its first byte matched 'a'. We’ll cover calling conventions and register roles later; right now, the binary itself is our focus.
Mechanics: Reading the File Layer by Layer
file: The File’s Fingerprint
$ file build/probe
build/probe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=52738eb92ecedc4e98016fa535e2450593089a41, for GNU/Linux 4.4.0, with debug_info, not strippedEach field answers a separate question:
ELF 64-bit— ELF class (64-bit addresses and header fields);LSB— little-endian byte order (more in lesson 06);executable— file type: an executable binary with fixed addresses, since it was built with-no-pie;x86-64— target architecture;version 1 (SYSV)— ELF format version 1 and the System V standard (its calling rules are covered in lesson 18);dynamically linked— the program loads external libraries (such aslibc) at runtime;interpreter /lib64/ld-linux-x86-64.so.2— path to the dynamic loader: on launch, the kernel maps both the ELF binary and this loader, and hands control told-linuxfirst;ld-linuxloads the required.solibraries and then passes control to_start;BuildID[sha1]=...— unique build hash used by debuggers to match debug symbols to an exact binary build;for GNU/Linux 4.4.0— minimum Linux kernel version and ABI target (more in lesson 18);with debug_info— DWARF data is embedded;not stripped— function and data symbol names are intact.
size: How Much Space It Takes
$ size build/probe
text data bss dec hex filename
1137 488 8 1633 661 build/probeWithout flags, size doesn’t print “file size”—it prints byte totals grouped into three permission categories:
text— all allocated read-only and executable sections;data— mutable data with initial values;bss— mutable data zero-initialized at startup.
dec and hex are the sum of those three numbers in decimal and hexadecimal. The file itself is larger on disk because it also contains headers, padding, and debug info.
The per-section breakdown shows where those numbers come from:
$ size -A build/probe | grep -E 'section|\.(text|rodata|data|bss)\b|\.comment|\.debug_info|Total'
section size addr
.text 296 4198432
.rodata 8 4202496
.data 16 4210688
.bss 8 4210704
.comment 27 0
.debug_info 312 0
Total 2610text = 1137 is the sum of all read-only allocated sections, not just .text (296 bytes) on its own. That total includes auxiliary sections such as:
.interp— the string holding the dynamic linker path;.dynsym— the symbol table needed for dynamic linking;.eh_frame— stack-unwinding tables used for exception handling and debugging.
Total = 2610 exceeds text + data + bss = 1633 because the full tally also counts non-loaded sections like .comment (the compiler version string) and every .debug_* section (some of them, along with auxiliary linker tables, were filtered out by grep, which is why the displayed rows sum to less than 2610). Their address is 0—the kernel doesn’t map them into RAM, though they still sit on disk. Here, .debug_info is uncompressed: in readelf -SW it has no C flag, and its Size field is 000138, matching the 312 bytes reported by size. Note that Total on another machine or in a different directory may differ from 2610 by tens of bytes: with -g, GCC records the build directory path (DW_AT_comp_dir) in DWARF as a string inside .debug_line_str, so path length changes debug section sizes.
size -A prints sizes and addresses in decimal (296 = 0x128, 4198432 = 0x401020), whereas readelf shows those same numbers in hex.
The 16 bytes of .data and 8 bytes of .bss don’t come from probe.c: CRT object files bring them in, and the first 4 bytes of .rodata are occupied by the internal _IO_stdin_used marker.
Under the hood: where the extra bytes in sections come from (CRT)
- a 4-byte zero object from
crt1.oplus__dso_handlefromcrtbegin.o(8 bytes), together with alignment padding, produce 16 bytes in.data; - the 1-byte
completed.0flag fromcrtbegin.oplus section-end alignment yields 8 bytes in.bss; - the first 4 bytes of
.rodatahold the internal_IO_stdin_usedmarker fromcrt1.o, pushingmarkerto+4bytes (we’ll inspect the raw bytes below in thexxdsection).
readelf: How the File Is Laid Out
The ELF header answers “what is this?” and “how many tables live inside?”:
$ readelf -hW build/probe | grep -E 'Magic|Class|Data|Type|Machine|Entry point|Number of'
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Entry point address: 0x401020
Number of program headers: 15
Number of section headers: 35Each header field answers a specific question:
Magic— the magic signature at the very start of the file, which the Linux kernel (execve) andfileuse to recognize ELF immediately (corrupt even one of these first four bytes and the kernel refuses to execute the file). The first byte is the non-printable control code0x7f(ASCIIDEL—chosen deliberately so no plain text file matches an ELF header), followed by the ASCII codes forE(45),L(4c), andF(46). In theMagic:row,readelfprints all 16 bytes of thee_identidentifier, where\x7fELFis immediately followed by ELF class (02), byte order (01), ELF version (01), and OS ABI (00);Class: ELF64— 64-bit addresses and header fields;Data: 2's complement, little endian— signed integers use two’s complement, and byte order is little-endian;Type: EXEC— an executable with fixed addresses (unlike a relocatableRELobject or a position-independent PIE binary, which has typeDYN);Entry point address: 0x401020— virtual address of the first instruction to execute (the first 4 KiB starting at0x400000hold ELF headers, and code begins on the next page at0x401000);Number of program headers: 15— number of entries in the loader’s memory map;Number of section headers: 35— number of entries in the file’s section table.
Entry point isn’t main: CRT provides the entry point (_start from crt1.o), which in turn calls main. We’ll write our own _start in lesson 04.
The file is built from sections. To avoid wading through all 35 entries, I filter down to the ones we care about:
$ readelf -SW build/probe | grep -E '\.(text|rodata|data|bss)\b'
[10] .text PROGBITS 0000000000401020 001020 000128 00 AX 0 0 16
[12] .rodata PROGBITS 0000000000402000 002000 000008 00 A 0 0 4
[23] .data PROGBITS 0000000000404000 003000 000010 00 WA 0 0 8
[24] .bss NOBITS 0000000000404010 003010 000008 00 WA 0 0 1Columns read left to right:
Nr— entry index;Name— section name;Type—PROGBITS(bytes exist in the file) orNOBITS(no bytes stored in the file; memory is zeroed on load);Address— virtual address;Off— offset inside the file;Size— section size;ES— table entry size (0for these sections);Flg— access flags:Ameans the section is allocated in process memory,Xallows instruction execution,Wallows writes;LkandInf— index links to related sections for metadata tables (for instance,.symtabpoints viaLkto.strtabholding its symbol name strings, while.rela.textpoints viaInfto.text, the section it patches; regular code and data sections have no links, so these are zero);Al— alignment.
Section flags:
.texthasAX: code is readable and executable;.rodatahas onlyA: writes are forbidden;.dataand.bsshaveWA: memory is writable.
NOBITS on .bss explains why it takes zero bytes on disk even though its size is 8.
Sections are grouped into segments, which are what the kernel actually maps:
$ readelf -lW build/probe | grep -E 'LOAD|GNU_STACK'
LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x000558 0x000558 R 0x1000
LOAD 0x001000 0x0000000000401000 0x0000000000401000 0x000155 0x000155 R E 0x1000
LOAD 0x002000 0x0000000000402000 0x0000000000402000 0x000160 0x000160 R 0x1000
LOAD 0x002e28 0x0000000000403e28 0x0000000000403e28 0x0001e8 0x0001f0 RW 0x1000
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10The four LOAD entries define a memory map with distinct permissions:
- first — read-only headers and metadata tables (
R); - second — code with
R Epermissions (read and execute); - third — read-only
.rodata(R); - fourth — writable
RWdata (read and write).
Permissions are enforced per memory page, which is why code, read-only data, and writable data live in separate segments—otherwise you couldn’t forbid writes to .text or .rodata. The 0x1000 alignment is 4096 bytes, the x86-64 page size; because the kernel maps memory in pages, segment boundaries are multiples of 4 KiB.
On the last LOAD segment, FileSiz and MemSiz differ: 0x1e8 vs. 0x1f0. The -byte difference is .bss, which doesn’t exist in the file but gets zeroed in memory. The GNU_STACK line showing RW without E confirms that the stack is non-executable.
The fourth LOAD segment starts at offset 0x2e28 and virtual address 0x403e28, ahead of .data itself (0x404000), because linker metadata sections (.init_array, .fini_array, .dynamic, .got) sit right before .data in the same RW segment. Debug sections (.debug_*) stay on disk only:
File on disk (offsets) Virtual memory (LOAD segments)
┌─────────────────────────┐ ┌───────────────────────────────────┐
│ Headers, .interp ... │ ──LOAD 1──► │ 0x400000 [R ] headers │
├─────────────────────────┤ ├───────────────────────────────────┤
│ .text (296 B) │ ──LOAD 2──► │ 0x401000 [R E] code │
├─────────────────────────┤ ├───────────────────────────────────┤
│ .rodata (8 B) │ ──LOAD 3──► │ 0x402000 [R ] constants │
├─────────────────────────┤ ├───────────────────────────────────┤
│ .dynamic, .got, .data │ ──LOAD 4──► │ 0x403e28 [RW ] mutable + │
├─────────────────────────┤ │ .bss (8 B zeros in RAM) │
│ .symtab, .debug_* │ (not in RAM) └───────────────────────────────────┘
└─────────────────────────┘nm: Symbols and Addresses
Function and data names live in the symbol table. In the C99 object file, we can see the call isn’t resolved yet:
$ nm -n build/probe.o
U asm_marker
0000000000000000 T mainU means undefined—the symbol is declared, though its definition lives in another object file. T marks a global function in .text. The asm_marker symbol is defined in the assembly object file:
$ nm -n build/probe_asm.o
0000000000000000 T asm_marker
0000000000000000 r markerT on asm_marker means an exported function; r on marker means local read-only data. Both addresses are still zero: those are offsets within the object file. After linking, the addresses become real:
$ nm -n build/probe | grep -E ' (T|t) (main|asm_marker)$| (r|R) marker$'
0000000000401116 T main
0000000000401140 T asm_marker
0000000000402004 r markerreadelf -r: Who Patches the Addresses
Until a string’s address is known, the linker needs to be told where to write it. Those unresolved slots are recorded as relocations:
$ readelf -rW build/probe.o | sed -n '/\.rela\.text/,/^$/p'
Relocation section '.rela.text' at offset 0x498 contains 1 entry:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000000009 0000000900000004 R_X86_64_PLT32 0000000000000000 asm_marker - 4
$ readelf -rW build/probe_asm.o | sed -n '/\.rela\.text/,/^$/p'
Relocation section '.rela.text' at offset 0x8c0 contains 1 entry:
Offset Info Type Symbol's Value Symbol's Name + Addend
0000000000000003 0000000200000002 R_X86_64_PC32 0000000000000000 .rodata - 4Relocation fields:
Offset— position of the field inside.textthat the linker will overwrite;Type— address calculation formula:R_X86_64_PC32means a plain offset relative to the current instruction, whileR_X86_64_PLT32means a call through the PLT (we cover the full mechanics of dynamic linking, PLT, and GOT in lesson 17). Inprobe.o, the compiler doesn’t know yet whetherasm_markerlives in a neighboring object file or an external.solibrary, so it emitsPLT32conservatively; after linking withprobe_asm.o, the linker sees the function is local and patches in a direct call with no stub;Symbol's Name— target of the relocation;Addend - 4— adjustment for the width of the 4-byte displacement field: at runtimerippoints to the end of theleainstruction rather than the start of the field, so we subtract the field’s start address plus its 4 bytes from the target address;- once linked, the target of the relocation in
probe_asm.obecomes0x402004 <marker>, whichobjdumpprints in a comment next tolea.
In the assembly object, Offset is 3: lea takes three bytes before its 4-byte displacement field. The Info column packs the symbol index and relocation type into one number; for reading, Type and Symbol's Name are all you need. Static relocations in .rela.text disappear from the final binary once all local code and data addresses are patched in (only dynamic slots in .rela.dyn and .rela.plt remain for external library functions, covered in lesson 17).
The linker and the CPU compute the offset in two independent steps:
- The linker takes the target symbol’s virtual address, adds
Addend(here −4), and subtracts the start address of the 4-byte displacement field inside the instruction. The result—disp32—is written into that 4-byte slot. - At runtime, the CPU adds
disp32to the address of the next instruction to obtain the final target address.
- 32-bit displacement written by the linker into the instruction’s field.
- final virtual address of the target symbol.
Addendcorrection from the relocation table; here-4.- start address of the 4-byte displacement field inside the instruction.
- address at which the processor continues execution after a jump.
- address of the instruction immediately following the current one.
For probe_asm.o, the field starts at 0x401143: lea uses three bytes starting from 0x401140. This layout diagram shows where A = -4 comes from in the formula:
address bytes meaning
0x401140 48 8d 05 lea rax, [rip + disp32]
0x401143 bd 0e 00 00 disp32 field: 4 bytes, addr(field)
0x401147 — rip_next = addr(field) + 4The linker knows the symbol’s address and the field’s start address, but not rip_next: the CPU measures the offset from the next instruction, not from the field. Those exact four bytes are what A = -4 (the length of the displacement field itself) compensates for:
With that substitution, the linker’s math matches what the CPU will do: add disp32 to the next instruction’s address. Plugging in the numbers from our testbed:
The target is the exact address of marker reported by nm.
objdump: Bytes and Instructions
By default, the disassembler prints AT&T syntax:
$ objdump -d build/probe | sed -n '/<asm_marker>:/,/^$/p'
0000000000401140 <asm_marker>:
401140: 48 8d 05 bd 0e 00 00 lea 0xebd(%rip),%rax # 402004 <marker>
401147: c3 retIn AT&T syntax, percent signs mark registers and the source precedes the destination: 0xebd(%rip),%rax reads as “compute offset 0xebd from rip and store it in rax.” Passing -M intel makes the same code look familiar after NASM:
$ objdump -d -M intel build/probe | sed -n '/<asm_marker>:/,/^$/p'
0000000000401140 <asm_marker>:
401140: 48 8d 05 bd 0e 00 00 lea rax,[rip+0xebd] # 402004 <marker>
401147: c3 retOnly the notation differs: Intel syntax puts the destination on the left, drops % from registers, and wraps displacements in square brackets. The bytes are identical:
48— 64-bit operand prefix: switchesleato 64-bit width (prefixes are covered in lesson 03);8d— opcode for theleainstruction;05— addressing-mode byte for “offset relative torip”;bd 0e 00 00— the displacement itself;c3— the single-byteretinstruction.
The bytes bd 0e 00 00 encode 0xebd: least significant byte first, which is little-endian order (covered in lesson 06).
xxd: Byte-by-Byte Hex Dump
The file header begins with the exact bytes readelf showed:
$ xxd -g 1 -l 16 build/probe
00000000: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 .ELF............-g 1 groups output one byte at a time; -l 16 limits the dump to 16 bytes. Header fields:
7f 45 4c 46— the\x7fELFsignature;02— ELF64 class;01— little-endian;01— format version;00— standardEI_OSABIvalue for System V (baseline Unix compatibility without OS-specific extensions).
The remaining zeros are reserved padding in the header. The column on the right shows those same bytes as printable ASCII characters, with dots replacing non-printable bytes.
We can inspect the .rodata string using the offset from readelf: .rodata starts at Off = 002000 and spans 8 bytes. Dumping the whole section:
$ xxd -g 1 -s 0x2000 -l 8 build/probe
00002000: 01 00 02 00 61 73 6d 00 ....asm.The first four bytes are the _IO_stdin_used constant from crt1.o, holding 0x00020001: since the late 1990s, glibc has used it to distinguish modern binaries from legacy ones built against an older internal FILE * layout in stdio. It has nothing to do with our marker string, though it still takes up the first four bytes of the section. Next come the character codes:
61,73,6d—a,s,min ASCII;00— the trailing null terminator byte.
Aliases: Four Commands Instead of Ten Flags
Long commands quickly pile up flags, so I keep short aliases in a separate file and source it from ~/.bashrc or ~/.zshrc:
# SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
# aliases.sh — shortcuts for inspecting binaries.
# Usage: source aliases.sh (in ~/.bashrc or ~/.zshrc).
alias elf='readelf -W'
alias disasm='objdump -d -M intel --no-show-raw-insn'
alias hex='xxd -g 1'
alias gdb-clean='gdb -q --nx'elf enables wide output, though it doesn’t choose what to display: -W is a width modifier, not an action. You still specify the view separately:
elf -h build/probe— header;elf -S build/probe— sections;elf -l build/probe— segments;elf -r build/probe.o— relocations;disasm— Intel syntax without raw bytes, when you only want instructions;hex— shorthand forxxd -g 1; just append-sand-l;gdb-clean— a helper for lesson 05 that launches the debugger without reading local config files (we don’t run GDB in this lesson).
When I need raw bytes, I call objdump -d -M intel directly. Running readelf -W build/probe without an action flag prints the Usage help text. GDB itself is covered in lesson 05.
After editing your shell rc file, open a new shell instance: an already running shell won’t reload the file. Verify with type disasm; if the shell prints not found, the alias isn’t loaded.
Common Pitfalls
-
"
readelfprints usage help instead of inspecting the file."
Fact:readelf -W build/probeoutputsUsage: readelf <option(s)> elf-file(s).
Cause:-Wonly widens lines; it doesn’t select any data to display.
Fix: Add an action flag—readelf -hW,readelf -SW,readelf -lW, orreadelf -rW. -
"
readelfoutput is too long and drowns out what I need."
Fact: Dozens of auxiliary sections and theKey to Flagslegend flood the terminal.
Cause: The utility prints everything it finds.
Fix: Filter by section names (grep -E '\.(text|rodata|data|bss)\b') and don’t copy the legend into notes—flag meanings live in theFlgcolumn. -
"
objdumpshows%raxinstead ofrax."
Fact: By default, the disassembler outputs AT&T syntax.
Cause: Historical GNU default.
Fix: Add-M intelso operand order and register names match NASM. -
"
nmshowsU asm_markerwith no address."
Fact: Inprobe.o, the symbol is markedU, whereas inprobeit’s markedTwith an address.
Cause: The object file hasn’t been linked yet, so no address has been assigned.
Fix: Runnmon the linked binary or on the object file where the symbol is defined. -
“The
xxddump doesn’t match the expected string.”
Fact: Offset0x2000yields01 00 02 00 61 73 6d 00instead of starting withasm.
Cause: The first 4 bytes are_IO_stdin_usedfromcrt1.o; the string starts at offset0x2004.
Fix: Check the section’sOffinreadelf -SW, account for linker startup objects, and verify file signatures via the leading bytes.
Lab
Goal. Build the hybrid probe.c + probe.asm testbed, inspect it with all six tools, and explain every non-trivial field.
Contract. Build build/probe.o, build/probe_asm.o, and build/probe using the commands in the Testbed section. Then collect six measurements:
file build/probeandsize -A build/probe.readelf -SW build/probefiltered down to the four core sections.readelf -lW build/probefiltered forLOADandGNU_STACK.nm -non both object files and the linked binary.readelf -rW build/probe_asm.oandobjdump -d -M intel build/probe.xxd -g 1 -s 0x2000 -l 8 build/probe.
Verification criteria.
filereportsELF 64-bit LSB executable,dynamically linked, andwith debug_info.- In
readelf -SW,.bsshas typeNOBITS, and insize -A,Totalexceedstext + data + bss. - In
readelf -lW, the lastLOADsegment hasFileSizsmaller thanMemSizby the exact size of.bss. - In
nm,asm_markerchanges fromUtoTwith a real address after linking. - In
readelf -rW,leausesR_X86_64_PC32, andOffsetequals the opcode length before the displacement field. xxd -g 1 -s 0x2000 -l 8shows01 00 02 00followed by61 73 6d 00.
Hints, expected output, and walkthrough
Expected values for this testbed:
file: ELF 64-bit LSB executable, x86-64, dynamically linked, with debug_info, not stripped
size: text 1137, data 488, bss 8, dec 1633 # sample output; numbers may vary
size -A: .text 296, .rodata 8, .data 16, .bss 8, Total 2610
sections: .text PROGBITS AX, .rodata PROGBITS A, .data PROGBITS WA, .bss NOBITS WA
segments: last LOAD FileSiz 0x1e8, MemSiz 0x1f0 (diff 8 = .bss)
nm: probe.o → U asm_marker; probe → T asm_marker 0x401140
reloc: .rela.text, Offset 3, R_X86_64_PC32, .rodata - 4
bytes: 48 8d 05 bd 0e 00 00 (lea), then c3 (ret)
xxd: 0x2000 → 01 00 02 00 (_IO_stdin_used), 0x2004 → 61 73 6d 00 ("asm\0")Walkthrough:
.bsshas typeNOBITS, so it holds no bytes on disk: it gets zeroed in memory and only increasesMemSizinLOAD;- a
Usymbol in an object file is normal—the linker hasn’t resolved its address yet; - relocation offset
3is the three bytes48 8d 05preceding the 4-byte displacement field; Addend - 4is needed becauserippoints to the end of the instruction, not the start of the field.
Address check: 0x401147 + 0xebd = 0x402004, which matches marker. If your numbers differ, check your compiler version and keep the commands as-is: exact addresses depend on layout, while the relationships (FileSiz, MemSiz, Offset, Addend) always hold.
Lab source code, Makefile, and automated tests for this lesson: lessons/02-terminal-tools.
Summary
fileanswers “what kind of file is this?” without replacing the rest of the toolkit.sizegroups bytes by access permissions, whilesize -Ashows each section and includes non-loaded debug data.readelf -hreads the header,-Sthe sections, and-lthe segments; legends and noise can be filtered out.nmshows symbol names and states:Ubefore linking,Twith a real address afterward.readelf -rreveals where the linker will patch an address, whileobjdumpshows bytes and instructions in AT&T or Intel syntax.xxd -g 1ties raw file bytes directly to header fields and.rodatacontents.
rax/eax/ax/ah/al sub-register windows, the zero-extension rule, and the mov r8b, ah error.