This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ld -shared -pie revisited
On Sat, Oct 03, 2009 at 08:29:50PM -0400, Mark Lodato wrote:
> > If you find that symbols you need are missing, use -rdynamic.
>
> How would I know when to use this, other than trial and error? I
> would like to learn more.
The description of --export-dynamic in the ld manual should be
helpful; -rdynamic is what GCC calls it.
> > However, symbol binding and access to global variables will be a bit
> > weird; it will be bound like an executable so it will not necessarily
> > search the 'real' executable or other shared libraries.
>
> I'm sorry, I don't understand. Could you explain further, or provide
> an example? Also, does this statement apply to the use of -rdynamic,
> or to PIE executables in general?
>
> While I'm asking questions, is -fPIC required in addition to -fPIE, or
> does the latter imply the former?
That's a related question. If you use -fPIE, the code will be
position-independent - but assume executable symbol binding rules.
I can't give you a full tutorial of this - that is, as they say,
beyond the scope of this forum - but here's the basic problem: when
you build a shared library, it allows any global symbol to be
overridden by a definition in the executable. But when you build an
executable, that can't happen. So for full generality, you really
want to link with -shared, not -pie.
But you've got to get the startup files from GCC, and you need -pie on
your GCC link command to get that.
So you might be able to get by with a custom ld command and -shared
and -e and some startfiles...
--
Daniel Jacobowitz
CodeSourcery