C Preprocessor/compiler 指令指定 ARM 或 Thumb 模式?

C Preprocessor/compiler directives to specify ARM or Thumb modes?

直接使用 ARM 汇编时,我可以使用 .thumb.thumb_func 及其类似的 arm 指令来指示汇编程序输出哪种指令。

开发C代码时是否有匹配的编译指令? GCC documentation I've seen 提到了各种命令行选项,允许 thumb 和 arm 代码在同一个二进制文件中工作,但输出看起来像是在 thumb 或 ARM 中的完整二进制文件。我希望能够指定各个函数的编译方式。

如果没有,是否有其他方法可以做到这一点?我在想我可以多次编译,然后手动拼接反汇编以手动将函数拼接在一个新的二进制文件中,但我希望有更简单的方法。

看起来你想要的是一个 target 函数属性。在 https://gcc.gnu.org/onlinedocs/gcc-8.2.0/gcc/ARM-Function-Attributes.html#ARM-Function-Attributes

查看 armthumb 属性

这些应该允许您在文件中为 A32 或 T32 编译单个函数。

不要使用除 gcc 之外的任何其他站点的 gcc 文档,因为它可能已过时。来自 gcc doc:

-mthumb
-marm
Select between generating code that executes in ARM and Thumb states. The default for most configurations is to generate code that executes in ARM state, but the default can be changed by configuring GCC with the --with-mode=state configure option.

You can also override the ARM and Thumb mode for each function by using the target("thumb") and target("arm") function attributes (see ARM Function Attributes) or pragmas (see Function Specific Option Pragmas).