Code fragments from two C source files:
Ac
Channel *testChannelGet()
{
Channel *ch = channelGet (parser,parserCh);
return ch;
}
Bc
Channel *channelGet(UINT8 parser, UINT16 parserCh)
{
chnl.player = &solPlayer;
return((Channel *)&chnl);
}
I compile both files and create a static and shared library. Now I call testChannelGet from the sample program. When I link it to a static library, it works fine. But if I link it to a shared library, its SEGFAULTing. Debugging tells me that the pointer returned from channelGet changes the moment it returns. Gdb below.
174 Channel *ch = channelGet (parser,parserCh);
(gdb) s
channelGet (parser=1 '\001', parserCh=1) at B.c:15174
15174 chnl.player = &solPlayer;
(gdb) n
15175 return((Channel *)&chnl);
(gdb) p ((Channel *)&chnl)
$1 = (Channel *) 0x7ffff7fed1a0
(gdb) n
15176 }
(gdb) n
testChannelGet at A.c:175
175 return ch;
(gdb) p ch
$2 = (Channel *) 0xfffffffff7fed1a0
The address value now seems to indicate a different offset - 0xfffffffff7fed1a0 vs 0x7ffff7fed1a0. The last bytes in both addresses are the same.
Any clues? I tried the -fPIC option to no avail.
source
share