This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc 3.4.6: exception handling not working for binary pre-compiled on Redhat


Problem Synopsis:
=================

Exception handling in C++ not working when a binary is compiled
against the standard Redhat release 4 update 4 that has gcc 3.4.6 and
libstd++ 6.0.3, glibc 2.3.6 with NPTL threads library linked
dynamically and run on a cross compiled environment that has the same
gcc 3.4.6, glibc 2.3.6 and NTPL linked dynamically to /lib/tls/libc.

In addition, problem does not happen if code is compiled with
-static-libgcc option.

Sample program used:
Sample Program: exceptionhandling.cpp
#include <stdlib.h>
#include <stdio.h>
class MyException {
public:
    MyException() {}
    ~MyException() {}
};

void foo() {
    printf("Inside foo\n");
    printf("About to throw an exception.\n");
    throw MyException();
    printf("Leaving foo\n");
}

int main(int argc, char* argv[]) {
    try {
        foo();
    } catch (MyException e) {
        printf("Caught MyException.\n");
    }
    return 0;
}

Compilation:
============
Redhat release 4 update 4.
g++ -g -o exception346 exceptionhandling.cpp

Problem details:
================

When the exceptions are thrown the stack trace looks like below
gdb32 ../exception346 core.exception346
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-spcdn-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
warning: Can't read pathname for load map: Input/output error.
warning: .dynamic section for "/lib/libstdc++.so.6" is not at the
expected address (wrong library or version mismatch?)
Reading symbols from /lib/libstdc++.so.6...done.
Loaded symbols for /lib/libstdc++.so.6
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./exception346'.
Program terminated with signal 6, Aborted.
#0  0xffffe410 in __kernel_vsyscall ()
(gdb) where
#0  0xffffe410 in __kernel_vsyscall ()
#1  0x556970b1 in ssignal () from /lib/libc.so.6
#2  0x55698829 in abort () from /lib/libc.so.6
#3  0x5561ac87 in __gnu_cxx::__verbose_terminate_handler () from
/lib/libstdc++.so.6
#4  0x55618815 in ?? () from /lib/libstdc++.so.6
#5  0x55618852 in std::terminate () from /lib/libstdc++.so.6
#6  0x556189d2 in __cxa_throw () from /lib/libstdc++.so.6
#7  0x0804861d in foo () at exceptionhandling.cpp:15
#8  0x08048640 in main (argc=1, argv=0xffffdda4) at exceptionhandling.cpp:23
(gdb)

Build environment details:
==================
Redhat release 4 update 4.
I386 platform: Redhat kernel based on 2.6.9-42.7.Esnp
Uname –a: Linux redhat-lnx 2.6.9-42.7.ELsmp #1 SMP Tue Sep 5 18:29:39
EDT 2006 i686 i686 i386 GNU/Linux
GCC: 3.4.6
GLIBC: 2.3.6
Libstd++: 6.0.3

GNU C Library stable release version 2.3.4, by Roland McGrath et al.
Copyright (C) 2005 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.
Compiled by GNU CC version 3.4.6 20060404 (Red Hat 3.4.6-3).
Compiled on a Linux 2.4.20 system on 2007-01-31.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        linuxthreads-0.10 by Xavier Leroy
        The C stubs add-on version 2.1.2.
        BIND-8.2.3-T5B
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        Glibc-2.0 compatibility add-on by Cristian Gafton
        GNU Libidn by Simon Josefsson
        libthread_db work sponsored by Alpha Processor Inc
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html >.

gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk
--host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-3)
Runtime Environment Details:
=====================
i386 platform: 32-bit kernel based on stock 2.6.10
I686 platform: 64-bit kernel based on stock 2.6.10
Uname –a: Linux runtime-lnx #1 SMP Tue Oct 2 13:21:34 PDT 2007 x86_64 unknown
GCC: 3.4.6
GLIBC: 2.3.6
Libstd++: 6.0.3

Run
/lib/libc.so.6
GNU C Library stable release version 2.3.6, by Roland McGrath et al.
Copyright (C) 2005 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.
Compiled by GNU CC version 3.4.5.
Compiled on a Linux 2.6.10 system on 2007-01-03.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html >.

gcc-cross-compile -v
Reading specs from
/auto/dev/spcdn-toolchain/i386-redhat-linux-cross-i686-spcdn-linux-gnu.20070925/lib/gcc/i686-spcdn-linux-gnu/3.4.6/specs
Configured with: /i686- spcdn-linux-1.lu/gcc/configure
--prefix=/auto/dev/spcdn-toolchain/i386-redhat-linux-cross-i686-spcdn-linux-gnu.20070925
--target=i686-spcdn-linux-gnu --host=i386-redhat-linux --enable-shared
--enable-clocale=gnu --enable-__cxa_atexit --enable-threads=posix
--enable-languages=c,c++
--libexecdir=/auto/dev/spcdn-toolchain/i386-redhat-linux-cross-i686-spcdn-linux-gnu.20070925/lib
--disable-multilib --disable-libunwind-exceptions
--disable-libstdcxx-pch
--with-local-prefix=/auto/dev/spcdn-toolchain/i386-redhat-linux-cross-i686-spcdn-linux-gnu.20070925/i686-spcdn-linux-gnu/usr
Thread model: posix

gcc version 3.4.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]