Section X overlaps section Y problem.

Sergei Organov osv@topconrd.ru
Thu Jun 30 09:40:00 GMT 2005


Jim Blandy <jimb@redhat.com> writes:

> Sergei Organov <osv@topconrd.ru> writes:
> > On embedded target, to copy at startup some data and/or code from ROM to
> > RAM at startup, I've been using the following technique that worked for
> > me for years. The last version of binutils where I know it works is
> > version 2.10.
> 
> So, your startup code copies the ROM contents (as given in .vect) into
> RAM (covered by .vect_image).  Why do both of those sections have the
> same LMA?

No, the opposite. Please take a look at the linker command file snippet
once again (I've changed VECT memory region to be called RAM to avoid
confusion): 

  [...]
  .vect : AT(__vect_image) {
    *(.vect)
    . = ALIGN(16);
  } > RAM
  [...]
  .vect_image : {
    __vect_image = .;
    . += SIZEOF(.vect);
  } > ROM
  [...]

.vect is in RAM but it's LMA is set to be equal to match the address of
the fake section .vect_image that is entirely in ROM. The purpose of
.vect_image is to provide the LMA value for .vect's AT() and to move
current allocation address in the ROM forward by the size of the .vect
section. At startup the SIZOF(.vect) bytes of data is copied from
__vect_image address (=LMA of .vect) to the VMA of .vect.

> 
> Do your ROM and RAM both appear at the same range of addresses in
> memory?  That is, do writes to those addresses always access RAM, but
> reads access ROM, until the ROM is switched out --- or something like
> that?

No, ROM and RAM are at separate non-overlapping addresses.

> 
> If your RAM and ROM appear in distinct address ranges, the usual way
> to do this is to give the ROM contents a VMA that refers to the RAM
> they will eventually occupy, but an LMA that refers to the ROM.

That's exactly what I do for .vect section: "> RAM" sets VMA to RAM and
AT(__vect_image) sets LMA to ROM.

> That way, the VMA ranges of .vect and .vect_image will overlap, but
> the LMA ranges will not.

No, VMA don't overlap, but LMAs do. The problem is that .vect_image has
LMA=VMA=LMA(.vect). In fact, it's LMA has no meaning as this fake
section doesn't contain any data, but it's set to be equal to the VMA by
default and is checked by the linker for overlapping.

Do you suggest I explicitly set LMA of .vect_image to something
different? Could you please modify the above linker command file snippet
to explain your point?

-- 
Sergei.



More information about the Binutils mailing list