gcc non-PIC shared library

gcc non-PIC shared library

Post by Z. Majee » Fri, 13 Apr 2001 04:27:03



I'm using g++ 2.95.3 on Solaris 8. I need to build a shared library
that pulls in some non-PIC objects from an archive library.
The problem is g++ -shared passes -z text to ld and that makes the
link fail.

If I don't say -shared and pass -G to ld through g++, g++
thinks I'm building an executable and tries to link some objects
needed to build an executable which causes the link to fail.

Is there a way to say g++ -shared but not have it pass -z text
to ld? Why is it passing -z text on Solaris by default anyway
since Solaris allows non-PIC shared libraries?

If not I will have to link in a separate step using ld directly and
I'd like to avoid that if at all possible.

Thanks,
Zartaj

 
 
 

gcc non-PIC shared library

Post by Sven Maschec » Fri, 13 Apr 2001 06:04:57



> I need to build a shared library that pulls in some non-PIC objects

[FYI: see also gnu.gcc.help, it was a multiposting]

Sven, fup2 poster

 
 
 

gcc non-PIC shared library

Post by Z. Majee » Fri, 13 Apr 2001 08:50:47



> [Argh, you made a multiposting to comp.unix.solaris!]


> > I'm using g++ 2.95.3 on Solaris 8. I need to build a shared library
> > that pulls in some non-PIC objects from an archive library.
> > The problem is g++ -shared passes -z text to ld and that makes the
> > link fail.
> > [...]
> > Why is it passing -z text on Solaris by default anyway
> > since Solaris allows non-PIC shared libraries?

> Unfortunately "-Wl,-z,textoff" is incompatible with "-z text".

> "-z text" is taken from the "specs" file.

> I haven't found anything about how to override specs-settings
> from the command line.  Am i overlooking the obvious?

> gcc has the original specs file also "compiled in".
> So you could move it away and edit a copy of the binary
> for special purposes, both version would work, but different.

This "specs" file led me to a few solutions.

1. There is a g++ global link_spec which contains the link command
options. There are other such variables in gcc.c. They can be patched
in the binary using gdb as you suggest. But ...

2. g++ -v displays the line:
Reading specs from etc./etc./specs
It turns out the specs are actually read in from a file! And what's more
g++ -specs=<file> will read specs from any file you want.
So all I had to do was remove the -z text option from the *link: line
in the specs file and I got what I wanted! Also ...

3. The original link line in the specs file indicated there is an option
that controls whether -z text is implicit with -shared or not. The option
is -mimpure-text and it seems to be undocumented. So I can use that
instead of providing my specs file. Of course since it is undocumented
it may change in the future.

Zartaj

- Show quoted text -

Quote:>   $ ./gcc -shared -o liblib1.so lib1.o
>   $ gcc -shared -o liblib1.so lib1.o
>   Text relocation remains [...]

> Sven

 
 
 

1. non-PIC ELF shared libraries (fwd)

I've been following this thread, though I actually do not care about it --
sure shared libs must be position independent, that's just the price you
have to pay. I have a question though: is there a way to generate fully
relocatable executables (not objects as produced by ld -r!)? I mean
executables that you could relocate to arbitrary offset in the data/code
segment at loadtime? And still be able to use gdb/binutils/etc.? Is there
any BFD file format that allows this or can ELF do this somehow?
I'd be very thankful for any info!

Martynas

2. How can I turn off screen paging in Slackware Linux

3. non-PIC ELF shared libraries

4. HTML to Postscript

5. Shared library and PIC

6. cat vs de-cat

7. how to remove blank line in a file with vi

8. shared libraries - PIC testing

9. PIC and Shared Libraries

10. shared library creation and -KPIC/pic clarification

11. Shared, non shared libraries need some information about this subject

12. Will strip(debug shared library) == nodebug shared library ?