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

building for older linkers #379

Open
asalwa opened this issue Sep 30, 2019 · 4 comments
Open

building for older linkers #379

asalwa opened this issue Sep 30, 2019 · 4 comments
Labels
triage-2024-keep Issues triaged in 2024 and considered OK to keep open

Comments

@asalwa
Copy link

asalwa commented Sep 30, 2019

I was trying to use embedded Rust for the first time in some real-life environment. I want to link my library written in Rust to existing C/C++ application.
It uses quite old GNU toolchain (GNU ld 2.25, dated 2015), and toolchain choice is out of my control.
So I build my library with:

  • --target armv7r-none-eabi
  • crate-type = ["staticlib"]
  • #![no_std]

I exported one function with no_mangle and extern "C".

I got my libhello_cargo.a and told that old linker to consume it.
But it complains about EABI:
Source object libhello_cargo.a(modsi3.o) has EABI version 5, but target <my_existing_project>.o has EABI version 0
So I added --no-warn-mismatch to see what will happen. No big surprise, it complains further about relocation size mismatch in object files inside my library.

With some dirty hacks I'm able to link my single function (as long as it is not using floating point, to avoid linking problems with compiler builtins) to my executable and run it. But it was ugly, not acceptable - I ripped single, stripped .o file from my library and passed it to my linker.

So what I'm asking for is some way to tell Rust toolchain to generate static library suitable for linking with older EABI/toolchains.

I understand that Rust is modern tool, based on recent LLVM, etc. But here is where it meets real life legacy application and some real life ugly limitations :)

Most likely there is no simple quick answer, but I hope it will trigger some discussion what can be done about it.

@RaphaelIsler
Copy link

i run in the same issue. LLVM supports old EABI version

https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-meabi

Is it possibly, to define clang options direct? => rust-lang/rust#26338

@BartMassey BartMassey added the triage-2024-keep Issues triaged in 2024 and considered OK to keep open label Jun 11, 2024
@Oneliness
Copy link

@asalwa same issue here, did you find any solution to this problem? thanks a lot

@BartMassey
Copy link
Member

BartMassey commented Aug 24, 2024

You can say

rustc --crate-type=staticlib --emit=obj

to get rustc to emit a .o directly. See https://github.com/pdx-cs-rust/mixy for a worked example.

I haven't tried it except on x86, but it looks like -C llvm-args=--meabi=0 will get you an EABI 0 object file if LLVM supports that EABI.

@BartMassey
Copy link
Member

(Just pushed some updates to https://github.com/pdx-cs-rust/mixy to clean up some cruft.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-2024-keep Issues triaged in 2024 and considered OK to keep open
Projects
None yet
Development

No branches or pull requests

4 participants