This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: PIC is wasteful
- From: Ian Lance Taylor <iant at google dot com>
- To: Agner Fog <agner at agner dot org>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 23 Jun 2011 11:07:43 -0700
- Subject: Re: PIC is wasteful
- References: <4E03410F.10201@agner.org>
Agner Fog <agner@agner.org> writes:
> I wonder why position-independent code (PIC) and global offset tables
> (GOT) are used in shared objects (.so) when these features are wasting
> resources and apparently unnecessary. The wasteful use of PIC and GOT
> in Linux is apparent in the following questions:
I think your view of shared library symbol semantics does not correspond
to the view of the people who designed the system many years ago at Sun.
The shared library system implements (by default) a single global
namespace of symbols. It also supports symbol interposition.
Symbol interposition means that the shared library is permit to define a
function "malloc" and to call that function itself. However, if the
executable defines a function "malloc" itself, then all the calls in the
shared library should call the implementation in the executable, rather
than the implementation in the shared library. The same applies to
global variables, e.g., "timezone".
These rules were adopted because they made shared libraries more similar
to the existing static archives, which have similar features albeit
implemented completely differently.
Once you accept that those are the rules, you will see where the
implementation of PIC and GOT come from.
Ian