C++ exceptions in cortex-m7 vs. cortex-m4

Report here problems in any of ChibiOS components. This forum is NOT for support.
dflogeras
Posts: 190
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 2 times
Been thanked: 13 times

C++ exceptions in cortex-m7 vs. cortex-m4

Postby dflogeras » Thu Jun 07, 2018 8:10 pm

Hi, does anyone know why this might be:

If I compile a simple C++ test program (say RT-STM32F407-DISCOVERY-G++ demo), and make sure to remove "-fno-exceptions" and place the following code in main:

Code: Select all

try {
  throw 1;
}
catch( ... ) {
  // all ok
}


It works as expected. That is, the exception is thrown, caught, and then main gets on with its progress.

Now the clincher. If I do the same thing but target my STM32F7 (starting with RT-STM32F769I-DISCOVERY demo) and add C++ support with exceptions, the same code as above doesn't get into the catch() block, and treats it as an unhandled exception (eventually ending up in the std abort handler and thus chSysHalt() infinite loop).

I've tried this on ChibiOS-18.2.1, with the ARM GCC7-2017-q4-major toolchain.

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby Giovanni » Thu Jun 07, 2018 8:19 pm

It could be an error in the linker script, you should verify the map file and compare with the one of F4.

Giovanni

dflogeras
Posts: 190
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 2 times
Been thanked: 13 times

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby dflogeras » Thu Jun 07, 2018 9:03 pm

Giovanni wrote:It could be an error in the linker script, you should verify the map file and compare with the one of F4.

Giovanni


Hi,

After inspecting both map files, in particular the exception handling functions (__cxa_*), I noted that in the F4 they were all in 0x8000000 flash, while on the F7 they were in the 0x200000 (F7 specific ITCM flash).

If I modify the F7's linker file and change the sections that were in flash1 to flash0, the exception handling works as expected. I'm sure this isn't the solution, but it is definitely part of the cause.

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby Giovanni » Thu Jun 07, 2018 9:15 pm

Moving in bug reports, I need to understand the issue.

Giovanni

dflogeras
Posts: 190
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 2 times
Been thanked: 13 times

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby dflogeras » Thu Jun 07, 2018 10:10 pm

Thanks!

According to https://stackoverflow.com/questions/40532180/understanding-the-linkerscript-for-an-arm-cortex-m-microcontroller

ARM.extab and .ARM.exidx are related to unwinding. You can find more information here http://infocenter.arm.com/help/topic/co ... index.html.


Also, I think this is related:
https://github.com/espressif/esp-idf/issues/459

and the patch:

https://github.com/espressif/esp-idf/pull/681

I don't pretend to understand but it may help you when you get back to this.

dflogeras
Posts: 190
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 2 times
Been thanked: 13 times

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby dflogeras » Fri Jun 08, 2018 11:24 am

Another tidbit, in case it helps you later. Only one of the changes was required in STM32F76xxI.ld to fix the problem I am seeing. Change:

REGION_ALIAS("VARIOUS_FLASH", flash1);

to flash0.

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby Giovanni » Fri Jun 15, 2018 10:30 am

Would be possible to setup a very simple example project for this?

Giovanni

dflogeras
Posts: 190
Joined: Tue Sep 03, 2013 8:16 pm
Has thanked: 2 times
Been thanked: 13 times

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby dflogeras » Fri Jun 15, 2018 7:07 pm

Absolutely,

This started as a copy of testhal/STM32/STM32F7xx/SPI from ChibiOS_18.2.1

I converted it to c++, then simplified main() to the most basic to show the problem. The way I uploaded it, it uses the default linker script, but I've also included a modified one to show how it changes the outcome (I wont say fixes it since it might just be a band-aid). Just uncomment the linker-script line I left in the Makefile to use the modified one.

I ran it on a F769NI but the original SPI demo was meant to run on a F746 and should be able to try it on that depending on which hardware you have in your arsenal.

I used the gcc-arm-none-eabi-7-2017-q4-major compiler to test with, if you want the exact same environment

exceptions.zip
(15.07 KiB) Downloaded 44 times


Thanks,
Dave

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby Giovanni » Mon Dec 31, 2018 11:10 am

bump

User avatar
Giovanni
Site Admin
Posts: 13115
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 765 times
Been thanked: 647 times
Contact:

Re: C++ exceptions in cortex-m7 vs. cortex-m4

Postby Giovanni » Sun Nov 10, 2019 10:29 am

Hi,

Scatter files received changes for a problem that could be the root cause for this. Would be possible to re-check this using the latest version?

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests