-
Notifications
You must be signed in to change notification settings - Fork 109
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-macosOperating system: MacOSOperating system: MacOShelp wantedExtra attention is neededExtra attention is needed
Description
Trying to run the cranelift testsuite on an x86_64 macOS system with Xcode 15 results in an error that looks roughly like this:
= note: ld: warning: search path '/Users/eric/Proj/rust/rustc_codegen_cranelift/./build/rtstartup/lib/rustlib/x86_64-apple-darwin/lib' not found
ld: warning: search path '/Users/eric/Proj/rust/rustc_codegen_cranelift/./build/rtstartup/lib/rustlib/x86_64-apple-darwin/lib' not found
ld: multiple errors: invalid r_symbolnum=16 in '/Users/eric/Proj/rust/rustc_codegen_cranelift/build/stdlib_target/x86_64-apple-darwin/release/deps/std-6043c0e15839b1b8.37dz0diu3mok62ud.rcgu.o'; invalid r_symbolnum=20 in '/Users/eric/Proj/rust/rustc_codegen_cranelift/build/stdlib_target/x86_64-apple-darwin/release/deps/std-6043c0e15839b1b8.3cpybd90f24iafu4.rcgu.o'; invalid r_symbolnum=11 in '/Users/eric/Proj/rust/rustc_codegen_cranelift/build/stdlib_target/x86_64-apple-darwin/release/deps/std-6043c0e15839b1b8.5dobmwxxuzv3ys1m.rcgu.o'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is fairly easily reproducible, though it doesn't seem to happen 100% of the time. This is a blocker for rust-lang/rust updating the Xcode version.
Currently tested Xcode 15.0 and 15.2. A significant thing to note is that Xcode 15 introduced ld-prime, their new linker. One thing to consider while investigating is to try setting the linker flag -ld_classic
to narrow down if the new linker is a factor (sorry, I'm not familiar with cranelift's setup to help more).
Tested at commit cdae185.
stanleyjzheng and yerke
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.O-macosOperating system: MacOSOperating system: MacOShelp wantedExtra attention is neededExtra attention is needed
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
bjorn3 commentedon Apr 6, 2024
The new linker indeed plays a role. With Xcode 15 it only reproduces when
-ld_classic
isn't passed.bjorn3 commentedon Apr 6, 2024
If someone with a mac is able to reproduce this and figure out to which function(s) these relocations which ld-prime complains about apply that would be very much appreciated. I don't have a mac myself, so I can't reproduce it locally.
Note: arm64 macOS is not supported yet, so if you want to reproduce it on Apple Silicon you need to run the following to use the x86_64 toolchain in Rosetta 2:
rustup toolchain install --force-non-host nightly-2024-03-30-x86_64-apple-darwin rustup override set nightly-2024-03-30-x86_64-apple-darwin
bjorn3 commentedon Apr 28, 2024
GHA has started using an XCode version with ld-prime by default. Had to downgrade it in 05367c5.
philipc commentedon Apr 29, 2024
I get this error
I'll look into it more, but do you have any tips on how to get the information you need?
bjorn3 commentedon Apr 29, 2024
I think the first step would be to try trimming down the crate it fails to link (in this case example/mini_core.rs) to try and narrow down which symbol it can't handle.
philipc commentedon Apr 29, 2024
Oh, I hadn't set the toolchain. Fixing that, I get this error:
Looking in those object files, there's only one relocation for each of the r_symbolnum. Here's the relocations and associated symbols.
Those symbols look wrong because they are in empty sections.
bjorn3 commentedon Apr 29, 2024
If a data object is empty, that will create a symbol to an empty section. Looks like LLVM adds a dummy byte in that case. Is this required by Mach-O?
philipc commentedon Apr 30, 2024
How did you determine that? The symbols I gave above were for uses of
""
. I haven't yet come up with a test case where rustc emits a symbol for""
on x86_64 using llvm, but for aarch64, rustc emits a length 1 symbol for""
, both when it is the only symbol in the section, and when there is another symbol following it.I don't know, but I don't understand how
MH_SUBSECTIONS_VIA_SYMBOLS
could work with zero size symbols. If two symbols have the same address, how does it determine which one is the zero size subsection?bjorn3 commentedon Apr 30, 2024
I created an static with a ZST as type: https://rust.godbolt.org/z/4f1f8eEj6
Anonymous allocations and statics are handled differently. Anonymous allocations get
unnamed_addr
and in some cases cg_llvm entirely skips creating a global variable for anonymous zero sized allocations.philipc commentedon Apr 30, 2024
""
can be static too though, right? Either of these will use a zero sized_.Ldata1
and reproduce the problem:Is this enough info to fix the problem? Here's a hack to
object::write::Object::add_symbol_data
that passes the tests:I'm not sure if this is the right place to fix this, and if it is we probably should only do this for symbols in Mach-O when using subsections. (Related to that, I notice cranelift never uses subsections for data, but for Mach-O
MH_SUBSECTIONS_VIA_SYMBOLS
applies to both text and data, so there might be ordering problems if we add data before text.)bjorn3 commentedon Apr 30, 2024
In those cases the static contains a pointer to an anonymous allocation. Only the latter is zero sized.
Makes sense to me to do it there and in
add_subsection
and I agree it should only be done when using subsections.That is because using subsections for data is not yet implemented: bytecodealliance/wasmtime#2368
8 remaining items