diff options
| author | bors <bors@rust-lang.org> | 2025-02-25 11:59:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-02-25 11:59:11 +0000 |
| commit | c51b9b6d5234aa8e50c3b87784113a1af1af47cb (patch) | |
| tree | 6f45da43f4f39e8e443f09cd058307f0d0ec47d7 /compiler/rustc_codegen_ssa/src/errors.rs | |
| parent | ad27045c31a9f37ad7d44ca2a403de52d1a896d3 (diff) | |
| parent | b2024300840c3ef94a97273531bdb37d56d50fb5 (diff) | |
| download | rust-c51b9b6d5234aa8e50c3b87784113a1af1af47cb.tar.gz rust-c51b9b6d5234aa8e50c3b87784113a1af1af47cb.zip | |
Auto merge of #133832 - madsmtm:apple-symbols.o, r=DianQK
Make `#[used]` work when linking with `ld64` To make `#[used]` work in static libraries, we use the `symbols.o` trick introduced in https://github.com/rust-lang/rust/pull/95604. However, the linker shipped with Xcode, ld64, works a bit differently from other linkers; in particular, [it completely ignores undefined symbols by themselves](https://github.com/apple-oss-distributions/ld64/blob/ld64-954.16/src/ld/parsers/macho_relocatable_file.cpp#L2455-L2468), and only consider them if they have relocations (something something atoms something fixups, I don't know the details). So to make the `symbols.o` file work on ld64, we need to actually insert a relocation. That's kinda cumbersome to do though, since the relocation must be valid, and hence must point to a valid piece of machine code, and is hence very architecture-specific. Fixes https://github.com/rust-lang/rust/issues/133491, see that for investigation. --- Another option would be to pass `-u _foo` to the final linker invocation. This has the problem that `-u` causes the linker to not be able to dead-strip the symbol, which is undesirable. (If we did this, we would possibly also want to do it by putting the arguments in a file by itself, and passing that file via ``@`,` e.g. ``@undefined_symbols.txt`,` similar to https://github.com/rust-lang/rust/issues/52699, though that [is only supported since Xcode 12](https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes#Linking), and I'm not sure we wanna bump that). Various other options that are probably all undesirable as they affect link time performance: - Pass `-all_load` to the linker. - Pass `-ObjC` to the linker (the Objective-C support in the linker has different code paths that load more of the binary), and instrument the binaries that contain `#[used]` symbols. - Pass `-force_load` to libraries that contain `#[used]` symbols. Failed attempt: Embed `-u _foo` in the object file with `LC_LINKER_OPTION`, akin to https://github.com/rust-lang/rust/issues/121293. Doesn't work, both because `ld64` doesn't read that from archive members unless it already has a reason to load the member (which is what this PR is trying to make it do), and because `ld64` only support the `-l`, `-needed-l`, `-framework` and `-needed_framework` flags in there. --- TODO: - [x] Support all Apple architectures. - [x] Ensure that this works regardless of the actual type of the symbol. - [x] Write up more docs. - [x] Wire up a few proper tests. `@rustbot` label O-apple
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/errors.rs')
0 files changed, 0 insertions, 0 deletions
