1-1. Analysis: Hello World

by gg582 · 2026-05-23 11:04:59 · 34 views

Rust Assembly—This is too dirty for low-level development.

When studying Rust, many C developers wonder if we can see assembly code clearly—the answer is no.

Unfortunately, Rust generates dirty and fast assembly that is not eligible.

In here, I will cut some parts of main function and see what is happening.


sed -n '/<hello_rust::main>:/,/^$/p' hello.asm

Now we can see what is actually happening.

0000000000009698 <hello_rust::main>: 
    9698:       d10243ff        sub     sp, sp, #0x90 
    969c:       a9087bfd        stp     x29, x30, [sp, #128] 
    96a0:       910203fd        add     x29, sp, #0x80 
    96a4:       910023e8        add     x8, sp, #0x8 
    96a8:       f90003e8        str     x8, [sp] 
    96ac:       b00001a0        adrp    x0, 3e000 <init_have_lse_atomics+0x14> 
    96b0:       911a2000        add     x0, x0, #0x688 
    96b4:       528001a9        mov     w9, #0xd                        // #13 
    96b8:       2a0903e1        mov     w1, w9 
    96bc:       94000198        bl      9d1c <<alloc::string::String as core::convert::From<&str>>::from> 
    96c0:       f94003e0        ldr     x0, [sp] 
    96c4:       d10083a8        sub     x8, x29, #0x20 
    96c8:       94000168        bl      9c68 <core::fmt::rt::Argument::new_display> 
    96cc:       14000008        b       96ec <hello_rust::main+0x54> 
    96d0:       910023e0        add     x0, sp, #0x8 
    96d4:       9400004c        bl      9804 <core::ptr::drop_in_place<alloc::string::String>> 
    96d8:       14000016        b       9730 <hello_rust::main+0x98> 
    96dc:       f81f03a0        stur    x0, [x29, #-16] 
    96e0:       2a0103e8        mov     w8, w1 
    96e4:       b81f83a8        stur    w8, [x29, #-8] 
    96e8:       17fffffa        b       96d0 <hello_rust::main+0x38> 
    96ec:       3cde03a0        ldur    q0, [x29, #-32] 
    96f0:       d100c3a1        sub     x1, x29, #0x30 
    96f4:       3c9d03a0        stur    q0, [x29, #-48] 
    96f8:       910083e8        add     x8, sp, #0x20 
    96fc:       900002a0        adrp    x0, 5d000 <__abi_tag+0xf9a0> 
    9700:       91080000        add     x0, x0, #0x200 
    9704:       94000069        bl      98a8 <core::fmt::rt::<impl core::fmt::Arguments>::new_v1> 
    9708:       14000001        b       970c <hello_rust::main+0x74> 
    970c:       910083e0        add     x0, sp, #0x20 
    9710:       94005b43        bl      2041c <std::io::stdio::_print> 
    9714:       14000001        b       9718 <hello_rust::main+0x80> 
    9718:       910023e0        add     x0, sp, #0x8 
    971c:       9400003a        bl      9804 <core::ptr::drop_in_place<alloc::string::String>> 
    9720:       a9487bfd        ldp     x29, x30, [sp, #128] 
    9724:       910243ff        add     sp, sp, #0x90 
    9728:       d65f03c0        ret 
    972c:       97fffe0d        bl      8f60 <core::panicking::panic_in_cleanup> 
    9730:       f85f03a0        ldur    x0, [x29, #-16] 
    9734:       97ffedab        bl      4de0 <_Unwind_Resume@plt>  

What…? new_display

As you can see, Rust makes a new display for just showing 'Hello World', making the whole program barely understandable.

This is only aiming for safety while delegating all debugging processes to a debugger and dirty automated traces.

But at least you can see where Rust dropped a local variable "Hello World" when escaping the scope.

   971c:       9400003a        bl      9804 <core::ptr::drop_in_place<alloc::string::String>>

Well….As a result, the scope ends at this line. And it does panic in cleanup.

In my opinion, rust did too many things to increase safety, and I am pretty sure none of us are coding space rockets.

My Opinion

At least Go provides better object dump tool inside, and Go tried to wrap things into runtime module. And it is quite clearly done at assembly level too.hello.asm

Back

Comments

No comments yet.