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

Exporting _Unwind_* symbols from libstd #62088

Closed
petrhosek opened this issue Jun 23, 2019 · 5 comments
Closed

Exporting _Unwind_* symbols from libstd #62088

petrhosek opened this issue Jun 23, 2019 · 5 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@petrhosek
Copy link
Contributor

We use the llvm-unwind feature which means that we build LLVM's libunwind and statically link it into Rust's libunwind. This is critical for our use cases because there's no system unwinder (e.g. libunwind or libgcc) available on systems we target (both Linux and Fuchsia).

dbebcee changed the Rust backend behavior where it no longer exports C symbols from rlibs and dylibs. This means that libstd no longer exports _Unwind_* symbols (that came from LLVM's libunwind which was built as part unwind rlib) and since no other library provides these symbols in our Rust toolchain, any crate that uses unwinding fails to link, most notably rustc itself:

  = note: ld.lld: error: build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_driver-3561bb4b801d0722.so: undefined reference to _Unwind_Resume
          ld.lld: error: build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-fef1aa24ee35e8f2.so: undefined reference to _Unwind_FindEnclosingFunction
          ld.lld: error: build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-fef1aa24ee35e8f2.so: undefined reference to _Unwind_GetIP
          ld.lld: error: build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-fef1aa24ee35e8f2.so: undefined reference to _Unwind_Backtrace

While I think that dbebcee behavior is desirable in general, it's undesirable in this specific case and I'd like to somehow mark _Unwind_* symbols to be exported if llvm-unwind feature is enabled, but I haven't found a way to do so.

cc @alexcrichton @Zoxc @cramertj @tmandry

@Zoxc
Copy link
Contributor

Zoxc commented Jun 24, 2019

It probably make sense to still export C symbols which are exported from Rust crates.

A workaround might be to export a dummy generic function in libunwind which calls the C functions.

@petrhosek
Copy link
Contributor Author

I tried the suggested workaround but it doesn't seem to be working.

@Zoxc
Copy link
Contributor

Zoxc commented Jun 26, 2019

I see we only export C symbols if #[link(name = "unwind", kind = "static")] is on the extern blocks, which libunwind.rs lacks. That's probably the solution here.

@alexcrichton
Copy link
Member

FWIW I think that the original change here only affects rust dylibs, when using rlibs we already limited symbols pretty aggressively and AFAIK it's only dylibs which were tweaked. Additionally basically the only project in the world using Rust dylibs is rustc, so the breakage here at least makes sense in that regard and I don't think is cause for alarm yet in terms of maybe there's more breakage lurking.

That being said we should still fix this particular use case! I think @Zoxc is right in that if rustc determines that a C symbol is both statically linked into a Rust dylib (which it deduces via a #[link] annotation) and the C symbol is publicly visible in Rust (aka foreign crates could then access it) then it should make the symbol visible. I'm not sure what the exact incantation is but there should be a way to define a name in Rust with #[link] and then it's hooked up to something explicitly printed by the build script which is actually where the static linkage happens.

@petrhosek if that's too vague though I can try to dig in more to actually remember the incantation here.

petrhosek added a commit to petrhosek/rust that referenced this issue Jul 2, 2019
When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 3, 2019
… r=tmandry

Use link attributes on extern "C" blocks with llvm-libuwind

When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
… r=tmandry

Use link attributes on extern "C" blocks with llvm-libuwind

When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
… r=tmandry

Use link attributes on extern "C" blocks with llvm-libuwind

When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
… r=tmandry

Use link attributes on extern "C" blocks with llvm-libuwind

When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
… r=tmandry

Use link attributes on extern "C" blocks with llvm-libuwind

When llvm-libunwind feature is enabled, we need to use link attribute on
extern "C" blocks to make sure that symbols provided by LLVM's libunwind
that's built as part of Rust's libunwind crate are re-exported.

This addresses issue rust-lang#62088.
@jonas-schievink jonas-schievink added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@Mark-Simulacrum
Copy link
Member

I believe this was fixed by #62287; closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. 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