From b1a38313cb0dee9a7c5573ae37ad48b0a347cb7c Mon Sep 17 00:00:00 2001 From: usamoi Date: Sun, 13 Apr 2025 23:18:39 +0800 Subject: set subsections_via_symbols for ld64 helper sections --- compiler/rustc_codegen_ssa/src/back/link.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'compiler') 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 { -- cgit 1.4.1-3-g733a5