Bug 20280 - gold output is different from ld when LMA is set
Summary: gold output is different from ld when LMA is set
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.27
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-20 22:47 UTC by Petr Hosek
Modified: 2016-06-20 22:47 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Petr Hosek 2016-06-20 22:47:02 UTC
I found a difference in behavior between gold and ld when LMA is set for a section but not for subsequent sections. See the example below:

---
$ cat test.S
.section .text
  nop
.section .data
  .long 123

$ cat test.ld
SECTIONS
{
  .text : AT(0x1000000) { *(.text) }
  .data : { *(.data) }
}

$ as test.S -o test.o

$ ld.bfd test.o -T test.ld -o test-bfd

$ readelf -lW test-bfd

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 1 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x200000 0x0000000000000000 0x0000000001000000 0x000005 0x000005 RWE 0x200000

 Section to Segment mapping:
  Segment Sections...
   00     .text .data

$ ld.gold test.o -T test.ld -o test-gold

$ readelf -lW test-gold

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x001020 0x0000000000000020 0x0000000000000020 0x000004 0x000004 RW  0x1000
  LOAD           0x002000 0x0000000000000000 0x0000000001000000 0x000001 0x000001 R E 0x1000

 Section to Segment mapping:
  Segment Sections...
   00     .data 
   01     .text
---

The important bit is the difference between the .data section physical address in case of ld and gold. Seems like ld reuses the existing memory region (the one used for .text section), for the .data section while gold believes that there is no suitable region for the .data section and sets its LMA to the VMA.