Skip to content

Commit c74d620

Browse files
authored
Rollup merge of #126803 - tgross35:verbose-asm, r=Amanieu
Change `asm-comments` to `verbose-asm`, always emit user comments Implements what is described in rust-lang/compiler-team#762 Tracking issue: #126802
2 parents c872a14 + 1a6893e commit c74d620

File tree

8 files changed

+94
-11
lines changed

8 files changed

+94
-11
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl OwnedTargetMachine {
3232
unique_section_names: bool,
3333
trap_unreachable: bool,
3434
singletree: bool,
35-
asm_comments: bool,
35+
verbose_asm: bool,
3636
emit_stack_size_section: bool,
3737
relax_elf_relocations: bool,
3838
use_init_array: bool,
@@ -64,7 +64,7 @@ impl OwnedTargetMachine {
6464
unique_section_names,
6565
trap_unreachable,
6666
singletree,
67-
asm_comments,
67+
verbose_asm,
6868
emit_stack_size_section,
6969
relax_elf_relocations,
7070
use_init_array,

compiler/rustc_codegen_llvm/src/back/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn target_machine_factory(
214214
sess.opts.unstable_opts.trap_unreachable.unwrap_or(sess.target.trap_unreachable);
215215
let emit_stack_size_section = sess.opts.unstable_opts.emit_stack_sizes;
216216

217-
let asm_comments = sess.opts.unstable_opts.asm_comments;
217+
let verbose_asm = sess.opts.unstable_opts.verbose_asm;
218218
let relax_elf_relocations =
219219
sess.opts.unstable_opts.relax_elf_relocations.unwrap_or(sess.target.relax_elf_relocations);
220220

@@ -289,7 +289,7 @@ pub fn target_machine_factory(
289289
funique_section_names,
290290
trap_unreachable,
291291
singlethread,
292-
asm_comments,
292+
verbose_asm,
293293
emit_stack_size_section,
294294
relax_elf_relocations,
295295
use_init_array,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ extern "C" {
21852185
UniqueSectionNames: bool,
21862186
TrapUnreachable: bool,
21872187
Singlethread: bool,
2188-
AsmComments: bool,
2188+
VerboseAsm: bool,
21892189
EmitStackSizeSection: bool,
21902190
RelaxELFRelocations: bool,
21912191
UseInitArray: bool,

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,6 @@ fn test_unstable_options_tracking_hash() {
757757
// tidy-alphabetical-start
758758
tracked!(allow_features, Some(vec![String::from("lang_items")]));
759759
tracked!(always_encode_mir, true);
760-
tracked!(asm_comments, true);
761760
tracked!(assume_incomplete_release, true);
762761
tracked!(binary_dep_depinfo, true);
763762
tracked!(box_noalias, false);
@@ -862,6 +861,7 @@ fn test_unstable_options_tracking_hash() {
862861
tracked!(uninit_const_chunk_threshold, 123);
863862
tracked!(unleash_the_miri_inside_of_you, true);
864863
tracked!(use_ctors_section, Some(true));
864+
tracked!(verbose_asm, true);
865865
tracked!(verify_llvm_ir, true);
866866
tracked!(virtual_function_elimination, true);
867867
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
407407
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
408408
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
409409
bool FunctionSections, bool DataSections, bool UniqueSectionNames,
410-
bool TrapUnreachable, bool Singlethread, bool AsmComments,
410+
bool TrapUnreachable, bool Singlethread, bool VerboseAsm,
411411
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
412412
const char *SplitDwarfFile, const char *OutputObjFile,
413413
const char *DebugInfoCompression, bool UseEmulatedTls,
@@ -435,8 +435,9 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
435435
Options.DataSections = DataSections;
436436
Options.FunctionSections = FunctionSections;
437437
Options.UniqueSectionNames = UniqueSectionNames;
438-
Options.MCOptions.AsmVerbose = AsmComments;
439-
Options.MCOptions.PreserveAsmComments = AsmComments;
438+
Options.MCOptions.AsmVerbose = VerboseAsm;
439+
// Always preserve comments that were written by the user
440+
Options.MCOptions.PreserveAsmComments = true;
440441
Options.MCOptions.ABIName = ABIStr;
441442
if (SplitDwarfFile) {
442443
Options.MCOptions.SplitDwarfFile = SplitDwarfFile;

compiler/rustc_session/src/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1630,8 +1630,6 @@ options! {
16301630
"only allow the listed language features to be enabled in code (comma separated)"),
16311631
always_encode_mir: bool = (false, parse_bool, [TRACKED],
16321632
"encode MIR of all functions into the crate metadata (default: no)"),
1633-
asm_comments: bool = (false, parse_bool, [TRACKED],
1634-
"generate comments into the assembly (may change behavior) (default: no)"),
16351633
assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
16361634
"assert that the incremental cache is in given state: \
16371635
either `loaded` or `not-loaded`."),
@@ -2107,6 +2105,8 @@ written to standard error output)"),
21072105
"Generate sync unwind tables instead of async unwind tables (default: no)"),
21082106
validate_mir: bool = (false, parse_bool, [UNTRACKED],
21092107
"validate MIR after each transformation"),
2108+
verbose_asm: bool = (false, parse_bool, [TRACKED],
2109+
"add descriptive comments from LLVM to the assembly (may change behavior) (default: no)"),
21102110
#[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]
21112111
verbose_internals: bool = (false, parse_bool, [TRACKED_NO_CRATE_HASH],
21122112
"in general, enable more debug printouts (default: no)"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# `verbose-asm`
2+
3+
The tracking issue for this feature is: [#126802](https://github.com/rust-lang/rust/issues/126802).
4+
5+
------------------------
6+
7+
This enables passing `-Zverbose-asm` to get contextual comments added by LLVM.
8+
9+
Sample code:
10+
11+
```rust
12+
#[no_mangle]
13+
pub fn foo(a: i32, b: i32) -> i32 {
14+
a + b
15+
}
16+
```
17+
18+
Default output:
19+
20+
```asm
21+
foo:
22+
push rax
23+
add edi, esi
24+
mov dword ptr [rsp + 4], edi
25+
seto al
26+
jo .LBB0_2
27+
mov eax, dword ptr [rsp + 4]
28+
pop rcx
29+
ret
30+
.LBB0_2:
31+
lea rdi, [rip + .L__unnamed_1]
32+
mov rax, qword ptr [rip + core::panicking::panic_const::panic_const_add_overflow::h9c85248fe0d735b2@GOTPCREL]
33+
call rax
34+
35+
.L__unnamed_2:
36+
.ascii "/app/example.rs"
37+
38+
.L__unnamed_1:
39+
.quad .L__unnamed_2
40+
.asciz "\017\000\000\000\000\000\000\000\004\000\000\000\005\000\000"
41+
```
42+
43+
With `-Zverbose-asm`:
44+
45+
```asm
46+
foo: # @foo
47+
# %bb.0:
48+
push rax
49+
add edi, esi
50+
mov dword ptr [rsp + 4], edi # 4-byte Spill
51+
seto al
52+
jo .LBB0_2
53+
# %bb.1:
54+
mov eax, dword ptr [rsp + 4] # 4-byte Reload
55+
pop rcx
56+
ret
57+
.LBB0_2:
58+
lea rdi, [rip + .L__unnamed_1]
59+
mov rax, qword ptr [rip + core::panicking::panic_const::panic_const_add_overflow::h9c85248fe0d735b2@GOTPCREL]
60+
call rax
61+
# -- End function
62+
.L__unnamed_2:
63+
.ascii "/app/example.rs"
64+
65+
.L__unnamed_1:
66+
.quad .L__unnamed_2
67+
.asciz "\017\000\000\000\000\000\000\000\004\000\000\000\005\000\000"
68+
69+
# DW_AT_external
70+
```

tests/assembly/asm-comments.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ assembly-output: emit-asm
2+
//@ only-x86_64
3+
// Check that comments in assembly get passed
4+
5+
#![crate_type = "lib"]
6+
7+
// CHECK-LABEL: test_comments:
8+
#[no_mangle]
9+
pub fn test_comments() {
10+
// CHECK: example comment
11+
unsafe { core::arch::asm!("nop // example comment") };
12+
}

0 commit comments

Comments
 (0)