1753960 Members
7513 Online
108811 Solutions
New Discussion юеВ

shl_load problem!

 
SOLVED
Go to solution
jack_8
Contributor

shl_load problem!

I have a program.
file load_test.cpp:

#include
int main(int argc, char* const* argv)
{
void *libptr;
int (*proc)();
shl_t lib;
lib = shl_load("loader.sl", BIND_IMMEDIATE|BIND_VERBOSE, 0L);
int result = shl_findsym(&lib,(const char*) "LibMain", TYPE_PROCEDURE, (void*)&proc);
(*proc)();
shl_unload(lib);
return 0;
}
file loader.sl:

include

void bye();

extern "C" {

int LibMain()
{
atexit(bye);
return 1;
}

}

void bye()
{
}

Makefile is:
all: loader.sl load_test

load_test: Makefile load_test.cpp
aCC -o load_test load_test.cpp -ldld

loader.sl: Makefile loader.cpp
aCC +z -b -o $@ loader.cpp
===========================================
when I run load_test. I found it is core dump.
I don't know why? Is there any methods to solve it?
3 REPLIES 3
jack_8
Contributor

Re: shl_load problem!

sorry, forget to say enviroment. I use hp11.0 compiler is aCC 3.25.
Sam Nicholls
Trusted Contributor
Solution

Re: shl_load problem!

Hi Jack,

The problem is that your atexit function (bye) is defined in the shared library. And you're unloading the shared library before the program exits. Thus the SEGV. Remove the shl_unload() or move bye() out of the shared library.

-sam
Thomas Kollig
Trusted Contributor

Re: shl_load problem!

Hi!

With "atexit" you register "bye" to be called at termination. If you unload your library, "bye" is gone and you get a segmentation fault
(You reference a function which doesn't exist any more).
If you don't unload your library or don't use "atexit" on "bye" it works fine.

Thomas