PIC is wasteful
Ian Lance Taylor
iant@google.com
Thu Jun 23 19:21:00 GMT 2011
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
More information about the Gcc-help
mailing list