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

Issue linking libunwind in release mode when using LTO #65

Closed
jethrogb opened this issue Jan 21, 2019 · 3 comments · Fixed by rust-lang/rust#57803 or rust-lang/rust#57914
Closed
Assignees
Labels
bug std/rustc Requires changes in Rust std/rustc
Milestone

Comments

@jethrogb
Copy link
Member

ring$ cargo +nightly rustc --test quic_tests --release --target=x86_64-fortanix-unknown-sgx -- -C codegen-units=1
   Compiling ring v0.14.2 (~/projects/rust-sgx/hello/ring)
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" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib" "~/projects/rust-sgx/hello/ring/target/x86_64-fortanix-unknown-sgx/release/deps/quic_tests-60cfc7f9614a1667.quic_tests.bo3mv8ta-cgu.0.rcgu.o" "-o" "~/projects/rust-sgx/hello/ring/target/x86_64-fortanix-unknown-sgx/release/deps/quic_tests-60cfc7f9614a1667" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "-L" "~/projects/rust-sgx/hello/ring/target/x86_64-fortanix-unknown-sgx/release/deps" "-L" "~/projects/rust-sgx/hello/ring/target/release/deps" "-L" "~/projects/rust-sgx/hello/ring/target/x86_64-fortanix-unknown-sgx/release/build/ring-9f5b619728470617/out" "-L" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib" "-Wl,-Bstatic" "/tmp/rustchwXbIV/libring-5d3d20b089bc71bf.rlib" "/tmp/rustchwXbIV/libbacktrace_sys-6741d64f34191261.rlib" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libcompiler_builtins-c8174d577f7ebb97.rlib" "-Wl,-Bdynamic" "~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind.a"
  = note: ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind.a(UnwindRustSgx.c.o):UnwindRustSgx.c:function libuw_malloc: error: undefined reference to '__rust_alloc'
          ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-fortanix-unknown-sgx/lib/libunwind.a(UnwindRustSgx.c.o):UnwindRustSgx.c:function libuw_free: error: undefined reference to '__rust_dealloc'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `ring`.

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

But without LTO:

ring$ cargo +nightly rustc --test quic_tests --release --target=x86_64-fortanix-unknown-sgx -- -C lto=no
   Compiling ring v0.14.2 (~/projects/rust-sgx/hello/ring)
    Finished release [optimized] target(s) in 0.59s
@jethrogb
Copy link
Member Author

I don't understand what's happening, the cc invocation doesn't include any std objects.

@jethrogb
Copy link
Member Author

jethrogb commented Jan 21, 2019

Simple repro:

$ cargo new ltotest --bin
     Created binary (application) `ltotest` package
$ cd ltotest/
$ cargo +nightly rustc --release --target=x86_64-fortanix-unknown-sgx -- -C lto -Z print-link-args

@jethrogb jethrogb added bug std/rustc Requires changes in Rust std/rustc labels Jan 21, 2019
@jethrogb jethrogb added this to the PROD-1267 milestone Jan 21, 2019
Centril added a commit to Centril/rust that referenced this issue Jan 24, 2019
…lexcrichton

Several changes to libunwind for SGX target

Two fixes:
* rust-lang#34978 bites again!
* __rust_alloc are actually private symbols. Add new public versions. Also, these ones are `extern "C"`.

Upstream changes (fortanix/llvm-project#2, fortanix/llvm-project#3):
* b7357de Avoid too new relocation types being emitted
* 0feefe5 Use new symbol names to call Rust allocator

Fixes fortanix/rust-sgx#65
@jethrogb jethrogb reopened this Jan 26, 2019
@jethrogb
Copy link
Member Author

New fix: fortanix/llvm-project#4

bors added a commit to rust-lang/rust that referenced this issue Jan 31, 2019
SGX target: clean up dist builder, update libunwind

This incorporates fortanix/llvm-project#4

Fixes fortanix/rust-sgx#65

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug std/rustc Requires changes in Rust std/rustc
Projects
None yet
2 participants