public inbox for sid@sourceware.org
 help / color / mirror / Atom feed
* SID ELF loader using wrong load address?
@ 2002-02-04 12:30 Dave Brolley
  2002-02-04 12:42 ` Frank Ch. Eigler
  2002-02-05  8:39 ` Dave Brolley
  0 siblings, 2 replies; 4+ messages in thread
From: Dave Brolley @ 2002-02-04 12:30 UTC (permalink / raw)
  To: sid

[-- Attachment #1: Type: text/plain, Size: 988 bytes --]

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

[-- Attachment #2: lma.ChangeLog --]
[-- Type: text/plain, Size: 157 bytes --]

2002-02-04  Dave Brolley  <brolley@redhat.com>

	* elfload.c (readElfFile): Obtain the load address from offset 24 for
	elf64 and from offset 12 for elf32.


[-- Attachment #3: lma.patch.txt --]
[-- Type: text/plain, Size: 1762 bytes --]

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,

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

* Re: SID ELF loader using wrong load address?
  2002-02-04 12:30 SID ELF loader using wrong load address? Dave Brolley
@ 2002-02-04 12:42 ` Frank Ch. Eigler
  2002-02-04 14:33   ` Dave Brolley
  2002-02-05  8:39 ` Dave Brolley
  1 sibling, 1 reply; 4+ messages in thread
From: Frank Ch. Eigler @ 2002-02-04 12:42 UTC (permalink / raw)
  To: Dave Brolley; +Cc: sid

[-- Attachment #1: Type: text/plain, Size: 468 bytes --]

Hi -

brolley wrote:
> [...]
> 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. [...]

Good catch, thanks!  Looking at include/elf/external.h, I guess we want
Elf32_External_Phdr.p_paddr instead of p_vaddr.


- FChE

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

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

* Re: SID ELF loader using wrong load address?
  2002-02-04 12:42 ` Frank Ch. Eigler
@ 2002-02-04 14:33   ` Dave Brolley
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Brolley @ 2002-02-04 14:33 UTC (permalink / raw)
  To: Frank Ch. Eigler; +Cc: sid

"Frank Ch. Eigler" wrote:

> Hi -
>
> brolley wrote:
> > [...]
> > 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. [...]
>
> Good catch, thanks!  Looking at include/elf/external.h, I guess we want
> Elf32_External_Phdr.p_paddr instead of p_vaddr.

Yes -- that makes sense. Can I consider this approval to commit?

Dave


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

* Re: SID ELF loader using wrong load address?
  2002-02-04 12:30 SID ELF loader using wrong load address? Dave Brolley
  2002-02-04 12:42 ` Frank Ch. Eigler
@ 2002-02-05  8:39 ` Dave Brolley
  1 sibling, 0 replies; 4+ messages in thread
From: Dave Brolley @ 2002-02-05  8:39 UTC (permalink / raw)
  To: sid

Approved by fche and committed.

Dave Brolley wrote:

> 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
>
>   ------------------------------------------------------------------------
>                     Name: lma.ChangeLog
>    lma.ChangeLog    Type: Plain Text (text/plain)
>                 Encoding: 7bit
>
>                     Name: lma.patch.txt
>    lma.patch.txt    Type: Plain Text (text/plain)
>                 Encoding: 7bit

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

end of thread, other threads:[~2002-02-05 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-04 12:30 SID ELF loader using wrong load address? Dave Brolley
2002-02-04 12:42 ` Frank Ch. Eigler
2002-02-04 14:33   ` Dave Brolley
2002-02-05  8:39 ` Dave Brolley

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).