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

Static Library with LTO option not working properly #91624

Open
sijupunnnoose opened this issue Dec 7, 2021 · 2 comments
Open

Static Library with LTO option not working properly #91624

sijupunnnoose opened this issue Dec 7, 2021 · 2 comments
Labels
A-lto Area: Link Time Optimization

Comments

@sijupunnnoose
Copy link

Greatings!!

We are facing a strange issue while building rust static library with "-Clinker-plugin-lto". On linking the generated library to C base results in linker error as below.

Fatal error: L6120U: Member mylibv7a.mylibv7a.e0989cce-cgu.0.rcgu.o in library libmylibv7a.so cannot be loaded. It is an LLVM bitcode file but the linker only accepts bitcode wrapped in an ELF object file.

When we checked more it is observed that the ELF header is corrupted in generated library.

arm-none-eabi-readelf -a liblib.a >test.out
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

Additional Details:
rustc --version
rustc 1.57.0 (f1edd04 2021-11-29)

Build command:
rustc -Clinker-plugin-lto --crate-type=staticlib src/lib.rs --target=armv7a-none-eabi

Looks like this issue is there with all targets, kindly please look into this issue on priority and suggest us a fix to resolve it.

Thanks
Siju

@bjorn3
Copy link
Member

bjorn3 commented Dec 7, 2021

How exactly are you invoking the linker? Do you use clang -flto=thin -fuse-ld=lld for this? Are you using a clang version matching the LLVM version used by rustc?

When we checked more it is observed that the ELF header is corrupted in generated library.

It isn't corrupted. Readelf is made for elf files, not llvm bitcode files.

For reference https://doc.rust-lang.org/rustc/linker-plugin-lto.html has instructions on how to use linker plugin LTO.

@bjorn3 bjorn3 added the A-lto Area: Link Time Optimization label Dec 7, 2021
@sijupunnnoose
Copy link
Author

Below error is when we use Arm DS5 toolchain.
Fatal error: L6120U: Member mylibv7a.mylibv7a.e0989cce-cgu.0.rcgu.o in library libmylibv7a.so cannot be loaded. It is an LLVM bitcode file but the linker only accepts bitcode wrapped in an ELF object file.

LLVM version is 13.0 for both Rust version 1.56.0 and Arm DS5 tool chain.

Why I said the llvm bitcode file is corrupted is due to the fact that ELF wrapping of first object file in object entries is only missing, remain all object files in it is properly wrapped.

https://llvm.org/docs/BitCodeFormat.html Section: Native Object File Wrapper Format
readelf could read any elf file even the wrapped, however it may not be able read the rest of the llvm bitcode.

Here in this case generated lib is corrupted and hence its not able to read it, same in case of DS5.

Also my local sample program, builds with arm-none-eabi, its the same error there also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lto Area: Link Time Optimization
Projects
None yet
Development

No branches or pull requests

2 participants