japaric / cargo-call-stack

Whole program static stack analysis
Apache License 2.0
560 stars 50 forks source link

BUG: callee `memcmp` is unknown #63

Closed lulf closed 2 years ago

lulf commented 2 years ago

With the latest version (0.1.10), and from the main branch, I'm getting this error when running call-stack:

thread 'main' panicked at 'BUG: callee `memcmp` is unknown', /home/lulf/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-call-stack-0.1.10/src/main.rs:741:25

Example reproducer:

git clone https://github.com/lulf/embassy.git
cd embassy/examples/stm32wl
git checkout call-stack
git submodule update --init
cargo call-stack --bin lorawan
japaric commented 2 years ago

minified:

#![no_main]
#![no_std]

use core::{cmp::Ordering, panic::PanicInfo};

#[no_mangle]
fn _start() -> usize {
    fun as usize
}

fn fun(a: &str, b: &str) -> bool {
    if a.len() == 4 && b.len() == 4 {
        a.cmp(b) == Ordering::Equal
    } else {
        false
    }
}

#[panic_handler]
fn panic(_: &PanicInfo) -> ! {
    loop {}
}
$ cargo call-stack --bin app --target thumbv7m-none-eabi
thread 'main' panicked at 'BUG: callee `memcmp` is unknown', src/main.rs:741:25

the LLVM IR contains a call i32 @memcmp(blah blah) but the machine code does not contain the memcmp symbol because the IR was directly lowered to machine code.