-
Notifications
You must be signed in to change notification settings - Fork 211
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
Sync x86 chkstk intrinsics with LLVM #575
Conversation
For reference, this resolves this linker failure on
/cc @mati865 FYI. |
Thank, looks good at the quick glance but I don't understand why it'd fail with rc2 (unless it's rc2 with llvm/llvm-project@7a5cba8 backported). |
Commit llvm/llvm-project@248aeac was cherry-picked/backported as llvm/llvm-project@7a5cba8 in LLVM 18.1.0-rc2. However, it's likely that LLVM 18.1.0-rc1 would also encounter the same linker failure on i386, since commit llvm/llvm-project@885d7b7 removed the misspelled form of the MSVC |
Oh, GitHub for some reason didn't show this commit belongs to rc2 tag and I assumed it'll be part of rc3. Makes sense now. |
CI should be fixed in today's nightly: rust-lang/rust#121552 Can you somehow trigger the build? |
Great! I just triggered the build via: $ git rebase --force-rebase upstream/master |
... it looks like this is blocked on #582. |
Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and add a patch to vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins.
Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and add a patch to vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins.
Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and add a patch to vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins.
CI should be fixed now, can you rebase? |
Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and add a patch to vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins.
Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and add a patch to vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins.
src/x86.rs
Outdated
); | ||
} | ||
|
||
// FIXME: __alloca should be an alias to __chkstk | ||
#[naked] | ||
#[cfg(all( | ||
windows, | ||
target_env = "gnu", | ||
not(feature = "no-asm") | ||
))] | ||
pub unsafe extern "C" fn __alloca() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this is correct? rustc's name mangling will add another underscore in front of this function, so the final symbol will be ___alloca
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this should of course be _alloca
. 🤦♂️
Commit d32d5ee fixes this.
Incorporates the following commits: llvm/llvm-project@885d7b7 llvm/llvm-project@1f9eff1 llvm/llvm-project@7a5cba8
This seems to have broken MSYS2's build of i686-pc-windows-gnu (with gcc):
We needed to backport this change to make i686-pc-windows-gnullvm (with clang) work, because of an error linking to |
@jeremyd2019 Ah, bummer. PR #452 ensures that each intrinsic is compiled into its own separate object file, which would avoid duplicate symbol definition errors. However, IIUC, this approach would only work if $ ar t i686-w64-mingw32/lib/gcc/i686-w64-mingw32/13.2.0/libgcc.a | grep -E "chkstk|alloca"
_chkstk.o
_chkstk_ms.o Perhaps adding Otherwise, I think marking |
I just applied the changes from this PR on top of whatever version of compiler_builtins was vendored into rust 1.77.1. I can try to backport that PR as well, if it hasn't already been included in that version. UPDATE: it does appear to already be present, at least
Hmm, I think there are a lot of GCC versions out there, and requiring a new one (or a patched one) may not be viable.
Maybe. Any time I see "weak" symbols it scares me now, we have had a lot of bugs/issues with weak symbols in gcc/binutils on Windows. I think this case would be fine though, the issues had to do with shared libraries IIRC. If the PR you referenced is already present, I can try slapping As a procedure question, should I have opened a new issue on this rather than commenting on the PR? I usually like to comment on the PR in cases like this so I know that all the relevant people (including the author) are subscribed to it. |
I guess I missed something:
|
It would have to be |
It was inside an |
Nope:
I noticed that there is a dll import library involved after all. I don't know if/how weak symbols work there, especially with binutils (as opposed to lld, which seems to handle weak symbols on Windows better). |
At least for us, everything worked while the function was called Let me restate in terms of msys2/MINGW-packages#20397:
|
Yes exactly, sorry for the confusion.
Indeed, marking
I think adding
According to commit llvm/llvm-project@885d7b7 only the symbols named If the |
I will try that, but don't hold out much hope of it working because there is in fact a dll import library involved. As I recall, Windows PE format does not have weak shared library symbols as ie ELF does, so this cannot really be expected to work. Perhaps @mstorsjo could elaborate?
I don't know about that assumption. I only deal with rust where there is a C toolchain for the target in question already present. I assume rust supports situations where that's not the case (otherwise, what's the point of this crate? why not always just link against the intrinsics from the C toolchain?) |
This compiles, but still fails linking with the same multiple definition of |
I didn't try to read up the whole discussion above to see which semantic of weak symbols this refers to. For static linking, LLVM/lld (and to some extend also GCC/binutils, although it's buggy in some cases) does support weak symbols in COFF - you can have a weak undefined, which resolves as a null pointer if there's no definition of the symbol, or you can have multiple weak definitions and zero/one non-weak definitions. This works for symbols within one module, but for symbols imported from a DLL, it gets resolved at link time, and if referenced, the symbol must exist at runtime when the module is loaded too, there's no weak behaviour left at runtime. (There's a mechanism for delay loading, but that just shifts the runtime cost of loading a DLL, it does not allow the symbol to be missing. And I guess this isn't the behaviour you're discussing above anyway.) |
That's how I understood weak symbols to work, that it meant at reference time. This discussion came about because of the idea that marking the function (one of the symbols) as weak would fix a multiple definition error at link time. That seems to be a different semantic of weak symbols that I was not familiar with. |
This probably wouldn't help in our particular case, we are still patching rust to build the {i686,x86_64}-pc-windows-gnu targets but actually be -gnullvm (not sure if I explained that well). We cannot switch to not lie about the target yet, due to microsoft/windows-rs#2960 |
* rust: update to 1.77.1 * libc++: enable frame apis in libunwind. The bootstrapping hack used by the rust package on clang subsystems (namely, substituting compiler-rt and libunwind for libgcc and using the official gcc-based binaries to bootstrap) attempts to link to __register_frame_info and __deregister_frame_info on i686. Enabling this option brings them back. * rust: backport rust-lang/compiler-builtins#575 Also, fix 0011 patch to Cargo.lock (it was adding the embed-manifest dependency to the wrong crate due to fuzziness), and vendor embed-manifest. This allows CLANG32 to build with --enable-vendor, which is required to use our now-patched version of compiler-builtins. Note the 67c1c0a71a204c089ddae4aec21ec75aa778c11b commit was *not* the version merged upstream, but *is* the version that does not fail on either MINGW32 or CLANG32. * rust: enable uac patch for all clang prefixes. It turns out to be required on i686 *and* aarch64, but shouldn't hurt on x86_64 either. --------- Co-authored-by: Jeremy Drake <[email protected]>
Incorporates the following commits:
llvm/llvm-project@885d7b7
llvm/llvm-project@1f9eff1
llvm/llvm-project@7a5cba8