Skip to contentSkip to conversation

New: Glibc C++ aplications crash if they use exceptions.

Buildroot bugzilla at busybox.net 2 participants 24 messages Jun 15, 2014 – Aug 17, 2014

lore
Share & tools
lore
#0 lore raw

https://bugs.busybox.net/show_bug.cgi?id=7208

Summary: Glibc C++ aplications crash if they use exceptions.
Product: buildroot
Version: 2014.05
Platform: PC
OS/Version: Linux
Status: NEW
Severity: critical
Priority: P5
Component: Other
AssignedTo: unassigned at buildroot.uclibc.org
ReportedBy: kwrzalik at gmail.com
CC: buildroot at uclibc.org
Estimated Hours: 0.0

I'm using a toolchain with glibc and the following simple program crashes:

#include <cstdio>

int main() {

  try {
    throw 42;
  } catch (int x) {
    printf("catch %d\n", x);

}
}

with the following backtrace:

#0  0xb7747a92 in ?? () from /lib/ld-linux.so.2
#1  0xb74ac6b8 in raise () from /lib/libc.so.6
#2  0xb74adbae in abort () from /lib/libc.so.6
#3  0xb763903a in ?? () from /lib/libgcc_s.so.1
#4  0xb763936b in _Unwind_RaiseException () from /lib/libgcc_s.so.1
#5  0xb76d0304 in __cxa_throw () from /usr/lib/libstdc++.so.6
#6  0x080486c1 in main ()

when run on the host with proper ld-linux.so and run paths the stack trace is as follows:

#0 0xb7fdc424 in __kernel_vsyscall ()
#1 0xb7d4073f in raise () from /opt/gnl/usr/i686-gnl-linux-gnu/sysroot/lib/libc.so.6
#2 0xb7d41c5e in abort () from /opt/gnl/usr/i686-gnl-linux-gnu/sysroot/lib/libc.so.6
#3 0xb7ecf0d9 in uw_init_context_1 (context=context at entry=0xbfffe680, outer_cfa=outer_cfa at entry=0xbfffe860, outer_ra=0xb7f66424 <__cxxabiv1::__cxa_throw(void*, std:
:type_info*, void (*)(void*))+97>) at ../../../libgcc/unwind-dw2.c:1567 #4 0xb7ecf40a in _Unwind_RaiseException (exc=0x804a048) at ../../../libgcc/unwind.inc:88
#5 0xb7f66424 in __cxxabiv1::__cxa_throw (obj=0x804a068, tinfo=0x8049e50 <_ZTIi@@CXXABI_1.3>, dest=0x0) at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:82
#6 0x08048924 in main () at dupa.cpp:8

In the discussion with tom_kos and wbx on IRC we managed to pin the problem libgcc_s.so. The problem only appears when linking with dynamic libgcc_s.so. If the program is compiled with -static-libgcc it runs correctly.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#1 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #1 from Thomas Petazzoni <[email protected]> 2014-06-15 10:39:13 UTC --- Which gcc version was used for the test? It can be useful to be able to match libgcc/unwind-dw2.c:1567 from the backtrace with the appropriate source code.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#2 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #2 from Krzysztof Wrzalik <[email protected]> 2014-06-15 10:43:08 UTC --- It comes from 4.9.0.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#3 lore raw
In reply to bugzilla at busybox.net
Quoted 5 lines · On Sun, 15 Jun 2014 10:29:22 +0000 (UTC) bugzilla at busybox.net wrote:

In the discussion with tom_kos and wbx on IRC we managed to pin the problem libgcc_s.so. The problem only appears when linking with dynamic libgcc_s.so. If the program is compiled with -static-libgcc it runs correctly.

The file libgcc_s.so is an ascii text, linker script. It should be patchable.

PS: It is being installed to the target -
My guess, it matches the pattern used to transfer libgcc_s.so.1 (which is a dynamic library binary).

Mike

#4 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #3 from Thomas De Schampheleire <[email protected]> 2014-06-15 14:40:11 UTC --- Please also provide your .config file so other people can try to look at the problem.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#5 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #4 from Krzysztof Wrzalik <[email protected]> 2014-06-15 14:52:47 UTC --- Created attachment 5456
--> https://bugs.busybox.net/attachment.cgi?id=5456
Buildroot configuration

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#6 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #5 from Krzysztof Wrzalik <[email protected]> 2014-06-15 17:54:22 UTC --- The difference between compiling with -static-libgcc seems to boil down to the following function:

_Unwind_Find_FDE

When compiled with -statlic-libgcc the function invocation ends up in glibc. When -static-libgcc is not given, then this function is located in libgcc.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#7 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #6 from Krzysztof Wrzalik <[email protected]> 2014-06-15 20:10:59 UTC --- It turns out that 900-musl-support.patch breaks exceptions when using glibc:

The proper exception handling in libgcc seems to need USE_PT_GNU_EH_FRAME definition in libgcc's unwind-dw2-fde-dip.c. However; the patch changes this file to:

+#if !defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)

 # define USE_PT_GNU_EH_FRAME

Configure in host-gcc-final seems to be unable to locate TARGET_DL_ITERATE_PHDR:
checking dl_iterate_phdr in target C library... unknown

In such case unwind-dw2-fde-dip.c falls back to unwind-dw2-fde.c which does not do the job of finding a FDE and hence the crash.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#8 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #7 from Thomas Petazzoni <[email protected]> 2014-06-15 22:55:49 UTC --- Thanks a lot for the debugging! I'll have a closer look and see what is the appropriate solution to make sure that C++ exceptions work with glibc, and that
we can still enable musl.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#9 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #8 from mail at waldemar-brodkorb.de 2014-06-16 08:28:30 UTC --- Hi,

there is a discussion about this problem on the musl mailing list. Just if you are not subscribed.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#10 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #9 from Krzysztof Wrzalik <[email protected]> 2014-06-16 09:05:27 UTC --- IMHO a good solution would be to make patches conditional in some cases, e.g. only use 900-musl-support.patch if C library is selected to musl. I guess it would require quite amount of work thought...

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#11 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #10 from Thomas Petazzoni <[email protected]> 2014-06-16 09:42:21 UTC --- (In reply to comment #8)

Quoted 2 lines

there is a discussion about this problem on the musl mailing list. Just if you are not subscribed.

Right, but I don't see our specific problem being taken into account. Rich Felker concluded the thread with:

"""
Please note that these changes are not mandatory; at present, everything works, but crtbegin.o and crtend.o are unnecessarily bloated and this affects static binary size.
"""

Maybe we should tell him that the changes are breaking C++ exception handling for glibc, when the musl patches are applied to gcc?

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#12 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #11 from Thomas Petazzoni <[email protected]> 2014-06-16 09:43:40 UTC --- (In reply to comment #9)

Quoted 3 lines

IMHO a good solution would be to make patches conditional in some cases, e.g. only use 900-musl-support.patch if C library is selected to musl. I guess it would require quite amount of work thought...

That's certainly a solution, but I wouldn't qualify it as a good solution. We try really hard to avoid having conditional patches.

Though, as a temporary solution it would certainly be acceptable. This problem is a major bug in Buildroot 2014.05, and we have to solve it somehow.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#13 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #12 from bugdal at aerifal.cx 2014-06-16 14:04:29 UTC --- The relevant part of the musl patch is intended to remove the hard-coding of USE_PT_GNU_EH_FRAME as glibc-specific and instead detect via configure that it should be used. My guess is that something's broken in the configure script whereby TARGET_DL_ITERATE_PHDR is not getting detected correctly; perhaps the test is not cross-compiler-compatible.

Based on the thread on the musl mailing list
(http://www.openwall.com/lists/musl/2014/06/16/2), I think if this is the problem it would go undetected by musl, since when targetting musl gcc is still producing an "old-style" crtbegin/crtend that works without USE_PT_GNU_EH_FRAME. With glibc that doesn't happen because the crtstuff preprocessor conditionals are still hard-coded for glibc.

In my opinion the "right" fix is finding and fixing whatever's wrong in configure, but as a short-term solution, the conditional could be fixed to hard-code USE_PT_GNU_EH_FRAME for glibc while detecting it elsewhere, as in:

+#if (!defined(inhibit_libc) && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)) || defined(__gnu_linux__)

 # define USE_PT_GNU_EH_FRAME

or something closer to whatever the upstream logic is for glibc.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#14 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #13 from Krzysztof Wrzalik <[email protected]> 2014-06-16 18:58:47 UTC --- If I'm looking at the right place, TARGET_DL_ITERATE_PHDR is defined in output/build/host-gcc-final-4.9.0/gcc/configure.ac at line 5079. It looks like it only gets set on a variant of solaris2. So this variable looks like a quick hack to me rather than something one can depend on.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#15 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #14 from Sven Neumann <[email protected]> 2014-06-23 09:32:06 UTC --- We are seeing the same problem with gcc 4.8.2 on our i586 platform. Code that uses C++ exceptions and which used to work fine with the buildroot 2014.02 release now aborts when an exception is thrown.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#16 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #15 from Sven Neumann <[email protected]> 2014-06-23 11:40:01 UTC --- (In reply to comment #14)

Quoted 3 lines

We are seeing the same problem with gcc 4.8.2 on our i586 platform. Code that uses C++ exceptions and which used to work fine with the buildroot 2014.02 release now aborts when an exception is thrown.

I have now verified that the problem goes away if I revert the commit that introduces musl support to gcc 4.8.2.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#17 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

Thomas De Schampheleire <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |2014.08

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#18 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #16 from David Bachelart <[email protected]> 2014-07-24 15:01:19 UTC --- Created attachment 5528
--> https://bugs.busybox.net/attachment.cgi?id=5528
Buildroot configuration

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#19 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #17 from David Bachelart <[email protected]> 2014-07-24 15:01:57 UTC --- Created attachment 5534
--> https://bugs.busybox.net/attachment.cgi?id=5534
C code using pthread_exit

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#20 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #18 from David Bachelart <[email protected]> 2014-07-24 15:09:29 UTC --- Hi,

The 900-musl-support.patch also breaks the pthread_exit() function in pure C-code. I enclose two files :
- basic buildroot configuration, toolchain using gcc 4.8.1 / glibc 2.18 / binutils 2.22
- basic C code creating a thread that kills itself using pthread_exit()

Using a toolchain built from master, the main process receives the SIGABRT signal.

If I remove the 900-musl-support.patch and rebuild the whole buildroot, the code exits normally.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#21 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

--- Comment #19 from Thomas De Schampheleire <[email protected]> 2014-08-09 15:44:53 UTC --- What to do with this bug? We need a proper solution for the upcoming release...

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#22 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

Thomas Petazzoni <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at buildroot.uclibc |thomas.petazzoni at free-elect
|.org |rons.com

--- Comment #20 from Thomas Petazzoni <[email protected]> 2014-08-14 17:24:35 UTC --- Re-assigning to me, I'm working on it now.

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
#23 lore raw

[Buildroot] [Bug 7208] Glibc C++ aplications crash if they use exceptions.

In reply to bugzilla at busybox.net

https://bugs.busybox.net/show_bug.cgi?id=7208

Peter Korsgaard <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #21 from Peter Korsgaard <[email protected]> 2014-08-17 07:43:23 UTC --- The patch series fixing this has now been applied:

http://git.buildroot.net/buildroot/commit/?id=fea35ce67317aa0eee678fb9440814d1346fb2fb

Signature · 3 lines
Configure bugmail: https://bugs.busybox.net/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.