GCC arm-none-eabi (Codesourcery) and C++ Exceptions

女生的网名这么多〃 提交于 2019-12-06 01:58:14

问题


I am using Raisonance's Ride7/Codesourcery (a.k.a Sourcery CodeBench Lite) with an STM32F4 board developing a bare metal HMI platform.

I will be making use of C++ exceptions in this system, but any exception I throw ends with a "Terminate called recursively" error written to stderr.

Code to reproduce the problem: (main.cpp)

int main(void)
{
    try {
        throw 1;
    }
    catch (...) {
        printf("caught");
    }
}

I've already tried Raisonance and other sources for a resolution, and have not received any actionable help.

Potential problem/solution 1:

I've asked on other forums and they mention I need to call static constructions in my startup assembly file to initialize the unwind tables (at least that's what I think they are talking about), but I have no idea how to do this.

Potential problem/solution 2

I have also discovered a bug in binutils/gas that may be the source of my problems here (http://sourceware.org/bugzilla/show_bug.cgi?id=13449). I've been trying to build my own version of the toolchain with this patch, but that's turning into a project of its own, and have not yet succeeded.

The Question

Do I need to do something in code to make use of C++ exceptions, or is this likely a bug in the toolchain? If the former, please elaborate.


回答1:


After some persuasion that shouldn't have been necessary, Raisonance finally came through with a modification to their default linker script that fixed the problem. It may not be legal for me to post the entire linker script, but here's the knowledge that one needs to know

Add this to the .text section

*(.eh_frame)

Add these sections (name YourMemory according to the memory blocks you've set up in your linker script. Mine was Flash)

.ARM.extab :
{
    *(.ARM.extab* .gnu.linkonce.armextab.*)
} >YourMemory

.ARM :
{
    __exidx_start = .;
    *(.ARM.exidx*)
    __exidx_end = .;
} >YourMemory

Ensure this line occurs in the bss section

*(.bss*)

While on this quest, I ran across the following useful resources

  • http://wiki.osdev.org/C%2B%2B_Exception_Support
  • https://docs.blackfin.uclinux.org/doku.php?id=toolchain:bare_metal:link
  • http://gcc.gnu.org/ml/gcc-help/2011-07/msg00112.html
  • http://www.airs.com/blog/archives/460


来源:https://stackoverflow.com/questions/12151397/gcc-arm-none-eabi-codesourcery-and-c-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!