Gcc 来自libm的函数sinf不';t臂式QEMU机器上的返回

Gcc 来自libm的函数sinf不';t臂式QEMU机器上的返回,gcc,arm,qemu,libm,Gcc,Arm,Qemu,Libm,我试图在用QEMU模拟的ARM机器上运行以下代码 #include "math.h" // Newlib doesn't implement this function. void _exit(int status) { while (1); } int main() { float a = 1.25; float b = sinf(a); return 0; } 使用的工具链: $ arm-none-eabi-gcc --version arm-none-eabi-

我试图在用QEMU模拟的ARM机器上运行以下代码

#include "math.h"

// Newlib doesn't implement this function.
void _exit(int status) {
    while (1);
}

int main() {
  float a = 1.25;

  float b = sinf(a);
  return 0;
}
使用的工具链:

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.3 20131129 (release) [ARM/embedded-4_8-branch revision 205641]
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
代码是用以下代码编译的:

arm-none-eabi-gcc -g -o math.elf math.c -lm
QEMU机器的启动方式如下:

$ qemu-system-arm -M realview-pbx-a9 -cpu cortex-a9 -kernel math.elf -nographic -serial /dev/null -s -S
GDB会话看起来像:

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x00008104 in _start ()
(gdb) set $pc = 0x822c
(gdb) break *0x8240
Breakpoint 1 at 0x8240: file math.c, line 10.
(gdb) break *0x824c
Breakpoint 2 at 0x824c: file math.c, line 11.
(gdb) c
Continuing.

Breakpoint 1, main () at math.c:10
10    float b = sinf(a);
(gdb) c
Continuing.
断点2设置在最后一行(返回0)。从GDB会话日志可以看出,第二个断点从未到达。计算只是停留在sinf函数中。知道为什么吗


我正在试验直接在ARM汇编中编写的类似代码,结果是一样的

看来我误用了gdb。我还在ARM-v6机器上测试了代码:

$ qemu-system-arm -M versatilepb -cpu arm1176 -kernel math.elf -nographic -serial /dev/null -s -S
QEMU 1.7.50 monitor - type 'help' for more information
(qemu) audio: Could not init `oss' audio driver
接下来的gdb会话返回正确的结果:

(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x00008104 in _start ()
(gdb) n
Single stepping until exit from function _start,
which has no line number information.
0x00009dec in memset ()
(gdb) set $pc = 0x822c
(gdb) n
8     float a = 1.25;
(gdb) n
10    float b = sinf(a);
(gdb) n
11    return 0;
(gdb) p/f $r0
$1 = 0.948984623
(gdb) 
这种情况的不同之处在于,先执行初始化函数,然后跳转到主函数。换句话说,scott的路径是正确的,需要一些寄存器初始化。我只是不确定这是否是VFP指令问题,因为我在ARM-v6机器上得到了正确的结果。当然,它现在也可以在ARM-v7上工作


看起来我需要学习更多关于ARM组装的知识,以找到必要的寄存器初始化参数

SP寄存器未初始化。以下是手臂装配中的一个工作示例:

        .text
entry:  b start           
fval:   .single 0e1.25
        .align

start:  mov sp, #0x80000
        ldr r0, fval
        bl sinf 
stop:   b stop

结果在R0寄存器中。

可能
sinf
正在使用VFP指令,并且您尚未在
CAR
FPEXC
寄存器中启用VFP(这将导致未定义处理器异常)。详见v7-A的臂架: