From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16526 invoked by alias); 11 Aug 2008 16:35:46 -0000 Received: (qmail 16505 invoked by uid 22791); 11 Aug 2008 16:35:45 -0000 X-Spam-Check-By: sourceware.org Received: from smtp1.dnsmadeeasy.com (HELO smtp1.dnsmadeeasy.com) (205.234.170.134) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 11 Aug 2008 16:35:05 +0000 Received: from smtp1.dnsmadeeasy.com (localhost [127.0.0.1]) by smtp1.dnsmadeeasy.com (Postfix) with ESMTP id ABF71320177; Mon, 11 Aug 2008 16:35:14 +0000 (UTC) X-Authenticated-Name: js.dnsmadeeasy X-Transit-System: In case of SPAM please contact abuse@dnsmadeeasy.com Received: from avtrex.com (unknown [67.116.42.147]) by smtp1.dnsmadeeasy.com (Postfix) with ESMTP; Mon, 11 Aug 2008 16:35:14 +0000 (UTC) Received: from dl2.hq2.avtrex.com ([192.168.7.26]) by avtrex.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 11 Aug 2008 09:35:02 -0700 Message-ID: <48A06A35.7080102@avtrex.com> Date: Mon, 11 Aug 2008 16:47:00 -0000 From: David Daney User-Agent: Thunderbird 2.0.0.14 (X11/20080501) MIME-Version: 1.0 To: Pan ruochen Cc: gcc-help@gcc.gnu.org Subject: Re: how to create a self-relocatable raw binary with gcc? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00103.txt.bz2 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