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

rustbuild: Support specifying archiver and linker explicitly #45191

Merged
merged 3 commits into from Oct 16, 2017

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Oct 10, 2017

With this patch x.py test passes without toolchain being in PATH if cc, cxx, ar, linker and gdb are specified in config.toml (except for a few run-make tests using nm).

Fixes #41821
r? @Mark-Simulacrum

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me pending review of the base PR, at least in terms of logic seeming sound. Not familiar enough with linkers and such to judge that part, but if it works, I'm happy with it.

.env("CFG_RELEASE_CHANNEL", &self.build.config.channel)
.env("RUSTDOC_REAL", self.rustdoc(host));
if let Some(linker) = self.build.linker(host) {
cmd.arg("--linker").arg(linker).arg("-Z").arg("unstable-options");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer this logic to be in src/bin/rustdoc.rs and we can just set RUSTDOC_LINKER here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this could actually solve the issue with doctests as well if I understand correctly.

@aidanhs aidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2017
@petrochenkov
Copy link
Contributor Author

To give some background, I need to build Rust on a Linux server 1) using specific toolchain that is not in PATH 2) that toolchain has c++, but doesn't have cc (only gcc) and doesn't have ar (only gar and gcc-ar wrapper) 3) there's another toolchain in PATH, but it's ancient and unusable.

Without this patch my workaround looks roughly like this (in shell pseudocode):

mkdir my_toolchain
ln -s actual_toolchain/gcc my_toolchain/cc
ln -s actual_toolchain/gar my_toolchain/ar
export PATH=my_toolchain:actual_toolchain:$PATH
./x.py build

Even ignoring ar, setting export CC=gcc (or cc = gcc in config.toml) is not enough because rustc will still attempt to use cc for linking Rust code and fail.

@bors
Copy link
Contributor

bors commented Oct 13, 2017

☔ The latest upstream changes (presumably #45233) made this pull request unmergeable. Please resolve the merge conflicts.

@kennytm kennytm 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 Oct 14, 2017
@petrochenkov
Copy link
Contributor Author

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Oct 14, 2017

📌 Commit 399ff29 has been approved by Mark-Simulacrum

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 14, 2017
@bors
Copy link
Contributor

bors commented Oct 15, 2017

⌛ Testing commit 399ff290c65df4a0f0381436a67c18b17f456fbc with merge 05c72874fef283a9dd41b2337b3cbef0e74404d5...

@bors
Copy link
Contributor

bors commented Oct 15, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Oct 15, 2017

Failed to find the symbol res_init in dist-x86_64-musl when building stage2-std (gnu → musl), legit. (needs to link to libresolv?)

[00:42:45] error: linking with `/musl-x86_64/bin/musl-gcc` failed: exit code: 1
[00:42:45]   |
[00:42:45]   = note: "/musl-x86_64/bin/musl-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/release/build/unwind-4fb8ab0cb26a92ad/build_script_build-4fb8ab0cb26a92ad.0.o" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/release/build/unwind-4fb8ab0cb26a92ad/build_script_build-4fb8ab0cb26a92ad" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/release/build/unwind-4fb8ab0cb26a92ad/build_script_build-4fb8ab0cb26a92ad.crate.allocator.o" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-std/release/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ee965bf30dd84348.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-11d028a4b5a1ee6a.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-2e20520a7c184bee.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-ea2f43e1e71cad7c.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-bb8002df75b7c03d.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-d5bdce442262816c.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-74bec6c5a1a4a26e.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-dbb735482143346f.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-646edc526b22cddf.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-beef29bda9c153db.rlib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-1a1fb4116f61f74c.rlib" "-Wl,-Bdynamic" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util"
[00:42:45]   = note: /usr/bin/ld: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-ee965bf30dd84348.rlib(std-ee965bf30dd84348.0.o): undefined reference to symbol '__res_init@@GLIBC_2.2.5'
[00:42:45]           //lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
[00:42:45]           collect2: error: ld returned 1 exit status
[00:42:45]           
[00:42:45] 
[00:42:45] error: aborting due to previous error
[00:42:45] 
[00:42:45] error: Could not compile `unwind`.

@kennytm kennytm 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 15, 2017
@bors
Copy link
Contributor

bors commented Oct 15, 2017

☔ The latest upstream changes (presumably #45224) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov
Copy link
Contributor Author

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Oct 15, 2017

📌 Commit 89d9ce4 has been approved by Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Oct 15, 2017

⌛ Testing commit 89d9ce4 with merge c09beac4654260fd53eb18db449229e7bb9c8385...

@bors
Copy link
Contributor

bors commented Oct 15, 2017

💔 Test failed - status-travis

@petrochenkov
Copy link
Contributor Author

Oops, that was silly.
@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Oct 16, 2017

📌 Commit 0577b60 has been approved by Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Oct 16, 2017

⌛ Testing commit 0577b60 with merge 9223c39...

bors added a commit that referenced this pull request Oct 16, 2017
rustbuild: Support specifying archiver and linker explicitly

With this patch `x.py test` passes without toolchain being in `PATH` if `cc`, `cxx`, `ar`, `linker` and `gdb` are specified in `config.toml` (except for a few `run-make` tests using `nm`).

Fixes #41821
r? @Mark-Simulacrum
@bors
Copy link
Contributor

bors commented Oct 16, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: Mark-Simulacrum
Pushing 9223c39 to master...

@bors bors merged commit 0577b60 into rust-lang:master Oct 16, 2017
o01eg added a commit to o01eg/gentoo-rust that referenced this pull request Oct 17, 2017
cnd added a commit to gentoo/gentoo-rust that referenced this pull request Oct 17, 2017
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 21, 2017
I believe this was forgotten from rust-lang#45191 but hopefully is a simple fix!
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Jan 2, 2018
I believe this was forgotten from rust-lang#45191 but hopefully is a simple fix!
@petrochenkov petrochenkov deleted the yesar branch June 5, 2019 15:56
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 10, 2020
rustbuild: Build tests with LLD if `use-lld = true` was passed

Addresses rust-lang#76127 (comment).

Our test suite is generally ready to run with an explicitly specified linker (rust-lang#45191),
 so LLD specified with `use-lld = true` works as well.

Only 4 tests fail (on `x86_64-pc-windows-msvc`):
```
ui/panic-runtime/lto-unwind.rs
run-make-fulldeps/debug-assertions
run-make-fulldeps/foreign-exceptions
run-make-fulldeps/test-harness
```
All of them are legitimate issues with LLD (or at least with combination Rust+LLD) and manifest in segfaults on access to TLS (rust-lang#76127 (comment)). UPD: These issues are caused by rust-lang#72145 and appear because I had `-Ctarget-cpu=native` set.

UPD: Further commits build tests with LLD for non-MSVC targets and propagate LLD to more places when `use-lld` is enabled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants