Statically linked library causes segmentation violation upon C++ throw

Discussion in 'C++' started by google@voom.net, Jun 3, 2006.

  1. Guest

    I statically link the Synopsys Milkyway C-API library ("MDA") into my
    C++ application. When my C++ application throws an exception, it seg
    faults instead.

    The details of my environment are:
    x86 (Pentium) CPU or AMD x86_64 (Opteron)
    Red Hat Enterprise Linux 3 OS
    gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54)
    Also reproduced with gcc version 3.3.2

    The Synopsys Milkyway C-API library is,
    Static linked library (dynamic linked not available)
    Developed in C, not C++
    supported on Red Hat Enterprise Linux 3.0, gcc version 3.3.2

    The problem is platform-dependent:

    - The problem occurs when I compile for 32 bits and link to the x86
    MDA library, and run on either x86 and AMD x86_64 (Opteron)

    - No problem when I compile for 64 bits and link to the x86_64 MDA,
    and run on AMD x86_64

    - No problem in the absence of IA32 MDE

    In summary, there is something wrong with the 32 bit x86 version of MDA
    library, regardless of whether it is run on an x86 machine or an AMD
    x86_64 machine. But how to fix it?

    The attached test program executes the MDA initialization function
    MWXDb_omwxInit(), and then throws an exception. This causes the seg
    fault as described above. When I comment out MWXDb_omwxInit(), throw
    works as expected.

    ---------
    #include <cstdio>
    #include <cstdlib>
    #include "omwx_proto.h" // Include file for MDA

    void
    thrower(const int in)
    {
    if (in > 1) {
    printf("Throw an exception.\n");
    throw 3;
    }
    printf("Did not throw an exception.\n");
    }

    int
    main(int argc,
    char **argv)
    {
    // When present, causes the mda lib to be included,
    // and the throw to fail with a segv.
    // When commented out, the throw works fine.
    MWXDb_omwxInit(argc, argv, 1);

    try {
    thrower(argc);

    } catch(int &excp) {
    printf("Caught exception %d.\n", excp);
    }
    }
    , Jun 3, 2006
    #1
    1. Advertising

  2. Salt_Peter Guest

    Re: Statically linked library causes segmentation violation uponC++ throw

    wrote:
    > I statically link the Synopsys Milkyway C-API library ("MDA") into my
    > C++ application. When my C++ application throws an exception, it seg
    > faults instead.
    >
    > The details of my environment are:
    > x86 (Pentium) CPU or AMD x86_64 (Opteron)
    > Red Hat Enterprise Linux 3 OS
    > gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54)
    > Also reproduced with gcc version 3.3.2
    >
    > The Synopsys Milkyway C-API library is,
    > Static linked library (dynamic linked not available)
    > Developed in C, not C++
    > supported on Red Hat Enterprise Linux 3.0, gcc version 3.3.2
    >
    > The problem is platform-dependent:
    >
    > - The problem occurs when I compile for 32 bits and link to the x86
    > MDA library, and run on either x86 and AMD x86_64 (Opteron)
    >
    > - No problem when I compile for 64 bits and link to the x86_64 MDA,
    > and run on AMD x86_64
    >
    > - No problem in the absence of IA32 MDE
    >
    > In summary, there is something wrong with the 32 bit x86 version of MDA
    > library, regardless of whether it is run on an x86 machine or an AMD
    > x86_64 machine. But how to fix it?
    >
    > The attached test program executes the MDA initialization function
    > MWXDb_omwxInit(), and then throws an exception. This causes the seg
    > fault as described above. When I comment out MWXDb_omwxInit(), throw
    > works as expected.
    >
    > ---------
    > #include <cstdio>
    > #include <cstdlib>
    > #include "omwx_proto.h" // Include file for MDA
    >
    > void
    > thrower(const int in)
    > {
    > if (in > 1) {
    > printf("Throw an exception.\n");
    > throw 3;
    > }
    > printf("Did not throw an exception.\n");
    > }
    >
    > int
    > main(int argc,
    > char **argv)
    > {
    > // When present, causes the mda lib to be included,
    > // and the throw to fail with a segv.
    > // When commented out, the throw works fine.
    > MWXDb_omwxInit(argc, argv, 1);
    >
    > try {
    > thrower(argc);
    >
    > } catch(int &excp) {
    > printf("Caught exception %d.\n", excp);
    > }
    > }
    >


    #include <iostream>
    #include <ostream>
    #include "omwx_proto.h" // Include file for MDA

    int main(int argc, char **argv)
    {
    try
    {
    thrower(argc);
    MWXDb_omwxInit(argc, argv, 1);
    // do stuff
    // release
    }
    catch(int& e const)
    {
    std::cout << "error: " << e << std::endl;
    }
    }
    Salt_Peter, Jun 3, 2006
    #2
    1. Advertising

  3. Guest

    The following is not the solution to *my particular problem* with the
    Synopsys Milkyway C-API. However, to make this a more useful thread
    for others, I will add some more information that I found. Perhaps
    this might even jog someone's memory wrt my problem.

    I discovered that this same problem has occured in other software, like
    MySQL, syslog(), libjpeg, and boost::python.

    I suspected gcc bug 16698:
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16698
    This bug was not in gcc 2.95.3, but did appear in 3.0.4, 3.2.3, 3.3.3,
    3.4.0, and 4.0.0. It is fixed in gcc 3.4.2. Perhaps if the Milkyway
    C-API 2004.06 was compiled with gcc 2.95, and the troublesome 2005.09
    was compiled with gcc 3.3.2?

    Alas, both versions of the Synopsys Milkyway C-API were compiled with
    gcc 3.2.2 and 3.3.2. If my problem was due to gcc bug 16698, I would
    have seen it in both versions of the Synopsys Milkyway C-API, or in
    neither version.

    Here are some more references. There is also some talk a problem with
    ABI (Application Binary Interface).

    Same problem, but with syslog():
    http://gcc.gnu.org/ml/gcc-help/2004-04/msg00069.html

    Same problem, but with libjpeg:
    https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=101448
    "simple fix is to rebuild libjpeg as C++":
    http://dburns.dhs.org/osgarchiver/archives/August2003/0000.html

    Same problem, but with boost::python:
    http://mail.python.org/pipermail/c -sig/2003-June/004246.html

    More information on ABI:
    http://www.usenix.org/publications/...apers/full_papers/browndavid/browndavid_html/

    John McGehee, Voom, Inc.
    , Jun 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Douthitt

    Statically-linked binary SegFaults

    David Douthitt, May 20, 2004, in forum: C Programming
    Replies:
    1
    Views:
    390
    Malcolm
    May 20, 2004
  2. Ralph Butler

    statically linked python

    Ralph Butler, Jun 17, 2006, in forum: Python
    Replies:
    3
    Views:
    505
    Serge Orlov
    Jun 20, 2006
  3. pratap
    Replies:
    20
    Views:
    758
    Flash Gordon
    Mar 7, 2007
  4. samsappleton
    Replies:
    0
    Views:
    311
    samsappleton
    Mar 11, 2008
  5. David Cournapeau

    Statically linked extension and relative import

    David Cournapeau, May 7, 2009, in forum: Python
    Replies:
    0
    Views:
    299
    David Cournapeau
    May 7, 2009
Loading...

Share This Page