about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-09-21 14:42:35 +1000
committerGitHub <noreply@github.com>2025-09-21 14:42:35 +1000
commit92ea947c782cbfb1f2e75e2c4b53ebe4158a7f33 (patch)
treecf699d979e0dc61bb28b491cfa12937f3c2b3cfa /compiler
parent5c1c47925e8669831f1c75eed0784d4ff9ac85fb (diff)
parentb27942853efdb2fde2b6f73023c38ebfec3fcb8f (diff)
downloadrust-92ea947c782cbfb1f2e75e2c4b53ebe4158a7f33.tar.gz
rust-92ea947c782cbfb1f2e75e2c4b53ebe4158a7f33.zip
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```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/naked_asm.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
index 31784cabf4a..e7239ebfecf 100644
--- a/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
@@ -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() {
@@ -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();
@@ -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();
@@ -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