UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer sgilbertson
Observer
4,362 Views
Registered: ‎01-05-2012

Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

I'm using Vivado 2017 for a project incorporating a Zynq 7020 running Linux. The compiler is:

arm-linux-gnueabihf-g++.exe (Linaro GCC Snapshot 6.2-2016.11) 6.2.1 20161114

I'm using Windows 10 for development.

 

C++ exceptions don't work. For example, if I do:

try
{
  throw new std::string("THIS IS AN EXCEPTION");
}
catch (...)
{
  std::cout << "EXCEPTION CAUGHT\n";
}

I get (for either a release or debug build)

terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*'
terminate called recursively
Aborted

and the program exits.

 

Running the same code in other environments (Windows / Visual C++, say), I get "EXCEPTION CAUGHT".

 

I tried adding "-fexceptions" to the command line for the G++ compiler, but it doesn't change anything. I need C++ exception handling for a couple of reasons:

  • Some C++11 library classes use it, and
  • I want to be able to abort a thread without aborting the entire program.

Is it possible to enable C++ exception processing for Linux programs built in the Vivado 2017.2 SDK?

If so, how?

 

Thanks.

 

 

 

 

0 Kudos
1 Solution

Accepted Solutions
Moderator
Moderator
4,555 Views
Registered: ‎10-06-2016

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Hi @sgilbertson

 

There are different questions reported in your last posts in this thread so let's see if I can cover all of them.

 

  • Error reproduced in the 2017.3 release

You are right the issue in 2017.3 release is still there as they are working to fix the issue in 2017.4 release.

 

  • arm-xilinx-gneueabi-g++ not recognized in 2017.3 release

Xilinx decided to deprecate the CodeSourcery based custom toolchain to just focus on supporting the Linaro toolchain in the newer releases. This has been documented in the SDK limitations.

 

  • Same toolchain in 2017.3

The toolchain is not modified in every release so the fact of having the same version is expected

 

  • Update/Modify toolchain.

You can use the SDK Preferences to modify your toolchain settings as described in the Help website, or in case of Linux machines modify the settings.sh scripts to modify the toolchain paths

 

  • Answer Record

There is already an ongoing work to publish the AR in the Known Issues.

 

  • Expected fix

There is already an ongoing work to fix the issue on 2017.4 release so if it goes fine we should see this issue fixed in the next Vivado release

 

Regards

Ibai


Ibai
Don’t forget to reply, kudo, and accept as solution.
11 Replies
Observer sgilbertson
Observer
4,313 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

UPDATE:

 

It looks like a bug in some of the toolchains provided with the SDK and not others.

 

I found that I can make exceptions work by going to Properties / C/C++ Build / Toolchain Editor and changing:

  • from: Xilinx ARM v7 GNU/Linux Toolchain
  • to: Xilinx ARM GNU/Linux Toolchain
  • but not: Xilinx ARM A53 32 Bit GNU/Linux Toolchain (it has the same problem as the v7 toolchain)

That's not any use as a fix, because the only toolchain that handles exceptions properly does soft floating-point, and my application's no good with that.

 

It appears, then, that there's a bug in at least the v7 and A53 toolchains, causing C++ exceptions not to work. Either that or it's something wrong with my system or configuration.

 

Can anybody confirm whether the same problem happens with the ARM v7 toolchain on some other system?

 

The entirety of the test program is:

#include <string>
#include <iostream>

int main()
{
	std::cout << "Start\n";
	try
	{
		throw new std::string("AN EXCEPTION");
	}
	catch (...)
	{
		std::cout << "EXCEPTION CAUGHT\n";
	}
	std::cout << "Done\n";
}

No special build settings are needed. Just create a Linux application in the SDK and paste that code in something like "main.cc". In case there's a library missing on the target system, though, you can put "-static" in the linker "Miscellaneous" options.

 

0 Kudos
Moderator
Moderator
4,280 Views
Registered: ‎10-06-2016

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Hi @sgilbertson

 

I just tested your code in SDK 2017.2 but my results are completely different, as it seems that Linaro toolchain works fine and CodeSourcery one not...

 

arm-xilinx-eabi-gcc -v

gcc version 4.9.2 (Sourcery CodeBench Lite 2015.05-16)

 

Building target: codeSourcery.elf
Invoking: ARM g++ linker
arm-xilinx-eabi-g++ -L../../codeSourcery_bsp/ps7_cortexa9_0/lib -o "codeSourcery.elf"  ./src/main.o   -l-Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group
/proj/gsd/vivado/SDK/2017.2/gnu/arm/lin/bin/../lib/gcc/arm-xilinx-eabi/4.9.2/../../../../arm-xilinx-eabi/bin/ld: cannot find -l-Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group
collect2: error: ld returned 1 exit status
make: *** [codeSourcery.elf] Error 1

arm-none-eabi-gcc -v

gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)

 

Building target: linaro.elf
Invoking: ARM v7 g++ linker
arm-none-eabi-g++ -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard -Wl,-build-id=none -specs=Xilinx.spec -Wl,-T -Wl,../src/lscript.ld -L../../linaro_bsp/ps7_cortexa9_0/lib -o "linaro.elf"  ./src/main.o   -Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group
Finished building target: linaro.elf

Using the A53 toolchain seems to not fail neither..

aarch64-none-elf-g++ -v

gcc version 6.2.1 20161114 (Linaro GCC Snapshot 6.2-2016.11)

Building target: a53exception.elf
Invoking: ARM A53 g++ linker
aarch64-none-elf-g++ -Wl,-T -Wl,../src/lscript.ld -L../../a53exception_bsp/psu_cortexa53_0/lib -o "a53exception.elf"  ./src/main.o   -Wl,--start-group,-lxil,-lgcc,-lc,-lstdc++,--end-group
Finished building target: a53exception.elf

Ibai
Don’t forget to reply, kudo, and accept as solution.
0 Kudos
Observer sgilbertson
Observer
4,275 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution
@ibaie

It's odd that one of your builds didn't finish, but the problem I'm reporting isn't a build problem. The problem happens when you run the built elf file on a target system.

In my case all of the builds succeed, but the elf files built with Linaro fail to catch the exception, instead aborting with the "terminate called after throwing" message.
0 Kudos
Observer sgilbertson
Observer
4,268 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Another update: Today I am on a different computer, which has both 2016.4 and 2017.2 versions of Vivado and the SDK installed. I built the test program on both, in both cases selecting linux / ps7_cortexa9 / C++. In both cases I added "-static" to the linker options.

 

Running them on the Zynq, the 2016.4 elf file works but the 2017.2 one does not:

Z-turn# ./exceptions_2016_4.elf
Start
EXCEPTION CAUGHT
Done
Z-turn# ./exceptions_2017_2.elf
Start
terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*'
terminate called recursively
Aborted

So the bug, assuming it's a bug, was introduced in some version newer than 2016.4. Perhaps that's a clue as to what's going on.

 

The 2016.4 compiler is:

arm-linux-gnueabihf-g++ (Linaro GCC 5.2-2015.11-2) 5.2.1 20151005

 

A possible workaround would be to downgrade my project to 2016.4, but I'd like to avoid that if I can.

0 Kudos
Observer sgilbertson
Observer
4,163 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

So far nobody has chimed in having attempted to disprove my assertion that this is a bug in the Linaro toolchains that come with Vivado SDK 2017.2.

 

Meanwhile I have confirmed that the problem is not with the Z-turn (Zynq 7020) board I'm using, or  with the Linux running on that board. 

 

I built the test program using "Xilinx ARM v7 GNU Toolchain" and ran it on an Orange Pi Zero:

root@orangepizero:/tmp# ./lintest.elf
Start
terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*'
terminate called recursively
Aborted

So exceptions working on that platform either, when the program is built with a Linaro toolchain. The OS on that system is:

Linux version 3.4.113-sun8i (root@devel) (gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) ) #10 SMP PREEMPT Thu Feb 23 19:55:00 CET 2017

and the processor is "ARMv7 Processor rev 5 (v7l)"

 

I'm surprised that I appear to be the only one reporting the bug, since it makes just about any non-trivial C++ Linux program not work. Is it possible that hardly anybody is building non-trivial C++ Linux applications in Vivado SDK?

 

Please ensure that this bug is fixed for all toolchains in the next Vivado SDK release. In 2017.2, C++ exception processing does not work at all for any Linux program built with one of the Linaro toolchains.

 

0 Kudos
Moderator
Moderator
4,147 Views
Registered: ‎10-06-2016

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Hi @sgilbertson

 

I just test the issue on my end using SDK 2017.2 and ZC702 board (A9 core) and I'm getting your same behaviour, so it seems that something is broken in the toolchain.

 

I reported internally to the development team so I will post once I get some feedback ;)

 

Regards,

Ibai


Ibai
Don’t forget to reply, kudo, and accept as solution.
Observer sgilbertson
Observer
3,852 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

I upgraded to Vivado 2017.3, and the C++ exceptions bug is still there.

 

I built the test program in SDK 2017.3 with the toolchain set to "Xilinx ARM v7 GNU/Linux Toolchain".  The "--version" argument reports:

arm-linux-gnueabihf-g++ (Linaro GCC Snapshot 6.2-2016.11) 6.2.1 20161114

That's the same as in 2017.2, so of course when I run the program on the Zynq I get the same result:

 

Z-turn# ./lintest.elf
Start
terminate called after throwing an instance of 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*'
terminate called recursively
Aborted

Also I noticed that when I change the toolchain to "Xilinx ARM GNU/Linux" (without "v7"), I get:

 

'arm-xilinx-linux-gnueabi-g++' is not recognized as an internal or external command,
operable program or batch file.
make: *** [src/main.o] Error 1

So I wondered whether I'm still getting the old toolchain. Nope, it's the one from the new 2017.3 install directory:

 

C:\xilinx\SDK\2017.3\gnu\aarch32\nt\gcc-arm-linux-gnueabi\bin>arm-linux-gnueabihf-g++.exe --version
arm-linux-gnueabihf-g++.exe (Linaro GCC Snapshot 6.2-2016.11) 6.2.1 20161114
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 That's the same as what I see in the SDK (2017.2 or 2017.3).

 

0 Kudos
Observer sgilbertson
Observer
3,844 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Is there an official or semi-official way to add or update toolchains in Vivado SDK?

 

Also, is there a reason Xilinx did not include the most recent released Linaro with Vivado (as opposed to a snapshot)?

It seems to me a release is likely to have fewer bugs than a snapshot.

 

I downloaded arm-linux-gnueabihf from https://www.linaro.org/downloads/

Then as Administrator I did something like:

 

C:
cd \Xilinx\SDK\2017.3\gnu\aarch32\nt ren gcc-arm-linux-gnueabi old.gcc-arm-linux-gnueabi mkdir gcc-arm-linux-gnueabi

Then I unpacked the new Linaro to C:\Xilinx\SDK\2017.3\gnu\aarch32\nt\gcc-arm-linux-gnueabi, and launched the SDK.

  

Building in the SDK seems to work OK. The compiler indicates:

gcc version 7.1.1 20170707 (Linaro GCC 7.1-2017.08)

 

The compiled test program correctly catches exceptions. That's with the "-static" linker argument, so that it's not looking for specific libraries on the target. This is a workaround, though, not a solution. The solution would be for Xilinx to upgrade Linaro in the next Vivado release.

 

 

0 Kudos
Observer sgilbertson
Observer
3,543 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

@ibaie wrote:

I reported internally to the development team so I will post once I get some feedback ;)

 


Should I expect to see the C++ exceptions bug on a list of known issues like https://www.xilinx.com/html_docs/xilinx2017_3/SDK_Doc/SDK_references/sdk_knownissues.html?

 

 

0 Kudos
Moderator
Moderator
4,556 Views
Registered: ‎10-06-2016

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Hi @sgilbertson

 

There are different questions reported in your last posts in this thread so let's see if I can cover all of them.

 

  • Error reproduced in the 2017.3 release

You are right the issue in 2017.3 release is still there as they are working to fix the issue in 2017.4 release.

 

  • arm-xilinx-gneueabi-g++ not recognized in 2017.3 release

Xilinx decided to deprecate the CodeSourcery based custom toolchain to just focus on supporting the Linaro toolchain in the newer releases. This has been documented in the SDK limitations.

 

  • Same toolchain in 2017.3

The toolchain is not modified in every release so the fact of having the same version is expected

 

  • Update/Modify toolchain.

You can use the SDK Preferences to modify your toolchain settings as described in the Help website, or in case of Linux machines modify the settings.sh scripts to modify the toolchain paths

 

  • Answer Record

There is already an ongoing work to publish the AR in the Known Issues.

 

  • Expected fix

There is already an ongoing work to fix the issue on 2017.4 release so if it goes fine we should see this issue fixed in the next Vivado release

 

Regards

Ibai


Ibai
Don’t forget to reply, kudo, and accept as solution.
Observer sgilbertson
Observer
2,025 Views
Registered: ‎01-05-2012

Re: Vivado 2017.2 SDK can't enable C++ exception processing in Zynq Linux programs

Jump to solution

Thanks. I look forward to being able to use 2017.4 unmodified.

 

The "SDK Preferences" dialog is indeed what I should have used for the workaround. I have a comment on the help page you linked, though. It tells you all about the options in that dialog, but it doesn't tell you how to get to the dialog in the first place. Hunting around, I found it in Window / Preferences / Xilinx SDK.

 

 

0 Kudos