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

Pass -lfoo to linker rather than -l foo. #51197

Closed
wants to merge 2 commits into from
Closed

Conversation

comex
Copy link
Contributor

@comex comex commented May 30, 2018

When invoking the linker and trying to link against a specific library, rustc currently passes -l foo as two separate arguments, rather than the more common syntax -lfoo. GCC, Clang, and GNU ld all support -l foo, but Darwin ld64 does not. By default, rustc currently uses the C compiler as its linker on all platforms (other than wasm), so it passes -l foo to clang, which then transforms it to -lfoo when invoking ld. However, if you try to pass -C linker=ld – or, more usefully, -C linker=ld64.lld – it gets confused. Since -lfoo is the preferred form on all Unix platforms, use it everywhere.

As a side benefit, this makes printed linker command lines significantly more succinct, given that rustc wraps every argument in quotes, so you currently get things like "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m". (Of course, this could be improved further by omitting the quotes entirely for arguments that don't contain spaces.)

This PR is simply a plagiarized subset of PR #46255, written by tamird, which @alexcrichton requested to be deferred until #48125 landed – something that's since happened. Actually, everything in that PR seems necessary for linking using ld64 directly to work properly, but since I'm not the original author, I'm too lazy to convince myself that it's all correct. Landing this by itself will at least make some basic cases work.

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 30, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/40/7b/dd2e1823627f38afb7e92e4e9792d81902c084ab7501c1f748169a5336ae/awscli-1.15.29-py2.py3-none-any.whl (1.3MB)
    0% |▎                               | 10kB 15.9MB/s eta 0:00:01
    1% |▌                               | 20kB 2.0MB/s eta 0:00:01
    2% |▉                               | 30kB 2.2MB/s eta 0:00:01
    3% |█                               | 40kB 2.1MB/s eta 0:00:01
---
[00:22:01]    Compiling std_unicode v0.0.0 (file:///checkout/src/libstd_unicode)
[00:22:02]    Compiling alloc_system v0.0.0 (file:///checkout/src/liballoc_system)
[00:22:03]    Compiling panic_abort v0.0.0 (file:///checkout/src/libpanic_abort)
[00:22:07]    Compiling panic_unwind v0.0.0 (file:///checkout/src/libpanic_unwind)
[00:22:19] error: linking with `cc` failed: exit code: 1
[00:22:19]   |
[00:22:19]   = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std0.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std1.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std10.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std11.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std12.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std13.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std14.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std15.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std2.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std3.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std4.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std5.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std6.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std7.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std8.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.std9.rcgu.o" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libstd-430d82d27c15fbbd.so" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.crate.metadata.rcgu.o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/std-430d82d27c15fbbd.crate.allocator.rcgu.o" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/native/libbacktrace/.libs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/build/compiler_builtins-57f7f72e03e89590/out" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/native/jemalloc/lib" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "backtrace" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/libpanic_unwind-0378392a13a013d5.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/liballoc_jemalloc-f7f30cbcf05fe7bc.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/libunwind-2203fa4844a0f487.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/liballoc_system-483973df02b77c30.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/liblibc-0ad5cdeabe892bcd.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/liballoc-629be8a8a92e38ff.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-l/tmp/rustc.LJIvzsTtHWg4/libcore-e3f2b558276b578b.rlib" "-Wl,--no-whole-archive" "/tmp/rustc.LJIvzsTtHWg4/libcompiler_builtins-d5d59b383a13b958.rlib" "-Wl,-Bdynamic" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil" "-shared" "-Wl,-rpath,$ORIGIN/../lib"
[00:22:19]   = note: /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/libpanic_unwind-0378392a13a013d5.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/liballoc_jemalloc-f7f30cbcf05fe7bc.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/libunwind-2203fa4844a0f487.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/liballoc_system-483973df02b77c30.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/liblibc-0ad5cdeabe892bcd.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/liballoc-629be8a8a92e38ff.rlib
[00:22:19]           /usr/bin/ld: cannot find -l/tmp/rustc.LJIvzsTtHWg4/libcore-e3f2b558276b578b.rlib
[00:22:19]           collect2: error: ld returned 1 exit status
[00:22:19] 
[00:22:19] error: aborting due to previous error
[00:22:19] 
[00:22:19] error: Could not compile `std`.
[00:22:19] error: Could not compile `std`.
[00:22:19] 
[00:22:19] Caused by:
[00:22:19]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name std libstd/lib.rs --color always --error-format json --crate-type dylib --crate-type rlib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 --cfg feature="alloc_jemalloc" --cfg feature="backtrace" --cfg feature="jemalloc" --cfg feature="panic-unwind" --cfg feature="panic_unwind" -C metadata=430d82d27c15fbbd -C extra-filename=-430d82d27c15fbbd --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libunwind-2203fa4844a0f487.rlib --extern compiler_builtins=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-d5d59b383a13b958.rlib --extern panic_unwind=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_unwind-0378392a13a013d5.rlib --extern rustc_asan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_asan-4db49b0dd85e1242.rlib --extern rustc_lsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_lsan-8938a0cc67c74121.rlib --extern panic_abort=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libpanic_abort-522278e9531b34c2.rlib --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liblibc-0ad5cdeabe892bcd.rlib --extern core=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-e3f2b558276b578b.rlib --extern alloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc-629be8a8a92e38ff.rlib --extern std_unicode=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libstd_unicode-8e07d23216ec47d8.rlib --extern rustc_msan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_msan-2fe78b695d4e7490.rlib --extern rustc_tsan=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/librustc_tsan-f51125d56cedaaa5.rlib --extern alloc_jemalloc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_jemalloc-f7f30cbcf05fe7bc.rlib --extern alloc_system=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/liballoc_system-483973df02b77c30.rlib -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/libbacktrace/.libs -l static=backtrace -l dl -l rt -l pthread -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/build/compiler_builtins-57f7f72e03e89590/out -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/native/jemalloc/lib` (exit code: 101)
[00:22:19] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:22:19] travis_fold:end:stage1-std


[00:22:19] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1091:9

[00:22:19] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:22:19] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:22:19] Build completed unsuccessfully in 0:17:24
[00:22:19] Build completed unsuccessfully in 0:17:24
[00:22:19] make: *** [all] Error 1
[00:22:19] Makefile:28: recipe for target 'all' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0632f030
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@comex
Copy link
Contributor Author

comex commented May 30, 2018

Whoops, I got two similar lines of code mixed up and changed the wrong one. Fixed.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:21:18]    Compiling build_helper v0.1.0 (file:///checkout/src/build_helper)
[00:21:18]    Compiling rustc_codegen_llvm v0.0.0 (file:///checkout/src/librustc_codegen_llvm)
[00:21:18]    Compiling cc v1.0.15
[00:21:19]    Compiling rustc_llvm v0.0.0 (file:///checkout/src/librustc_llvm)
[00:21:28] error[E0283]: type annotations required: cannot resolve `str: std::convert::AsRef<_>`
[00:21:28]    --> librustc_codegen_llvm/back/linker.rs:164:21
[00:21:28]     |
[00:21:28] 164 |         os.push(lib.as_ref());
[00:21:28] 
[00:21:28] 
 --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-ac6d20f88773f905.so --extern tempdir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libtempdir-29f7cb771c179438.rlib --extern jobserver=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libjobserver-e8a1df2f3ad631bc.rlib --extern rustc_target=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_target-58741ed9de9aae4f.so --extern rustc_platform_intrinsics=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_platform_intrinsics-584193bd2f2f0208.so --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-4074300b8e2af006.so --extern rustc_llvm=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_llvm-03cd04183e7fa779.rlib --extern libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblibc-54cee618814524ce.rlib --extern rustc_allocator=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_allocator-ca7321e9b3ae1aa8.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-5073f1296cd24b67.rlib -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-62d80197b9ec531e/out -Ltravis_time:start:0f5bcf98
[   11.022072] init: failsafe main process (1093) killed by TERM signal
travis_time:end:0f5bcf98:start=1527646904943453220,finish=1527646904960437869,duration=16984649
travis_fold:end:after_failure.4

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@shepmaster
Copy link
Member

Ping from triage, @michaelwoerister !

@michaelwoerister
Copy link
Member

Looks good but seems to have compilation errors still.

@shepmaster shepmaster added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 2, 2018
@TimNN
Copy link
Contributor

TimNN commented Jun 12, 2018

@comex, This PR failed travis, do you think you'll be able to look into that?

@pietroalbini
Copy link
Member

Thank you for this PR @comex! Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again!

@pietroalbini pietroalbini added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants