Problem with static linking
Robert A Nesius
rnesius@ichips.intel.com
Fri Jan 18 15:51:00 GMT 2002
On Fri, 18 Jan 2002, Hendrik Muhs wrote:
> Hi,
>
> I have a problem with static linking. Please look at the following example.
>
> The main programm foo "dlopens" the shared library bar and calls the function
> in bar.
>
> If I compile at least bar.c or foo.c not static:
> ...
>
> it works. But if compile both static:
>
> ...
>
> I get a segfault(in malloc):
>
> hendrik@tux:~> ./foo
> we are in bar
> Segmentation fault
>
> Why does it segfaults?
>
Hi Hendrik,
Perhaps the problem is that when you compile both binaries
"statically" the binaries generated do not use address independent
memmory references? That is, maybe in both binaries, the memory
references begin at the same point in memory, and your malloc
is stomping over part of your running code.
I'm wondering if using -fPIC to build your binaries would help.
I'm not 100% sure if -fPIC and 'static' binaries go together, but
this is the only thing I can think of.
-Rob
--
#include <sig.h>
------------------------------------------------------------------
Robert Nesius rnesius@ichips.intel.com 503.712.2181
DPG Engineering Computing SW Applications Team
More information about the Gcc-help
mailing list