From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12992 invoked by alias); 4 Feb 2002 20:30:15 -0000 Mailing-List: contact sid-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: sid-owner@sources.redhat.com Received: (qmail 12818 invoked from network); 4 Feb 2002 20:30:02 -0000 Received: from unknown (HELO lacrosse.corp.redhat.com) (12.107.208.154) by sources.redhat.com with SMTP; 4 Feb 2002 20:30:03 -0000 Received: from redhat.com (IDENT:root@tooth.toronto.redhat.com [172.16.14.29]) by lacrosse.corp.redhat.com (8.11.6/8.9.3) with ESMTP id g14KU1I06924 for ; Mon, 4 Feb 2002 15:30:01 -0500 Message-ID: <3C5EEF5F.77116D06@redhat.com> Date: Mon, 04 Feb 2002 12:30:00 -0000 From: Dave Brolley X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.16-22 i686) X-Accept-Language: en MIME-Version: 1.0 To: sid@sources.redhat.com Subject: SID ELF loader using wrong load address? Content-Type: multipart/mixed; boundary="------------82C2F549F63F2077868D10D6" X-SW-Source: 2002-q1/txt/msg00022.txt.bz2 This is a multi-part message in MIME format. --------------82C2F549F63F2077868D10D6 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-length: 988 Hi, I have a linker script for an application on an ELF target which contains something like the following: .reloc_section 0x1000 : AT (LOADADDR(.text)+SIZEOF(.text)) { *(.reloc_section) } This is a section of code which should be loaded at the end of the .text section and is intended to be copied (by the application itself) to address 0x1000 before being executed. However, the SID ELF loader currently loads this section at address 0x1000 (the VMA) instead of at the given LMA. Visual inspection of a hex dump of my executable shows that, for elf32, the address being used at offset 8 of the section header is indeed the VMA and that the LMA is at offset 12 (can anyone confirm this?). The attached patch gets the section loaded at the proper LMA and has been tested against my port (an internal one) and against xstormy16. I would not expect any regressions since the LMA and the VMA are the same unless one plays linker script tricks like the one above. OK to commit? Dave --------------82C2F549F63F2077868D10D6 Content-Type: text/plain; charset=us-ascii; name="lma.ChangeLog" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="lma.ChangeLog" Content-length: 157 2002-02-04 Dave Brolley * elfload.c (readElfFile): Obtain the load address from offset 24 for elf64 and from offset 12 for elf32. --------------82C2F549F63F2077868D10D6 Content-Type: text/plain; charset=us-ascii; name="lma.patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="lma.patch.txt" Content-length: 1762 Index: sid/component/loader/elfload.c =================================================================== RCS file: /cvs/src/src/sid/component/loader/elfload.c,v retrieving revision 1.2 diff -c -p -r1.2 elfload.c *** sid/component/loader/elfload.c 2001/01/13 14:26:05 1.2 --- sid/component/loader/elfload.c 2002/02/04 20:23:40 *************** readElfFile (PFLOAD func, unsigned* entr *** 93,99 **** } if (fetchWord (psymHdr, littleEndian) == PT_LOAD) { ! loadAreas[loadAreaCount].loadAddr = fetchQuad(psymHdr+16, littleEndian); loadAreas[loadAreaCount].offset = fetchQuad(psymHdr+8, littleEndian); loadAreas[loadAreaCount].filesize = fetchQuad(psymHdr+32, --- 93,99 ---- } if (fetchWord (psymHdr, littleEndian) == PT_LOAD) { ! loadAreas[loadAreaCount].loadAddr = fetchQuad(psymHdr+24, littleEndian); loadAreas[loadAreaCount].offset = fetchQuad(psymHdr+8, littleEndian); loadAreas[loadAreaCount].filesize = fetchQuad(psymHdr+32, *************** readElfFile (PFLOAD func, unsigned* entr *** 111,117 **** } if (fetchWord (psymHdr, littleEndian) == PT_LOAD) { ! loadAreas[loadAreaCount].loadAddr = fetchWord(psymHdr+8, littleEndian); loadAreas[loadAreaCount].offset = fetchWord(psymHdr+4, littleEndian); loadAreas[loadAreaCount].filesize = fetchWord(psymHdr+16, --- 111,117 ---- } if (fetchWord (psymHdr, littleEndian) == PT_LOAD) { ! loadAreas[loadAreaCount].loadAddr = fetchWord(psymHdr+12, littleEndian); loadAreas[loadAreaCount].offset = fetchWord(psymHdr+4, littleEndian); loadAreas[loadAreaCount].filesize = fetchWord(psymHdr+16, --------------82C2F549F63F2077868D10D6--