public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to create a self-relocatable raw binary with gcc?
@ 2008-08-11 16:32 Pan ruochen
  2008-08-11 16:47 ` David Daney
  2008-08-12 14:25 ` Ian Lance Taylor
  0 siblings, 2 replies; 3+ messages in thread
From: Pan ruochen @ 2008-08-11 16:32 UTC (permalink / raw)
  To: gcc-help

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?

Best Regards,
PRC
Apr 11, 2008

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to create a self-relocatable raw binary with gcc?
  2008-08-11 16:32 how to create a self-relocatable raw binary with gcc? Pan ruochen
@ 2008-08-11 16:47 ` David Daney
  2008-08-12 14:25 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: David Daney @ 2008-08-11 16:47 UTC (permalink / raw)
  To: Pan ruochen; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to create a self-relocatable raw binary with gcc?
  2008-08-11 16:32 how to create a self-relocatable raw binary with gcc? Pan ruochen
  2008-08-11 16:47 ` David Daney
@ 2008-08-12 14:25 ` Ian Lance Taylor
  1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2008-08-12 14:25 UTC (permalink / raw)
  To: Pan ruochen; +Cc: gcc-help

"Pan ruochen" <panruochen@gmail.com> writes:

> 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?

There isn't any way to do this without some hacking.

gcc and gas used to support that for the MIPS.  The option was
-membedded-pic.  It was removed because it stopped working and nobody
was interested in fixing it.  So one approach would be to look at old
releases for that code and fix it up.

Ian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-08-12 14:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-11 16:32 how to create a self-relocatable raw binary with gcc? Pan ruochen
2008-08-11 16:47 ` David Daney
2008-08-12 14:25 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).