This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: relocatable code and object files and shared libraries


"ranjith kumar" <ranjithproxy@gmail.com> writes:

> 1)Are all object files are relocatable???

When I use the term "relocatable" I mean an object file which contains
relocation entries (as printed by objdump -r).  In that sense, all
object files are relocatables, and executables are not.

> http://ehuss.com/shared/
> The above  link says
> "To create a shared library, you write the code like you normally
> would. When you go to compile your code, you should indicate that the
> code needs to be "position independent". You do this with the gcc
> compile option "-fPIC". For example:
>
>     gcc -fPIC -c my_library.c "

This is talking about position independent code, which is not the same
as relocatable code.  Relocatable code is code whose address may be
assigned at link time.  Position independent code is code whose
address may be assigned at run time.

All object files are relocatable.  For most targets, only object files
compiled with -fpic or -fPIC or -pie are position independent.

> 2) If we dont use -fPIC will the object file produced will not be relocatable??

If you don't use -fPIC (-fpic, -pie) the object file will be
relocatable, but when you link it into an executable, that executable
will be required to run at a fixed address specified at link time.

> 3) What exactly does relocatable code means? any links explaning it please.

http://www.airs.com/blog/archives/41

> 4) Why do we need shared library when we can create object files which
> are relocatable??

See above.

> 5)Why the size of shared library file(*.so) is very large than the
> object file from which it is produced??

Normally because other objects are linked into the shared library.  If
you are careful to only include a single object in your link, the
shared library should not be much larger than the object.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]