This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: -shared under SunOS
- To: dneil at etak dot com
- Subject: Re: -shared under SunOS
- From: Manfred Hollstein <manfred at s-direktnet dot de>
- Date: Sat, 27 Feb 1999 18:31:31 +0100 (MET)
- Cc: egcs-bugs at egcs dot cygnus dot com
- References: <19990224095027.A3292@etak.com>
- Reply-To: manfred at s-direktnet dot de, mh at exept dot de
On Wed, 24 February 1999, 09:50:29, dneil@etak.com wrote:
> Is the following a bug? (SunOS 4.1.4, egcs 1.1.1.)
>
> $ cat > foo.c
> int foo() { return 42; }
> $ egcs -fPIC -c foo.c
> $ egcs -shared -o libfoo.so foo.o
> ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 3c in /usr/tmp/ccmJgnEY.o
>
> ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 40 in /usr/tmp/ccmJgnEY.o
>
> ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 44 in /usr/tmp/ccmJgnEY.o
>
> ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 48 in /usr/tmp/ccmJgnEY.o
>
> ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 50 in /usr/tmp/ccmJgnEY.o
>
> collect2: ld returned 2 exit status
>
>
> This error does not occur with gcc 2.7.2.3. The problem appears to come
> from collect2. For reasons that I do not fully understand, collect2 is
> generating and compiling a small file containing some stub functions
> (appended below). This file is the one generating the ld pure-text
> assertion errors above, as it is not being compiled with -fPIC.
>
> I can make the problem go away by adding -fPIC to the link line:
> $ egcs -fPIC -shared -o libfoo.so foo.o
>
> Is this what I am supposed to be doing?
Yes!
> I would think that -fPIC would
> normally be used only on compilation lines, not link lines.
But you're actually compiling here, too.
> Shouldn't
> collect automatically add -fPIC to anything it generates and compiles,
> if it is destined for a shared object?
That would be fine, but which flag '-fpic' or '-fPIC' should it choose
then? There are several platforms (SunOS is one of them) where the
system's native linker refuses to link .o files compiler with differing
PICFLAGS.
Please see also <http://egcs.cygnus.com/faq.html#picflag-needed>.
Later,
manfred