ELF executable & relocatable

Michael Eager eager@eagercon.com
Tue Jun 24 20:43:00 GMT 2003


S kris wrote:
> hi
> 
> I have a very strange query? please clarify.
> 
> I understand that the ELF executable binary in Linux is usually not 
> relocatable. So how to make or produce an ELF executable binary to be 
> relocatable? Eventually the image should be both executable and 
> relocatable, so that if binary in not loaded at its preferred load 
> address then it should be able to fixup the addresses using .reloc section.

Try these linker flags:

`-q'
`--emit-relocs'
      Leave relocation sections and contents in fully linked
      exececutables.  Post link analysis and optimization tools may need
      this information in order to perform correct modifications of
      executables.  This results in larger executables.

`-r'
`--relocateable'
      Generate relocatable output--i.e., generate an output file that
      can in turn serve as input to `ld'.  This is often called "partial
      linking".  As a side effect, in environments that support standard
      Unix magic numbers, this option also sets the output file's magic
      number to `OMAGIC'.  If this option is not specified, an absolute
      file is produced.  When linking C++ programs, this option _will
      not_ resolve references to constructors; to do that, use `-Ur'.

      When an input file does not have the same format as the output
      file, partial linking is only supported if that input file does
      not contain any relocations.  Different output formats can have
      further restrictions; for example some `a.out'-based formats do
      not support partial linking with input files in other formats at
      all.

      This option does the same thing as `-i'.


-- 
Michael Eager	 Eager Consulting     eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077



More information about the Gcc mailing list