I had not taken the time to try and work with Rust on ARM64 in the past. Since I was doing disassembly of simple C programs on an one of our servers, I figured it couldn’t hurt to try the same thing with rust.
sudo yum install rust sudo yum install cargo cd devel/ cargo init hello cd hello/ cargo run |
that gives me
Finished dev [unoptimized + debuginfo] target(s) in 0.03s Running `target/debug/hello` Hello, world! |
but lets try it without debugging
# cargo build --release Compiling hello v0.1.0 (/root/devel/hello) Finished release [optimized] target(s) in 0.27s # objdump -d target/release/hello | wc -l 51553 |
50K Instructions of generated code for:
# cat src/main.rs fn main() { println!("Hello, world!"); } |
is the debug as big?
# cargo build Compiling hello v0.1.0 (/root/devel/hello) Finished dev [unoptimized + debuginfo] target(s) in 0.18s [root@eng16sys-r105 hello]# objdump -d target/debug/hello | wc -l 51699 |
Yes it is. Why so big? Boilerplate functions. Lots of them.
objdump -d target/debug/hello | awk '$2 ~ /<.*/ { print $2}' | wc -l 610 |
The Rust println! macro does not convert to a function direction, but if you look, you can see where it gets called. First, looking for main….
_ZN5hello4main17h90d99111aaa17f8eE 6ad8: d10103ff sub sp, sp, #0x40 6adc: a902fbff stp xzr, x30, [sp, #40] 6ae0: f00002a8 adrp x8, 5d000 <GCC_except_table175+0x1c6d0> 6ae4: 91206108 add x8, x8, #0x818 6ae8: 52800029 mov w9, #0x1 // #1 6aec: 910003e0 mov x0, sp 6af0: f90003ff str xzr, [sp] 6af4: a90127e8 stp x8, x9, [sp, #16] 6af8: f0000168 adrp x8, 35000 <_ZN4core7unicode12unicode_data15grapheme_extend6lookup17h5f4d177ea695cd95E+0x144> 6afc: 911a8108 add x8, x8, #0x6a0 6b00: f90013e8 str x8, [sp, #32] 6b04: 9400442d bl 17bb8 <_ZN3std2io5stdio6_print17hbe477eb3a718a117E> 6b08: f9401bfe ldr x30, [sp, #48] 6b0c: 910103ff add sp, sp, #0x40 6b10: d65f03c0 ret |
There are a few functions with “main” in them ,but this seems to be the one that calls a print function. bl 17bb8 <_ZN3std2io5stdio6_print17hbe477eb3a718a117E>