Re: how to create a self-relocatable raw binary with gcc?

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

 



Pan ruochen wrote:
Hi All,

I want to create a raw binary excutable for MIPS arch, which can relocate
itself to any load address at runtime without an externel loader.
How should I compile the sources and write the linker script for this purpose?


The Linux glibc dynamic linker is such a program.  So I would say: Do what glibc does.

At a minimum you will need to write a little bit of assembly code to calculate the load address at runtime (using the bal instruction) and set the stack pointer.  Then if you end up with any relocations you will have to process them.

Assuming you use the o32 ABI, if you compile everything with -fpic there will only be relocations for global data.  If you can arrange for no global data, you will not have to process any relocations.

David Daney


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux