Skip to content

Rustc build doesn't pass RUSTFLAGS "-L native=/path" to linker commands with -lffi #48409

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

Closed
apaprocki opened this issue Feb 21, 2018 · 3 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.

Comments

@apaprocki
Copy link

Carried over from rust-lang/cargo#4452 per @alexcrichton

I have libffi in a non-standard location. I set RUSTFLAGS to contain -L native=/path when building rustc itself. Cargo passes this -L path when compiling individual objects, but does not pass the -L path when attempting to link anything that also gets -lffi on the linker command line. The end result is that the link fails because -lffi can't be found.

edit: I worked around this by making a wrapper to gcc that passes the -L rule and passing it as the --default-linker option.

Example breakage, when RUSTFLAGS has -L native=/path:

Build failed, waiting for other jobs to finish...
error: Could not compile pulldown-cmark.

Caused by:
process didn't exit successfully: /dev/shm/rustc-1.19.0-src/build/bootstrap/debug/rustc --crate-name build_script_build /dev/shm/rust-1.19/debian/cargo_home/registry/src/github.com-1ecc6299db9ec823/pulldown-cmark-0.0.14/build.rs --error-format json --crate-type bin --emit=dep-info,link -C opt-level=2 -C metadata=94247588bee65632 -C extra-filename=-94247588bee65632 --out-dir /dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/pulldown-cmark-94247588bee65632 -L dependency=/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps --cap-lints allow (exit code: 101)
--- stderr
error: linking with gcc failed: exit code: 1
|
= note: "gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/pulldown-cmark-94247588bee65632/build_script_build-94247588bee65632.0.o" "-o" "/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/release/build/pulldown-cmark-94247588bee65632/build_script_build-94247588bee65632" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1-rustc/release/deps" "-L" "/dev/shm/rustc-1.19.0-src/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" <a bunch of .rlib files> "-Wl,-Bdynamic" "-l" "ffi" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "ffi" "-l" "ffi" "-l" "ffi" "-l" "ffi" "-l" "ffi" "-l" "ffi" "-l" "gcc_s" "-l" "ffi" "-l" "ffi" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util" "-l" "ffi" "-l" "ffi"
= note: ld: cannot find -lffi
collect2: error: ld returned 1 exit status

@apaprocki
Copy link
Author

(Even though that output was generated against rust 1.19, I verified the same thing happens with the current 1.24 release)

@cuviper
Copy link
Member

cuviper commented Feb 21, 2018

This reminds me of #40717, where we found that -lfoo args are remembered by crates, but not -Lpath.

@pietroalbini pietroalbini added A-linkage Area: linking into static, shared libraries and binaries T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 27, 2018
@Enselic Enselic added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Oct 2, 2023
@jackh726
Copy link
Member

I'm going to close this since there is no clear reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-cargo Relevant to the cargo team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants