473,473 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Statically linked library causes segmentation violation upon C++ throw

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 '06 #1
2 2458
go****@voom.net 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;
}
}
Jun 3 '06 #2
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....cgi?id=101448
"simple fix is to rebuild libjpeg as C++":
http://dburns.dhs.org/osgarchiver/ar...2003/0000.html

Same problem, but with boost::python:
http://mail.python.org/pipermail/c++...ne/004246.html

More information on ABI:
http://www.usenix.org/publications/l...owndavid_html/

John McGehee, Voom, Inc.

Jun 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Francis Bell | last post by:
Hello, I'm trying to read data from a file and then insert that into a linked list. The way I have it, the program compiles, however, I'm getting a segmentation fault error message when I run...
2
by: Kevin Crosbie | last post by:
Hi, I have the following situation: I have a 3rd party DLL which does not include a LIB file, just a header file with typedef declarations for exported functions (It is intended for dynamic...
2
by: Jill Elaine | last post by:
I am building an Access 2002 frontend with linked tables to an encrypted Paradox 7 database. When I first create these linked tables, I'm asked for the password to the encrypted Paradox database,...
57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
0
by: Frank Duan via .NET 247 | last post by:
Hi, I am trying to create a Windows User Control, which uses a commercial native C dll and will be hosted in IE. Using P/Invoke to call C dll functions in Windows User Control (written in C#)...
8
by: bonk | last post by:
Is it generally OK for an EXE that has MFC linked statically to load an use another DLL wich has MFC linked as shared DLL ? To be more specific: I have an EXE that links a lib. Let's call it...
6
by: DanielJohnson | last post by:
int main() { printf("\n Hello World"); main; return 0; } This program terminate just after one loop while the second program goes on infinitely untill segmentation fault (core dumped) on...
36
by: Martin Larsen | last post by:
Hi, When a PHP program links to a library using include or require (or their _once variations), is the library then linked dynamically or statically? While it might seem irrelevant from a...
3
by: Bret Kuhns | last post by:
I recently started a co-op/internship at a company and they are looking to migrate a large legacy supported application from OLEDB to SQL Server. I'm doing prelim work in experimenting with the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.