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

error: relocation refers to local symbol "" [12], which is defined in a discarded section only when using ld.gold linker with --gc-sections #59652

Closed
ghost opened this issue Apr 2, 2019 · 27 comments
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Apr 2, 2019

tl;dr: #59652 (comment)

Cannot compile firefox anymore due to:
error: linking with ... cargo-linker
error: relocation refers to local symbol "" [12], which is defined in a discarded section

UPDATE bisect shows it's PR 59401

https://bugzilla.mozilla.org/show_bug.cgi?id=1541214

old info This issue doesn't happen with Last **good** nightly: nightly-2019-03-28-x86_64-unknown-linux-gnu (default) rustc 1.35.0-nightly (33ef0ba 2019-03-27) binary: rustc commit-hash: 33ef0ba commit-date: 2019-03-27 host: x86_64-unknown-linux-gnu release: 1.35.0-nightly LLVM version: 8.0 nightly-2019-03-29-x86_64-unknown-linux-gnu (default) rustc 1.35.0-nightly (237bf32 2019-03-28) binary: rustc commit-hash: 237bf32 commit-date: 2019-03-28 host: x86_64-unknown-linux-gnu release: 1.35.0-nightly LLVM version: 8.0

The issue happens with
First bad nightly:
nightly-2019-03-29-x86_64-unknown-linux-gnu (default)
rustc 1.35.0-nightly (237bf32 2019-03-28)
binary: rustc
commit-hash: 237bf32
commit-date: 2019-03-28
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0

nightly-2019-03-30-x86_64-unknown-linux-gnu (default)
rustc 1.35.0-nightly (e782d79 2019-03-29)
binary: rustc
commit-hash: e782d79
commit-date: 2019-03-29
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0

For each test I was using the same cargo:
cargo 1.35.0-dev (025b01ed 2019-04-01)
release: 1.35.0
commit-hash: 025b01edd0bba49b7e49c1cacc65bb1f6462ee57
commit-date: 2019-04-01

Errors look like this:

0:16.63 = note: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9b00dedc0dda6ebf.rlib(compiler_builtins-9b00dedc0dda6ebf.compiler_builtins.cqcjgied-cgu.0.rcgu.o)(.stack_sizes+0x0): error: relocation refers to local symbol "" [12], which is defined in a discarded section

0:16.84 section group signature: "(null)"
0:16.84 /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-e4188d26f42911c5.rlib(std-e4188d26f42911c5.std.b8iklw2d-cgu.0.rcgu.o)(.stack_sizes+0x1b): error: relocation refers to local symbol "" [696], which is defined in a discarded section
0:16.84 section group signature: "(null)"

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-nominated regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 2, 2019
@ghost
Copy link
Author

ghost commented Apr 3, 2019

UPDATE: ignore this comment.

I was wrong about first bad nightly: it's not nightly-2019-03-29-x86_64-unknown-linux-gnu but instead it's:

nightly-2019-03-30-x86_64-unknown-linux-gnu (default)
rustc 1.35.0-nightly (e782d790f 2019-03-29)
binary: rustc
commit-hash: e782d790f1b63d82af39248bebe027f92d891bcc
commit-date: 2019-03-29
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0

And nightly-2019-03-29-x86_64-unknown-linux-gnu is a good nightly.(confirmed firefox compilation succeeded with it!)

I'm still double-checking but it takes some time...done
I'm also trying to do a rust bisect (even more time) [does anyone know if I have to do a git submodule update after each git bisect good/bad ? answer: not really, ./x.py build does it automatically for changed submodules, but just to be sure I'm doing git submodule update --init --recursive --progress followed by ./x.py clean && time ./x.py build --stage 1 -j 5 then clean firefox build dir(ie. remove it) and retry compiling, error usually appears after 8mins, but to be sure I've to leave it compiling for like 23mins]

@mati865
Copy link
Contributor

mati865 commented Apr 3, 2019

@ghost
Copy link
Author

ghost commented Apr 3, 2019

8b8488c is the first bad commit, made from PR #59401

    bootstrap: build compiler-builtins with -Z emit-stack-sizes
$ git bisect log
git bisect start
# good: [237bf3244fffef501cf37d4bda00e1fce3fcfb46] Auto merge of #59478 - Centril:rollup, r=Centril
git bisect good 237bf3244fffef501cf37d4bda00e1fce3fcfb46
# bad: [e782d790f1b63d82af39248bebe027f92d891bcc] Auto merge of #59522 - Centril:rollup, r=Centril
git bisect bad e782d790f1b63d82af39248bebe027f92d891bcc
# bad: [e782d790f1b63d82af39248bebe027f92d891bcc] Auto merge of #59522 - Centril:rollup, r=Centril
git bisect bad e782d790f1b63d82af39248bebe027f92d891bcc
# bad: [3df97f9da8e4a23772f5845bc641adae03e032be] Rollup merge of #59401 - japaric:compiler-builtins-stack-sizes, r=alexcrichton
git bisect bad 3df97f9da8e4a23772f5845bc641adae03e032be
# good: [b75b1655895e69f074936b73394a72e98aa067b9] Rollup merge of #59398 - phansch:rustfix_coverage, r=oli-obk
git bisect good b75b1655895e69f074936b73394a72e98aa067b9
# good: [8794e21ff329d1201d484c015d48e85490a64fa9] Rollup merge of #58019 - Zoxc:combine-late-lints, r=estebank
git bisect good 8794e21ff329d1201d484c015d48e85490a64fa9
# good: [6c8e3a5378e41e08a323139bb7aaa8a8823ec9bc] Remove unused variable
git bisect good 6c8e3a5378e41e08a323139bb7aaa8a8823ec9bc
# good: [f9262afa4d1a88715ff57907bd17eda4d039cea6] Rollup merge of #59394 - mark-i-m:dup-matcher-bindings-2, r=Centril
git bisect good f9262afa4d1a88715ff57907bd17eda4d039cea6
# bad: [7d365cf27f4249fc9b61ba8abfc813abe43f1cb7] compile all crates under test w/ -Zemit-stack-sizes
git bisect bad 7d365cf27f4249fc9b61ba8abfc813abe43f1cb7
# bad: [8b8488ce8fc047282e7159343f30609417f9fa39] bootstrap: build compiler-builtins with -Z emit-stack-sizes
git bisect bad 8b8488ce8fc047282e7159343f30609417f9fa39
# first bad commit: [8b8488ce8fc047282e7159343f30609417f9fa39] bootstrap: build compiler-builtins with 

Just tested commit f8673e0 (HEAD -> master, origin/master, origin/HEAD)
with this patch applied:

diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs
index 7429492f91..d508969d29 100644
--- a/src/bootstrap/bin/rustc.rs
+++ b/src/bootstrap/bin/rustc.rs
@@ -211,7 +211,7 @@ fn main() {
                 || target.contains("-none-eabi")
                 || target.ends_with("-none-elf"))
         {
-            cmd.arg("-Zemit-stack-sizes");
+            //cmd.arg("-Zemit-stack-sizes");
         }
 
         if let Ok(s) = env::var("RUSTC_CODEGEN_UNITS") {

and can confirm that firefox compiled past the issue.

Will test without the patch next...done: confirmed the issue exists without the above patch!

Will test again with the patch and allow firefox to fully compile&install (done, it worked!)

@mati865
Copy link
Contributor

mati865 commented Apr 4, 2019

CC @japaric

@pnkfelix
Copy link
Member

pnkfelix commented Apr 4, 2019

triage: P-high. Leaving nominated for now (What is going on here with -Z emit-stack-sizes ...?)

@pnkfelix pnkfelix added the P-high High priority label Apr 4, 2019
@japaric
Copy link
Member

japaric commented Apr 9, 2019

Sorry for the breakage here. If PR #59401 is blocking anything feel free to revert it. It will probably be several days before I have some free time to dig into this (though my guess is that one of the extra, custom linker flags that firefox uses in their builds (see MOZ_CARGO_WRAP_LDFLAGS in the linked bugzilla ticket) is not playing nicely with the new .stack_sizes section)

@ghost
Copy link
Author

ghost commented Apr 10, 2019

If I remove -Wl,--gc-sections from the args to cargo-linker then the issue doesn't happen!

--gc-sections is set not by MOZ_CARGO_WRAP_LDFLAGS but rather by lib/librustc_codegen_ssa-6bcbc85a2479ae62.so (I know because it's the only place I hexedited it to --hc-sections and got /usr/bin/ld.gold: --hc-sections: unknown option, and it also shows in the exact same place in the args to cargo-linker)

#!/bin/bash

rustup default master-stage1

export MOZ_CARGO_WRAP_LD='/usr/bin/clang -std=gnu99'
export MOZ_CARGO_WRAP_LDFLAGS='-lpthread -Wl,-O1,--sort-common,--as-needed,-z,relro -Wl,-rpath,/usr/lib/firefox -fuse-ld=gold -Wl,-z,noexecstack -Wl,-z,text -Wl,-z,relro -Wl,-z,nocopyreloc -Wl,-Bsymbolic-functions -Wl,--build-id=sha1 -fstack-protector-strong -Wl,--icf=safe -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/bin -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/lib -fcolor-diagnostics'

# shellcheck disable=SC2016
#CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION_PATCH=27 CARGO_PKG_VERSION_PRE='' CARGO_TARGET_BINFILE_FULLPATH=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build-script-build CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_DESCRIPTION='A stable implementation of the upcoming new `proc_macro` API. Comes with an option, off by default, to also reimplement itself in terms of the upstream unstable API.' LD_LIBRARY_PATH='/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps:/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib' CARGO_MANIFEST_DIR=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION=0.4.27 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_NAME=proc-macro2 CARGO=/home/user/build/2nonpkgs/rust.stuff/cargo/cargo/target/release/cargo /home/user/bin/rustc --crate-name build_script_build /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2/build.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=2 -C codegen-units=1 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=3b19a3eb863545be -C extra-filename=-3b19a3eb863545be --out-dir /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be -C linker=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker -L dependency=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps --cap-lints warn

err="-Wl,--gc-sections"
#err="" #uncomment this line to avoid errors like: /home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a9bb89774eb1c5f2.rlib(std-a9bb89774eb1c5f2.4ujdo36uwwum3zzu.rcgu.o)(.stack_sizes+0x0): error: relocation refers to local symbol "" [5], which is defined in a discarded section
"/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.build_script_build.ea30uw23-cgu.0.rcgu.o" "-o" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.1zobs1pcbqt3rtjo.rcgu.o" "$err" "-pie" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps" "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a9bb89774eb1c5f2.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-01499d126af771f6.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-8b152c95a80afef5.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-14c23aab33e6c5f4.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-41eb09b84b2625ab.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-44a20fe3a684e072.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e5275540f2101631.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-9f560ba3dfa532fe.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1f1fadf3472d3239.rlib" "-Wl,--end-group" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9e3a9887668f9c30.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"

@ghost
Copy link
Author

ghost commented Apr 10, 2019

Apparently one of these:

// If we're building a dylib, we don't use --gc-sections because LLVM
// has already done the best it can do, and we also don't want to
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
self.linker_arg("--gc-sections");
}
}

fn gc_sections(&mut self, _keep_metadata: bool) {
self.cmd.arg("--gc-sections");
}

@ghost
Copy link
Author

ghost commented Apr 10, 2019

By adding a digit to each of those two --gc-sections occurrences, recompiling rust and rerunning the (uhm, commented out line of the)script above(actually see the section at the end of this comment for the exact script) I determined it's exactly the first one, that is, this:

// If we're building a dylib, we don't use --gc-sections because LLVM
// has already done the best it can do, and we also don't want to
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
self.linker_arg("--gc-sections");
}
}

Does anyone think that maybe it's --gc-sections in combination with some other arg that's causing the issue? Or wants me to try something else? or can someone provide a simpler reproduction sample? Either way I'm out of ideas ;-)

actual script ran
#!/bin/bash

rustup default master-stage1

export MOZ_CARGO_WRAP_LD='/usr/bin/clang -std=gnu99'
export MOZ_CARGO_WRAP_LDFLAGS='-lpthread -Wl,-O1,--sort-common,--as-needed,-z,relro -Wl,-rpath,/usr/lib/firefox -fuse-ld=gold -Wl,-z,noexecstack -Wl,-z,text -Wl,-z,relro -Wl,-z,nocopyreloc -Wl,-Bsymbolic-functions -Wl,--build-id=sha1 -fstack-protector-strong -Wl,--icf=safe -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/bin -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/lib -fcolor-diagnostics'

# shellcheck disable=SC2016
CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION_PATCH=27 CARGO_PKG_VERSION_PRE='' CARGO_TARGET_BINFILE_FULLPATH=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build-script-build CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_DESCRIPTION='A stable implementation of the upcoming new `proc_macro` API. Comes with an option, off by default, to also reimplement itself in terms of the upstream unstable API.' LD_LIBRARY_PATH='/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps:/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib' CARGO_MANIFEST_DIR=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION=0.4.27 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_NAME=proc-macro2 CARGO=/home/user/build/2nonpkgs/rust.stuff/cargo/cargo/target/release/cargo /home/user/bin/rustc --crate-name build_script_build /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2/build.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=2 -C codegen-units=1 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=3b19a3eb863545be -C extra-filename=-3b19a3eb863545be --out-dir /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be -C linker=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker -L dependency=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps --cap-lints warn

@ghost
Copy link
Author

ghost commented Apr 10, 2019

Here's the output with both -Wl,--print-gc-sections(manually added) and -Wl,--gc-sections
https://gist.github.com/howaboutsynergy/065ec6322866b5defa28d1ec5989675d

EDIT:
I have further reduced the script, as long as it gives me the discarded type of errors, output here, script also here:

#!/bin/bash

#rustup default master-stage1

#export MOZ_CARGO_WRAP_LD='/usr/bin/clang -std=gnu99'
#export MOZ_CARGO_WRAP_LDFLAGS='-lpthread -Wl,-rpath,/usr/lib/firefox -fuse-ld=gold -Wl,-z,noexecstack -Wl,-z,text -Wl,-Bsymbolic-functions -Wl,--build-id=sha1 -fstack-protector-strong -Wl,--icf=safe -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/bin -Wl,-rpath-link,/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/dist/lib -fcolor-diagnostics'

# shellcheck disable=SC2016
#CARGO_PKG_REPOSITORY='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION_PATCH=27 CARGO_PKG_VERSION_PRE='' CARGO_TARGET_BINFILE_FULLPATH=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build-script-build CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_DESCRIPTION='A stable implementation of the upcoming new `proc_macro` API. Comes with an option, off by default, to also reimplement itself in terms of the upstream unstable API.' LD_LIBRARY_PATH='/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps:/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib' CARGO_MANIFEST_DIR=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2 CARGO_PKG_HOMEPAGE='https://github.com/alexcrichton/proc-macro2' CARGO_PKG_VERSION=0.4.27 CARGO_PKG_VERSION_MINOR=4 CARGO_PKG_AUTHORS='Alex Crichton <alex@alexcrichton.com>' CARGO_PKG_NAME=proc-macro2 CARGO=/home/user/build/2nonpkgs/rust.stuff/cargo/cargo/target/release/cargo /home/user/bin/rustc --crate-name build_script_build /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/third_party/rust/proc-macro2/build.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=2 -C codegen-units=1 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=3b19a3eb863545be -C extra-filename=-3b19a3eb863545be --out-dir /home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be -C linker=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker -L dependency=/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps --cap-lints warn

#err=("-Wl,--print-gc-sections" "-Wl,--gc-sections")
##err="" #uncomment this line to avoid errors like: /home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a9bb89774eb1c5f2.rlib(std-a9bb89774eb1c5f2.4ujdo36uwwum3zzu.rcgu.o)(.stack_sizes+0x0): error: relocation refers to local symbol "" [5], which is defined in a discarded section
#"/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.build_script_build.ea30uw23-cgu.0.rcgu.o" "-o" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.1zobs1pcbqt3rtjo.rcgu.o" "${err[@]}" "-pie" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps" "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a9bb89774eb1c5f2.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-01499d126af771f6.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-8b152c95a80afef5.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-14c23aab33e6c5f4.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-41eb09b84b2625ab.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-44a20fe3a684e072.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e5275540f2101631.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-9f560ba3dfa532fe.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1f1fadf3472d3239.rlib" "-Wl,--end-group" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9e3a9887668f9c30.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
#"/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/build/cargo-linker" 

success=0 #1 if you want to see successful compilation(assuming $causetheissue is not 1), any other value(like 0) otherwise
causetheissue=1 #if 1 you will see 'discarded' type of errors, regardless of the value of $success
if test "$causetheissue" == '1'; then
  err="-Wl,--gc-sections"
else
  err="" #no errors
fi
#noeffect=("-pie" "-m64")
noeffect=("-nopie") #it's -pie by default if -nopie isn't specified
#debug=("-Wl,--no-threads" "-Wl,--debug=all")  #XXX uncomment of lots of seemingly useless(to this issue) information ?!
debug=()

##Won't compile without the following but at least one of them is required to see the 'discarded' type of errors(set $pickone below):
oops1=(
"/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-a9bb89774eb1c5f2.rlib"
"/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-01499d126af771f6.rlib"
"/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-1f1fadf3472d3239.rlib"
)
oops2=(
"/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-9e3a9887668f9c30.rlib"
)
if test "$success" != '1'; then
  pickone=1 #0,1,2
  oops1=("${oops1[$pickone]}")
  oops2=()
fi
/usr/bin/clang -v "${noeffect[@]}" -std=gnu99 "${debug[@]}" -lpthread -fuse-ld=gold -fcolor-diagnostics "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.build_script_build.ea30uw23-cgu.0.rcgu.o" "-o" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/build/proc-macro2-3b19a3eb863545be/build_script_build-3b19a3eb863545be.1zobs1pcbqt3rtjo.rcgu.o" "$err" "-nodefaultlibs" "-L" "/home/user/build/1packages/4used/firefox-hg/makepkg_pacman/firefox-hg/src/firefox-hg/obj-x86_64-pc-linux-gnu/release/deps" "-L" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "${oops1[@]}" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-8b152c95a80afef5.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-14c23aab33e6c5f4.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-41eb09b84b2625ab.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-44a20fe3a684e072.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-e5275540f2101631.rlib" "/home/user/build/2nonpkgs/rust.stuff/rust/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-9f560ba3dfa532fe.rlib" "-Wl,--end-group" "${oops2[@]}" "-Wl,-Bdynamic" "-ldl" "-lgcc_s" "-lc"

@vorner
Copy link
Contributor

vorner commented Apr 11, 2019

I don't think this is anything specific to firefox. I'm getting this error on today's nightly as well (rustc 1.35.0-nightly (96d700f 2019-04-10)). I don't set any linker flags manually as far as I know.

          /home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-40d980a809fdc985.rlib(std-40d980a809fdc985.std.2pwkdt1a-cgu.0.rcgu.o)(.stack_sizes+0x0): error: relocation refers to local symbol "" [1760], which is defined in a discarded section

But maybe some of the dependencies do something?

  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.0.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.1.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.10.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.11.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.12.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.13.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.14.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.15.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.2.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.3.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.4.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.5.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.6.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.7.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.8.rcgu.o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.build_script_build.f5cx6kaq-cgu.9.rcgu.o" "-o" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc" "/home/vorner/.rust-target/normal/debug/build/num-traits-2ba80e41556ab8cc/build_script_build-2ba80e41556ab8cc.1i7z7qhcjdrul5p9.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/vorner/.rust-target/normal/debug/deps" "-L" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-40d980a809fdc985.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-2133eb2e78115669.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-76a1e895b942f4f1.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-4423e7ad8fae78b0.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-121d18364f871b00.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-684dc35735333b20.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-65ae63f7a5616b63.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-c91f0330d41106a6.rlib" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-71db3eaafaac5eb0.rlib" "-Wl,--end-group" "/home/vorner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-138ab271264ca64d.rlib" "-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"

Should I try finding some more info?

@pnkfelix
Copy link
Member

@vorner any other details you can figure out would be appreciated.

Even just a standalone test (so that we didn't have to try to recreate this via a firefox build) would be immensely helpful.

@pnkfelix
Copy link
Member

assigning to self to:

  1. Attempt to identify a standalone test (or prod other people into providing one)
  2. Reproduce the bug locally
  3. Revert the offending PR if we can confirm that does indeed fix the problem.

@pnkfelix pnkfelix self-assigned this Apr 11, 2019
@vorner
Copy link
Contributor

vorner commented Apr 11, 2019

  • Create a new bin project
  • Add this to Cargo.toml:
[dependencies]
dipstick = "0.7"
  • Run cargo +nightly check

It seems to fail on building a C or C++ code somewhere in numtraits. Assuming it is using the cc from the system, this is mine:

$ cc --version
cc (Gentoo 8.3.0-r1 p1.1) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The default ld is:

$ ld --version
GNU gold (Gentoo 2.32 p1 2.32.0) 1.16
Copyright (C) 2019 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

I expect this problem can be triggered by other things too, dipstick is just the first dependency in my project that caused it.

@ghost
Copy link
Author

ghost commented Apr 11, 2019

tl;dr: can't trigger issue with dipstick 0.7.2 but can still trigger it with compiling firefox (used 3 different rustc compiler versions to test both disptick and firefox)

@vorner By using the same rustc compiler(master-stage1) that I used to trigger this issue with firefox, I cannot trigger it with a new project with dipstick = "0.7" and just cargo check. I immediately retried compiling firefox after that(with cleaned/removed build dir), to confirm that it still triggered the issue and it did.

but my cc and ld versions differ from yours:

$ cc --version
cc (GCC) 8.2.1 20181127
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ ld --version
GNU ld (GNU Binutils) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

cargo +nightly check shows error: no such subcommand: +nightly - not sure what I'm missing here,
but I then tried this instead: rustup default nightly (rustc 1.35.0-nightly (3750348 2019-04-08)) and then cargo clean && cargo check and still couldn't trigger the issue(Finished dev [unoptimized + debuginfo] target(s) in 19.23s).
I even retried after a rustup update (rustc 1.35.0-nightly (96d700f 2019-04-10)) to no avail (Finished dev [unoptimized + debuginfo] target(s) in 19.25s).
Cargo.lock shows dipstick 0.7.2 was used.
I even tried cargo build and cargo run with this nightly.
Then I kept this latest nightly, cleaned/removed firefox build dir and tried recompiling firefox: issue is still triggered( 7:29.38 /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-71db3eaafaac5eb0.rlib(core-71db3eaafaac5eb0.core.bpa42w6m-cgu.0.rcgu.o)(.stack_sizes+0x0): error: relocation refers to local symbol "" [855], which is defined in a discarded section)

In the dipstick console, after having done all of the above, I cannot find any numtraits text, however.
I even renamed ~/.cargo/registry/ (to emulate removal) and did a cargo clean&&cargo check (still using latest nightly): Finished dev [unoptimized + debuginfo] target(s) in 45.50s). Still no mention of numtraits. (EDIT2: firefox compilation with new build dir and this new registry still triggered the issue)
Oh, I just realized it's num_traits and there are plenty of referenced when -v is used, but still no errors and I cannot trigger this issue.

     Running `rustc --crate-name num_traits /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/num-traits-0.2.6/src/lib.rs --color always --crate-type lib --emit=dep-info,metadata -C debuginfo=2 -C metadata=f4779c1b3a57d428 -C extra-filename=-f4779c1b3a57d428 --out-dir /tmp/pro/target/debug/deps -L dependency=/tmp/pro/target/debug/deps --cap-lints allow -C target-cpu=native --cfg has_i128`

EDIT1: That output made me realize and remember that I've this ~/.cargo/config contents:

[target.'cfg(any(windows, unix))']                                              
rustflags = ["-C", "target-cpu=native"]
# src: https://users.rust-lang.org/t/auto-vectorization-in-rust/24379/4

EDIT3: no effect if I comment out the contents of ~/.cargo/config, on either dipstick 0.7.2 (clean, check, build, run)[doesn't trigger] or firefox[does trigger].

I even tried making sure Cargo.lock has dipstick 0.7.0 by setting =0.7.0 in Cargo.toml, issue won't trigger.

$ rustv
!! LD_LIBRARY_PATH=
!! Executing '/home/user/.cargo/bin/rustc' in pwd='/tmp/pro' with args: '-vV'
!! !MOZ_CARGO_WRAP_LD=''
!! !MOZ_CARGO_WRAP_LDFLAGS=''!
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.35.0-nightly (96d700f1b 2019-04-10)
binary: rustc
commit-hash: 96d700f1b7bc9c53fa0d11567adb1ed2c1c27e79
commit-date: 2019-04-10
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0
!! LD_LIBRARY_PATH=
!! Executing '/home/user/build/2nonpkgs/rust.stuff/cargo/cargo//target/release//cargo' in pwd='/tmp/pro' with args: '-vV'
!! !MOZ_CARGO_WRAP_LD=''
!! !MOZ_CARGO_WRAP_LDFLAGS=''!
nightly-x86_64-unknown-linux-gnu (default)
cargo 1.35.0-dev (f5b60ac5 2019-04-05)
release: 1.35.0
commit-hash: f5b60ac5cc61621f99ba702e8130af49020ea109
commit-date: 2019-04-05

@mati865
Copy link
Contributor

mati865 commented Apr 11, 2019

Reproduced with @vorner example using RUSTFLAGS="-C link-arg=-fuse-ld=gold" cargo +nightly check.
Gold linker seems to be the culprit here.

@vorner
Copy link
Contributor

vorner commented Apr 11, 2019

I can confirm. If I switch my linker to ld.bfd, the problem goes away.

I have the vague impression that firefox somehow prefers to link with gold in its build system, but I might be wrong about that one.

@ghost
Copy link
Author

ghost commented Apr 11, 2019

Gold linker seems to be the culprit here.

Confirmed! Issue triggered for me too(even though I can't use the cargo +nightly check command), by $ cargo clean && RUSTFLAGS="-C link-arg=-fuse-ld=gold" cargo check
(tested 2 rustc compilers)

This is really cool, thanks @mati865 and @vorner for easy reproduction steps[1,2] that don't involve firefox!

EDIT:

I have the vague impression that firefox somehow prefers to link with gold in its build system, but I might be wrong about that one.

yes, firefox does use ld.gold indeed(but not by default! see edit3 below): ref0 ref1 ref2
EDIT2: Actually it might be my fault for explicitly setting it in mozconfig as ac_add_options --enable-gold
EDIT3 ./configure --help says --enable-gold Enable GNU Gold Linker when it is not already the default (that seems to imply it would be used by default) and commenting out my mozconfig line as #ac_add_options --enable-gold then recompiling firefox with empty build dir ... doesn't seem to cause the issue yet(30minutes into compilation, the issue would be caused around minute 7.5), and I see no mention of gold thus I can only assume it doesn't use gold by default! ergo, it's my fault for explicitly telling it to use it.

readelf output

@ghost ghost changed the title [firefox] error: relocation refers to local symbol "" [12], which is defined in a discarded section error: relocation refers to local symbol "" [12], which is defined in a discarded section only when using ld.gold linker with --gc-sections Apr 11, 2019
@ghost
Copy link
Author

ghost commented Apr 11, 2019

So when using ld.gold linker with the implied --gc-sections that rust adds(when not a dynamic library crate?), coupled with the .stack_sizes linker section(added by PR #59401) then the issue triggers (error: relocation refers to local symbol "" [12], which is defined in a discarded section)

--gc-sections is used when crate_type != config::CrateType::Dylib as seen in this code:

let keep_metadata = crate_type == config::CrateType::Dylib;
cmd.gc_sections(keep_metadata);

--gc-sections is added by this code:
// If we're building a dylib, we don't use --gc-sections because LLVM
// has already done the best it can do, and we also don't want to
// eliminate the metadata. If we're building an executable, however,
// --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
// reduction.
} else if !keep_metadata {
self.linker_arg("--gc-sections");
}

@ghost
Copy link
Author

ghost commented Apr 11, 2019

@vorner How did you have ld.gold set in #59652 (comment) ? I assume you had to have had it set since I couldn't reproduce without setting it in RUSTFLAGS. Was it set in ~/.cargo/config or via RUSTFLAGS ? something else?

though you do mention that

The default ld is:

not ld-gold but a normal ld which is a higher version(2.32 p1 2.32.0) than mine(2.31.1). Should I expect then that my future ld version(whenever ArchLinux update binutils package - currently at 2.31.1-4) will break just like ld.gold did and thus trigger this issue without needing ld.gold ?

oh wait, it does say gold in your output(weird that I only see that now!!):

$ ld --version
GNU gold (Gentoo 2.32 p1 2.32.0) 1.16

that was unexpected, here's how it looks on ArchLinux:

$ ld --version
GNU ld (GNU Binutils) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

$ ld.gold --version
GNU gold (GNU Binutils 2.31.1) 1.16
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

@vorner
Copy link
Contributor

vorner commented Apr 11, 2019

Well, gentoo allows you to tweak the system a lot and you do a lot of compilation with that system. I discovered gold is a bit faster in most cases, so I set it as the my system default linker. It's not the general default if you get a fresh gentoo system.

@ghost
Copy link
Author

ghost commented Apr 12, 2019

I have another workaround, for those who still want to use ld.gold but don't mind recompiling it(binutils), which I've tested to pass dipstick and firefox compilations. I used the following patch. (Then I recompiled binutils without the patch to test that both dipstick and firefox compilations fail without it.)

diff --git a/gold/target-reloc.h b/gold/target-reloc.h
index 97e45da619..20a6fc0542 100644
--- a/gold/target-reloc.h
+++ b/gold/target-reloc.h
@@ -136,6 +136,8 @@ class Default_comdat_behavior
     if (Layout::is_debug_info_section(name))
       return CB_PRETEND;
     if (strcmp(name, ".eh_frame") == 0
+        || strncmp(name, ".stack_sizes", 12+1) == 0
+        //|| strncmp(name, ".gnu.build.attributes", 21) == 0  // FIXME: We should really be checking the section type for ST_NOTE... // NOTE: this line(and inspiration for the above .stack_sizes line) from: https://bugzilla.redhat.com/show_bug.cgi?id=1600431#c6 ) // decided to comment out this line since I cannot repro that bug that it supposedly fixes with GNU gold (GNU Binutils 2.31.1) 1.16 or with GNU gold (GNU Binutils 2.32) 1.16
 	|| strcmp(name, ".gcc_except_table") == 0)
       return CB_IGNORE;
     return CB_ERROR;

So, is there something that Rust can do here or shall this be solely ld.gold's issue? if the latter, please close the issue, I guess.

I'm personally gonna be using this patch, for fun :))

For completion, other workarounds were:

@pnkfelix
Copy link
Member

pnkfelix commented Apr 12, 2019

Okay, thank you @vorner, that is very helpful.

Just to share knowledge, I don't see the same problem with the dipstick test on my Linux host; here are my versions of cc and ld:

% cc --version
cc (GCC) 8.2.1 20181105 (Red Hat 8.2.1-5)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% ld --version
GNU ld version 2.31.1-13.fc29
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

I'll see if I can switch either of those around on this box in order to try to replicate the bug.

Update: Ooops, I should have reloaded the ticket before posting, there's been 16 hours of comments since @vorner posted.

@pnkfelix
Copy link
Member

pnkfelix commented Apr 12, 2019

Okay so my next question is what action to take at this point.

  • First of all, the change to -Z emit-stack-sizes was part of the recent nightly-to-beta promotion. So this ticket is now a regression from stable-to-beta. I'm going to change the labels accordingly.
  • So an obvious change is to just remove the -Z emit-stack-sizes` emission (i.e. revert PR bootstrap: build crates under libtest with -Z emit-stack-sizes #59401, as suggested by @japaric above), unconditionally. I'm inclined to at least do that on the beta channel right now, to ensure that the regression is limited to nightly, not beta.
  • The next question is whether to also remove that flag unconditionally on nightly too, or if we should somehow connect it to the choice of linker.
  • Of course another option is to just say "this is a bug in ld.gold; we are not going to try to work around it on our end."
  • (We could take an alternative route of trying to avoid injecting --gc-sections when it will break things. That would require, I think, inspecting whether the already-built libtest/libstd has a stack_sizes section when we are building up our linker invocation. That, or assuming it has such a section whenever we are on the target that happens to match the strings as is done in PR bootstrap: build crates under libtest with -Z emit-stack-sizes #59401's bootstrap changes.)

@pnkfelix pnkfelix added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Apr 12, 2019
pnkfelix added a commit to pnkfelix/rust that referenced this issue Apr 12, 2019
…eta regression).

This is result of squashing two revert commits:

Revert "compile all crates under test w/ -Zemit-stack-sizes"

This reverts commit 7d365cf.

Revert "bootstrap: build compiler-builtins with -Z emit-stack-sizes"

This reverts commit 8b8488c.
@pnkfelix
Copy link
Member

pnkfelix commented Apr 12, 2019

I've posted a PR to do the revert. Rather than solely cherry-pick it to beta, I have posted it against master (that is, rather than let the issue persist on the nightly builds, I want the behavior on nightly to match that of beta here).

I do welcome a more nuanced implementation, if someone wants to make one, for nightly. But I want to deploy the simplest way to address the regression on both master and beta right now. (And that's what PR #59911 is.)

Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…t-stack-sizes-gc-sections-ld-gold-bug, r=alexcrichton

Revert "compile crates under test w/ -Zemit-stack-sizes"

Revert PR rust-lang#59401 to fix issue rust-lang#59652 (a stable-to-beta regression).

This is result of squashing two revert commits:

Revert "compile all crates under test w/ -Zemit-stack-sizes"

This reverts commit 7d365cf.

Revert "bootstrap: build compiler-builtins with -Z emit-stack-sizes"

This reverts commit 8b8488c.

----

(My intention is that someone can re-add this code again later, either after the `ld.gold` issue itself is fixed, or with safe-guards to check whether `ld.gold` is in use and then issuing warnings about the problems here when they arise.)
Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…t-stack-sizes-gc-sections-ld-gold-bug, r=alexcrichton

Revert "compile crates under test w/ -Zemit-stack-sizes"

Revert PR rust-lang#59401 to fix issue rust-lang#59652 (a stable-to-beta regression).

This is result of squashing two revert commits:

Revert "compile all crates under test w/ -Zemit-stack-sizes"

This reverts commit 7d365cf.

Revert "bootstrap: build compiler-builtins with -Z emit-stack-sizes"

This reverts commit 8b8488c.

----

(My intention is that someone can re-add this code again later, either after the `ld.gold` issue itself is fixed, or with safe-guards to check whether `ld.gold` is in use and then issuing warnings about the problems here when they arise.)
Centril added a commit to Centril/rust that referenced this issue Apr 13, 2019
…t-stack-sizes-gc-sections-ld-gold-bug, r=alexcrichton

Revert "compile crates under test w/ -Zemit-stack-sizes"

Revert PR rust-lang#59401 to fix issue rust-lang#59652 (a stable-to-beta regression).

This is result of squashing two revert commits:

Revert "compile all crates under test w/ -Zemit-stack-sizes"

This reverts commit 7d365cf.

Revert "bootstrap: build compiler-builtins with -Z emit-stack-sizes"

This reverts commit 8b8488c.

----

(My intention is that someone can re-add this code again later, either after the `ld.gold` issue itself is fixed, or with safe-guards to check whether `ld.gold` is in use and then issuing warnings about the problems here when they arise.)
@ghost
Copy link
Author

ghost commented Apr 16, 2019

Closing due to 633fc9e having landed

@ghost ghost closed this as completed Apr 16, 2019
bors-servo pushed a commit to servo/servo that referenced this issue Apr 18, 2019
Update to 4/18 Rust nightly.

Contains the fix for rust-lang/rust#59652 which has been reported by several people on IRC.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23230)
<!-- Reviewable:end -->
pietroalbini pushed a commit to pietroalbini/rust that referenced this issue Apr 26, 2019
…eta regression).

This is result of squashing two revert commits:

Revert "compile all crates under test w/ -Zemit-stack-sizes"

This reverts commit 7d365cf.

Revert "bootstrap: build compiler-builtins with -Z emit-stack-sizes"

This reverts commit 8b8488c.
This issue was closed.
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. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants