Post by John SmithCan any of you explain what the difference is between gcc option -fpic
and -fPIC. The option -fpic works under Linux x86 but not under Mac OSX and
I'd like to know why. Gcc under OS X said I should use -fPIC instead.
I read the gcc documentation but didn't understand the difference between
them.
Both seems to make position-independent-code needed for dynamlic libraries.
That's correct. And the difference between -fpic and -fPIC is due to
the way the code is made position independent. To do that you're not
allowed to have any absolute addresses in the machine code because
the library will get loaded at an address that can't be forseen. Thus
instead of having absolute addresses in the code such addresses are to
be calculated via a so-called global offset table (GOT), so basically
you have instead of an address the index in the GOT which is used for
a replacement by the "real" address when the library gets loaded. For
example, if you have a call to a function you normally would have some
kind of jump instruction to the address where the function is located
in memory. Since that wouldn't work with a shared library some an index
into the GOT is stored in the shared library for that jump instruction
instead and the run-time linker will replace it by the address of the
function when the libary is loaded, which it can do because it knows
where the library is going to be in the memory.
On some systems there are certain restrictions to the size of the GOT.
When there are too many symbols that require an entry in the GOT using
-fpic won't work anymore on these systems and -fPIC is to be used
instead to get around this limitation. Doing that will probably require
some extra work during run-time linking of the library but it will work
on all machines (that allow to create position-independent code).
Regards, Jens
--
\ Jens Thoms Toerring ___ ***@physik.fu-berlin.de
\__________________________ http://www.toerring.de