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

Question: whose responsibility is it to provide builtins used by C code? #217

Closed
parched opened this issue Dec 12, 2017 · 9 comments
Closed

Comments

@parched
Copy link
Contributor

parched commented Dec 12, 2017

If you link some C code into your rust executable (e.g., libc) and that code uses some builtins that aren't needed by Rust (e.g., long double builtins), whose responsibility is it to provide them? This crate or something else?

In other words, should this crate provide C builtins or, if the target is linker_flavour is gcc or ld, should libgcc be added to the list of things linked?

CC @alexcrichton @japaric

Related #201

@alexcrichton
Copy link
Member

I'd personally expect these to come from libgcc, not compiler-builtins. This crate is in general targeted only at Rust's needs, not C's.

@Amanieu
Copy link
Member

Amanieu commented Dec 13, 2017

In the case of #201, the musl libc is shipped as part of the compiler. In that case it should be the responsibility of the compiler to provide the necessary symbols for linking the provided libc. I agree with alex though, this should be done by linking in libgcc or libcompiler-rt.

@parched
Copy link
Contributor Author

parched commented Dec 13, 2017

Ok, so rustc should add libgcc to the linker commandline for all targets that use gcc or ld linker flavor?

What happens when someone wants to use compiler-rt instead, do we add a flag to rustc allowing the user to specify the c-builtins library, if and when that is needed?

@alexcrichton
Copy link
Member

I don't personally think that rustc should do this, but rather a user should explicitly request libgcc.

@parched
Copy link
Contributor Author

parched commented Dec 13, 2017

@alexcrichton Do you mean via #[link(name = gcc)] or RUSTFLAGS? It's really just a coincidence that every (std) rust executable doesn't need libgcc because all the libcs support long double.

@alexcrichton
Copy link
Member

Yeah that's what I'd personally expect.

@Amanieu
Copy link
Member

Amanieu commented Dec 13, 2017

An alternative could be to add the libgcc dependency to the libc crate.

bors added a commit to rust-lang/libc that referenced this issue Jul 9, 2018
Link to libgcc when statically linking musl

On some architectures (e.g. aarch64) musl depends on some libgcc functions (`__addtf3`, `__multf3`, `__subtf3`) for `long double` arithmetic that it uses internally. Unfortunately we don't provide these functions in compiler-builtins, so we instead need to get them from libgcc.

Fixes:
rust-lang/rust#46651
rust-lang/compiler-builtins#201
rust-lang/compiler-builtins#217
@Amanieu
Copy link
Member

Amanieu commented Jul 9, 2018

I think this is resolved by rust-lang/libc#1034.

We will link to libgcc when we provide a statically linked libc as part of the libc crate (musl), but otherwise leave it to the dynamic linker to find libgcc.so if it is required by libc.so.

@alexcrichton
Copy link
Member

👍

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

3 participants