Bug 5785 - Spurious "section xxx overlaps section yyy"
Summary: Spurious "section xxx overlaps section yyy"
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-21 18:15 UTC by Sergei Organov
Modified: 2008-02-22 14:20 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: sparc-unknown-elf
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
Respect the AT> syntax even if no other memory region for the section has been specified (318 bytes, patch)
2008-02-22 11:27 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Organov 2008-02-21 18:15:45 UTC
LD version 2.18.x produces bogus "section .xxx overlaps section .bss", while LD
version 2.16.1 works just fine. Here is cut-down test to reproduce the problem:

$ echo -n | ~/try/bin/sparc-elf-as -o test.o
$ ~/try/bin/sparc-elf-ld -v -o test -T test.lnk test.o
GNU ld (GNU Binutils) 2.18.50.20080218
/home/osv/try/bin/sparc-elf-ld: section .xxx [00000110 -> 0000011f] overlaps
section .bss [00000110 -> 0000022f]
$ cat test.lnk
MEMORY
{
  ROM    : ORIGIN = 0,      LENGTH = 0x1000
  RAM    : ORIGIN = 0x4000, LENGTH = 0x1000
}

SECTIONS
{
  .data : AT(__data_image) {
    . += 0x110;
  } > RAM

  .bss : {
    . += 0x120;
  } > RAM

  .data_image (NOLOAD): {
    __data_image = .;
    . += SIZEOF(.data);
  } > ROM

  .xxx : {
    . += 0x10;
  } > ROM

  .text : { *(.text) } > ROM
}
$
Comment 1 Nick Clifton 2008-02-22 11:27:51 UTC
Created attachment 2287 [details]
Respect the AT> syntax even if no other memory region for the section has been specified
Comment 2 Nick Clifton 2008-02-22 11:29:51 UTC
Subject: Re:  New: Spurious "section xxx overlaps section yyy"

Hi Sergei,

> LD version 2.18.x produces bogus "section .xxx overlaps section .bss", while LD
> version 2.16.1 works just fine.

Well the 2.18 linker is behaving as documented.  Specifically in the bit 
on the "Output Section LMA" in the manual:

   If neither AT nor AT> is specified for an allocatable section,
   the linker will set the LMA such that the difference between
   VMA and LMA for the section is the same as the preceding output
   section in the same region.

Since the .bss section does not have an AT or an AT> directive its LMA 
is set to 0x110, so that difference between its VMA (0x4110), as set by 
the "> RAM" directive, and its LMA is 0x4000, ie the same as the 
difference between the VMA and the LMA of the .data section.  (Try 
running the linker with the --no-check-sections option and then looking 
at the section headers to see this).

This is a change in the linker's behaviour that was made for the 2.18 
release.  There is even a mention of it in the NEWS file.

It does suggest a workaround for the problem:  Change the "> RAM" in the 
description of the .bss section to "AT> RAM".  ie:

    .bss : {
      . += 0x120;
    } AT> RAM

According to the manual this will set both the LMA and the VMA for the 
section, and you will end up with the same behaviour as the 2.16 linker. 
  (This change is backwards compatible, i.e. it will work with the 2.16 
linker as well).  Unfortunately there is a bug in the current linker 
sources such that the "AT> [region-name]" syntax is ignored unless there 
is  also an "> [region-name-2]" specified for the section, and the two 
regions are different.  I can see no good reason for this, and the 
behaviour certainly isn't documented, so I am planning to check in the 
uploaded patch to remove this restriction unless my regression testing 
shows up a problem.

Cheers
   Nick
Comment 3 Nick Clifton 2008-02-22 14:20:40 UTC
Patch checked in with this changelog entry.

ld/ChangeLog
2008-02-22  Nick Clifton  <nickc@redhat.com>

	PR ld/5785
	* ldlang.c (lang_size_sections_1): Honour the setting of an
	lma_region even if there is no vma region set, or the vma region
	is the same as the lma region.