Prerequisites
The input must be a compiled object file (.o or .obj) or assembly file (.s or .asm). If you have source code, compile it first (e.g. via CMake build or standalone clang -S).
Arguments
$1 = input file (.o, .obj, .s, or .asm)
$2 = function name (optional — if omitted, disassemble the entire file)
Examples:
trees.c.o compress_block — single function
trees.c.o — entire file
trees.s my_function
trees.obj compress_block
Steps
1. Disassemble object files (.o / .obj)
Use the appropriate tool for the platform:
| Platform |
Tool |
Notes |
| macOS |
llvm-objdump |
Ships with Xcode |
| Linux |
objdump |
GNU binutils 2.32+ |
| Windows |
llvm-objdump |
Ships with VS LLVM/clang workload or standalone LLVM |
Single function ($2 provided):
| Platform |
Command |
| macOS |
llvm-objdump --disassemble-symbols=_<name> --no-show-raw-insn <file> |
| Linux |
objdump --disassemble=<name> --no-show-raw-insn <file> |
| Windows |
llvm-objdump --disassemble-symbols=<name> --no-show-raw-insn <file> |
Entire file ($2 omitted):
| Platform |
Command |
| macOS |
llvm-objdump -d --no-show-raw-insn <file> |
| Linux |
objdump -d --no-show-raw-insn <file> |
| Windows |
llvm-objdump -d --no-show-raw-insn <file> |
Windows dumpbin fallback — if llvm-objdump is not available:
VSPATH=$(vswhere -latest -property installationPath)
cmd.exe /c "call \"${VSPATH}\VC\Auxiliary\Build\vcvarsall.bat\" amd64 >nul 2>&1 && dumpbin /disasm <file>.obj"
Then manually extract the function: find <function_name>: label, collect until the next label or summary line.
2. Extract from assembly files (.s / .asm)
Read the file directly. If $2 is provided, extract the named function:
- Mach-O: Find
_<function_name>:, collect until next ^_[a-zA-Z] label (excluding _Ltmp, _LCFI, _LBB prefixes).
- ELF/other: Find
<function_name>:, collect until the next function label.
3. Clean up and output
- Filter out assembler directives (
. prefix), comments (#, ;, //, @), and blank lines
- Keep only instruction lines
- Output the assembly to stdout with a summary line showing the instruction count
Symbol Names
Symbol names differ by platform — use this when passing to --disassemble-symbols or searching in .s files:
| Platform |
C function foo |
C++ function foo |
| macOS (Mach-O) |
_foo |
_Z3foov (Itanium mangled, _ prefixed) |
| Linux (ELF) |
foo |
_Z3foov (Itanium mangled) |
| Windows (PE/COFF) |
foo |
?foo@@YAXXZ (MSVC decorated) |
Architecture Notes
| Architecture |
Key details |
| x86-64 |
offset(%reg) memory syntax. leaq (%rip) is PC-relative, not a load. |
| AArch64 |
[reg, #offset] memory syntax. Loads: ldr, ldur, ldp, ldrb, ldrh, ldrsw. Stores: str, stur, stp, strb, strh. Apple Silicon compiles natively. |
| x86-64 (MSVC) |
Intel syntax (dest first): mov rax, [rcx+168]. Args in rcx, rdx, r8, r9. C++ names may be decorated (?name@@...). |
CMake Build Paths
- Unix:
build/CMakeFiles/<target>.dir/<source>.o
- Windows (Ninja):
build/CMakeFiles/<target>.dir/<source>.obj
- Windows (VS):
build/CMakeFiles/<target>.dir/<config>/<source>.obj
1---2name: extract-asm3description: Extract assembly from an object file or assembly file, optionally for a specific function4---56## Prerequisites7The input must be a compiled object file (`.o` or `.obj`) or assembly file (`.s` or `.asm`). If you have source code, compile it first (e.g. via CMake build or standalone `clang -S`).89## Arguments10- `$1` = input file (`.o`, `.obj`, `.s`, or `.asm`)11- `$2` = function name (optional — if omitted, disassemble the entire file)1213Examples:14- `trees.c.o compress_block` — single function15- `trees.c.o` — entire file16- `trees.s my_function`17- `trees.obj compress_block`1819## Steps2021### 1. Disassemble object files (`.o` / `.obj`)2223Use the appropriate tool for the platform:2425| Platform | Tool | Notes |26|----------|------|-------|27| macOS | `llvm-objdump` | Ships with Xcode |28| Linux | `objdump` | GNU binutils 2.32+ |29| Windows | `llvm-objdump` | Ships with VS LLVM/clang workload or standalone LLVM |3031**Single function** (`$2` provided):3233| Platform | Command |34|----------|---------|35| macOS | `llvm-objdump --disassemble-symbols=_<name> --no-show-raw-insn <file>` |36| Linux | `objdump --disassemble=<name> --no-show-raw-insn <file>` |37| Windows | `llvm-objdump --disassemble-symbols=<name> --no-show-raw-insn <file>` |3839**Entire file** (`$2` omitted):4041| Platform | Command |42|----------|---------|43| macOS | `llvm-objdump -d --no-show-raw-insn <file>` |44| Linux | `objdump -d --no-show-raw-insn <file>` |45| Windows | `llvm-objdump -d --no-show-raw-insn <file>` |4647**Windows `dumpbin` fallback** — if `llvm-objdump` is not available:48```49VSPATH=$(vswhere -latest -property installationPath)50cmd.exe /c "call \"${VSPATH}\VC\Auxiliary\Build\vcvarsall.bat\" amd64 >nul 2>&1 && dumpbin /disasm <file>.obj"51```52Then manually extract the function: find `<function_name>:` label, collect until the next label or summary line.5354### 2. Extract from assembly files (`.s` / `.asm`)5556Read the file directly. If `$2` is provided, extract the named function:57- **Mach-O:** Find `_<function_name>:`, collect until next `^_[a-zA-Z]` label (excluding `_Ltmp`, `_LCFI`, `_LBB` prefixes).58- **ELF/other:** Find `<function_name>:`, collect until the next function label.5960### 3. Clean up and output6162- Filter out assembler directives (`.` prefix), comments (`#`, `;`, `//`, `@`), and blank lines63- Keep only instruction lines64- Output the assembly to stdout with a summary line showing the instruction count6566## Symbol Names6768Symbol names differ by platform — use this when passing to `--disassemble-symbols` or searching in `.s` files:6970| Platform | C function `foo` | C++ function `foo` |71|----------|------------------|--------------------|72| macOS (Mach-O) | `_foo` | `_Z3foov` (Itanium mangled, `_` prefixed) |73| Linux (ELF) | `foo` | `_Z3foov` (Itanium mangled) |74| Windows (PE/COFF) | `foo` | `?foo@@YAXXZ` (MSVC decorated) |7576## Architecture Notes7778| Architecture | Key details |79|-------------|-------------|80| **x86-64** | `offset(%reg)` memory syntax. `leaq (%rip)` is PC-relative, not a load. |81| **AArch64** | `[reg, #offset]` memory syntax. Loads: `ldr`, `ldur`, `ldp`, `ldrb`, `ldrh`, `ldrsw`. Stores: `str`, `stur`, `stp`, `strb`, `strh`. Apple Silicon compiles natively. |82| **x86-64 (MSVC)** | Intel syntax (dest first): `mov rax, [rcx+168]`. Args in `rcx`, `rdx`, `r8`, `r9`. C++ names may be decorated (`?name@@...`). |8384## CMake Build Paths85- Unix: `build/CMakeFiles/<target>.dir/<source>.o`86- Windows (Ninja): `build/CMakeFiles/<target>.dir/<source>.obj`87- Windows (VS): `build/CMakeFiles/<target>.dir/<config>/<source>.obj`