japaric / cargo-call-stack

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

assertion failure on ARM thumb #77

Closed aholtzma closed 1 year ago

aholtzma commented 1 year ago

[2022-11-02T16:09:07Z WARN cargo_call_stack] assuming that asm!("push {lr}\0Asub sp, sp, #4\0Amov r2, sp\0Abl udivmodsi4\0Aldr r1, [sp]\0Aadd sp, sp, #4\0Apop {pc}") does not use the stack in `aeabi_uidivmod thread 'main' panicked at 'assertion failed:(left != right) left:14, right:14`', /Users/aholtzma/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-call-stack-0.1.12/src/thumb.rs:136:13 stack backtrace: 0: rust_begin_unwind at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/std/src/panicking.rs:517:5 1: core::panicking::panic_fmt at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35/library/core/src/panicking.rs:101:14 2: core::panicking::assert_failed_inner 3: core::panicking::assert_failed 4: cargo_call_stack::thumb::analyze 5: cargo_call_stack::run 6: cargo_call_stack::main

aholtzma commented 1 year ago

Maybe related to #24?

japaric commented 1 year ago

I cannot reproduce the issue with cargo-call-stack v0.1.12; rustc 1.67.0-nightly (96ddd32c4 2022-11-14); the thumbv7m-none-eabi, thumbv7em-none-eabi or thumbv7em-none-eabihf targets; and the following program.

// file: firmware/examples/uidivmod.rs in this repository
#![no_main]
#![no_std]

use panic_halt as _;

#[no_mangle]
fn _start() -> usize {
    extern "C" {
        fn __aeabi_uidivmod();
    }
    __aeabi_uidivmod as usize
}

I get a warning but no assertion

[2022-11-15T18:02:22Z WARN  cargo_call_stack] assuming that asm!("push {lr}\0Asub sp, sp, #4\0Amov r2, sp\0Abl __udivmodsi4\0Aldr r1, [sp]\0Aadd sp, sp, #4\0Apop {pc}") does *not* use the stack in `__aeabi_uidivmod`

cg

can you provide an example that reproduces the issue? what version of compiler_builtins do you see in the output of cargo-call-stack? you may need to call cargo clean to see the compiler-builtins line

$ cd firmware # in this repository
$ cargo clean
$ cargo call-stack --example uidivmod > /tmp/cg.dot
(..)
   Compiling compiler_builtins v0.1.82
(..)
japaric commented 1 year ago

I was able to reproduce this with thumbv6m-none-eabi after realizing bug #79 was getting in the way. PR #80 should fix this.

japaric commented 1 year ago

closing as fixed by #80

japaric commented 1 year ago

release v0.1.13 includes a fix for this