This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Building libstdc++ non-shared with -fpic ?
> How is this possible ?
By means of the relocation section present in every shared library.
> That would imply that you are able to build shared libraries, which
> use code which is not position independent
That is indeed the case.
> so why would it be necessary at all to use the -fPIC compiler switch
> to create a shared library ?
It is not necessary. However, if it is not done, the dynamic linker
will have to relocate the library at load time. As a result, the
start-up time will increase, as will the memory consumption, since the
shared library won't be shared across processes.
On some systems, it used to be that the dynamic linker refuses to do
any relocations. However, these systems are broken, and have been all
corrected, AFAIK.
> (Why should it be possible that some of the code has do be PIC and
> some of it doesn't need to be PIC ?
I don't know whether it *should be* possible - I know it is.
If you are willing to accept this, some useful cases come to mind. It
is know possible to link a static library into a shared library, even
if that library was not compiled with -fPIC, and even if you can't
recompile the library.
> I think the all or nothing principle should apply:
> All PIC -> shared library possible
> Not all PIC -> shared library impossible
Why do you require artificial limitations on the compilation system,
when there is no technical reason to require them?
Regards,
Martin