This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: -shared under SunOS


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]