other/7516: Ambiguous driver behaviour with "-shared -static" cmd line options combination

grigory@stl.sarov.ru grigory@stl.sarov.ru
Tue Aug 6 23:56:00 GMT 2002


>Number:         7516
>Category:       other
>Synopsis:       Ambiguous driver behaviour with "-shared -static" cmd line options combination
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 06 23:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Grigory Zagorodnev
>Release:        3.1.1
>Organization:
>Environment:
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure --enable-threads
>Description:
1. Intro
--------
GCC manual defines the following cmd line options meaning:
"-static
On systems that support dynamic linking, this prevents linking with the shared libraries.

-shared 
Produce a shared object..."


2. The issue
------------
So, if we wish to produce a shared object linked against static libraries, we have to specify "-shared -static" driver options. For instance:
	$ gcc foo.c -shared -o libfo.so -static

But if we check the library built we will see that it is linked against some shared libs.
	$ ldd ./libfoo.so
	/lib/libNoVersion.so.1 => /lib/libNoVersion.so.1 (0x40003000)
	libc.so.6 => /lib/i686/libc.so.6 (0x40015000)
	/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x2aaaa000)

*** This is not what expected! ***


3. Driver work
--------------
Let's check what the GCC compiler driver is doing. We use --verbose to see details.

$ gcc foo.c -shared -o libfo.so -static --verbose
...
 /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/collect2 -m elf_i386 -shared -o libfoo.so /usr/lib/crti.o /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/crtbeginT.o -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1 -L/usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/../../.. /home/grigory/tmp/cc6Ymc3Z.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1.1/crtendS.o /usr/lib/crtn.o

We can see a kind of ambiguity here:
(a) linker command line does not contain '-static' option requested, but at the same time, (b) the set of libraries "-lgcc -lgcc_eh -lc -lgcc -lgcc_eh" is specific for static build. I.e. we can see the same set while building executable linked against static libraries.

4. Question
-----------
So, what is going on here:
  - Driver just lost '-static' in the linker command line?
  - Or this is intentional restriction?
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list