This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] ld: Track changes to default region LMA even for empty sections


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=14ea2c1b230a62f312346fb16716b3dd4850815b

commit 14ea2c1b230a62f312346fb16716b3dd4850815b
Author: Andrew Burgess <andrew.burgess@embecosm.com>
Date:   Tue Jan 17 19:13:29 2017 +0000

    ld: Track changes to default region LMA even for empty sections
    
    Given a linker script fragment like this:
    
       SECTIONS {
         . = 0x1000;
         .text   : AT(0x100) { *(.text)   }
         .data   : AT(0x200) { *(.data)   }
         .rodata : AT(0x300) { *(.rodata) }
       }
    
    and an input file containing sections, '.text', '.data.1', and
    '.rodata', then we'd expect the linker to place '.text' and '.rodata' in
    the obvious way, and the '.data.1' orphan section would be located after
    the '.data' section (assuming similar section properties).
    
    Further, I believe that the expectation would be that the LMA for the
    orphan '.data.1' section would start from 0x200 (as there is no '.data'
    content).
    
    However, right now, the LMA for '.data.1' would be 0x101, following on
    from the '.text' section, this is because the change in LMA for the
    '.data' section is not noticed by the linker, if there's no content in
    the '.data' section.
    
    What can be even more confusing to a user (though the cause is obvious
    once you understand what's going on) is that adding some content to
    '.data' will cause the orphan '.data.1' to switch to an LMA based off of
    0x200.
    
    This commit changes the behaviour so that an empty section that is in
    the default lma region, and sets its lma, will adjust the lma of the
    default region, this change will then be reflected in following sections
    within the default lma memory region.
    
    There's a new test to cover this issue that passes on a range of
    targets, however, some targets generate additional sections, or have
    stricter memory region size requirements that make it harder to come
    up with a generic pass pattern, that still tests the required
    features.  For now I've set the test to ignore these targets.
    
    ld/ChangeLog:
    
    	* ldlang.c (lang_size_sections_1): Shortcut loop only after
    	tracking changes to the default regions LMA.
    	* testsuite/ld-elf/orphan-9.ld: Extend header comment.
    	* testsuite/ld-elf/orphan-10.d: New file.
    	* testsuite/ld-elf/orphan-10.s: New file.
    	* NEWS: Mention change in behaviour.

Diff:
---
 ld/ChangeLog                    |  9 +++++++++
 ld/NEWS                         |  3 +++
 ld/ldlang.c                     | 14 ++++++++++----
 ld/testsuite/ld-elf/orphan-10.d | 10 ++++++++++
 ld/testsuite/ld-elf/orphan-10.s |  8 ++++++++
 ld/testsuite/ld-elf/orphan-9.ld | 10 +++++++---
 6 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index c1c977a..adefe32 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,14 @@
 2017-03-09  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* ldlang.c (lang_size_sections_1): Shortcut loop only after
+	tracking changes to the default regions LMA.
+	* testsuite/ld-elf/orphan-9.ld: Extend header comment.
+	* testsuite/ld-elf/orphan-10.d: New file.
+	* testsuite/ld-elf/orphan-10.s: New file.
+	* NEWS: Mention change in behaviour.
+
+2017-03-09  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* ldlang.c (lang_leave_output_section_statement): Move lma_region
 	logic to...
 	(lang_propagate_lma_regions): ...this new function.
diff --git a/ld/NEWS b/ld/NEWS
index 86e9073..972e7a8 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -8,6 +8,9 @@
 * Improve assignment of LMAs to orphan sections in some edge cases where a
   mixture of both AT>LMA_REGION and AT(LMA) are used.
 
+* Orphan sections placed after an empty section that has an AT(LMA) will now
+  take an load memory address starting from LMA.
+
 Changes in 2.28:
 
 * The EXCLUDE_FILE linker script construct can now be applied outside of the
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 89b896f..6011a00 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5197,9 +5197,6 @@ lang_size_sections_1
 	      }
 	    os->processed_lma = TRUE;
 
-	    if (bfd_is_abs_section (os->bfd_section) || os->ignored)
-	      break;
-
 	    /* Keep track of normal sections using the default
 	       lma region.  We use this to set the lma for
 	       following sections.  Overlays or other linker
@@ -5207,7 +5204,13 @@ lang_size_sections_1
 	       default lma == vma is incorrect.
 	       To avoid warnings about dot moving backwards when using
 	       -Ttext, don't start tracking sections until we find one
-	       of non-zero size or with lma set differently to vma.  */
+	       of non-zero size or with lma set differently to vma.
+	       Do this tracking before we short-cut the loop so that we
+	       track changes for the case where the section size is zero,
+	       but the lma is set differently to the vma.  This is
+	       important, if an orphan section is placed after an
+	       otherwise empty output section that has an explicit lma
+	       set, we want that lma reflected in the orphans lma.  */
 	    if (!IGNORE_SECTION (os->bfd_section)
 		&& (os->bfd_section->size != 0
 		    || (r->last_os == NULL
@@ -5219,6 +5222,9 @@ lang_size_sections_1
 		&& !bfd_link_relocatable (&link_info))
 	      r->last_os = s;
 
+	    if (bfd_is_abs_section (os->bfd_section) || os->ignored)
+	      break;
+
 	    /* .tbss sections effectively have zero size.  */
 	    if (!IS_TBSS (os->bfd_section)
 		|| bfd_link_relocatable (&link_info))
diff --git a/ld/testsuite/ld-elf/orphan-10.d b/ld/testsuite/ld-elf/orphan-10.d
new file mode 100644
index 0000000..a5cf6d9
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-10.d
@@ -0,0 +1,10 @@
+#source: orphan-10.s
+#ld: -N -T orphan-9.ld
+#objdump: -h
+#notarget: d30v-* dlx-* fr30-* frv-* ft32-* iq2000-* mn10200-* moxie-* ms1-* msp430-* mt-* pj-*
+
+#...
+  . \.text         0+(08|10)  [0-9a-f]+  0+200 .*
+#...
+  . \.data\.1       0+8  [0-9a-f]+  0+300 .*
+#pass
diff --git a/ld/testsuite/ld-elf/orphan-10.s b/ld/testsuite/ld-elf/orphan-10.s
new file mode 100644
index 0000000..b198966
--- /dev/null
+++ b/ld/testsuite/ld-elf/orphan-10.s
@@ -0,0 +1,8 @@
+        .text
+        .byte 0, 0, 0, 0, 0, 0, 0, 0
+
+        .section ".data.1", "aw"
+        .byte 0, 0, 0, 0, 0, 0, 0, 0
+
+        .section ".rodata", "a"
+        .byte 0, 0, 0, 0, 0, 0, 0, 0
diff --git a/ld/testsuite/ld-elf/orphan-9.ld b/ld/testsuite/ld-elf/orphan-9.ld
index 1a6773d..d8a3917 100644
--- a/ld/testsuite/ld-elf/orphan-9.ld
+++ b/ld/testsuite/ld-elf/orphan-9.ld
@@ -1,8 +1,12 @@
-/* This linker script is used for orphan-9 test.
+/* This linker script is used for orphan-9 and orphan-10 test.
 
-   We have a single byte in .data, and an orphan .data.1
+   orphan-9: We have a single byte in .data, and an orphan .data.1
    section.  We are checking that the .data.1 orphan is assigned an
-   LMA after .data rather than picking up the lma region of .rodata.  */
+   LMA after .data rather than picking up the lma region of .rodata.
+
+   orphan-10: In this case we have nothing in .data and an orphan
+   .data.1, we are checking that .data.1 is assigned an LMA after
+   .data, rather than defaulting to take LMA == VMA.  */
 
 MEMORY
 {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]