Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC: support LTCG native libraries in rlibs #26003

Open
alexcrichton opened this issue Jun 4, 2015 · 3 comments
Open

MSVC: support LTCG native libraries in rlibs #26003

alexcrichton opened this issue Jun 4, 2015 · 3 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. O-windows-msvc Toolchain: MSVC, Operating system: Windows

Comments

@alexcrichton
Copy link
Member

MSVC supports the option to compile native libraries with link-time code generation enabled via the /GL switch to the compiler. This cause the compiler to change the format of the *.obj file emitted to no longer be a COFF object file. When MSVC's lib.exe tool is used to assemble these object files into a .lib, it will correctly detect that these are LTCG-enabled files, adding an appropriate symbol table to the archive being generated. This means that when the linker comes along to link the library, the internal symbol table of the archive points at the LTCG files, allowing the linker to find where symbols are and also produce object files on-the-fly.

With rustc, however, the symbol tables for LTCG files can be lost. Whenever a native library is included statically into an rlib, the objects are extracted by the compiler and then re-inserted into an rlib. This operation loses the entries in the symbol table of the rlib (LLVM doesn't understand the format of the file being inserted), causing the linker to later on ignore all LTCG enabled files.

Long story short, if a LTCG enabled C library is linked statically into an rlib, the linker will not resolve any of the symbols in the C library. This means that all native code linked statically to rlibs cannot have LTCG enabled, and this is occasionally somewhat difficult to retrofit on existing build systems.

Fixing this will involve improving the merging process of two archives, probably just blindly carrying over the symbol table from one archive to another (at least on MSVC). I'm not sure what the best route to do this is, but our options are:

  • Add support to llvm-ar.exe to do this.
  • Split apart llvm-ar.cpp into a library-like interface, and then rewrite the "driver" in rustc itself
  • Port llvm-ar.exe to Rust, and do everything in Rust

The latter two options have the great benefit of lifting the compiler's dependence on an ar tool, which would be nice!

@alexcrichton alexcrichton added O-windows Operating system: Windows E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-tools labels Jun 4, 2015
@retep998
Copy link
Member

retep998 commented Jul 7, 2015

Now I'm wondering if a library built by cl.exe has PDB data, will llvm-ar.exe properly carry forward that debug info?

@retep998
Copy link
Member

As a workaround, instead of using kind=static, consider using the recently implemented kind=static-nobundle. This way the library is passed directly to the linker (instead of being mangled by rustc) bypassing this issue entirely.

@steveklabnik
Copy link
Member

Triage: not aware of any changes here.

@wesleywiser wesleywiser added O-windows-msvc Toolchain: MSVC, Operating system: Windows and removed O-windows Operating system: Windows labels Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. O-windows-msvc Toolchain: MSVC, Operating system: Windows
Projects
None yet
Development

No branches or pull requests

5 participants