coolxv / cpp-stub

C++ unit test stub(not mock) and awesome.Surpported ISA x86,x86-64,arm64,arm32,arm thumb,mips64,riscv,loongarch64.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

交叉编译arm32无法正确运行程序

RelaxOne opened this issue · comments

前两天在使用 stub 进行插桩时,遇到了在 arm32 上执行段错误的问题,通过对源代码的反汇编分析发现,使用 arm-linux-g++ 编译器编译出来的地址和程序中获取函数的地址有差距,后来发现需要在编译的时候添加 -marm 参数。这样就能得到正确的地址了。
11f6541a1ddc6849375b98c057e77f2

对thumb模式跟arm模式混合使用的话,现在的打桩需要做下处理,
我现在正在使用rt-thread,它的qemu-vexpress-a9是使用的thumb模式的libc,然后用cpp-stub打桩的话之后会挂掉。

 arm-none-eabi-gcc -march=armv7-a -marm -msoft-float --print-file-name=libc.a
gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/lib/thumb/v7/nofp/libc.a

初步想法是, 对于thumb模式的话,获取的符号地址的最地位是1,增对这个需要做下特殊处理,但是我现在还没有成功构建thumb到arm的跳转指令