-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
External linker arguments should be topologically ordered #12287
Comments
Nominating. |
I have worried about this in the past, and right now we use a |
Hm, I'm actually not sure that there is a bug here, but I'm not quite sure why. When passing libraries to the linker, we currently pass this ordering of arguments (left to right on the command line):
This means that if you have a native library like #[link(name = "sqlite3")] // shows up first on the command line
#[link(name = "c")] // shows up next
extern {} With this, everything is ok. What I don't understand is how a nondeterministic ordering of upstream crates doesn't cause problems. For example, I have this setup: // a.c
void a() {}
// b.c
extern void a();
void b() { a(); }
// c.c
extern void b();
int main() { b(); } When compiled, it yields problems:
Naturally, // a.rs
fn foo() {}
// b.rs
extern mod a;
fn foo() { a::foo(); }
// c.rs
extern mod a;
extern mod b;
fn main() { b::foo(); } Now when we compile, we get no errors!
Notice how All-in-all it looks like there is actually no bug today, although I don't understand why there isn't a bug? |
Related to #11124? |
"This is just a bug." Assigning P-low, not assigning to 1.0 milestone. |
I forgot to close this at the time, but this is closed by 17ad504 |
Add lint `manual_inspect` fixes rust-lang#12250 A great example of a lint that sounds super simple, but has a pile of edge cases. ---- changelog: Add lint `manual_inspect`
Simple example:
When compiled with
rustc a.rs && rustc -L. b.rs && rustc -L. c.rs
, this obviously results in the linker error, but multiple trials reveal the random order of-laaa
and-lbbb
. Iflibbbb.a
depends onlibaaa.a
then-laaa
should be put before-lbbb
; the current behavior is not acceptable for the purpose of FFI.Some practical problem caused by this issue: If the external library (say,
-lsqlite3
) depends on libc (-lc
) and the binding crate for that library is compiled as rlib, then the executable crate using those library and crate will randomly fail to link since we no longer implicitly link to-lc
(#12205) and thus the order of-lc
and-lsqlite3
is random. (We do still have-lc
since libstd depends on libc.)The text was updated successfully, but these errors were encountered: