-
Notifications
You must be signed in to change notification settings - Fork 13k
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
🐛 Symbol multiply defined since nightly-2023-12-02 with custom builtins. #118609
Comments
cc @DianQK working on another regression by the same commit: |
I'm not sure if this is a Rust bug, I don't think defining the builtins from a user crate like that was ever allowed. It was already broken before with build-std + lto=fat. |
WG-prioritization assigning priority (Zulip discussion). @ithinuel Would it be possible to reduce the sample code provided and include more debug information about the linking issue? Just as an additional help figuring out this issue. Thanks. @rustbot label -I-prioritize +P-high +E-needs-mcve |
In fact, compiler-builtins provide customization options through weak linkage at https://github.com/rust-lang/compiler-builtins/blob/2731a4837bfe091a0ba3e449e3ebeff73a6d2562/Cargo.toml#L69-L78. I tried it but I got a new error:
I am investigating this issue while looking for a suitable solution. LLVM provides a symbol override method for linking IRs, which is one possible way. |
@apiraino the sample provided on the @DianQK That is an interesting feature but it doesn't seem to be enabled by default. Does this mean that to get this to work as expected, we'd have to rely on nighlty's |
We're seeing the same issue with |
fn main() {
}
#[no_mangle]
pub fn __addsf3() {
return;
} Then just run @rustbot label -E-needs-mcve
I'm sorry, I'm not sure. If |
|
Adding weak will solve part of the issue. The following error is due to LLVM IR not recognizing symbols defined in ASM.
Refer: llvm/llvm-project#75696 (comment). To solve this issue, we should use the |
Since nightly-2023-12-02, I have encountered a similar issue involving The original reproducer is somewhat complex (it involves building librsvg and dependencies), but I managed to reduce it to this Dockerfile: Details# Build with:
# docker build -t llvm-mingw .
FROM mstorsjo/llvm-mingw:latest
# 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 x86_64-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 cargo new foo --lib --vcs none && \
cd foo && \
echo "pub fn foo() {}" > src/lib.rs && \
cargo rustc --release --crate-type=staticlib --target=x86_64-pc-windows-gnullvm -Zbuild-std=std,panic_abort -Zbuild-std-features=compiler-builtins-weak-intrinsics && \
llvm-nm -u target/x86_64-pc-windows-gnullvm/release/libfoo.a | grep -c ___chkstk_ms Doing: @@ -18,7 +18,7 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
--no-modify-path \
--profile minimal \
--target x86_64-pc-windows-gnullvm \
- --default-toolchain nightly \
+ --default-toolchain nightly-2023-12-01 \
--component rust-src
WORKDIR /build Makes the build pass. While investigating this further, I managed to resolve this issue with this commit: This solution involves not treating weak symbols as built-in functions during LTO, but I'm not sure if that would be a correct fix. |
Thanks! This is a good work-around for my use-case, which is that I build a staticlib crate compiler_builtins = { version = "0.1.105", features = ["weak-intrinsics"] } When comparing
I'm not sure what a size of zero means. Essentially the symbol was already defined before when it was working, but it was empty (IIUC) so probably was being merged without complaining? Then it got some size and failed. And with weak it's simply overwritten or merged. |
I tried a way to do it without the naked function at llvm/llvm-project#76040. I'm not sure it's appropriate to do so, though. |
I'm not sure if there is a issue. Can you provide a reproduction? |
Here's a tarball to reproduce: 118609.tar.gz
Building with an "old" nightly works.
Building with a "new" nightly fails.
Building with
Building with
Note that the duplicate symbols are provided in a seemingly non-deterministic order, so the first one may be different when reproducing. |
Something to notice (maybe it's useful to debug) is that you have to put the |
nightly-2023-12-15 breaks compilation of native applets by having symbols from `compiler_builtins` conflict between the applet static library and the platform during linking. This was not the case with nightly-2023-11-14. This rollback is temporary until rust-lang/rust#118609 is fixed or provides guidance on how to address this issue. Currently the only work-arounds are: - Compile the applet to an object file (like `applet.o`) and let the platform link all the dependencies of the applet. This is not obvious to do generically at the moment. - Require applets that need to compile natively to directly depend on `compiler_builtins` with the `weak-intrinsics` feature. If the dependency could been indirect, the prelude would have been the perfect place to introduce it. But given the dependency must be direct, this adds a small burden on applets.
nightly-2023-12-15 breaks compilation of native applets by having symbols from `compiler_builtins` conflict between the applet static library and the platform during linking. This was not the case with nightly-2023-11-14. This rollback is temporary until rust-lang/rust#118609 is fixed or provides guidance on how to address this issue. Currently the only work-arounds are: - Compile the applet to an object file (like `applet.o`) and let the platform link all the dependencies of the applet. This is not obvious to do generically at the moment. - Require applets that need to compile natively to directly depend on `compiler_builtins` with the `weak-intrinsics` feature. If the dependency could been indirect, the prelude would have been the perfect place to introduce it. But given the dependency must be direct, this adds a small burden on applets.
This is similar to an issue I saw earlier, but I can't find it at the moment. Can you tell us why you created the rust static library? Why can't you just add it as a dependency? This builtin symbol should become a local symbol. I'm not sure why it's a global symbol now. There is a workaround that changes the symbols of the object file to local via a symbol export file. |
The static library doesn't need to be written in Rust, it just happens to be in that case. And another reason I can't add it as a dependency is that it's not always the same library (it's not even taken from a finite set, it can be anything exporting the right symbols). For more contextWasefire provides a platform, written in Rust, on which WebAssembly applets can run. There is an option to actually bypass WebAssembly and run an applet natively. In that case, the applet is compiled to a static library for the same target architecture as the platform. Applets may be written in any language that targets WebAssembly in the general case, or the target architecture of the platform for the native case.
Could you tell more about this? Can this be specifically applied to |
It looks like the compiler-rt builtins provided by LLVM are always compiled with Perhaps Rust should do the same thing in this case? I think that would make it possible for non-LTO projects to link to static Rust archives built under FatLTO (i.e. the case mentioned in comment #118609 (comment)). |
That is what we did before #113923. The problem with that is that compiler-builtins tends to depend on libcore, whose symbols will be made private by LTO resulting in a linker error, unless it is compiled in exactly the right way to avoid this dependency. |
Not surprisingly, this now also affects beta. (1.76.0-beta.1) |
I apologize for my late response. This is only available in Mach-O. But you can use |
Rollup merge of rust-lang#119885 - DianQK:revert-pr-113923, r=petrochenkov Revert rust-lang#113923 Per [#t-compiler/meetings > [weekly] 2024-01-11](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11) discussion, revert rust-lang#113923. Also revert associated rust-lang#118568. The PR rust-lang#113923 causes the regression issue rust-lang#118609. We need more time to find a proper solution. Discussions start at [412365838](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412365838) and continue to [412369643](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412369643). Fixes rust-lang#118609. r? compiler
Now that rust-lang/rust#118609 is fixed. The previous nightly was broken and rolled-back in google#338.
Thanks for the fix! |
Now that rust-lang/rust#118609 is fixed. The previous nightly was broken and rolled-back in #338.
Thanks for addressing this, it was also blocking Rust rolls in Chrome, due to collisions between C++ and Rust, which we were trying to find ways to work around. https://bugs.chromium.org/p/chromium/issues/detail?id=1509926 |
So the issue was initially undefined symbols then become multiply defined symbols? Since revert is now an undefined symbol issue again? |
Hey Dian, good question, the bug has a lot going on. The problem was missing symbols when LTO is enabled on Android. (Note: we are using lld as the linker, and linker-driven thin LTO.) https://bugs.chromium.org/p/chromium/issues/detail?id=1509926#c9 was my best guess at what was wrong, but might be way off. The problem changed later to duplicates only because of how we tried to work around the problem, by playing with --whole-archive on the clang compiler-builtins archive, so that's not related really. Since revert, I expect there's no problem at the moment, but we'll see how the next roll attempt goes. I will let you know here if there's still something wrong after the revert, but expect otherwise. |
[beta] Revert rust-lang#113923 Per [#t-compiler/meetings > [weekly] 2024-01-11](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11) discussion, revert rust-lang#113923. Also revert associated rust-lang#118568. The PR rust-lang#113923 causes the regression issue rust-lang#118609. We need more time to find a proper solution. Discussions start at [412365838](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412365838) and continue to [412369643](https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202024-01-11/near/412369643). Fixes rust-lang#118609. Same as rust-lang#119885 but backported to beta. r? compiler
cargo build --release
fails when building an rp2040 application withlto=fat
.Code
To reproduce:
git clone https://github.com/ithinuel/sandbox-rp2040 -b rust-regression cd sandbox-rp2040 cargo build --release
I expected to see the project build successfully.
Instead, it fails with:
bisect-rustc
searched nightlies: from nightly-2023-12-01 to nightly-2023-12-03
regressed nightly: nightly-2023-12-02
searched commit range: 87e1447...8c2b577
regressed commit: 8c2b577
bisected with cargo-bisect-rustc v0.6.7
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged
Background
The rp2040 mcu has in-ROM implementation of some builtins. The
rp2040-hal
implements the necessary magic in order to use these rather than the regular compiler-builtins that would otherwise consume flash are induce unecessary execution latency.See here for memcpy, memset (and a few other) and here for float related builtins.
Such magic can be disabled with
--features disable-intrinsics
which allows to build on nightly-2023-12-02 at the cost of flash storage & execution speed.initial report
The text was updated successfully, but these errors were encountered: