https://bugs.llvm.org/show_bug.cgi?id=41357
Bug ID: 41357
Summary: LLD . assignment outside of SECTIONS can overflow
MEMORY Region spuriously
Product: lld
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedb...@nondot.org
Reporter: peter.sm...@linaro.org
CC: llvm-bugs@lists.llvm.org, peter.sm...@linaro.org
Consider the following example:
cat memregions.lds
MEMORY {
FLASH (rx) : ORIGIN = (0x0 + 0x0), LENGTH = (256*1K - 0x0)
SRAM (wx) : ORIGIN = 0x20000000, LENGTH = (64 * 1K)
}
SECTIONS {
.text : { *(.text) } > FLASH
. = 0x20000000;
.data : { *(.data) } > SRAM AT> FLASH
}
cat memregion.s
.text
nop
.data
.word 0
ld.lld memregion.o -T memregion.lds
ld.lld: error: section '.text' will not fit in region 'FLASH': overflowed by
536608768 bytes
ld.lld: error: section '.data' will not fit in region 'FLASH': overflowed by
536608768 bytes
ld.lld: error: section '.data' will not fit in region 'FLASH': overflowed by
536608770 bytes
I tracked this down to LinkerScript::setDot(), in particular:
// Update to location counter means update to section size.
if (InSec)
expandOutputSection(Val - Dot);
else
expandMemoryRegions(Val - Dot);
The . = 0x20000000; in the linker script which is supposed to set dot for the
next memory region is adding 512 Megabytes to the size of the .text
OutputSection. This does not happen with ld.bfd.
I believe this part of the code was added for
https://bugs.llvm.org//show_bug.cgi?id=37836 which had a linker script with
something like:
MEMORY
{
ram (wxa) : ORIGIN = 0x42000, LENGTH = 0x100000
}
SECTIONS
{
.text :
{
*(.text*)
}
aligned_dot = ALIGN(0x10 * 1024);
.data aligned_dot :
{
*(.data*)
}
}
I would certainly not expect assigning to . to add anything to a memory region,
what I would expect is that the effect of assigning to . would affect the start
address of the next OutputSection and that would trigger a corresponding change
in the Memory Region. So I think we may need to add/alter the fix for pr37836.
The linker script was cut down from the Zephyr RTOS Linker Script so this is a
use case from a real program.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs