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

Support for excluding rust compiler_builtin from staticlib #431

Closed
Andarwinux opened this issue Dec 24, 2024 · 3 comments
Closed

Support for excluding rust compiler_builtin from staticlib #431

Andarwinux opened this issue Dec 24, 2024 · 3 comments

Comments

@Andarwinux
Copy link

Andarwinux commented Dec 24, 2024

Some targets use llvm's compiler-rt by default, in which case cargo-c should exclude rust's compiler-rt from staticlib in order to use what the C toolchain provides. Otherwise it will increase the size or cause symbol conflicts.

Here's one way to hack it, but it's ugly.

llvm-ar t staticlib.a | grep '^compiler_builtins.*\.o$' | xargs -I {} llvm-ar d staticlib.a {}
@lu-zero
Copy link
Owner

lu-zero commented Dec 24, 2024

Could you please provide more information? which are the targets? is there a rustc and cargo issue for the problem? Staticlibs are produced by rustc using its provided information.

@Andarwinux
Copy link
Author

Hi, the target is x86_64-pc-windows-gnullvm.

I noticed when building libdovi with -Zbuild-std and -Clinker-plugin-lto -Ccodegen-units=1 that there is still a non-LTO bitcode object compiler_builtins-e758a9b796fd24a6.compiler_builtins.45bebbe1a3522e0e-cgu.0.rcgu.o inside libdovi.a that defines some of the same symbols as libclang-rt.builtins.a.

Some old issues mentioned that this would cause symbol conflicts, but I did not encounter such a phenomenon. After searching, I found that for my platform, rustc has defined all compiler_builtins symbols as weak symbols to avoid conflicts, but if I use llvm-ar to remove compiler_builtins from libdovi.a, I can still link it and the final exe/dll becomes smaller.

@Andarwinux Andarwinux changed the title Support for excluding rust compiler_builtin and unwind from staticlib Support for excluding rust compiler_builtin from staticlib Dec 25, 2024
@lu-zero
Copy link
Owner

lu-zero commented Dec 25, 2024

you can tell the final linker invocation to gc what's redundant, but this is an issue for rustc to solve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants