You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
redundant linker flag warning is wrong and breaks linking #47989
If one passes the same -lfoo option twice to rustc it warns redundant linker flag specified for library `foo` and ignores the second argument. Linkers are sensitive to the order of their arguments and passing the same argument twice is common and sometimes necessary to get a program to link correctly.
In fact, rustc itself passes the linker (cleaned up a bit) -ldl -lrt -lpthread -lpthread -lgcc_s -lc -lm -lrt -lpthread -lutil -lutil, which includes four "redundant" linker flags (at least two of which are actually redundant, to be fair).
This is somewhat not trivial to fix as we don't know whether a given -l flag was passed with the purpose of changing the link kind or name, or actually passing the same library twice for linkage. This branch has the initial workings of a viable idea, but it doesn't pass tests.
There are also to an extent some backwards compatibility concerns here.
I was recently bitten by this bug, trying to link multiple internal helper C++ libraries into a Rust executable. I was able to put together a minimal repro: on Linux, one of the subpackages builds successfully, and one gets linker errors, and the only difference between the two is the order in which the helper libraries are built and added to the linker command line.
I wrote up a potential fix in #57018. We'd still remove redundant -l flags from the linker command, but instead of keeping the first one, we'd now keep the last one. The new behavior passes CI, and I've verified (via cargo +local build) that it also fixes all of the linker errors in my repro repo.
Activity
Mark-Simulacrum commentedon Feb 4, 2018
This is somewhat not trivial to fix as we don't know whether a given
-lflag was passed with the purpose of changing the link kind or name, or actually passing the same library twice for linkage. This branch has the initial workings of a viable idea, but it doesn't pass tests.There are also to an extent some backwards compatibility concerns here.
lovesegfault commentedon Oct 11, 2018
Could we perhaps at least add some option to ignore this?
dcreager commentedon Dec 20, 2018
I was recently bitten by this bug, trying to link multiple internal helper C++ libraries into a Rust executable. I was able to put together a minimal repro: on Linux, one of the subpackages builds successfully, and one gets linker errors, and the only difference between the two is the order in which the helper libraries are built and added to the linker command line.
dcreager commentedon Dec 21, 2018
I wrote up a potential fix in #57018. We'd still remove redundant
-lflags from the linker command, but instead of keeping the first one, we'd now keep the last one. The new behavior passes CI, and I've verified (viacargo +local build) that it also fixes all of the linker errors in my repro repo.rohit-136 commentedon Mar 4, 2019
@dcreager It still says "redundant linker flag specified for library stdc++".