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

rustc -v should print out linker output #38206

Open
jsgf opened this issue Dec 7, 2016 · 15 comments · May be fixed by #119286
Open

rustc -v should print out linker output #38206

jsgf opened this issue Dec 7, 2016 · 15 comments · May be fixed by #119286
Assignees
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-linkage Area: linking into static, shared libraries and binaries C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jsgf
Copy link
Contributor

jsgf commented Dec 7, 2016

If I compile something with rustc -v, it doesn't show the linker invocations or anything else:

$ echo "fn main() {}" > t.rs
$ rustc -v --crate-type bin t.rs
$ ls -l t
-rwxr-xr-x. 1 jsgf users 2052670 Dec  6 17:15 t
@alexcrichton
Copy link
Member

Currently we don't actually print anything on -v other than rustc -h -v has an extended help message. Seems reasonable to me though that we'd extend the output quite a bit (e.g. with linker invocations)

@jsgf
Copy link
Contributor Author

jsgf commented Dec 7, 2016

It used to show the linker command lines. Was dropping that a deliberate decision?

@alexcrichton
Copy link
Member

Oh dear I had no idea that it ever used to emit the linker command line, if that stopped working it's definitely a regression!

@retep998
Copy link
Member

retep998 commented Feb 9, 2017

I'd really appreciate if we printed the output from the linker when using -v as sometimes linkers will print out exceptionally helpful warnings.

@Mark-Simulacrum Mark-Simulacrum changed the title rustc -v is completely silent rustc -v should print out linker output May 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-frontend Area: Compiler frontend (errors, parsing and HIR) label May 22, 2017
@Mark-Simulacrum Mark-Simulacrum added C-feature-request Category: A feature request, i.e: not implemented / a PR. A-linkage Area: linking into static, shared libraries and binaries labels Jul 26, 2017
@Nemikolh
Copy link

I found a way to get the linker output today if you need it now. You can set the RUST_LOG environnement variable to rustc_trans=info. With the nightly rust version I am using, you should see a line that says linker output.

@shepmaster
Copy link
Member

Copying @japaric's useful tip for those of us that need the info before the request is implemented:

FWIW, you can use rustc -Z print-link-args foo.rs to see the linker invocation.

@retep998
Copy link
Member

-Z print-link-args only prints the arguments to the linker, not the output from the linker.

@sevki
Copy link

sevki commented Oct 12, 2019

also...

error: the option `Z` is only accepted on the nightly compiler

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 18, 2019
@12101111
Copy link
Contributor

You can use

export RUSTC_LOG=rustc_codegen_ssa::back::link=info

to get linker command line and stderr+stdout.

example:

RUSTFLAGS="-C link-arg=-Wl,--verbose"

Output:

> export RUSTFLAGS="-C link-arg=-Wl,--verbose"
> export RUSTC_LOG=rustc_codegen_ssa::back::link=info
> cargo build -v
   Compiling hello v0.1.0 (/tmp/hello)
     Running `rustc --crate-name hello --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=45f8637d16581c8f -C extra-filename=-45f8637d16581c8f --out-dir /usr/obj/rust/debug/deps -C incremental=/usr/obj/rust/debug/incremental -L dependency=/usr/obj/rust/debug/deps -C link-arg=-Wl,--verbose`
INFO rustc_codegen_ssa::back::link preparing Executable to "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f"
INFO rustc_codegen_ssa::back::link "cc" "-m64" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-Wl,--as-needed" "-nostartfiles" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o" "-L" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-L" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.12qz3h90flkmctyy.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.18bwyoe3zsankc6h.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.1evuf5tptkdn3v4y.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.1ks010txjl1pix0f.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.23lkiijklf2p4g21.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.38sw7slh52jfxdr3.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.52b1zbprkak691s9.rcgu.o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.5a02jqibtvw5j173.rcgu.o" "-o" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f" "/usr/obj/rust/debug/deps/hello-45f8637d16581c8f.3xix89bijvttq8xf.rcgu.o" "-Wl,--gc-sections" "-static-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/usr/obj/rust/debug/deps" "-L" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-3b4724f13fd9b314.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-8370d68adc8c1b27.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-a8d5199c03b80566.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-64842aa7c220460e.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-193c992b516cb994.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-530bc5c0808f03e3.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-f1e3de972413762a.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-0708ef471f010f9e.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-e0ac20be4751c3d2.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-bfee6cb7e808ec7f.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-b22097ce75ccf616.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-1f58ee4ae7403119.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-4a9ec9bb065104e9.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-683c2ad1ec876f13.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-d5514ba8af77a08c.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-9af05494f0573e1b.rlib" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-60eab00334ec8288.rlib" "-Wl,--end-group" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-7a2a7a2602cba6f5.rlib" "-Wl,--verbose" "-Wl,-Bdynamic" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
INFO rustc_codegen_ssa::back::link linker stderr:
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.12qz3h90flkmctyy.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.18bwyoe3zsankc6h.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.1evuf5tptkdn3v4y.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.1ks010txjl1pix0f.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.23lkiijklf2p4g21.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.38sw7slh52jfxdr3.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.52b1zbprkak691s9.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.5a02jqibtvw5j173.rcgu.o
ld.lld: /usr/obj/rust/debug/deps/hello-45f8637d16581c8f.3xix89bijvttq8xf.rcgu.o
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-3b4724f13fd9b314.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-8370d68adc8c1b27.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-a8d5199c03b80566.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-64842aa7c220460e.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-193c992b516cb994.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-530bc5c0808f03e3.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-f1e3de972413762a.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-0708ef471f010f9e.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-e0ac20be4751c3d2.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-bfee6cb7e808ec7f.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-b22097ce75ccf616.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-1f58ee4ae7403119.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-4a9ec9bb065104e9.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-683c2ad1ec876f13.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-d5514ba8af77a08c.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-9af05494f0573e1b.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-60eab00334ec8288.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-7a2a7a2602cba6f5.rlib
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o
ld.lld: /home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o

INFO rustc_codegen_ssa::back::link linker stdout:

    Finished dev [unoptimized + debuginfo] target(s) in 0.39s

@yanok
Copy link
Contributor

yanok commented Nov 2, 2021

@rustbot claim

@ChrisDenton
Copy link
Member

@yanok are you still working on this?

@yanok
Copy link
Contributor

yanok commented Mar 2, 2022

Yes, I have a commit for this bug. I wasn't happy about it somehow and wanted to do some more but I guess I will make a PR and discuss it with reviewers.

@Tooniis
Copy link

Tooniis commented Jul 31, 2022

Copying @japaric's useful tip for those of us that need the info before the request is implemented:

FWIW, you can use rustc -Z print-link-args foo.rs to see the linker invocation.

Was this removed at some point? because

error: unknown unstable option: `print-link-args`
$ rustc -V
rustc 1.64.0-nightly (0f4bcadb4 2022-07-30)

@ChrisDenton
Copy link
Member

It was stabilized as --print link-args

@keith
Copy link
Contributor

keith commented Nov 30, 2023

It looks like there's a difference in --print link-args vs export RUSTC_LOG=rustc_codegen_ssa::back::link=info where with the env var if you also pass -Clink-args=-v you will only see the linkers stdout/stderr with the env var, which makes sense based on the link-args name, but depending on your use case you might want that too

@jyn514 jyn514 linked a pull request Dec 24, 2023 that will close this issue
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jan 26, 2024
show linker output even if the linker succeeds

- show stderr by default
- show stdout if `--verbose` is passed
- remove both from RUSTC_LOG
- hide the linker cli args unless `--verbose` is passed

fixes rust-lang#83436. fixes rust-lang#38206. fixes rust-lang#109979. helps with rust-lang#46998. cc https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408986134

this is based on rust-lang#119129 for convenience so i didn't have to duplicate the changes around saving `--verbose` in rust-lang@cb6d033#diff-7a49efa20548d6806dbe1c66dd4dc445fda18fcbbf1709520cadecc4841aae12

r? `@bjorn3`
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 30, 2024
show linker output even if the linker succeeds

- show stderr by default
- show stdout if `--verbose` is passed
- remove both from RUSTC_LOG
- hide the linker cli args unless `--verbose` is passed

fixes rust-lang#83436. fixes rust-lang#38206. fixes rust-lang#109979. helps with rust-lang#46998. cc https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408986134

this is based on rust-lang#119129 for convenience so i didn't have to duplicate the changes around saving `--verbose` in rust-lang@cb6d033#diff-7a49efa20548d6806dbe1c66dd4dc445fda18fcbbf1709520cadecc4841aae12

r? `@bjorn3`
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 11, 2024
show linker output even if the linker succeeds

- show stderr by default
- show stdout if `--verbose` is passed
- remove both from RUSTC_LOG
- hide the linker cli args unless `--verbose` is passed

fixes rust-lang#83436. fixes rust-lang#38206. fixes rust-lang#109979. helps with rust-lang#46998. cc https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408986134

this is based on rust-lang#119129 for convenience so i didn't have to duplicate the changes around saving `--verbose` in rust-lang@cb6d033#diff-7a49efa20548d6806dbe1c66dd4dc445fda18fcbbf1709520cadecc4841aae12

r? `@bjorn3`
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 11, 2024
show linker output even if the linker succeeds

- show stderr by default
- show stdout if `--verbose` is passed
- remove both from RUSTC_LOG
- hide the linker cli args unless `--verbose` is passed

fixes rust-lang#83436. fixes rust-lang#38206. fixes rust-lang#109979. helps with rust-lang#46998. cc https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408986134

this is based on rust-lang#119129 for convenience so i didn't have to duplicate the changes around saving `--verbose` in rust-lang@cb6d033#diff-7a49efa20548d6806dbe1c66dd4dc445fda18fcbbf1709520cadecc4841aae12

r? `@bjorn3`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-linkage Area: linking into static, shared libraries and binaries C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.