Modify

Opened 5 years ago

Last modified 2 years ago

#9185 reopened defect

C++ throw exception

Reported by: aswin.paranji@… Owned by: developers
Priority: normal Milestone: Barrier Breaker 14.07
Component: toolchain Version: Trunk
Keywords: Cc:

Description

Hi,

i'm porting a C++ application using the latest trunk toolchain. The application compiles and runs on the router. however,the application is getting aborted when it tries to throw an exception.

Could someone please let me know as to why the application is getting aborted when it tries to throw exception. i'm using the latest uclibc and it is linked with the application.

Aswin

Attachments (2)

athread.cpp (1.3 KB) - added by aswin.paranji@… 5 years ago.
exptest.cpp (146 bytes) - added by aswin.paranji@… 5 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 follow-up: Changed 5 years ago by florian

Please check that your toolchain is built with c++ exception support enabled. If you are linking with uclibc++, check this is also available.

comment:2 in reply to: ↑ 1 Changed 5 years ago by anonymous

Replying to florian:

Please check that your toolchain is built with c++ exception support enabled. If you are linking with uclibc++, check this is also available.

Hi,

i'm using boost libraries in the application.Some of the api from boost libraries is not compatible with uclibc++.
When i compile the application it shows some error. however, when the application is compiled using stdc++, it compiles without a problem. Hence i'm sticking with stdc++

Also, where is the option to enable C++ exception, i do not see it in the advance toolchain option after selecting uclibc.

is there a problem using stdc++ which is causing this issue? when the stdc++ is linked statically, the exceptions are getting handled. However, pthread is not getting linked.

when the application is built using shared link it is getting compiled but aborts when the application is throwing exception.

Any help on this.

Aswin

Changed 5 years ago by aswin.paranji@…

Changed 5 years ago by aswin.paranji@…

comment:3 Changed 5 years ago by aswin.paranji@…

Hi
i have attached 2 sample cpp files showcasing the issue.

exptest:
this program will throw an exception which has to be caught by the handler. this is not happening and the application is getting aborted.
command:
mipsel-openwrt-linux-uclibc-g++ exptest.cpp -o exptest -lstdc++
output:
Starting
Abort

this can be solved by linking statically

command:
mipsel-openwrt-linux-uclibc-g++ exptest.cpp -o exptest -static -lstdc++

output:
Starting
AfterExp

i would like to know why the application is aborted when it is built using shared library.

Similarly, i have created an program using pthread and exception handling (athread.cpp). Since exceptions are handled during static build i tried to build the program using static build but the compiler shows link errors.

error:
athread.cpp: In function 'int main()':
athread.cpp:14: warning: deprecated conversion from string constant to 'char*'
athread.cpp:15: warning: deprecated conversion from string constant to 'char*'
/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-4.4.5_uClibc-0.9.32/lib/gcc/mipsel-openwrt-linux-uclibc/4.4.5/../../../../mipsel-openwrt-linux-uclibc/lib/libc.a(sigaction.os): In function `libc_sigaction':
sigaction.c:(.text.
libc_sigaction+0x0): multiple definition of `libc_sigaction'
/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-4.4.5_uClibc-0.9.32/lib/gcc/mipsel-openwrt-linux-uclibc/4.4.5/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.a(pt-sigaction.os):pt-sigaction.c:(.text.
libc_sigaction+0x0): first defined here
/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-4.4.5_uClibc-0.9.32/lib/gcc/mipsel-openwrt-linux-uclibc/4.4.5/../../../../mipsel-openwrt-linux-uclibc/lib/libc.a(sigaction.os): In function `sigaction':
sigaction.c:(.text.sigaction+0x0): multiple definition of `sigaction'
/openwrt/trunk/staging_dir/toolchain-mipsel_gcc-4.4.5_uClibc-0.9.32/lib/gcc/mipsel-openwrt-linux-uclibc/4.4.5/../../../../mipsel-openwrt-linux-uclibc/lib/libpthread.a(pt-sigaction.os):pt-sigaction.c:(.text.sigaction+0x0): first defined here
collect2: ld returned 1 exit status

when i compile using shared linkage, it is getting compiled.however exceptions are not handeled.

can you let me know why this is happening.

Thanks,
Aswin

comment:4 Changed 5 years ago by highfly22@…

try to compile with --enable-sjlj-exceptions

comment:5 Changed 5 years ago by David Kuehling <dvdkhlng TA gmx TOD de>

We have the same problem with openwrt-trunk compiling for NanoNote. The following patch creates a new toolchain option to select setjump/longjump exceptions.

http://qi-hw.com/p/openwrt-xburst/2c58e58

With that option enabled, C++ exceptions work for us.

comment:6 Changed 5 years ago by jow

I added the Qi patch in r27261 but I'll leave this ticket open for tracking as there clearly seems to be an underlying issue with the toolchain here

comment:7 Changed 5 years ago by nbd

  • Resolution set to fixed
  • Status changed from new to closed

fixed in r27347, switching to sjlj exceptions is no longer necessary

comment:8 Changed 3 years ago by anonymous

  • Resolution fixed deleted
  • Status changed from closed to reopened

I still have this problem.
My cpu is armv7.
Build amule 2.3.1 with wxwidgets 2.8.12.
Use uclibc.
I can catch the throw, but can't catch rethrow. It cause abort.

comment:9 Changed 3 years ago by anonymous

This is strace output:

open("/lib/libgcc_s.so.1", O_RDONLY) = 40
fstat(40, {st_mode=S_IFREG|0755, st_size=43942, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|0x4000000, -1, 0) = 0x40008000
read(40, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0T;\0\0004\0\0\0"..., 4096) = 4096
mmap2(NULL, 77824, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40d17000
mmap2(0x40d17000, 43444, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 40, 0) = 0x40d17000
mmap2(0x40d29000, 2982, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 40, 0xa) = 0x40d29000
close(40) = 0
munmap(0x40008000, 4096) = 0
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
tgkill(3782, 3782, SIGABRT) = 0
--- SIGABRT (Aborted) @ 0 (0) ---

comment:10 Changed 2 years ago by jow

  • Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07

Milestone Attitude Adjustment 12.09 deleted

Add Comment

Modify Ticket

Action
as reopened .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.