about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-24 22:59:00 +0000
committerbors <bors@rust-lang.org>2025-04-24 22:59:00 +0000
commit847e3ee6b0e614937eee4e6d8f61094411eadcc0 (patch)
tree39adc11d0d7e3e7cb21421c9a2e2a83c89daa8d6 /compiler/rustc_codegen_ssa/src
parentd7ea436a02d5de4033fcf7fd4eb8ed965d0f574c (diff)
parentb1a38313cb0dee9a7c5573ae37ad48b0a347cb7c (diff)
downloadrust-847e3ee6b0e614937eee4e6d8f61094411eadcc0.tar.gz
rust-847e3ee6b0e614937eee4e6d8f61094411eadcc0.zip
Auto merge of #139752 - usamoi:macos-used, r=saethlin,madsmtm
set subsections_via_symbols for ld64 helper sections

closes https://github.com/rust-lang/rust/issues/139744
cc `@madsmtm`
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs6
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 {