public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* LMA XXX Overlaps Previous Sections When Using PHDRS
@ 2007-12-19 22:19 DeRosa, Anthony
  2007-12-24 17:21 ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: DeRosa, Anthony @ 2007-12-19 22:19 UTC (permalink / raw)
  To: binutils

Hello,

I want to install the contents of an ELF file on a flash device, using
the LMA of the sections (or rather p_paddr of program header) in the ELF
as the addresses in flash.  The VMA and LMA will thus be different.  I
am using "PHDRS" in my linker script in order to specify where the
various sections should be installed on flash.  The problem I am seeing
is the following message:

$ i686-elf-gcc -o test.elf test.S -T link.ld -nostartfiles

/opt/cross-tools/binutils-2.17-gcc-4.1.1-newlib-1.14.0/lib/gcc/i686-elf/
4.1.1/../../../../i686-elf/bin/ld: test.elf: section .section_0 lma
0x1000 overlaps previous sections

/opt/cross-tools/binutils-2.17-gcc-4.1.1-newlib-1.14.0/lib/gcc/i686-elf/
4.1.1/../../../../i686-elf/bin/ld: test.elf: section .section_1 lma
0x1020 overlaps previous sections


Is this a warning, an error, or neither?  Why does it say "lma 0x1000"?
I thought the VMA was 0x1000, and the LMA is 0x4000.

Here is the example code and a contrived linker script.

------------------------------------------------------------------------
----
-- code
------------------------------------------------------------------------
----

.global _start

.section .text_0, "ax"
_start:
    jmp foo

.section .text_1, "ax"
foo:
    jmp foo

------------------------------------------------------------------------
----
-- linker script
------------------------------------------------------------------------
----

ENTRY (_start)

MEMORY 
{
    ram_0 : ORIGIN = 0x00001000, LENGTH = 32
    ram_1 : ORIGIN = 0x00001020, LENGTH = 32
}

PHDRS
{
    phdr_0 PT_LOAD AT (0x4000);
    phdr_1 PT_LOAD AT (0x5000);
}


SECTIONS
{

    .section_0 :
    { 
        *(.text)
        *(.data)
        *(.bss)
        *(.text_0) 

    } >ram_0 : phdr_0

    .section_1 :
    {
        *(.text_1) 
    } >ram_1 : phdr_1
    
}


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

* Re: LMA XXX Overlaps Previous Sections When Using PHDRS
  2007-12-19 22:19 LMA XXX Overlaps Previous Sections When Using PHDRS DeRosa, Anthony
@ 2007-12-24 17:21 ` Nick Clifton
  2007-12-25 23:09   ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2007-12-24 17:21 UTC (permalink / raw)
  To: DeRosa, Anthony; +Cc: binutils

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

Hi Anthony,

> /opt/cross-tools/binutils-2.17-gcc-4.1.1-newlib-1.14.0/lib/gcc/i686-elf/
> 4.1.1/../../../../i686-elf/bin/ld: test.elf: section .section_0 lma
> 0x1000 overlaps previous sections

This is a bogus error message due to a spurious check in the linker.  Please 
try the attached patch and let me know if you have any problems.

Cheers
   Nick

bfd/ChangeLog

2007-12-24  Nick Clifton  <nickc@redhat.com>

	* elf.c (assign_file_positions_for_load_sections): Do not complain
	when then LMA is lower than the VMA.


[-- Attachment #2: elf.c.patch --]
[-- Type: text/x-patch, Size: 1111 bytes --]

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.426
diff -c -3 -p -r1.426 elf.c
*** bfd/elf.c	11 Dec 2007 13:13:59 -0000	1.426
--- bfd/elf.c	24 Dec 2007 17:18:50 -0000
*************** assign_file_positions_for_load_sections 
*** 4339,4357 ****
  		      && ((this_hdr->sh_flags & SHF_TLS) == 0
  			  || p->p_type == PT_TLS)))
  		{
! 		  if (adjust < 0)
  		    {
! 		      (*_bfd_error_handler)
! 			(_("%B: section %A lma 0x%lx overlaps previous sections"),
! 			 abfd, sec, (unsigned long) sec->lma);
! 		      adjust = 0;
! 		    }
! 		  p->p_memsz += adjust;
  
! 		  if (this_hdr->sh_type != SHT_NOBITS)
! 		    {
! 		      off += adjust;
! 		      p->p_filesz += adjust;
  		    }
  		}
  	    }
--- 4339,4353 ----
  		      && ((this_hdr->sh_flags & SHF_TLS) == 0
  			  || p->p_type == PT_TLS)))
  		{
! 		  if (adjust > 0)
  		    {
! 		      p->p_memsz += adjust;
  
! 		      if (this_hdr->sh_type != SHT_NOBITS)
! 			{
! 			  off += adjust;
! 			  p->p_filesz += adjust;
! 			}
  		    }
  		}
  	    }

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

* Re: LMA XXX Overlaps Previous Sections When Using PHDRS
  2007-12-24 17:21 ` Nick Clifton
@ 2007-12-25 23:09   ` Alan Modra
  2007-12-26 19:02     ` Nick Clifton
  0 siblings, 1 reply; 6+ messages in thread
From: Alan Modra @ 2007-12-25 23:09 UTC (permalink / raw)
  To: Nick Clifton; +Cc: DeRosa, Anthony, binutils

On Mon, Dec 24, 2007 at 05:21:06PM +0000, Nick Clifton wrote:
> Hi Anthony,
> 
> >/opt/cross-tools/binutils-2.17-gcc-4.1.1-newlib-1.14.0/lib/gcc/i686-elf/
> >4.1.1/../../../../i686-elf/bin/ld: test.elf: section .section_0 lma
> >0x1000 overlaps previous sections
> 
> This is a bogus error message due to a spurious check in the linker.  

Eh?  I think the error message is correct.  We really do have an error
of some sort here, most likely the linker ignoring phdr "AT" when
assigning section lmas in ldlang.c.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: LMA XXX Overlaps Previous Sections When Using PHDRS
  2007-12-25 23:09   ` Alan Modra
@ 2007-12-26 19:02     ` Nick Clifton
  2007-12-26 21:40       ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Clifton @ 2007-12-26 19:02 UTC (permalink / raw)
  To: binutils

Hi Alan,

>> This is a bogus error message due to a spurious check in the linker.  
> 
> Eh?  I think the error message is correct.  We really do have an error
> of some sort here, most likely the linker ignoring phdr "AT" when
> assigning section lmas in ldlang.c.

Ok - can you explain what that piece of code was doing then ?  I could not work 
out what it was trying to achieve.

Cheers
   Nick


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

* Re: LMA XXX Overlaps Previous Sections When Using PHDRS
  2007-12-26 19:02     ` Nick Clifton
@ 2007-12-26 21:40       ` Alan Modra
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Modra @ 2007-12-26 21:40 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

On Wed, Dec 26, 2007 at 07:02:17PM +0000, Nick Clifton wrote:
> Hi Alan,
> 
> >>This is a bogus error message due to a spurious check in the linker.  
> >
> >Eh?  I think the error message is correct.  We really do have an error
> >of some sort here, most likely the linker ignoring phdr "AT" when
> >assigning section lmas in ldlang.c.
> 
> Ok - can you explain what that piece of code was doing then ?  I could not 
> work out what it was trying to achieve.

The linker sets up section vma and lma, and section to segment mapping
well before assign_file_positions_for_load_sections.  In cases where
the segment (program header) p_paddr is set, it ought to match the
first section lma mapped to that segment.  The same goes for p_vaddr
and section vma.  (Both can be offset by some amount, for file header
and program header space, but this is the general idea.)  After adding
the first section to the segment, we increase p_memsz to account for
space taken by that section.  Any following section in that segment
can't start before the end of the previous section.  ie. for lma,
section lma must be greater than p_paddr + p_memsz.  The same goes for
vma and p_vaddr + p_memsz but it doesn't look like we check that..
There can of course be gaps between sections, but overlap is an error.

The testcase is failing the consistency check on the first section
due to section lma disagreeing with header p_paddr.

-- 
Alan Modra
Australia Development Lab, IBM

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

* LMA XXX Overlaps Previous Sections When Using PHDRS
@ 2007-12-19 22:15 DeRosa, Anthony
  0 siblings, 0 replies; 6+ messages in thread
From: DeRosa, Anthony @ 2007-12-19 22:15 UTC (permalink / raw)
  To: binutils



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

end of thread, other threads:[~2007-12-26 21:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-19 22:19 LMA XXX Overlaps Previous Sections When Using PHDRS DeRosa, Anthony
2007-12-24 17:21 ` Nick Clifton
2007-12-25 23:09   ` Alan Modra
2007-12-26 19:02     ` Nick Clifton
2007-12-26 21:40       ` Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2007-12-19 22:15 DeRosa, Anthony

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