This is the mail archive of the
mailing list for the glibc project.
Re: Shared library -shared vs. -fpic
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: Re: Shared library -shared vs. -fpic
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Tue, 23 May 2000 08:57:21 +0200
- CC: glibc-linux at ricardo dot ecn dot wfu dot edu
- References: <Pine.LNX.4.10.10005221824580.11839-100000@ashi.FootPrints.net>
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
> PIC stands for Position-Independent Code.
> Code isn't position-independent (or ``relocatable'') cannot be
> loaded at an arbitrary address;
> it requires some references to be patched at load time.
> Shared libraries need to be relocatable because it's not known
> beforehand what address they will be loaded at
Correct, depending on the meaning of "relocatable". PIC code typically
does not contain relocations; that's why its position-independent.
> Just because you don't specify -fPIC doesn't mean that the compiler
> won't emit position-independent code; the option prevents it from
> emitting position-dependent code in situations where it otherwise
Correct. However, a non-trivial shared library typically won't be
position-independent unless explicitly compiled with
-fPIC. Linux/glibc indeed does not require a shared library to be
position-independent; instead, it will perform the relocations in the
binary, even if they refer to code pages. As a result, those relocated
pages won't be shared across processes, anymore.