rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.83k stars 12.66k forks source link

`emit-stack-sizes` not reporting correct stack size #108741

Open xphoniex opened 1 year ago

xphoniex commented 1 year ago

I have a library and and app using the library, and compiling for AVR target using avr-gcc. It's seem to be overflowing the device so I want to check stack usage. I tried building my library which is pure rust and got:

$ RUSTFLAGS="-Z emit-stack-sizes" cargo  build --lib -r
...

$ size -A target/release/libnoble_secp256k1.rlib | grep -A1 -B1 double
.text                                                                               0      0
.text._ZN15noble_secp256k15point5Point17double_assign_mod17h64c79c0a4005e01fE    3040      0
.stack_sizes                                                                       10      0

which makes no sense as the function works with 64-byte numbers, and does a few allocations. I turned to cargo-call-stack and as it doesn't support AVR either (https://github.com/japaric/cargo-call-stack/issues/92), I chose an ARM target to view call-stack output: Screenshot from 2023-03-04 17-33-27

so according to cargo-call-stack which uses emit-stack-sizes under the hood, the same function double_assign_mod uses 1424 bytes, which makes more sense.

related:

rustc --version --verbose:

nightly-2022-07-10

@japaric

xphoniex commented 1 year ago

@Nilstrieb this is not exactly AVR as I'm running RUSTFLAGS="-Z emit-stack-sizes" when building library, which is pure rust, and target shouldn't matter.

xphoniex commented 1 year ago

maybe this is related:

The tool only supports ELF binaries because -Z emit-stack-sizes only supports the ELF format.