GCC LTO objects and system ar archive interoperability
0 reputation · 16 Jun 2020, 00:25 UTC
Goal
Determine whether GCC -flto object files can be archived with the host system's ar and later linked with ld without the GCC LTO plugin, or whether gcc-ar and gcc-ranlib are required for correct symbol-table indexing at the compiler-to-linker boundary.
Constraints and uncertainty
GCC -flto translation units contain GIMPLE intermediate representation rather than final native code. Standard binutils ar and ld may not parse LTO symbol tables unless the GCC linker plugin is loaded. GCC supplies gcc-ar and gcc-ranlib wrappers for this purpose, but the exact behavior when using plain ar varies by GCC major version and target architecture. Mixing LTO and non-LTO objects is supported, yet cross-translation-unit optimization applies only among LTO-compiled units.
Specific questions:
- Does a plain system ar archive index preserve LTO symbols sufficiently for ld to resolve references without gcc-ar?
- If plain ar produces a linkable archive, are cross-TU inlining and interprocedural optimizations still applied during the final link?
- Which GCC major versions and targets require gcc-ar/gcc-ranlib versus tolerating standard binutils tools?