Exception handling in GCC 3.0.1 on AIX platform
Dmitry Dolgopolov
d.dolgopolov@websci.ru
Wed Sep 5 20:53:00 GMT 2001
Hello,
We encountered the problem with exceptions handling in GCC 3.0.1 on
AIX 4.3.2.0 platform. Specifically, when exception is generated in
a dynamicaly loaded module and tried to be catched in the program
that loads that module. Following are the sample programs:
---
// testmain.cpp
#include <iostream>
#include <dlfcn.h>
int main() {
void* handle = dlopen("./libshared.a", RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {
std::cerr << "main:: Error during dlopen()" << std::endl;
return 0;
}
void* symbol = dlsym(handle, "some_function");
if (symbol) try {
((void (*)())symbol)();
} catch (const std::string&) {
std::cerr << "main:: Exception catched" << std::endl;
} else {
std::cerr << "main:: Error during dlsym()" << std::endl;
}
dlclose(handle);
return 0;
}
---
// sharedlibrary.cpp
#include <iostream>
#include <dlfcn.h>
extern "C"
void some_function() {
std::cerr << "some_function:: trace point" << std::endl;
void* handle = dlopen("./libdeep.a", RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {
std::cerr << "some_function:: Error during dlopen()" << std::endl;
return;
}
void* symbol = dlsym(handle, "deep_function");
if (symbol) try {
((void (*)())symbol)();
} catch (const std::string&) {
std::cerr << "some_function:: Exception catched" << std::endl;
} else {
std::cerr << "some_function:: Error during dlsym()" << std::endl;
}
dlclose(handle);
}
---
// deeplibrary.cpp
#include <iostream>
extern "C"
void deep_function() {
std::cerr << "deep_function:: trace point" << std::endl;
throw std::string("exception");
}
---
Following commands were used during build:
c++ -pthread -Wl,-brtl -Wl,-bh:8 -o testmain testmain.cpp
c++ -pthread -shared -Wl,-G -Wl,-bh:8 -o libshared.a sharedlibrary.cpp
c++ -pthread -shared -Wl,-G -Wl,-bh:8 -o libdeep.a deeplibrary.cpp
Results of execution are as follows:
# ./testmain
some_function:: trace point
deep_function:: trace point
IOT/Abort trap (core dumped)
--
Best regards,
Dmitry Dolgopolov mailto:d.dolgopolov@websci.ru
More information about the Gcc
mailing list