Topic : C++ Exceptions

Forum : ARM

Original Post
Post Information Post
August 25, 2012 - 4:18am
Guest

I'm using Ride 7 with an STM32F4 based board. Although unusual in the embedded world, I would like to make use of C++ exceptions in my current product. However, it appears that this functionality is broken in Ride7/Codesourcery.

The Problem:
The following code will cause any program to abort. with the message

Replies
Post Information Post
+1
0
-1
August 27, 2012 - 10:26am
Raisonance Support Team

Hi,

Sorry your post was snipped. Please re-post it.

Did you have a look at this C++ example that comes with Ride?
\Examples\ARM\REva\STM32F103_Toggle_cpp

Also, The GettingStartedARM doc contains some useful tips about using C++ in Ride.

Best Regards,

Vincent

+1
0
-1
August 27, 2012 - 4:49pm
Guest

Yes, I've seen the C++ examples and I have been quite successful over the past couple of months using C++ in my project (with the exception below).

My Original Post
*****************************
I'm using Ride 7 with an STM32F4 based board. Although unusual in the embedded world, I would like to make use of C++ exceptions in my current product. However, it appears that this functionality is broken in Ride7/Codesourcery.

The Problem:
The following code will cause any program to abort. with the message "terminate called recursively" written to stderr.

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

Can you please confirm this? If it is a bug in the toolchain, can you provide me a workaround or a patch?

+1
0
-1
August 27, 2012 - 5:50pm
Raisonance Support Team

Hi,

Thanks for reposting.
Sorry I temporarily banned you while trying to promote you to Approved Member status... wrong click. ;)
It should be all right now.

For sure the ARM GCC from CodeSourcery can handle C++ exceptions.
When this is said, there is no reason why it couldn't be done when GCC is driven by Ride.

However, we never really looked in to this, because as you say, it is "unusual" ;) in the embedded world.
So for what we know, some configuration might have to be performed, and it might be hardware-specific.
Or there might be some options to (de)activate.

Did you modify your startup for calling the static constructors?
The exceptions mechanism relies on a table that needs to be initialized, so the static constructors should be called, even if you have no global class instances in your application...

That's the first thing I would look at
But in fact this question should be better asked to CodeSourcery or ARM.
Probably there are example projects available. Even if they are for the CodeSourcery or Keil IDE, as long as they are designed for GCC, they can be ported in Ride easily.

I hope it helps.

Best Regards,

Vincent

+1
0
-1
August 27, 2012 - 7:31pm
Guest

>> Did you modify your startup for calling the static constructors?"

I'm sorry, but I don't know what this entails. Can you please elaborate and possibly give me the necessary code?

+1
0
-1
August 28, 2012 - 10:09am
Raisonance Support Team

Hi,

For initializing C++ static constructors, your startup must calla function called __libc_init_array before calling main. (or any other C function)

We don't do this in our default startup because it is for C, not C++. And also because many C++ applications don't need the static constructors. So you have to use a custom startup (usualy a copy of the default) and add a call to __libc_init_array before the jump to main.

To see the associated code, open the example, edit the startup source file, and search it for "__libc_init_array".

You will also find more information on this in the GettingStarted.

Best Regards,

Vincent

+1
0
-1
August 28, 2012 - 2:58pm
Guest

Thank you Vincent, I really appreciate your efforts.

I have already been through the examples and the documentation. I have a custom startup file that calls the __libc_init_array function, am linking to the C++ libraries, and have selected the options

+1
0
-1
August 28, 2012 - 3:00pm
Guest

Why is my post getting truncated. Trying again...

Thank you Vincent, I really appreciate your efforts.

I have already been through the examples and the documentation. I have a custom startup file that calls the __libc_init_array function, am linking to the C++ libraries, and have selected the options Use GCC Startups which seems to just remove the -nostartupfiles switch.

If someone could confirm that C++ exceptions do or don't work in Ride7 that would be wonderful. If it not supported I would at least know to give up pursue other options.

+1
0
-1
August 28, 2012 - 3:09pm
Raisonance Support Team

Hi,

I think it's a bad idea to use the GCC startups, that are designed to run in an OS, which I guess you don't have.
Using them makes your custom startup ignored, and this might explain your problems.

As I said at the beginning, exceptions ARE supported by GCC for ARM. There are many references to it on the ARM and CodeSourcery websites, and I guess you would find your answers there.

This has nothing to do with calling GCC from Ride or from another IDE or from a batch file or from anything else...

Best Regards,

Vincent

+1
0
-1
August 29, 2012 - 4:16am
Guest

Using the GCC Startups is suggested in the Getting Started guide, which you suggested I follow.

>> But in fact this question should be better asked to CodeSourcery or ARM

This is not a question for CodeSourcery or ARM as I paid Raisonance for the Ride7 toolchain. I didn't pay Mentor Graphics or ARM for their tools, so they have no obligation to support me. Since I paid Raisonance, I would appreciate support from Raisonace on this matter.

Raisonance's staff should have access to the Ride7 toolchain, yes? Is it really too much of a burden for someone there to make a try/catch sample program and verify if it is broken or not?

I've also submitted a support request in case this forum is not the right place to ask for support from Raisonance's staff.

+1
0
-1
August 29, 2012 - 10:06am
Raisonance Support Team

Hello,

Support on C++ is officialy provided only to customers who purchased the Enterprise version of RKit-ARM. (see the Getting Started ARM document) And I think it is not your case...? If it is, please send your request to , or on the Support section of our Extranet website. And tell us your Serial Number. If not, please keep in mind that all the help we provide on these topics is "bonus" for you.

Now, we are nice people and there are other customers who might have the same question in the future, so we'll try to help anyways. But if you did not pay for it, you cannot seriously expect us to make it high priority. And we will not accept more unpleasant admonition about it from you.

I will try a "try/catch" later today. But even if it doesn't work right away, it does not mean that it is "broken". It just means that there is some configuration to change. So this test, successful or not, will not provide much useful information and this is why I did not do it before.

Best Regards,

Vincent

+1
0
-1
August 29, 2012 - 6:05pm
Raisonance Support Team

Hi,

I confirm that it does not work because the Ride default linker script does not take the exception handlers, tables, ids, etc.

But I could make it work quite easily by using a linker script from CodeSourcery. (which I don't think I'm allowed to post here)

Tomorow I'll send you a new version of the default linker script for Ride.

Best Regards,

Vincent

+1
0
-1
August 30, 2012 - 3:45pm
Raisonance Support Team

Hi,

Here is a new version of the sections_FLASH default sub-linker script:
ftp://www.raisonance.com/temp/arm/sections_FLASH.ld

Copy it there (backup the original first):
\lib\ARM\sections_FLASH.ld

Then rebuild your C++ projects and exceptions will work.

Thanks for the reporting.

Best Regards,

Vincent