如何在 ARM 架构的中断上下文中禁用 GCC 11.1 -mgeneral-regs-only' -Wattributes 中的警告?

问题描述

我已将 GCC 编译器从 10.3 更新到 11.1。我用它来编译带有 FPU 的目标 cpu cortex-m4。

在我的代码中,有很多函数__attribute__((interrupt)) 标记为中断,例如:

__attribute__((interrupt)) void systick_isr_vector() {
}

遗憾的是,更新后,编译器开始为中断属性生成警告

../unittests_entry.cpp:138:52: warning: FP registers might be clobbered despite 'interrupt' attribute: compile with '-mgeneral-regs-only' [-Wattributes]
  138 | __attribute__((interrupt)) void systick_isr_vector() {
      |          

这里出现的问题是如何关闭此警告。我不想禁用 -Wattributes 我只想禁用针对这种特殊情况的警告。

为什么 GCC 试图禁止在中断服务程序上使用 FPU 上下文?它在 ARMv7m 架构的中断上下文中是允许的,并且在硬件中是支持的。

我想这是 GCC 中的一个错误

解决方法

我不知道你为什么会收到警告,但如果你知道它是无害的,你应该能够像这样在本地抑制它:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
__attribute__((interrupt)) void systick_isr_vector() {
}
#pragma GCC diagnostic pop

有关详细信息,请参阅 GCC documentation

,

可能 Cortex M 架构(ARMv6M、v7M、v8M)的最大定义特性是您不需要对中断函数进行任何特殊处理。任何符合 ABI 的函数都可以用作中断处理程序,以前用属性(中断)等完成的所有有趣的业务现在都由硬件完成。所以只需删除该属性。