public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Strange LMA/VMA behavior with regions
@ 2010-11-29 13:15 Sebastian Huber
  2010-11-30 17:00 ` Sebastian Huber
  0 siblings, 1 reply; 17+ messages in thread
From: Sebastian Huber @ 2010-11-29 13:15 UTC (permalink / raw)
  To: Binutils

Hi,

I have to write a custom linker script to distribute various output sections to
various physical memory regions (for embedded devices).  I have this linker
SECTIONS part:

	.jcr : {
		KEEP (*(.jcr))
	} > REGION AT > REGION
	.rodata : {
		*(.rodata .rodata.* .gnu.linkonce.r.*)
	} > REGION AT > REGION

The .rodata section has a section alignment of 8 (the alignment depends on the
application, it may be higher).  Now suppose that the .jcr end is not 8 bytes
aligned.  We may have this:

.jcr            0x00000000800198b0        0x4
 *(.jcr)
 .jcr           0x00000000800198b0        0x0 crtbegin.o
 .jcr           0x00000000800198b0        0x4 crtend.o

.rodata         0x00000000800198b8     0x2ba8 load address 0x00000000800198b4
 *(.rodata .rodata.* .gnu.linkonce.r.*)

This is pretty bad, since this introduces a 4 byte offset in the .rodata
section.  If I use this SECTIONS part:

	.jcr : {
		KEEP (*(.jcr))
	} > REGION AT > REGION
	.rodata : ALIGN (8) {
		*(.rodata .rodata.* .gnu.linkonce.r.*)
	} > REGION AT > REGION

We get this:

.jcr            0x00000000800198b0        0x4
 *(.jcr)
 .jcr           0x00000000800198b0        0x0 crtbegin.o
 .jcr           0x00000000800198b0        0x4 crtend.o

.rodata         0x00000000800198b8     0x2ba8
 *(.rodata .rodata.* .gnu.linkonce.r.*)

Unfortunately the section alignment is unknown in advance, so .rodata : ALIGN
(ALIGNOF(.rodata)) { ... } is not possible.  Please observe that LMA==VMA in
.jcr.  Let OFFSET := LMA - VMA.  I think that LD should not introduce an OFFSET
!= 0 due to alignment constraints if the load and runtime region are equal.

Have a nice day!

-- 
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: Strange LMA/VMA behavior with regions
@ 2011-05-11  7:20 Abnikant Singh
  2011-05-11  7:45 ` Alan Modra
  0 siblings, 1 reply; 17+ messages in thread
From: Abnikant Singh @ 2011-05-11  7:20 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Hi Alan,

 I have tested your patch for LMA/VMA alignment issue on AVR
toolchain.I am facing the following issue when using the ALIGN
dirctive to align
 the VMA. I am linking the following program object files..[1 & 2]

1. asm.s

.section .mysec1, "ax"
nop

.text
  .balign 8
.global _balignfunc
.type _balignfunc, @function

_balignfunc:

  NOP

2. asm2.s

.section .mysec1, "ax"
.global _func
.type _func, @function

_func:

  NOP

The following linker script I am using to link the above programs.

MEMORY
{
    FLASH (rxai!w) : ORIGIN = 0x80000000, LENGTH = 512K
}


SECTIONS
{
  .mysec1_os          :
  {
    *(.mysec1)
  } >FLASH AT>FLASH
  .text_os ALIGN(8) :
  {
    *(.text .text.* )
  } > FLASH AT>FLASH

}

The objdump -h shows the following output:

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .mysec1_os    00000002  80000000  80000000  00000400  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text_os      00000008  80000008  80000002  00000408  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

As we can notice the Algn filed shown is 2**3, LMA is not following
the section alignment [which is 80000002]. In asm.s

.balign is 8, which I think should be taken as the input section
alignment and in init_os it should set section alignment as 8.

However if I directly give output section alignment, LMA get the
required alignment i.e. if in the linker script I use
......
.......
  .text_os ALIGN(8) : ALIGN(8)
  {
    *(.text .text.* )
  } > FLASH AT>FLASH

}

I get the following output..

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .mysec1_os    00000002  80000000  80000000  00000400  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .text_os      00000008  80000008  80000008  00000408  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

Please give the inputs...
Is this the expected behavior or am I missing something ?

Regards,
Abnikant

^ permalink raw reply	[flat|nested] 17+ messages in thread
[parent not found: <BANLkTi=+O9YvCp42jT3k0fKiC4z0opvAdA@mail.gmail.com>]

end of thread, other threads:[~2011-05-13  5:45 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-29 13:15 Strange LMA/VMA behavior with regions Sebastian Huber
2010-11-30 17:00 ` Sebastian Huber
2010-12-01 13:13   ` Alan Modra
2010-12-01 15:03     ` Sebastian Huber
2010-12-02  0:46       ` Alan Modra
2010-12-02  8:03         ` Sebastian Huber
2011-05-11  7:20 Abnikant Singh
2011-05-11  7:45 ` Alan Modra
     [not found] <BANLkTi=+O9YvCp42jT3k0fKiC4z0opvAdA@mail.gmail.com>
     [not found] ` <BANLkTinEBMoiGna1KJKn1KqtvNsHdHynoA@mail.gmail.com>
2011-05-12 14:09   ` Anitha Boyapati
2011-05-12 23:34     ` Alan Modra
2011-05-13  2:44       ` Anitha Boyapati
2011-05-13  3:41         ` Alan Modra
2011-05-13  4:15           ` Anitha Boyapati
2011-05-13  5:26             ` Alan Modra
2011-05-13  5:45               ` Boyapati, Anitha
2011-05-13  5:02           ` Boyapati, Anitha
2011-05-13  5:42             ` Alan Modra

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