Show referenced strings
I'm just learning assembly, so not sure if this makes sense, but when I use godbolt, it includes all referenced strings, such as the const array below. Would it be possible for cargo-asm to include them as well?
pub fn g(i:usize) -> usize {
const XX:[usize;2] = [1,2];
XX[i]
}
$ cargo asm play::g
play::g:
push rax
mov rax, rdi
cmp rdi, 1
ja .LBB0_2
lea rcx, [rip, +, .Lbyte_str.0]
mov rax, qword, ptr, [rcx, +, 8*rax]
pop rcx
ret
.LBB0_2:
lea rdi, [rip, +, .Lpanic_bounds_check_loc.2]
mov edx, 2
mov rsi, rax
call core::panicking::panic_bounds_check
ud2
Godbolt:
example::g:
sub rsp, 24
mov rax, qword ptr [rip + .Lbyte_str.0]
mov qword ptr [rsp + 8], rax
mov rax, qword ptr [rip + .Lbyte_str.0+8]
mov qword ptr [rsp + 16], rax
cmp rdi, 2
setb cl
test cl, 1
mov qword ptr [rsp], rdi
jne .LBB0_1
jmp .LBB0_2
.LBB0_1:
mov rax, qword ptr [rsp]
mov rax, qword ptr [rsp + 8*rax + 8]
add rsp, 24
ret
.LBB0_2:
lea rdi, [rip + .Lpanic_bounds_check_loc.2]
mov eax, 2
mov edx, eax
mov rsi, qword ptr [rsp]
call core::panicking::panic_bounds_check@PLT
ud2
.Lbyte_str.0:
.asciz "\001\000\000\000\000\000\000\000\002\000\000\000\000\000\000"
str.1:
.ascii "/tmp/compiler-explorer-compiler118711-63-nn53u9.3jk4/example.rs"
.Lpanic_bounds_check_loc.2:
.quad str.1
.quad 63
.long 3
.long 5
I'm just learning assembly, so not sure if this makes sense, but when I use godbolt, it includes all referenced strings, such as the const array below. Would it be possible for cargo-asm to include them as well?
Thanks for the issue! Yes, this makes sense, would make cargo-asm much better, and shouldn't be too hard to implement.
The main issue here (and you will see that when you use godbolt more) is that when you put more functions in the program, these constant arrays get put at the beginning or end of the binary, so there might be functions in between.
Once we have the assembly for a function, we can check that all labels (.L...) that are used in the function, are actually displayed. Most of them are used to jump around inside the function, like .LBB0_2 above, but some like the .Lbyte_str.0: won't be. We can then search for them in the disassembly of the whole program, and print them after the function.