[llvm-bugs] [Bug 38624] New: section with start address causes lld to expand the previous region incorrectly

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 17 23:07:54 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38624

            Bug ID: 38624
           Summary: section with start address causes lld to expand the
                    previous region incorrectly
           Product: lld
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: djc at djc.id.au
                CC: llvm-bugs at lists.llvm.org

Say you are linking for an embedded target, with two disjoint memory regions
FLASH and RAM. If you declare a section with a specific start address in a new
memory region, lld incorrectly tries to expand the *previous* section's memory
region to reach the specified address.

Here is a reproducer, using lld 7.0.0rc1:

$ cat test.c 
void _start(void) {
}
$ gcc -nostdlib -nostartfiles -c test.c
$ cat link.x 
MEMORY
{
  FLASH : ORIGIN = 0x20400000, LENGTH = 512M
  RAM : ORIGIN = 0x80000000, LENGTH = 16K
}
SECTIONS
{
  .text :
  {
    *(.text);
  } > FLASH

  .rodata :
  {
    *(.rodata);
  } > FLASH

  PROVIDE(_sbss = ORIGIN(RAM));
  .bss _sbss :
  {
    *(.bss);
  } > RAM

  .data : AT(LOADADDR(.rodata) + SIZEOF(.rodata))
  {
    *(.data);
  } > RAM

  /DISCARD/ :
  {
    *(.eh_frame);
  }
}
$ lld -flavor gnu -Tlink.x -o test test.o
lld: error: section '.text' will not fit in region 'FLASH': overflowed by
1069547520 bytes

The problematic part is here:

  PROVIDE(_sbss = ORIGIN(RAM));
  .bss _sbss :
  {

where it specifies the _sbss symbol as the start address for .bss. Lld is
trying to expand the FLASH region up to reach this address, but it's wrong
because .bss is going into the RAM region not FLASH. It fails because FLASH is
not large enough.

If you remove the start address for .bss, namely:

  .bss :
  {

then it links successfully and you get the expected result (.bss is placed at
the beginning of the RAM region, and everything fits normally).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180818/8cad8ba1/attachment.html>


More information about the llvm-bugs mailing list