Skip to content

Instantly share code, notes, and snippets.

@yytyd
Last active May 27, 2020 02:06
Show Gist options
  • Save yytyd/aadf6ae49d3b95a02dc4ad21c8d07263 to your computer and use it in GitHub Desktop.
Save yytyd/aadf6ae49d3b95a02dc4ad21c8d07263 to your computer and use it in GitHub Desktop.
C++ raw pointer vs Rust
foo(int*): # @foo(int*)
push rbx
mov rbx, rdi
cmp dword ptr [rdi], 43
jl .LBB0_2
mov rdi, rbx
call bar(int*)
mov dword ptr [rbx], 42
.LBB0_2:
mov rdi, rbx
pop rbx
jmp baz(int*) # TAILCALL
<&T as core::fmt::Display>::fmt:
mov rdi, qword ptr [rdi]
jmp qword ptr [rip + _ZN4core3fmt3num3imp52_$LT$impl$u20$core..fmt..Display$u20$for$u20$i32$GT$3fmt17hd426623d2aeaa98aE@GOTPCREL]
core::ptr::drop_in_place:
mov rdi, qword ptr [rdi]
mov esi, 4
mov edx, 4
jmp qword ptr [rip + __rust_dealloc@GOTPCREL]
example::bar:
sub rsp, 72
mov qword ptr [rsp], rdi
mov rax, rsp
mov qword ptr [rsp + 8], rax
lea rax, [rip + <&T as core::fmt::Display>::fmt]
mov qword ptr [rsp + 16], rax
lea rax, [rip + .L__unnamed_1]
mov qword ptr [rsp + 24], rax
mov qword ptr [rsp + 32], 1
mov qword ptr [rsp + 40], 0
lea rax, [rsp + 8]
mov qword ptr [rsp + 56], rax
mov qword ptr [rsp + 64], 1
lea rdi, [rsp + 24]
call qword ptr [rip + std::io::stdio::_print@GOTPCREL]
add rsp, 72
ret
example::baz:
push rbx
sub rsp, 80
mov qword ptr [rsp + 8], rdi
lea rax, [rsp + 8]
mov qword ptr [rsp + 16], rax
lea rax, [rip + <&T as core::fmt::Display>::fmt]
mov qword ptr [rsp + 24], rax
lea rax, [rip + .L__unnamed_1]
mov qword ptr [rsp + 32], rax
mov qword ptr [rsp + 40], 1
mov qword ptr [rsp + 48], 0
lea rax, [rsp + 16]
mov qword ptr [rsp + 64], rax
mov qword ptr [rsp + 72], 1
lea rdi, [rsp + 32]
call qword ptr [rip + std::io::stdio::_print@GOTPCREL]
mov rdi, qword ptr [rsp + 8]
mov esi, 4
mov edx, 4
call qword ptr [rip + __rust_dealloc@GOTPCREL]
add rsp, 80
pop rbx
ret
mov rbx, rax
lea rdi, [rsp + 8]
call core::ptr::drop_in_place
mov rdi, rbx
call _Unwind_Resume@PLT
ud2
example::foo:
push rbx
mov rbx, rdi
cmp dword ptr [rdi], 43
jl .LBB4_2
mov rdi, rbx
call example::bar
mov dword ptr [rbx], 42
.LBB4_2:
mov rdi, rbx
pop rbx
jmp example::baz
.L__unnamed_2:
.L__unnamed_1:
.quad .L__unnamed_2
.zero 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment