-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
windows-gnullvm: Avoid linking to libunwind statically #121794
windows-gnullvm: Avoid linking to libunwind statically #121794
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Failed to set assignee to
|
These commits modify compiler targets. |
This comment has been minimized.
This comment has been minimized.
71a9b1b
to
ba888f8
Compare
This comment has been minimized.
This comment has been minimized.
ba888f8
to
5b24cc1
Compare
I don't see how rust/library/unwind/src/lib.rs Lines 52 to 54 in 878c8a2
I'll test it during the weekend. Also I think it might be the best to just build the unwinder during Rust build and always link it statically like here: rust/library/unwind/src/lib.rs Line 49 in 878c8a2
|
Avoid linking against the static variant of libunwind, which is not always available. Instead, prefer to use the unwind library from the toolchain, which the linker will automatically include, depending on what's available.
5b24cc1
to
7af0f34
Compare
Ah, you're right, it looks like that only applies to Linux and Fuchsia targets. rust/library/unwind/Cargo.toml Lines 31 to 34 in 6cbf092
I just clarified my commit message. FWIW, here's a Dockerfile to reproduce this: Details# Build with:
# docker build -t llvm-mingw .
FROM docker.io/mstorsjo/llvm-mingw:latest
# Supported architectures: x86_64, i686, aarch64 and armv7
ARG ARCH=x86_64
# Path settings
ENV RUSTUP_HOME="/usr/local/rustup" \
CARGO_HOME="/usr/local/cargo" \
PATH="/usr/local/cargo/bin:$PATH"
# Install curl
RUN apt-get update -qq && \
apt-get install -qqy --no-install-recommends curl && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/*
# Install Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
--no-modify-path \
--profile minimal \
--target $ARCH-pc-windows-gnullvm \
--default-toolchain nightly \
--component rust-src
WORKDIR /build
# Special flags for Rust
ENV CARGO_PROFILE_RELEASE_DEBUG=false \
CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1 \
CARGO_PROFILE_RELEASE_INCREMENTAL=false \
CARGO_PROFILE_RELEASE_LTO=true \
CARGO_PROFILE_RELEASE_OPT_LEVEL=z \
CARGO_PROFILE_RELEASE_PANIC=abort
RUN rm /opt/llvm-mingw/$ARCH-w64-mingw32/lib/libunwind.a
RUN cargo new foo --lib --vcs none && \
cd foo && \
echo "pub fn foo() {}" > src/lib.rs && \
cargo rustc --release --crate-type=cdylib --target=$ARCH-pc-windows-gnullvm -Zbuild-std=std,panic_abort && \
llvm-readobj --coff-imports target/$ARCH-pc-windows-gnullvm/release/foo.dll |
Not my area of expertise |
r? @petrochenkov |
The problem linking dynamic libunwind is the need of shipping libunwind together with the library/binary. I'll try if I can get |
Ah, I see. LLVM just uses If you pass |
Opened #122003 that builds libunwind for these targets so we become independent of host toolchain when it comes to libunwind. Did some testing during Sunday and it seems to work fine but I'll try it with your Dockerfile using toolchain built the official way. |
…try> Build libunwind for pc-windows-gnullvm Alternative to rust-lang#121794 The changes in this PR: - build libunwind for `pc-windows-gnullvm` targets - join paths with `join()` instead of slashes to avoid mixing slashes on windows, this changes it them from `"H:\\projects\\rust\\src/llvm-project/libunwind\\include"` to `"H:\\projects\\rust\\src\\llvm-project\\libunwind\\include"` - include `libunwind/src`, some of the includes are located inside `src` and without this change the build fails with: ``` running: "h:/msys64/clang64/bin/clang++.exe" "-O3" "-ffunction-sections" "-fdata-sections" "--target=x86_64-pc-windows-gnullvm" "-I" "H:\\projects\\rust\\src\\llvm-project\\libunwind\\include" "-nostdinc++" "-fno-exceptions" "-fno-rtti" "-fstrict-aliasing" "-funwind-tables" "-fvisibility=hidden" "-fvisibility-global-new-delete-hidden" "-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS" "-D_LIBUNWIND_HIDE_SYMBOLS=1" "-D_LIBUNWIND_IS_NATIVE_ONLY=1" "-o" "H:\\projects\\rust\\build\\x86_64-pc-windows-gnullvm\\native\\libunwind\\Unwind-EHABI.o" "-c" "\\\\?\\H:\\projects\\rust\\src\\llvm-project\\libunwind\\src\\Unwind-EHABI.cpp" cargo:warning=\\?\H:\projects\rust\src\llvm-project\libunwind\src\Unwind-EHABI.cpp:12:10: fatal error: 'Unwind-EHABI.h' file not found cargo:warning= 12 | #include "Unwind-EHABI.h" cargo:warning= | ^~~~~~~~~~~~~~~~ cargo:warning=1 error generated. exit code: 1 ```
…=petrochenkov link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets Alternative to rust-lang#121794 ``` $ cargo b -r Finished `release` profile [optimized] target(s) in 0.38s $ ntldd target/release/hello.exe | rg unwind libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000) $ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r Finished `release` profile [optimized] target(s) in 0.23s $ ntldd target/release/hello.exe | rg unwind ```
…=petrochenkov link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets Alternative to rust-lang#121794 ``` $ cargo b -r Finished `release` profile [optimized] target(s) in 0.38s $ ntldd target/release/hello.exe | rg unwind libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000) $ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r Finished `release` profile [optimized] target(s) in 0.23s $ ntldd target/release/hello.exe | rg unwind ```
…=petrochenkov link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets Alternative to rust-lang#121794 ``` $ cargo b -r Finished `release` profile [optimized] target(s) in 0.38s $ ntldd target/release/hello.exe | rg unwind libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000) $ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r Finished `release` profile [optimized] target(s) in 0.23s $ ntldd target/release/hello.exe | rg unwind ```
Rollup merge of rust-lang#122003 - mati865:gnullvm-build-libunwind, r=petrochenkov link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets Alternative to rust-lang#121794 ``` $ cargo b -r Finished `release` profile [optimized] target(s) in 0.38s $ ntldd target/release/hello.exe | rg unwind libunwind.dll => H:\msys64\clang64\bin\libunwind.dll (0x0000020c35df0000) $ RUSTFLAGS="-C target-feature=+crt-static" cargo b -r Finished `release` profile [optimized] target(s) in 0.23s $ ntldd target/release/hello.exe | rg unwind ```
Avoid linking against the static variant of libunwind, which is not always available. Instead, prefer to use the unwind library from the toolchain, which the linker will automatically include, depending on what's available.