-
Hello, I'm trying to learn I want to track the syscall doing the writing of an "hello world" to the console but I don't find it in the assembly. I'm using the Rust auto-generated hello world project. I know the syscall is done because write(1, "Hello, world!\n", 14Hello, world!) = 14 I've also wrote the hello world in .global _start
.intel_syntax noprefix
_start:
# sys_write hello world
mov rax, 1 # sys_write number is 1
mov rdi, 1 # fd 1 is stdout
lea rsi, [hello_world]
mov rdx, 14 # We hardcode the len of hello world
syscall
# sys_exit error code
mov rax, 60 # sys_exit number is 60
mov rdi, 0 # the error code we want to give
syscall
hello_world:
.asciz "Hello, World!\n" But if try to find the cargo asm --everything | grep syscall I have not result. Same thing with the As the assembly for the Rust function is: .section .text.foo::main,"ax",@progbits
.p2align 4, 0x90
.type foo::main,@function
foo::main:
.cfi_startproc
sub rsp, 56
.cfi_def_cfa_offset 64
lea rax, [rip + .L__unnamed_2]
mov qword ptr [rsp + 24], rax
mov qword ptr [rsp + 32], 1
mov qword ptr [rsp + 8], 0
lea rax, [rip + .L__unnamed_3]
mov qword ptr [rsp + 40], rax
mov qword ptr [rsp + 48], 0
lea rdi, [rsp + 8]
call qword ptr [rip + std::io::stdio::_print@GOTPCREL]
add rsp, 56
.cfi_def_cfa_offset 8
ret I suppose the syscall happen within |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You are correct, syscall happens inside |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer! I have tried to link statically the stdlib using the musl target. But then when looking at the assembly, still no syscall: cargo asm --everything --target x86_64-unknown-linux-musl | grep syscall I have also tried to rebuild the std for my crate using build-std feature : cargo +nightly asm --everything -Z build-std --target x86_64-unknown-linux-musl | grep syscall But without success also. |
Beta Was this translation helpful? Give feedback.
-
A recent version of |
Beta Was this translation helpful? Give feedback.
cargo-show-asm
(at least at the moment) does not decompile the binary produced. It instead asks forrustc
to emit generated assembly (or llvm, mir, etc) and works with that. Static linking with musl happens after. And even withbuild-std
compilation of stdlib happens as a separate compilation unit - not somewherecargo-show-asm
looks.