如何解析ARM64组件Sigbus错误?

发布于 2025-02-09 18:39:03 字数 613 浏览 1 评论 0原文

我写了一个非常简单的ARM64汇编功能:
这样:

.global asmQuickSort \
asmQuickSort: \
 1  sub x2, x1, #1 \
 2  mov x1, #0 \
 3  sub sp, sp, #8 \
 4  str w1, [sp] \
 5  add sp, sp, #8 \
 6  ret

和主要CPP称呼它:

int main(int argc ,char** argv){ \
    int a[7] = {5,4,3,4,3,2,1}; \
    asmQuickSort(a,7); \
    for(int i=0;i< 7;i++){ \
        printf("%d\n",a[i]); \
    } \
    return 1;\
}

但是,当我将其放入Aarch64板并运行时,它会满足

第4行W1处的Sigbus错误,[SP]

此可执行文件使用QEMU-AARCH64运行良好,但在臂板中,它收到了Sigbus。

那么,为什么该应用会收到Sigbus错误?
我应该检查什么?

I wrote a very simple ARM64 assembler function:
Like this:

.global asmQuickSort \
asmQuickSort: \
 1  sub x2, x1, #1 \
 2  mov x1, #0 \
 3  sub sp, sp, #8 \
 4  str w1, [sp] \
 5  add sp, sp, #8 \
 6  ret

and main cpp to call it:

int main(int argc ,char** argv){ \
    int a[7] = {5,4,3,4,3,2,1}; \
    asmQuickSort(a,7); \
    for(int i=0;i< 7;i++){ \
        printf("%d\n",a[i]); \
    } \
    return 1;\
}

But, when I put it into aarch64 board and run it ,it met

sigbus error at line 4 str w1, [sp]

This executable file ran well using qemu-aarch64 ,but in arm board it received sigbus.

So, why does the app receive sigbus error?
And what should I to check?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空气里的味道 2025-02-16 18:39:04

这可能是堆栈对齐。

手册在“ load/load/store store asseling modes”(c1.3.3333333333333333333333333333333) ):

当系统软件启用堆栈对齐检查并且基本寄存器是SP时,当前的堆栈指针必须最初对准QuadWord,该指针与16个字节保持一致。未对准会产生堆栈对准故障。偏移不必是16个字节的倍数,除非特定的负载/商店指令需要此。

听起来像是在操作系统上启用了堆栈对齐检查,并且您通过向其添加8个堆栈指针将堆栈指针错过。因此,将该价值更改为16,您应该很好。


我假设您知道这一点,但是以防万一:您当前的堆栈用法asmquicksort无论如何都没有目的。

It's probably stack alignment.

The manual has this to say on "Load/store addressing modes" (C1.3.3):

When stack alignment checking is enabled by system software and the base register is the SP, the current stack pointer must be initially quadword aligned, that is aligned to 16 bytes. Misalignment generates a Stack Alignment fault. The offset does not have to be a multiple of 16 bytes unless the specific load/store instruction requires this.

It sounds like stack alignment checking is enabled on your OS, and you misalign the stack pointer by adding 8 to it. So change that value to 16 and you should be good.


And I'm assuming you're aware of this, but just in case: your current stack usage inside asmQuickSort serves no purpose anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文