Skip to content

Commit 92ea947

Browse files
authored
Rollup merge of #146793 - folkertdev:naked-asm-func-end, r=Amanieu
naked_asm: emit a label starting with `func_end` The `cargo asm` tool (`cargo install cargo-show-asm`) pattern matches on such labels to figure out where functions end: normal functions generated by LLVM always do have such a label. We don't guarantee that naked functions emit such a label, but having `cargo asm` work is convenient. https://github.com/pacak/cargo-show-asm/blob/be45f67454ad8b634246a7fc69b3c6a963ee93f1/src/asm/statements.rs#L897-L901 To make the label name unique it's suffixed with the name of the current symbol. r? ```@Amanieu```
2 parents 5c1c479 + b279428 commit 92ea947

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ fn prefix_and_suffix<'tcx>(
228228
writeln!(begin, "{asm_name}:").unwrap();
229229

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

248251
writeln!(end).unwrap();
252+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
249253
writeln!(end, ".popsection").unwrap();
250254
if !arch_suffix.is_empty() {
251255
writeln!(end, "{}", arch_suffix).unwrap();
@@ -263,6 +267,7 @@ fn prefix_and_suffix<'tcx>(
263267
writeln!(begin, "{asm_name}:").unwrap();
264268

265269
writeln!(end).unwrap();
270+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
266271
writeln!(end, ".popsection").unwrap();
267272
if !arch_suffix.is_empty() {
268273
writeln!(end, "{}", arch_suffix).unwrap();
@@ -287,6 +292,7 @@ fn prefix_and_suffix<'tcx>(
287292
writeln!(end).unwrap();
288293
// .size is ignored for function symbols, so we can skip it
289294
writeln!(end, "end_function").unwrap();
295+
writeln!(end, ".Lfunc_end_{asm_name}:").unwrap();
290296
}
291297
BinaryFormat::Xcoff => {
292298
// the LLVM XCOFFAsmParser is extremely incomplete and does not implement many of the

tests/assembly-llvm/naked-functions/wasm32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use minicore::*;
2121
// CHECK: .functype nop () -> ()
2222
// CHECK-NOT: .size
2323
// CHECK: end_function
24+
// CHECK-LABEL: .Lfunc_end_nop:
2425
#[no_mangle]
2526
#[unsafe(naked)]
2627
extern "C" fn nop() {

0 commit comments

Comments
 (0)