Operating System - HP-UX
1748169 Members
4225 Online
108758 Solutions
New Discussion юеВ

Re: creating static object in library causing application to crash

 
SOLVED
Go to solution
pramodsharma
Advisor

creating static object in library causing application to crash

Here is my scenario,
1. mylib.cpp contains the code for library libfoo.sl
2. main.cpp uses the above library using dlopen.

mylib.cpp is attached and the main.cpp is like this
#include
#include
#include
typedef void (*f)(void) ;
int main()
{
void *handle = dlopen("/tmp/test/libfoo.sl",RTLD_NOW);
f cb = (f)dlsym(handle,"function");
cb();
dlclose(handle);
sleep(5);
return 0 ;
}

and the command lines are as follows
1. g++ -g -Wall -c -fPIC -D_PSTAT_64 -DPTHREAD_COMPAT_MODE -DREENTRANT -D_REENTRANT -o foo.o mylib.cpp
2. g++ -g -fPIC -shared -o libfoo.sl -lgcc_s -lstdc++ foo.o
3.gcc -g -Wl,-E main.cpp -o testexecutable


At the program exit there is a segmentation fault and the core is getting generated. Core is not telling much .

May be some flags at compile time or I am doing something really bad in code.

If I remove the static inside the void tuctuc() then everything works fine.

Any pointers will be appreciated.

Thanks,
Pramod
3 REPLIES 3
Dennis Handly
Acclaimed Contributor
Solution

Re: creating static object in library causing application to crash

Step 3 is broken, you must link with g++, otherwise I get unsats on IPF.

You are out of luck, g++ is broken and doesn't handle dlclose with destruction of function scope statics. (I was using 4.2.1.)

aCC6 is designed to handle it.
pramodsharma
Advisor

Re: creating static object in library causing application to crash

Thanks Denis. About this 3rd step we tried both gcc and g++ with the same result.

Ya even I figured that out that somehow g++ has some issues here but your confirmation will definetly help.

I am using gcc 4.0.1 so even moving to newer version is not going to help. Will recommend aCC to our team for next release.





Dennis Handly
Acclaimed Contributor

Re: creating static object in library causing application to crash

Our g++ expert says this is a known problem. It is due to the differences in atexit(3) between libc on HP-UX and on Linux.