Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use rustc_codegen_ssa::traits::{
};
use rustc_middle::bug;
use rustc_middle::ty::Instance;
use rustc_span::Span;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::asm::*;

use crate::builder::Builder;
use crate::callee::get_fn;
use crate::context::CodegenCx;
use crate::errors::UnwindingInlineAsm;
use crate::errors::{NullBytesInAsm, UnwindingInlineAsm};
use crate::type_of::LayoutGccExt;

// Rust asm! and GCC Extended Asm semantics differ substantially.
Expand Down Expand Up @@ -859,7 +859,7 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
template: &[InlineAsmTemplatePiece],
operands: &[GlobalAsmOperandRef<'tcx>],
options: InlineAsmOptions,
_line_spans: &[Span],
line_spans: &[Span],
) {
let asm_arch = self.tcx.sess.asm_arch.unwrap();

Expand Down Expand Up @@ -926,6 +926,13 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
}
// NOTE: seems like gcc will put the asm in the wrong section, so set it to .text manually.
template_str.push_str("\n.popsection");
// NOTE: GCC's add_top_level_asm uses CString which cannot contain null bytes.
// Emit an error if there are any null bytes in the template string.
Comment thread
antoyo marked this conversation as resolved.
Outdated
if template_str.contains('\0') {
let span = line_spans.first().copied().unwrap_or(DUMMY_SP);
self.tcx.dcx().emit_err(NullBytesInAsm { span });
return;
}
self.context.add_top_level_asm(None, &template_str);
}

Expand Down
7 changes: 7 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ pub(crate) struct LtoBitcodeFromRlib {
#[derive(Diagnostic)]
#[diag("explicit tail calls with the 'become' keyword are not implemented in the GCC backend")]
pub(crate) struct ExplicitTailCallsUnsupported;

#[derive(Diagnostic)]
#[diag("asm contains a NULL byte")]
pub(crate) struct NullBytesInAsm {
Comment thread
antoyo marked this conversation as resolved.
Outdated
#[primary_span]
pub span: Span,
}