linkers-lto
Master linker selection, essential flags, and link-order resolution for GNU ld, gold, and lld. Learn to enable LTO with GCC or Clang, strip dead code with --gc-sections, and debug common linker errors like undefined symbols and circular dependencies.
Linkers and LTO helps you resolve undefined reference errors, fix link-order issues, and safely enable link-time optimization in your projects.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-06-27
Linkers and LTO helps you resolve undefined reference errors, fix link-order issues, and safely enable link-time optimization in your projects. Master linker selection, essential flags, and link-order resolution for GNU ld, gold, and lld. Learn to enable LTO with GCC or Clang, strip dead code with --gc-sections, and debug common linker errors like undefined symbols and circular dependencies.
Use it when
- linkers-lto addresses undefined reference errors by teaching link-order resolution and proper library linking.
- linkers-lto shows how to enable full or thin LTO for production builds.
Verify before relying
Read SKILL.md below before installing (2 files). Open directory: indexed for reading, not audited.
Install
mohitmishra786/low-level-dev-skills/linkers-lto · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What does linkers-lto cover?
linkers-lto teaches you how to master linker selection, essential flags, and link-order resolution for GNU ld, gold, and lld. You'll learn to enable LTO with GCC or Clang, strip dead code with --gc-sections, and debug common linker errors like undefined symbols and circular dependencies.
How do I fix an undefined reference linker error?
linkers-lto addresses undefined reference errors by teaching link-order resolution and proper library linking. Common causes include incorrect library order (libraries must come after object files that use them), missing libraries, or circular dependencies. Use -Wl,--start-group and -Wl,--end-group to handle circular deps, and check your linker map file to verify symbol resolution.
How do I enable LTO in my C++ project?
linkers-lto shows how to enable full or thin LTO for production builds. Add -flto to both compilation and linking flags with GCC or Clang. For thin LTO (faster), use -flto=thin. When using archives, use gcc-ar and gcc-ranlib instead of standard ar and ranlib to preserve LTO metadata. Enable LTO consistently across all object files and libraries.
Which linker is fastest: gcc ld, gold, or lld?
linkers-lto covers choosing and configuring the right linker for your needs. GNU ld is the default but slower; gold is faster for large projects; lld is the fastest modern option. Select gold with -fuse-ld=gold or lld with -fuse-ld=lld. Performance depends on project size and complexity, so benchmark your specific build to decide.
How can I reduce binary size with gc-sections?
linkers-lto teaches dead-code stripping via section garbage collection. Compile with -ffunction-sections -fdata-sections to place each function and data item in its own section, then link with -Wl,--gc-sections to remove unused sections. This significantly reduces binary size in production builds by eliminating unreachable code and unused data.
What are the trade-offs of link time optimization?
linkers-lto explains LTO trade-offs for informed production decisions. LTO enables whole-program optimization and better dead-code elimination, improving performance and reducing size. However, it increases compilation time substantially and requires more memory during linking. Thin LTO offers a middle ground with faster builds than full LTO but less optimization.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Linkers and LTO
Purpose
Guide agents through linker selection, common linker flags, link-order issues, LTO setup, and symbol-visibility management.
Triggers
- "I'm getting
undefined referenceat link time" - "How do I enable LTO for a real project?"
- "Which linker should I use: ld, gold, or lld?"
- "How do I reduce binary size with
--gc-sections?" - "How do I write or understand a linker script?"
- "I have duplicate symbol or weak symbol issues"
Workflow
1. Linker selection
| Linker | Invocation | Strengths |
|---|---|---|
| GNU ld (BFD) | default on Linux | Universal, stable |
| gold | -fuse-ld=gold |
Faster than ld for C++; supports LTO plugins |
| lld (LLVM) | -fuse-ld=lld |
Fastest, parallel, required |
(truncated - see the full file via the links below)
File tree — 2 files
skills/binaries/linkers-lto/SKILL.md
skills/binaries/linkers-lto/references/flags.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Resolve undefined reference and link-order errors at link time”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Master Clang's superior diagnostics, optimization remarks, and static analysis capabilities. Learn to interpret inlining and vectorization decisions, configure clang-tidy for automated checks, and leverage ThinLTO for faster builds with comparable code quality.
Master GCC flag selection for debug and release builds, from optimization levels and warning discipline to link-time optimization and profile-guided optimization. Covers common compilation errors, sanitizer instrumentation, and integration with GNU Make and CMake.
Master Linux shared library fundamentals: create position-independent libraries with proper soname versioning, embed search paths using RPATH or RUNPATH, and debug loading failures with LD_DEBUG and ldd. Build plugin systems with dlopen/dlsym, intercept functions via LD_PRELOAD, and control symbol visibility to reduce binary bloat and namespace collisions.
Dive into compiler internals: understand why loops fail to vectorize, how register pressure causes spills, and when to deploy PGO or BOLT. Covers mid-level IR optimizations, instruction selection, and post-link optimization strategies with practical triage workflows.
Binary Hardening guides you through applying and validating security protections for C/C++ executables. Learn compiler and linker flags for RELRO, PIE, stack canaries, FORTIFY_SOURCE, and CFI, plus seccomp-bpf syscall filtering and hardware defenses like Intel CET and ARM BTI. Use checksec to audit existing binaries and confirm mitigations are in place.
Binutils guides you through GNU's binary manipulation toolkit for static library management, debug info handling, address-to-source mapping, and symbol demangling. Master ar for archives, strip and objcopy for binary processing, addr2line for crash analysis, and c++filt for C++ symbol names.
More skills elf-inspection (MIT) · dwarf-debug-format (MIT) · msvc-cl (MIT)