This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
fix memory regions with displaced BSS data
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: binutils <binutils at sources dot redhat dot com>
- Date: Wed, 20 May 2009 11:33:24 +0100
- Subject: fix memory regions with displaced BSS data
This patch fixes a problem with memory regions and bss-like sections. consider
the following linker script:
SECTIONS {
.text : { *(.text) } >ram AT>rom
.data : { *(.data) } >ram
.bss : { *(.bss) } >ram
.trail : { LONG(5) } >ram
Here, we're storing an initial image in ROM, intending to copy it to RAM in
startup code. Clearly we don't want an image of the bss section in ROM, and the
.bss section does not cause the advancement of the allocation point (the LMA).
So .trail ends up with an LMA just after .data. This coincides with .bss, and
so the overlap checking code issues an error message. A real script may have
multiple data/bss-like tuples for different physical RAMs.
Notice that the overlap checking code checks LMAs because:
/* We must check the sections' LMA addresses not their VMA
addresses because overlay sections can have overlapping VMAs
but they must have distinct LMAs. */
which is fine for overlays, but breaks this usage. the attached patch relaxes
the check slightly further by only checking LOAD sections, rather than (nearly)
all ALLOC sections.
Ideally we'd do two checks, one on LMAs, for LOAD sections and one on VMAs
skipping overlay sections. Unfortunately, AFAICT, we don't know at this point
what sections are overlay sections -- that information is in the linker script
statement tree, not the output section list.
built and tested for i686-elf, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
2009-05-19 Nathan Sidwell <nathan@codesourcery.com>
* ldlang.c (lang_check_section_addresses): Ignore non-loadable
sections when checking for overlap. Clarify error message
concerns load address.
testsuite/
* ld-scripts/rgn-at4.t: New.
* ld-scripts/rgn-at4.d: New.
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.308
diff -c -3 -p -r1.308 ldlang.c
*** ld/ldlang.c 15 May 2009 14:22:35 -0000 1.308
--- ld/ldlang.c 19 May 2009 15:46:38 -0000
*************** lang_check_section_addresses (void)
*** 4498,4504 ****
for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
{
/* Only consider loadable sections with real contents. */
! if (IGNORE_SECTION (s) || s->size == 0)
continue;
sections[count] = s;
--- 4498,4504 ----
for (s = link_info.output_bfd->sections; s != NULL; s = s->next)
{
/* Only consider loadable sections with real contents. */
! if ((s->flags & SEC_NEVER_LOAD) || !(s->flags & SEC_LOAD))
continue;
sections[count] = s;
*************** lang_check_section_addresses (void)
*** 4529,4535 ****
/* Look for an overlap. */
if (s_end >= os_start && s_start <= os_end)
! einfo (_("%X%P: section %s [%V -> %V] overlaps section %s [%V -> %V]\n"),
s->name, s_start, s_end, os->name, os_start, os_end);
}
--- 4529,4535 ----
/* Look for an overlap. */
if (s_end >= os_start && s_start <= os_end)
! einfo (_("%X%P: section %s loaded at [%V,%V] overlaps section %s loaded at [%V,%V]\n"),
s->name, s_start, s_end, os->name, os_start, os_end);
}
Index: ld/testsuite/ld-scripts/rgn-at4.d
===================================================================
RCS file: ld/testsuite/ld-scripts/rgn-at4.d
diff -N ld/testsuite/ld-scripts/rgn-at4.d
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/rgn-at4.d 19 May 2009 15:46:42 -0000
***************
*** 0 ****
--- 1,13 ----
+ # name: rgn-at4
+ # source: rgn-at.s
+ # ld: -T rgn-at4.t
+ # objdump: -w -h
+
+ .*: file format .*
+
+ Sections:
+ Idx +Name +Size +VMA +LMA +File off +Algn +Flags
+ 0 .text +0+[0-9a-f][0-9a-f] +0+0010000 +0+0020000 +.*
+ 1 .data +0+[0-9a-f][0-9a-f] +0+00100[0-9a-f]+ +0+00200[0-9a-f]+ +.*
+ 2 .bss +0+[0-9a-f][0-9a-f] +0+00100[0-9a-f]+ +0+00200[0-9a-f]+ +.*
+ 3 .trail +0+[0-9a-f][0-9a-f] +0+00100[0-9a-f]+ +0+00200[0-9a-f]+ +.*
Index: ld/testsuite/ld-scripts/rgn-at4.t
===================================================================
RCS file: ld/testsuite/ld-scripts/rgn-at4.t
diff -N ld/testsuite/ld-scripts/rgn-at4.t
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-scripts/rgn-at4.t 19 May 2009 15:46:42 -0000
***************
*** 0 ****
--- 1,14 ----
+ /* Memory region at test, >AT should propagate by default */
+
+ MEMORY {
+ ram : ORIGIN = 0x10000, LENGTH = 0x100
+ rom : ORIGIN = 0x20000, LENGTH = 0x200
+ }
+ _start = 0x1000;
+ SECTIONS {
+ .text : { *(.text) } >ram AT>rom
+ .data : { *(.data) } >ram
+ .bss : { *(.bss) } >ram
+ .trail : { LONG(5) } >ram
+ /DISCARD/ : { *(*) }
+ }