Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate commented assembly with --emit=asm #35741

Closed
jrmuizel opened this issue Aug 17, 2016 · 10 comments · Fixed by #53290
Closed

Generate commented assembly with --emit=asm #35741

jrmuizel opened this issue Aug 17, 2016 · 10 comments · Fixed by #53290
Labels
A-frontend Area: frontend (errors, parsing and HIR) C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@jrmuizel
Copy link
Contributor

clang -S produces nicely commented .s files. It would be nice if rustc did this too.

e.g. simd shuffles are commented
.loc directives have the corresponding line number comment
.loc 1 4 25 is_stmt 1 ## test.c:4:25
debug information is commented
.byte 14 ## DW_FORM_strp
.byte 17 ## DW_AT_low_pc
.byte 1 ## DW_FORM_addr
.byte 18 ## DW_AT_high_pc
.byte 1 ## DW_FORM_addr

@eddyb
Copy link
Member

eddyb commented Aug 18, 2016

There might be a -C or -Z flag already for this. AFAIK what clang emits comes from LLVM.

@Mark-Simulacrum
Copy link
Member

This flag is already added, should be usable (issue can be closed?):
-Z asm-comments -- generate comments into the assembly (may change behavior)

@jrmuizel
Copy link
Contributor Author

Any reason not to make this the default?

@Mark-Simulacrum
Copy link
Member

Likely the fact that it may change the behavior (I don't actually know what that means but this seems like a valid assumption).

@jrmuizel
Copy link
Contributor Author

it looks like -Z asm-comments doesn't do this. MCOptions.AsmVerbose must be set to true for the assembler to emit them.

@Mark-Simulacrum
Copy link
Member

So it looks like -Zasm-comments isn't actually used anywhere based on what I can find in the source... or, rather, its uses are in methods that are themselves never called.

@Mark-Simulacrum Mark-Simulacrum added A-inline-assembly Area: inline asm!(..) A-frontend Area: frontend (errors, parsing and HIR) and removed A-inline-assembly Area: inline asm!(..) labels May 20, 2017
@jrmuizel
Copy link
Contributor Author

Yeah, to get comments I believe I needed to set a verbose flag in some llvm context. Clang does this by default and it would be nice if rustc did too.

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 25, 2017
@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 7, 2018

IIUC without this neither the playground nor godbolt (compiler-explorer) can map assembly to lines of Rust source code.

@hanna-kruppe
Copy link
Contributor

Godbolt uses debug info AFAIK? Our debug info isn't always great but in general it's working, isn't it?

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 7, 2018

It seems like they just don't do it much. Godbolt uses .loc directives in the assembly file, which rustc seems to generate correctly, sorry for the noise.

kennytm pushed a commit to kennytm/rust that referenced this issue Aug 12, 2018
kennytm added a commit to kennytm/rust that referenced this issue Aug 12, 2018
Make LLVM emit assembly comments with -Z asm-comments

Fixes rust-lang#35741, and makes `-Z asm-comments` actually do something useful.

Before:
```
	.section	.text.main,"ax",@progbits
	.globl	main
	.p2align	4, 0x90
	.type	main,@function
main:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)
	movq	%rax, %rsi
	movq	(%rsp), %rdx
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
```

After:
```
	.section	.text.main,"ax",@progbits
	.globl	main                    # -- Begin function main
	.p2align	4, 0x90
	.type	main,@function
main:                                   # @main
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)            # 8-byte Spill
	movq	%rax, %rsi
	movq	(%rsp), %rdx            # 8-byte Reload
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
                                        # -- End function
```
kennytm added a commit to kennytm/rust that referenced this issue Aug 13, 2018
Make LLVM emit assembly comments with -Z asm-comments

Fixes rust-lang#35741, and makes `-Z asm-comments` actually do something useful.

Before:
```
	.section	.text.main,"ax",@progbits
	.globl	main
	.p2align	4, 0x90
	.type	main,@function
main:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)
	movq	%rax, %rsi
	movq	(%rsp), %rdx
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
```

After:
```
	.section	.text.main,"ax",@progbits
	.globl	main                    # -- Begin function main
	.p2align	4, 0x90
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)            # 8-byte Spill
	movq	%rax, %rsi
	movq	(%rsp), %rdx            # 8-byte Reload
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
                                        # -- End function
```
kennytm added a commit to kennytm/rust that referenced this issue Aug 14, 2018
Make LLVM emit assembly comments with -Z asm-comments

Fixes rust-lang#35741, and makes `-Z asm-comments` actually do something useful.

Before:
```
	.section	.text.main,"ax",@progbits
	.globl	main
	.p2align	4, 0x90
	.type	main,@function
main:
	.cfi_startproc
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)
	movq	%rax, %rsi
	movq	(%rsp), %rdx
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
```

After:
```
	.section	.text.main,"ax",@progbits
	.globl	main                    # -- Begin function main
	.p2align	4, 0x90
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movslq	%edi, %rax
	leaq	_ZN1t4main17he95a7d4f1843730eE(%rip), %rdi
	movq	%rsi, (%rsp)            # 8-byte Spill
	movq	%rax, %rsi
	movq	(%rsp), %rdx            # 8-byte Reload
	callq	_ZN3std2rt10lang_start17h3121da83b2bc3697E
	movl	%eax, %ecx
	movl	%ecx, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	main, .Lfunc_end8-main
	.cfi_endproc
                                        # -- End function
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: frontend (errors, parsing and HIR) C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants