Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ fn prefix_and_suffix<'tcx>(
writeln!(begin, "{asm_name}:").unwrap();

writeln!(end).unwrap();
// emit a label starting with `func_end` for `cargo asm` and other tooling that might
// pattern match on assembly generated by LLVM.
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
writeln!(end, ".size {asm_name}, . - {asm_name}").unwrap();
writeln!(end, ".popsection").unwrap();
if !arch_suffix.is_empty() {
Expand All @@ -246,6 +249,7 @@ fn prefix_and_suffix<'tcx>(
writeln!(begin, "{asm_name}:").unwrap();

writeln!(end).unwrap();
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
writeln!(end, ".popsection").unwrap();
if !arch_suffix.is_empty() {
writeln!(end, "{}", arch_suffix).unwrap();
Expand All @@ -263,6 +267,7 @@ fn prefix_and_suffix<'tcx>(
writeln!(begin, "{asm_name}:").unwrap();

writeln!(end).unwrap();
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
writeln!(end, ".popsection").unwrap();
if !arch_suffix.is_empty() {
writeln!(end, "{}", arch_suffix).unwrap();
Expand All @@ -287,6 +292,7 @@ fn prefix_and_suffix<'tcx>(
writeln!(end).unwrap();
// .size is ignored for function symbols, so we can skip it
writeln!(end, "end_function").unwrap();
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
}
BinaryFormat::Xcoff => {
// the LLVM XCOFFAsmParser is extremely incomplete and does not implement many of the
Expand Down
1 change: 1 addition & 0 deletions tests/assembly-llvm/naked-functions/wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use minicore::*;
// CHECK: .functype nop () -> ()
// CHECK-NOT: .size
// CHECK: end_function
// CHECK-LABEL: .Lfunc_end_nop:
#[no_mangle]
#[unsafe(naked)]
extern "C" fn nop() {
Expand Down
Loading