GCC 别名在翻译单元之外运行 -AKA- 这是否是适合这项工作的工具?
我正在 STM32 (Cortex-M3) 上使用 FreeRTOS,并使用 ST 的 CMSIS 库来引导一切。
CMSIS 库在启动“.s”文件中定义了弱符号SVC_Handler
。必须在某个地方重写它才能将 ISR 放入中断向量表中。 FreeRTOS 定义了 vPortSVCHandler,这是我想要处理 SVC 中断的 ISR。
我想使用我的应用程序代码将两者“粘合”在一起(即不修改 FreeRTOS 或 CMSIS 源代码)。我认为别名是完成这项工作的正确工具,所以我尝试了这个(在单独的源文件 main.c 中):
void SVC_Handler(void) __attribute__ ((alias ("vPortSVCHandler")));
这会导致:错误:“SVC_Handler”别名为未定义的符号“vPortSVCHandler”
事实证明,根据此处的 GCC 文档 http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html,为了使用 alias
属性,您不能为符号添加别名在翻译单元之外。所以我想我应该尝试将符号 extern
放入 main.c 中,如下所示:
extern void vPortSVCHandler( void ) __attribute__ (( naked ));
void SVC_Handler(void) __attribute__ ((alias ("vPortSVCHandler")));
这会生成相同的错误。有什么建议吗???
我真的很想避免修改任何一个库。我知道我可以编写一个函数 SVC_Handler
来简单地调用 vPortSVCHandler
,但这可能会给 ISR 增加不必要的开销(可能取决于优化设置)。注意:FreeRTOS 示例通过自定义启动文件完成此操作。我正在寻找一种从 C 或我的链接器脚本执行此操作的方法。
- 编译器版本:gcc 版本 4.5.2 (Sourcery G++ Lite 2011.03-42)
- 目标:arm-none-eabi
I'm working with FreeRTOS on an STM32 (Cortex-M3), and using the CMSIS library from ST to bootstrap everything.
The CMSIS library defines the weak symbol SVC_Handler
in the startup ".s" file. It must be overridden somewhere in order to get your ISR in the interrupt vector table. FreeRTOS defines vPortSVCHandler
, which is the ISR I want to have handle the SVC interrupt.
I would like to "glue" the two together using my application code (i.e. w/o modifyng FreeRTOS or the CMSIS source code). I thought an alias would be the right tool for the job, so I tried this (in a separate source file, main.c):
void SVC_Handler(void) __attribute__ ((alias ("vPortSVCHandler")));
That results in: error: 'SVC_Handler' aliased to undefined symbol 'vPortSVCHandler'
Turns out, according to GCC documentation here http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html, in order to use the alias
attribute, you cannot alias a symbol outside of the translation unit. So I thought I'd try to extern
the symbol into main.c like so:
extern void vPortSVCHandler( void ) __attribute__ (( naked ));
void SVC_Handler(void) __attribute__ ((alias ("vPortSVCHandler")));
This generates the same error. Any suggestions???
I would really like to avoid modifying either of the libraries. I know I could write a function SVC_Handler
that simply calls vPortSVCHandler
, but that could add unnecessary overhead to the ISR (possibly depending on optimization settings). Note: The FreeRTOS examples accomplish this via a custom startup file. I'm looking for a way to do this from C or my linker script.
- Compiler Version: gcc version 4.5.2 (Sourcery G++ Lite 2011.03-42)
- Target: arm-none-eabi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该能够使用链接器脚本或通过将适当的选项传递给链接器来完成此操作,例如。对于 ld,
--defsym=SVC_Handler=vPortSVCHandler
有关 ld
--defsym
选项,以及 链接描述文件中的赋值You should be able to do this either with a linker script, or by passing the appropriate option to the linker, eg. for ld,
--defsym=SVC_Handler=vPortSVCHandler
See the binutils documentation for more information on the ld
--defsym
option, and assignments in linker scripts我认为别名的问题是,它需要一个声明和定义的函数,因为它只是一个别名。您想将其用作另一个函数的前向声明。我有一个类似的工作:
这会重命名 SVC_Handler 的入口点,如果您不定义它,它应该找到 vPortSVCHandler。
请参阅:https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels .html
I think the problem with alias is, that it expects a declared and defined function, since it is just an alias. You want to use it as a forward-declaration of another function. I got a similar thing to work like that:
This renames the entry point of the SVC_Handler, and if you then do not define it, it should find vPortSVCHandler.
See: https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html
我从 FreeRTOS 示例之一中收集到的另一个解决方案是将以下内容添加到 FreeRTOSConfig.h ...
原始文件来自 FreeRTOS/Demo/CORTEX_M0_LPC1114_LPCXpresso/RTOSDemo/Source/FreeRTOSConfig.h,它还将 CMSIS 系统时钟集成到配置。 CMSIS/FreeRTOS 项目的一个非常好的起点。
Another solution that I gleaned from one of the FreeRTOS examples is to add the following to your FreeRTOSConfig.h ...
The original file is from FreeRTOS/Demo/CORTEX_M0_LPC1114_LPCXpresso/RTOSDemo/Source/FreeRTOSConfig.h which also integrates the CMSIS system clock into the config. A very nice starting point for a CMSIS/FreeRTOS project.
我很确定 SVC 处理程序仅由 FreeRTOS 使用
在初始启动时,因此添加间接异常
处理程序不会损害性能(但它
丑陋的)。最好在 FreeRTOS 论坛上提问,回复
通常都很棒。
希望这有帮助,最好的问候,戴夫
I'm pretty sure SVC handler is only used by FreeRTOS
at initial startup, so adding an indirection exception
handler isn't going to hurt performance (but its
ugly). Best ask this on the FreeRTOS forum, response
there is usually great.
Hope this helps, Best Regards, Dave