1

I have a simple asm file with 3 sections:

.code 32
.section sec1
    MOV R3, #10 
.section sec2
    MOV R1, #10 
.section sec3
    MOV R2, #10
.end

And a linker script:

MEMORY 
{
    ram : ORIGIN = 0x00200000, LENGTH = 1K
    rom : ORIGIN = 0x00100000, LENGTH = 1K
}

SECTIONS
{   
    .text : 
    {       
        *(.glue_7t) 
        *(.glue_7)      
        *(.text)
    }>rom   

    .sec1 :
    {   
        *(sec1) 
    }>rom  

    .sec2 :     
    {
        _ram_start = .;
        *(sec2)
    }>ram AT> rom

    .sec3 :
    {
        *(sec3)
    }>ram  AT> rom

    .data :
    {
        *(.data)
    }>ram 

    .bss :
    {
        *(.bss)
    }>ram  
}

I assume that .sec2 should have VMA address set to ram's origin, but the LMA should be the address after .sec1, but objdump gives me:

test2.o:     file format elf32-littlearm

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .sec1         00000004  00100000  00100000  00000034  2**0
                  CONTENTS, READONLY
  1 .sec2         00000004  00200000  00200000  00000038  2**0
                  CONTENTS, READONLY
  2 .sec3         00000004  00200004  00200004  0000003c  2**0
                  CONTENTS, READONLY

Why is the .sec2 LMA set to ram?

Bart
  • 420
  • 3
  • 18
  • I have never had luck with `AT>REGION`. I would suggest you use the form `sec1_end = .; .sec3 : AT(sec1_end) { ... } >ram`. This is very similar to [ld giving unexpected load address](http://stackoverflow.com/questions/14453996/gnu-linker-map-file-giving-unexpected-load-addresses). The real test of this would be to use `objcopy` to make a binary and look at the file size. Is it 24 bytes or 0x1008 bytes. – artless noise Nov 28 '13 at 15:56
  • btw, are you sure you want the .data section not to be placed on the rom as well? – ordahan Nov 30 '13 at 20:45
  • This is just a test script, written solely to let me see what's under the linkers hood. The .data section would normally go to the rom, yes. – Bart Dec 03 '13 at 08:44

1 Answers1

3

It turns out that my sections from the .s file were not allocatable. That's why the LMA was wrong. If the sections won't be allocated, the LMA can be the same as VMA. I've found it out while playing with objcopy - the output binary file was always empty. The asm file should look like this:

.code 32
.section sec1, "a"
    MOV R3, #10 
.section sec2, "a"
    MOV R1, #10 
.section sec3, "a"
    MOV R2, #10
.end

Normally the code would go to the .text section, which is allocatable by default. After adding "a" the linker produces proper LMA addresses.

Bart
  • 420
  • 3
  • 18