-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Support using const pointers in asm const operand
#138618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
086e52e
8337efc
e7467b6
b60bb73
b5bfc59
9822024
5916d6e
d6b2782
0846b11
f4011e8
7c877c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,15 @@ | ||
| //! The AOT driver uses [`cranelift_object`] to write object files suitable for linking into a | ||
| //! standalone executable. | ||
|
|
||
| use std::fmt::Write as _; | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
| use std::process::{Command, Stdio}; | ||
| use std::sync::Arc; | ||
|
|
||
| use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; | ||
| use rustc_codegen_ssa::traits::{AsmCodegenMethods, GlobalAsmOperandRef}; | ||
| use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar as ConstScalar}; | ||
| use rustc_middle::ty::TyCtxt; | ||
| use rustc_middle::ty::layout::{ | ||
| FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers, | ||
|
|
@@ -108,27 +110,54 @@ fn codegen_global_asm_inner<'tcx>( | |
| InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span } => { | ||
| use rustc_codegen_ssa::back::symbol_export::escape_symbol_name; | ||
| match operands[operand_idx] { | ||
| GlobalAsmOperandRef::Const { ref string } => { | ||
| global_asm.push_str(string); | ||
| } | ||
| GlobalAsmOperandRef::SymFn { instance } => { | ||
| if cfg!(not(feature = "inline_asm_sym")) { | ||
| tcx.dcx().span_err( | ||
| span, | ||
| "asm! and global_asm! sym operands are not yet supported", | ||
| ); | ||
| } | ||
| GlobalAsmOperandRef::Const { value, ty, instance: _ } => { | ||
| match value { | ||
| ConstScalar::Int(int) => { | ||
| let string = rustc_codegen_ssa::common::asm_const_to_str( | ||
| tcx, | ||
| int, | ||
| FullyMonomorphizedLayoutCx(tcx).layout_of(ty), | ||
| ); | ||
| global_asm.push_str(&string); | ||
| } | ||
|
|
||
| let symbol = tcx.symbol_name(instance); | ||
| let symbol_name = if tcx.sess.target.is_like_darwin { | ||
| format!("_{}", symbol.name) | ||
| } else { | ||
| symbol.name.to_owned() | ||
| }; | ||
| ConstScalar::Ptr(ptr, _) => { | ||
| let (prov, offset) = ptr.prov_and_relative_offset(); | ||
| let global_alloc = tcx.global_alloc(prov.alloc_id()); | ||
| let symbol = match global_alloc { | ||
| GlobalAlloc::Function { instance } => { | ||
| if cfg!(not(feature = "inline_asm_sym")) { | ||
| tcx.dcx().span_err( | ||
| span, | ||
| "asm! and global_asm! sym operands are not yet supported", | ||
| ); | ||
| } | ||
|
|
||
| // 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)); | ||
| // FIXME handle the case where the function was made private to the | ||
| // current codegen unit | ||
| tcx.symbol_name(instance) | ||
| } | ||
| GlobalAlloc::Static(def_id) => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would tend to agree with removing |
||
| let instance = Instance::mono(tcx, def_id); | ||
| tcx.symbol_name(instance) | ||
| } | ||
| GlobalAlloc::Memory(_) | ||
| | GlobalAlloc::VTable(..) | ||
| | GlobalAlloc::TypeId { .. } => unreachable!(), | ||
| }; | ||
| 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)); | ||
|
|
||
| if offset != Size::ZERO { | ||
| let offset = tcx.sign_extend_to_target_isize(offset.bytes()); | ||
| write!(global_asm, "{offset:+}").unwrap(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| GlobalAsmOperandRef::SymStatic { def_id } => { | ||
| if cfg!(not(feature = "inline_asm_sym")) { | ||
|
|
@@ -137,7 +166,6 @@ fn codegen_global_asm_inner<'tcx>( | |
| "asm! and global_asm! sym operands are not yet supported", | ||
| ); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please restore this newline. |
||
| let instance = Instance::mono(tcx, def_id); | ||
| let symbol = tcx.symbol_name(instance); | ||
| let symbol_name = if tcx.sess.target.is_like_darwin { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error should apply to all constants that reference a symbol.
View changes since the review