Skip to content

Commit 0e31b92

Browse files
committed
Add codegen for global_asm! sym operands
1 parent 249d3e9 commit 0e31b92

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/asm.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,14 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
258258
}
259259

260260
InlineAsmOperandRef::SymFn { instance } => {
261+
// TODO(@Amanieu): Additional mangling is needed on
262+
// some targets to add a leading underscore (Mach-O)
263+
// or byte count suffixes (x86 Windows).
261264
constants_len += self.tcx.symbol_name(instance).name.len();
262265
}
263266
InlineAsmOperandRef::SymStatic { def_id } => {
267+
// TODO(@Amanieu): Additional mangling is needed on
268+
// some targets to add a leading underscore (Mach-O).
264269
constants_len += self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name.len();
265270
}
266271
}
@@ -412,13 +417,16 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
412417
}
413418

414419
InlineAsmOperandRef::SymFn { instance } => {
420+
// TODO(@Amanieu): Additional mangling is needed on
421+
// some targets to add a leading underscore (Mach-O)
422+
// or byte count suffixes (x86 Windows).
415423
let name = self.tcx.symbol_name(instance).name;
416424
template_str.push_str(name);
417425
}
418426

419427
InlineAsmOperandRef::SymStatic { def_id } => {
420-
// TODO(@Commeownist): This may not be sufficient for all kinds of statics.
421-
// Some statics may need the `@plt` suffix, like thread-local vars.
428+
// TODO(@Amanieu): Additional mangling is needed on
429+
// some targets to add a leading underscore (Mach-O).
422430
let instance = Instance::mono(self.tcx, def_id);
423431
let name = self.tcx.symbol_name(instance).name;
424432
template_str.push_str(name);
@@ -656,8 +664,8 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
656664
}
657665
}
658666

659-
impl<'gcc, 'tcx> AsmMethods for CodegenCx<'gcc, 'tcx> {
660-
fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[GlobalAsmOperandRef], options: InlineAsmOptions, _line_spans: &[Span]) {
667+
impl<'gcc, 'tcx> AsmMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
668+
fn codegen_global_asm(&self, template: &[InlineAsmTemplatePiece], operands: &[GlobalAsmOperandRef<'tcx>], options: InlineAsmOptions, _line_spans: &[Span]) {
661669
let asm_arch = self.tcx.sess.asm_arch.unwrap();
662670

663671
// Default to Intel syntax on x86
@@ -690,6 +698,22 @@ impl<'gcc, 'tcx> AsmMethods for CodegenCx<'gcc, 'tcx> {
690698
// here unlike normal inline assembly.
691699
template_str.push_str(string);
692700
}
701+
702+
GlobalAsmOperandRef::SymFn { instance } => {
703+
// TODO(@Amanieu): Additional mangling is needed on
704+
// some targets to add a leading underscore (Mach-O)
705+
// or byte count suffixes (x86 Windows).
706+
let name = self.tcx.symbol_name(instance).name;
707+
template_str.push_str(name);
708+
}
709+
710+
GlobalAsmOperandRef::SymStatic { def_id } => {
711+
// TODO(@Amanieu): Additional mangling is needed on
712+
// some targets to add a leading underscore (Mach-O).
713+
let instance = Instance::mono(self.tcx, def_id);
714+
let name = self.tcx.symbol_name(instance).name;
715+
template_str.push_str(name);
716+
}
693717
}
694718
}
695719
}

0 commit comments

Comments
 (0)