Use when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi.
日本語の概要は準備中です。原文の説明を表示しています。
Use when choosing a linker, fixing link order or undefined symbol errors, enabling LTO or ThinLTO, or cutting dead code with --gc-sections. Not for inspecting the linked binary: use elf-inspection.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
The linker turns object files into one binary and decides what survives from each translation unit. Most link failures are order problems; most size wins are LTO plus dead-code removal.
| Field | Bound contract |
|---|---|
| Trigger | The task fixes undefined reference or multiple definition errors, selects a linker, enables LTO or ThinLTO, removes dead code, controls symbol visibility, or reads a linker map. |
| Authority | Reversible local: writes only build flags, linker scripts, and build outputs; rollback is version control and a rebuild. No remote mutation. |
| Side effect | Local writes to the outputs the build produces and to build configuration the user names. |
| Done | The link succeeds with the intended flags, or the size and visibility changes are proven by the map, --print-gc-sections, or nm -D output. |
ld is the universal default, gold is the retired-in-name C++ linker kept for legacy builds, lld is the fast choice and the practical requirement for Clang LTO on large projects. Verify which linker actually ran from the driver's verbose output. Done when: the build uses the intended linker.gcc -fuse-ld=lld -o prog main.c
clang -fuse-ld=lld -o prog main.c
gcc -v main.c -o prog 2>&1 | grep 'collect2\|ld\.new\|lld'
-Wl, with commas instead of spaces. Done when: readelf -d or the map shows the flag took effect.gcc main.o -o prog \
-Wl,-rpath,/opt/mylibs/lib \
-Wl,--as-needed \
-Wl,--gc-sections \
-Wl,-z,relro -Wl,-z,now \
-L/opt/mylibs/lib -lfoo
gcc main.o -lfoo -ldep -o prog # dependents first
gcc main.o -Wl,--start-group -lfoo -lbar -Wl,--end-group -o prog
-flto with the same optimization level. LTO archives must be built with gcc-ar and gcc-ranlib, because plain ar cannot build the LTO symbol index. Done when: the link succeeds and size or performance improves against the non-LTO build.gcc -O2 -flto -ffunction-sections -fdata-sections -c foo.c -o foo.o
gcc -O2 -flto -Wl,--gc-sections foo.o bar.o -o prog
gcc-ar rcs libfoo.a foo.o
gcc-ranlib libfoo.a
gcc -O2 -flto=auto foo.o bar.o -o prog # parallel, uses the make jobserver
clang -O2 -flto=thin -fuse-ld=lld foo.c bar.c -o prog
In CMake, set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) selects the right LTO mode per compiler.
--gc-sections discards unreferenced sections, which only exist if compilation used -ffunction-sections -fdata-sections. Done when: --print-gc-sections reports the removals and the binary still runs.gcc -O2 -ffunction-sections -fdata-sections -c foo.c -o foo.o
gcc -Wl,--gc-sections -Wl,--print-gc-sections foo.o -o prog
nm -D --defined-only libfoo.so lists only the public API.gcc -fvisibility=hidden -O2 -shared -fPIC foo.c -o libfoo.so
# foo.ver
{
global: my_public_function; my_other_public;
local: *;
};
gcc -Wl,--version-script=foo.ver -shared -fPIC -o libfoo.so foo.o
gcc -Wl,-Map=prog.map -o prog foo.o bar.o
| Error | Cause | Fix |
|---|---|---|
undefined reference to 'foo' | Missing or misordered library | Add -lfoo after the objects that need it |
multiple definition of 'foo' | Symbol defined in two objects | Keep one definition, or declare the other extern |
cannot find -lfoo | Library outside -L paths | Add -L or install the development package |
relocation truncated to fit | Address outside the relocation's reach | Use -mcmodel=large, or restructure the image layout |
version 'GLIBC_2.xx' not found | Built on a newer glibc | Build on the older host or link statically |
| LTO bytecode mismatch | Mixed LTO and non-LTO objects | Recompile every object with the same -flto |
file format not recognized | Foreign architecture object | Use the matching cross toolchain for all objects |
| Failure class | Behavior |
|---|---|
| LTO build fails on one object | That object was compiled without -flto. Recompile it with the same flags as the rest. |
--gc-sections removed a needed section | Something referenced it only from assembly or a linker script. Add KEEP(*(...)) in the script, or the reference. |
| ThinLTO cache grows without bound | Point -Wl,--thinlto-cache-dir at a managed path and clear it on a schedule. |
| A group link got slow | --start-group rescans archives until fixed point. Resolve the cycle explicitly instead of leaving the group in place. |
| LTO changed behavior | Inlining across units can expose latent UB. Reproduce without LTO, then fix the source. |
The linked binary plus the evidence for each decision: linker chosen, map excerpts, --print-gc-sections output, or nm -D export lists. The full flag tables, lld extras, MSVC /GL /LTCG, and a linker script skeleton are in references/flags.md.
まだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Use when explaining System V AMD64, ARM AAPCS, RISC-V psABI, stack frames, variadic calls, or FFI register rules. Not for the Rust FFI binding layer: use rust-ffi.
日本語の概要は準備中です。原文の説明を表示しています。
Use when configuring ADC sampling time, DMA-driven ADC, calibration, or DAC channel setup on bare-metal MCUs. Not for the DMA stream itself: use dma-baremetal.
日本語の概要は準備中です。原文の説明を表示しています。
Use when creating AF_XDP sockets, configuring UMEM and XSK rings, writing an XDP redirect program, or choosing copy versus zero-copy mode. Not for full kernel bypass: use dpdk.
日本語の概要は準備中です。原文の説明を表示しています。
Use when a completed session needs an agent-environment retrospective. Not for an engineering retrospective from telemetry: use engineering-retrospective.
日本語の概要は準備中です。原文の説明を表示しています。
Use when a redacted, trimmed agent transcript must be appended to a GitHub PR or issue body, with human approval and preview. Not for automated or model-initiated insertion.
日本語の概要は準備中です。原文の説明を表示しています。
Use when a repo needs agent setup, AGENTS.md added or made lean, CLAUDE.md audited, or agent instructions scored or pruned. Not for remote, credential, publish, deploy, or irreversible changes.
日本語の概要は準備中です。原文の説明を表示しています。