[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: gcc and -fPIC



On Wednesday 20 Mar 2002 5:46 pm, Simon Richter wrote:

> In general, you need to compile everything that could be mapped at
> arbitrary addresses (in the process's virtual address space) with the
> -fPIC option to make it position independent (whatever that means for the
> target platform). Programs are loaded at a fixed address (for i386 Linux,
> this is somewhere around 0x80000000), so they needn't be compiled with
> -fPIC, while shared libraries can be mapped to different addresses in

I understand the need for PIC, but I was asking whether or not compiling 
whole binaries with PIC unnecesarily might be a bad thing. e.g. if I cannot 
control the granularity of compiler options easily in a build system and I 
build an executable with -fPIC in order to build an accompanying library 
correctly, am I trading off speed or footprint to any significant degree?

> different processes and thus need -fPIC. Static libraries are collections
> of .o files, also called relocatable objects, which are not position
> independent, but contain the information how to move them to a specified
> position ("relocate", which basically means adding the start address to
> all pointers). Thus, they don't need -fPIC either.

Unless they are later linked into a dynamic library. :)

> For the "which architectures" question: Do not think about that.
> Architectures which don't require -fPIC simply have compilers that ignore
> it. :-)

Hmm, it seems like a bad way to do this by adding

export CC="gcc -fPIC"

to the top of the Makefile. I'll have to think about this some more...



Reply to: