This is the mail archive of the
mailing list for the binutils project.
Re: ld -shared -pie revisited
On Sat, Oct 03, 2009 at 07:10:42PM -0400, Mark Lodato wrote:
> I saw a 2007 discussion* of whether to allow both -shared and -pie
> from gcc, where it was decided to use only the last one specified.
> But `ld -shared -pie` seems to work fine on x86_64, and in fact allows
> one to have an executable shared library - you can both dlopen the
> library and run it. This is awesome! Am I missing something here?
> Will this break in subtle ways? If so, how do you properly make a
> shared library that can be executed (like /lib/ld.so)? If not, should
> gcc x86_64 allow both -shared and -pie to make such libraries, so that
> one does not have to invoke the linker manually?
ld.so is extraordinarily special; don't read too much into it as an
example. It's linked by using -shared and -e (for --entry). But it
has custom system-specific startup code.
All you need to create something you can load or run should be -pie.
If you find that symbols you need are missing, use -rdynamic.
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.