diff options
| author | usamoi <usamoi@outlook.com> | 2025-04-13 23:18:39 +0800 |
|---|---|---|
| committer | usamoi <usamoi@outlook.com> | 2025-04-25 01:41:25 +0800 |
| commit | b1a38313cb0dee9a7c5573ae37ad48b0a347cb7c (patch) | |
| tree | ad9109c49a5d15cd4885accb5d778e13499b65b3 /compiler | |
| parent | 65fa0ab9246da73183b848a0c29b033779fe6f6c (diff) | |
set subsections_via_symbols for ld64 helper sections
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 8de68925cab..f0c47ac41e8 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2015,6 +2015,12 @@ fn add_linked_symbol_object( file.set_mangling(object::write::Mangling::None); } + if file.format() == object::BinaryFormat::MachO { + // Divide up the sections into sub-sections via symbols for dead code stripping. + // Without this flag, unused `#[no_mangle]` or `#[used]` cannot be discard on MachO targets. + file.set_subsections_via_symbols(); + } + // ld64 requires a relocation to load undefined symbols, see below. // Not strictly needed if linking with lld, but might as well do it there too. let ld64_section_helper = if file.format() == object::BinaryFormat::MachO { |
