public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@avtrex.com>
To: Pan ruochen <panruochen@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: how to create a self-relocatable raw binary with gcc?
Date: Mon, 11 Aug 2008 16:47:00 -0000	[thread overview]
Message-ID: <48A06A35.7080102@avtrex.com> (raw)
In-Reply-To: <af0faace0808102336r149a2268obea5efcca5a74c54@mail.gmail.com>

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

  reply	other threads:[~2008-08-11 16:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-11 16:32 Pan ruochen
2008-08-11 16:47 ` David Daney [this message]
2008-08-12 14:25 ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48A06A35.7080102@avtrex.com \
    --to=ddaney@avtrex.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=panruochen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).