Skip to content

Commit 8b478b4

Browse files
authored
Merge pull request #1630 from CathalMullan/mach-o
Add leading underscore to asm symbols on Mach-O
2 parents e722ae6 + cf6e7bc commit 8b478b4

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/global_asm.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,15 @@ fn codegen_global_asm_inner<'tcx>(
120120
}
121121

122122
let symbol = tcx.symbol_name(instance);
123+
let symbol_name = if tcx.sess.target.is_like_darwin {
124+
format!("_{}", symbol.name)
125+
} else {
126+
symbol.name.to_owned()
127+
};
128+
123129
// FIXME handle the case where the function was made private to the
124130
// current codegen unit
125-
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
131+
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));
126132
}
127133
GlobalAsmOperandRef::SymStatic { def_id } => {
128134
if cfg!(not(feature = "inline_asm_sym")) {
@@ -134,7 +140,13 @@ fn codegen_global_asm_inner<'tcx>(
134140

135141
let instance = Instance::mono(tcx, def_id);
136142
let symbol = tcx.symbol_name(instance);
137-
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
143+
let symbol_name = if tcx.sess.target.is_like_darwin {
144+
format!("_{}", symbol.name)
145+
} else {
146+
symbol.name.to_owned()
147+
};
148+
149+
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));
138150
}
139151
}
140152
}

src/inline_asm.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,13 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
574574
CInlineAsmOperand::Const { ref value } => {
575575
generated_asm.push_str(value);
576576
}
577-
CInlineAsmOperand::Symbol { ref symbol } => generated_asm.push_str(symbol),
577+
CInlineAsmOperand::Symbol { ref symbol } => {
578+
if binary_format == BinaryFormat::Macho {
579+
generated_asm.push('_');
580+
}
581+
582+
generated_asm.push_str(symbol);
583+
}
578584
}
579585
}
580586
}

0 commit comments

Comments
 (0)