japaric / cargo-call-stack

Whole program static stack analysis
Apache License 2.0
579 stars 52 forks source link

LLVM reported that `__aeabi_memcpy` uses 0 bytes of stack but this doesn't match our analysis #37

Closed teamplayer3 closed 3 years ago

teamplayer3 commented 3 years ago

I tried analyzing the cortex-m-test crate, more specific the hello example and cargo-call-stack panicked.

Compiled with:

executed command:

cargo +nightly-2021-09-12 call-stack --target thumbv7m-none-eabi --example hello

And I got the following:

[2021-09-16T07:20:37Z WARN  cargo_call_stack] ad-hoc: injecting stack usage information for `__aeabi_memcpy` (last checked: Rust 1.33.0)
[2021-09-16T07:20:37Z WARN  cargo_call_stack] ad-hoc: injecting stack usage information for `__aeabi_memcpy4` (last checked: Rust 1.33.0)
[2021-09-16T07:20:37Z WARN  cargo_call_stack] no type information for `memcpy`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `0`: BUG: LLVM reported that `__aeabi_memcpy` uses 0 bytes of stack but this doesn't match our analysis', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-call-stack-0.1.5/src/main.rs:1003:29

I recognized that this could happen in the future, as it said in the README.

I tried it with older versions and recognized that in version 1.53.0-nightly I only get the warnings, but it compiles.

[2021-09-16T09:28:08Z WARN  cargo_call_stack] ad-hoc: injecting stack usage information for `__aeabi_memcpy` (last checked: Rust 1.33.0)
[2021-09-16T09:28:08Z WARN  cargo_call_stack] ad-hoc: injecting stack usage information for `__aeabi_memcpy4` (last checked: Rust 1.33.0)

When I use the version 1.54.0-nightly and above I get the panicking from above.

japaric commented 3 years ago

minimal repro:

#![no_main]
#![no_std]

use nrf52840_hal as _; // device-specific vector table (probably not necessary to repro)

#[cortex_m_rt::entry]
fn main() -> ! {
    loop {}
}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
    loop {}
}

assertion:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `16`,
 right: `0`: BUG: LLVM reported that `__aeabi_memcpy` uses 0 bytes of stack but this doesn't match our analysis', src/main.rs:1012:29

Machine code:

$ arm-none-eabi-objdump -Cd target/thumbv7em-none-eabihf/release/hello
00000192 <__aeabi_memcpy>:
 192:   f000 b843   b.w 21c <memcpy>
japaric commented 3 years ago

assertion fixed in #41