Skip to content

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

Description

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)"

Activity

added
A-linkageArea: linking into static, shared libraries and binaries
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 2, 2019
ghost

ghost commented on Apr 3, 2019

@ghost

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]

ghost

ghost commented on Apr 3, 2019

@ghost

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

mati865 commented on Apr 4, 2019

@mati865
Member
pnkfelix

pnkfelix commented on Apr 4, 2019

@pnkfelix
Member

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

japaric

japaric commented on Apr 9, 2019

@japaric
Member

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

ghost commented on Apr 10, 2019

@ghost

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

ghost commented on Apr 10, 2019

@ghost

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

ghost commented on Apr 10, 2019

@ghost

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

31 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @pnkfelix@mati865@jonas-schievink@japaric@vorner

      Issue actions

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