[ld] Inferred section LMA in the absence of AT> or AT()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[ld] Inferred section LMA in the absence of AT> or AT()

Fangrui Song-2
https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html#Output-Section-LMA says

> If the section has a specific VMA address, then this is used as the LMA address as well.

However, the behavior seems different from the documentation.

cat > a.s <<e
  .globl _start; _start: ret;
    .section .a,"a"; .byte 0;
    .section .b,"a"; .byte 0;
    .section .c,"a"; .byte 0;
    .section .d,"a"; .byte 0;
    .data; .byte 0
e
cat > a.x <<e
  SECTIONS {
    . = 0x1000;
    .a : { *(.a) }
    .b : AT(0x2005) { *(.b) }
    /* "If the section has a specific VMA address, then this is used as the LMA address as well." is not obeyed */
    .c 0x1006 : { *(.c) }
    .d : AT(0x2007) { *(.d) }
    /* "If the section has a specific VMA address, then this is used as the LMA address as well." is not obeyed */
    .data 0x2008 : { *(.data) }
  }
e
as a.s -o a.o
ld.bfd -T a.x a.o -o a
readelf -Wl a

Program Headers:
   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
   LOAD           0x001000 0x0000000000001000 0x0000000000001000 0x000002 0x000002 R E 0x1000
   LOAD           0x001002 0x0000000000001002 0x0000000000002005 0x000001 0x000001 R   0x1000
   LOAD           0x001007 0x0000000000001007 0x0000000000002007 0x000001 0x000001 R   0x1000
   LOAD           0x002006 0x0000000000001006 0x0000000000002009 0x000001 0x000001 R   0x1000
   LOAD           0x002008 0x0000000000002008 0x0000000000003008 0x000001 0x000001 RW  0x1000

  Section to Segment mapping:
   Segment Sections...
    00     .text .a
    01     .b
    02     .d
    03     .c
    04     .data
Reply | Threaded
Open this post in threaded view
|

Re: [ld] Inferred section LMA in the absence of AT> or AT()

Sourceware - binutils list mailing list
On Wed, Apr 01, 2020 at 11:31:43AM -0700, Fangrui Song wrote:
> https://sourceware.org/binutils/docs/ld/Output-Section-LMA.html#Output-Section-LMA says
>
> > If the section has a specific VMA address, then this is used as the LMA address as well.
>
> However, the behavior seems different from the documentation.

Yes, the documentation isn't up to date.  ldlang.c:5743

--
Alan Modra
Australia Development Lab, IBM