GCC 4.0.3 -shared creates segfault

William Harrington wwh20610 at cmsu2.cmsu.edu
Mon Apr 16 21:19:32 PDT 2007

On Apr 16, 2007, at 2:30 PM, Tijnema ! wrote:

> Hi,
> Is it normal when using -shared to create binaries that they are a  
> segfault.
> This is what i did for example
> /# echo "main(){}" > dummy.c
> /# gcc -shared dummy.c -o dummy
> /# ./dummy
> Segmentation fault
> I'm using GCC-4.0.3 (LFS-6.2 pre-release).
> removing the -shared solves the problem. Also using -static there's  
> no segfault.
> Is this normal behaviour because -shared should be used on  
> libraries only?
> Tijnema
> -- 
> http://linuxfromscratch.org/mailman/listinfo/blfs-support
> FAQ: http://www.linuxfromscratch.org/blfs/faq.html
> Unsubscribe: See the above information page

First,  I think it'd be appropriate that you read what -shared does  
in gcc, not for OSX systems...  and do this for some experimentation...

echo "int main(){}" > dummy.c
gcc -shared -fPIC dummy.c -o libdummy.so
gcc -L./ -ldummy -o test
LD_LIBRARY_PATH=./ ldd ./test

You don't even have to use position independent code with dummy.c!

gcc -shared dummy.c -o libdummy.so
gcc -L./ -ldummy -o test
LD_LIBRARY_PATH=./ ldd ./test

no segfaults!

Why do you get segfaults when you attempt to run an object that is to  
be used
to link dynamically?

I want you to compare what the nm output of both libdummy.so and test  
give you.
I'm sure you can figure it out with some research.

Even libdummy.so segfaults, but test will not.

yes, it is normal for -shared to segfault when the resulting output  
is not a library. It's not restricted to just 4.0.3.

I think the gcc documentation does a good job at explaining what - 
shared does, and I'm not sure exactly what you are trying to do.

Hope this helps you get closer to your understanding of how it works.


William Harrington

More information about the blfs-support mailing list