Add leading underscore to asm symbols on Mach-O

This commit is contained in:
Cathal Mullan
2026-03-02 20:32:29 +00:00
parent e722ae6dba
commit cf6e7bcf59
2 changed files with 21 additions and 3 deletions
+14 -2
View File
@@ -120,9 +120,15 @@ fn codegen_global_asm_inner<'tcx>(
}
let symbol = tcx.symbol_name(instance);
let symbol_name = if tcx.sess.target.is_like_darwin {
format!("_{}", symbol.name)
} else {
symbol.name.to_owned()
};
// FIXME handle the case where the function was made private to the
// current codegen unit
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));
}
GlobalAsmOperandRef::SymStatic { def_id } => {
if cfg!(not(feature = "inline_asm_sym")) {
@@ -134,7 +140,13 @@ fn codegen_global_asm_inner<'tcx>(
let instance = Instance::mono(tcx, def_id);
let symbol = tcx.symbol_name(instance);
global_asm.push_str(&escape_symbol_name(tcx, symbol.name, span));
let symbol_name = if tcx.sess.target.is_like_darwin {
format!("_{}", symbol.name)
} else {
symbol.name.to_owned()
};
global_asm.push_str(&escape_symbol_name(tcx, &symbol_name, span));
}
}
}
+7 -1
View File
@@ -574,7 +574,13 @@ fn generate_asm_wrapper(&self, asm_name: &str) -> String {
CInlineAsmOperand::Const { ref value } => {
generated_asm.push_str(value);
}
CInlineAsmOperand::Symbol { ref symbol } => generated_asm.push_str(symbol),
CInlineAsmOperand::Symbol { ref symbol } => {
if binary_format == BinaryFormat::Macho {
generated_asm.push('_');
}
generated_asm.push_str(symbol);
}
}
}
}