Skip to content

Commit 4808cd0

Browse files
committed
emit .weak_definition instead of .weak on macos
1 parent 10faf24 commit 4808cd0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,23 @@ fn prefix_and_suffix<'tcx>(
153153
("", "")
154154
};
155155

156+
let asm_binary_format = AsmBinaryFormat::from_target(&tcx.sess.target);
157+
158+
let weak_directive = match asm_binary_format {
159+
AsmBinaryFormat::Elf | AsmBinaryFormat::Coff => ".weak",
160+
AsmBinaryFormat::Macho => ".weak_definition",
161+
};
162+
156163
let emit_fatal = |msg| tcx.dcx().span_fatal(tcx.def_span(instance.def_id()), msg);
157164

158165
// see https://godbolt.org/z/cPK4sxKor.
159166
// None means the default, which corresponds to internal linkage
160167
let linkage = match item_data.linkage {
161168
Linkage::External => Some(".globl"),
162-
Linkage::LinkOnceAny => Some(".weak"),
163-
Linkage::LinkOnceODR => Some(".weak"),
164-
Linkage::WeakAny => Some(".weak"),
165-
Linkage::WeakODR => Some(".weak"),
169+
Linkage::LinkOnceAny => Some(weak_directive),
170+
Linkage::LinkOnceODR => Some(weak_directive),
171+
Linkage::WeakAny => Some(weak_directive),
172+
Linkage::WeakODR => Some(weak_directive),
166173
Linkage::Internal => None,
167174
Linkage::Private => None,
168175
Linkage::Appending => emit_fatal("Only global variables can have appending linkage!"),
@@ -179,7 +186,7 @@ fn prefix_and_suffix<'tcx>(
179186

180187
let mut begin = String::new();
181188
let mut end = String::new();
182-
match AsmBinaryFormat::from_target(&tcx.sess.target) {
189+
match asm_binary_format {
183190
AsmBinaryFormat::Elf => {
184191
let section = link_section.unwrap_or(format!(".text.{asm_name}"));
185192

0 commit comments

Comments
 (0)