Bug 1775750

Summary: gold: Patch that stops gold from aborting when it encounters input sections with the same name and different flags breaks Rust builds for x86_64-fortanix-unknown-sgx target
Product: [Fedora] Fedora Reporter: Tadej Janež <tadej.j>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 31CC: aoliva, dvlasenk, fweimer, jakub, nickc
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: binutils-2.32-30.fc31, binutils-2.33.1-9.fc32 binutils-2.32-30.fc31 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-12-06 05:44:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tadej Janež 2019-11-22 17:25:48 UTC
Description of problem:

Running 'cargo build --target x86_64-fortanix-unknown-sgx' results in the following error:

root@68da9fc5eeb1 hello-world]# cargo build --target x86_64-fortanix-unknown-sgx
   Compiling hello-world v0.1.0 (/hello-world)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-fuse-ld=gold" "-nostdlib" "-shared" "-Wl,-e,sgx_entry" "-Wl,-Bstatic" "-Wl,--gc-sections" "-Wl,-z,text" "-Wl,-z,norelro" "-Wl,--rosegment" "-Wl,--no-undefined" "-Wl,--error-unresolved-symbols" "-Wl,--no-undefined-version" "-Wl,-Bsymbolic" "-Wl,--export-dynamic" "-Wl,-u,__rust_abort" "-Wl,-u,__rust_c_alloc" "-Wl,-u,__rust_c_dealloc" "-Wl,-u,__rust_print_err" "-Wl,-u,__rust_rwlock_rdlock" "-Wl,-u,__rust_rwlock_unlock" "-Wl,-u,__rust_rwlock_wrlock" "-L" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.3n08cepw9fmvwdf4.rcgu.o" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.4dhjuwfwpenz7g15.rcgu.o" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.4phwazwecl8txiu2.rcgu.o" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.ct3cblzl102jh7f.rcgu.o" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.jtj6fm5wfnz4scg.rcgu.o" "-o" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps/hello_world-3e7d722fcb909c28.41tsn9j4jx72k45i.rcgu.o" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/hello-world/target/x86_64-fortanix-unknown-sgx/debug/deps" "-L" "/hello-world/target/debug/deps" "-L" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib" "-Wl,-Bstatic" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libstd-86f35d7b99d22ed4.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libpanic_unwind-a72070139220275e.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libdlmalloc-c75eb11913489f9b.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libfortanix_sgx_abi-431a40a94e96f765.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libhashbrown-093434daf7d99801.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/librustc_std_workspace_alloc-24daf38551b7a03b.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libbacktrace-36d70d9746402ce9.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/librustc_demangle-eb2e0f5fe057b8b3.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind-75e9ddd83715a368.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libcfg_if-af51e7c6fd7d1248.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/liblibc-27f2a77b2995d98c.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/liballoc-ad10152c26711a1e.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/librustc_std_workspace_core-291bd2456cb6c9fe.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libcore-fc6e9071307a3016.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libcompiler_builtins-ebe4001ded7f33e7.rlib" "-Wl,-Bdynamic" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind.a"
  = note: /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libstd-86f35d7b99d22ed4.rlib(std-86f35d7b99d22ed4.std.dn9jryo2-cgu.0.rcgu.o)(.text+0xa4): error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          src/libstd/sys/sgx/abi/mem.rs:25: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          /cargo/registry/src/github.com-1ecc6299db9ec823/dlmalloc-0.1.3/src/sgx.rs:16: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          /root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind.a(UnwindRustSgx.c.o):UnwindRustSgx.c:function libuw_dl_iterate_phdr: error: relocation refers to global symbol "IMAGE_BASE", which is defined in a discarded section
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `hello-world`.

To learn more, run the command again with --verbose.


How reproducible:
Always

Steps to Reproduce:
dnf install -y gcc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add x86_64-fortanix-unknown-sgx
USER=root cargo new --bin hello-world
cd hello-world/
cargo build --target x86_64-fortanix-unknown-sgx

Actual results:
See above.

Expected results:
The Rust hello-world project would build normally.

Additional info:

This works on Fedora 30.

After reporting the issue to Fortanix's upstream (https://github.com/fortanix/rust-sgx/issues/193), the Fortanix author pinpointed the following patch to the gold linker to be the issue:
https://src.fedoraproject.org/rpms/binutils/c/c6c79eaa2c2530ae28f6041b3bcf5deb277d763b

I've rebuilt F31's binutils without this patch:
- https://src.fedoraproject.org/rpms/binutils/c/c6c79eaa2c2530ae28f6041b3bcf5deb277d763b
- https://copr.fedorainfracloud.org/coprs/tadej/binutils/
and confirmed that this fixes the issue.

Comment 1 Nick Clifton 2019-11-25 13:18:15 UTC
Hi Tadej,

  Thanks for a very detailed bug report.  The fragment of code causing the problem is a mistake.  It should never have been in the patch in the first place.  I have now fixed the patches and built updated binutils.  Please try either binutils-2.32-30.fc31 or binutils-2.33.1-9.fc32.

Cheers
  Nick

Comment 2 Tadej Janež 2019-11-25 13:45:04 UTC
Hi Nick,

thanks for fixing this so fast!

Comment 3 Tadej Janež 2019-12-02 08:59:21 UTC
> I have now fixed the patches and built updated binutils.  Please try either binutils-2.32-30.fc31 or binutils-2.33.1-9.fc32.

Nick, could you submit the binutils-2.32-30.fc31 as a new update in Bodhi?

Comment 4 Nick Clifton 2019-12-02 11:35:00 UTC
(In reply to Tadej Janež from comment #3)
> Nick, could you submit the binutils-2.32-30.fc31 as a new update in Bodhi?

Err no. :-(  I have been trying to, but the auto-populating build section of the form locks up.  The only error message that I can see is: "Builds : ACL validation mechanism was unable to determine ACLs.", but I do not know what this means.  Perhaps there is an internal problem with Bodhi at the moment.  I will try again tomorrow.

Comment 5 Tadej Janež 2019-12-03 08:40:36 UTC
> Err no. :-(  I have been trying to, but the auto-populating build section of the form locks up.  The only error message that I can see is: "Builds : ACL validation mechanism was unable to determine ACLs.", but I do not know what this means.  Perhaps there is an internal problem with Bodhi at the moment.  I will try again tomorrow.

I see :-). I've tried just now and I could select binutils-2.32-30.fc31 under the Builds section, so perhaps it's been fixed?

Comment 6 Fedora Update System 2019-12-03 15:58:59 UTC
FEDORA-2019-644add8fbf has been submitted as an update to Fedora 31. https://bodhi.fedoraproject.org/updates/FEDORA-2019-644add8fbf

Comment 7 Nick Clifton 2019-12-03 15:59:41 UTC
(In reply to Tadej Janež from comment #5)

> I see :-). I've tried just now and I could select binutils-2.32-30.fc31
> under the Builds section, so perhaps it's been fixed?

Yup - it is working now.  Bodhi update request submitted.

Comment 8 Fedora Update System 2019-12-04 02:20:32 UTC
binutils-2.32-30.fc31 has been pushed to the Fedora 31 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2019-644add8fbf

Comment 9 Fedora Update System 2019-12-06 05:44:58 UTC
binutils-2.32-30.fc31 has been pushed to the Fedora 31 stable repository. If problems still persist, please make note of it in this bug report.