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/binutils-2_26-branch] Fix PR 20221 - adjust syms and relocs only if relax shrunk section.


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

commit b3ec896b257ceb9765c1dd8667673c63ce5330c2
Author: Denis Chertykov <chertykov@gmail.com>
Date:   Thu Jun 9 19:17:43 2016 +0300

    Fix PR 20221 - adjust syms and relocs only if relax shrunk section.
    
    This patch fixes an edge case in linker relaxation that causes symbol
    values to be computed incorrectly in the presence of align directives
    in input source code.
    
    bfd/
    	* elf32-avr.c (elf32_avr_relax_delete_bytes): Adjust syms
    	and relocs only if shrinking occurred.
    
    ld/
    	* testsuite/ld-avr/avr-prop-5.d: New.
    	* testsuite/ld-avr/avr-prop-5.s: New.

Diff:
---
 bfd/ChangeLog                    |  9 +++++++++
 bfd/elf32-avr.c                  | 21 ++++++++++++++++++---
 ld/ChangeLog                     |  9 +++++++++
 ld/testsuite/ld-avr/avr-prop-5.d | 10 ++++++++++
 ld/testsuite/ld-avr/avr-prop-5.s |  7 +++++++
 5 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6d70417..c601d00 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,12 @@
+2016-06-13  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
+
+	Backport from master
+	2016-06-08  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
+
+	PR ld/20221
+	* elf32-avr.c (elf32_avr_relax_delete_bytes): Adjust syms
+	and relocs only if shrinking occurred.
+
 2016-06-09  Alan Modra  <amodra@gmail.com>
 
 	PR ld/20159
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index 9aa5a68..422c4ac 100644
--- a/bfd/elf32-avr.c
+++ b/bfd/elf32-avr.c
@@ -1832,6 +1832,7 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
   unsigned int symcount;
   struct avr_relax_info *relax_info;
   struct avr_property_record *prop_record = NULL;
+  bfd_boolean did_shrink = FALSE;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
@@ -1867,10 +1868,16 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
 
   /* Actually delete the bytes.  */
   if (toaddr - addr - count > 0)
-    memmove (contents + addr, contents + addr + count,
-             (size_t) (toaddr - addr - count));
+    {
+      memmove (contents + addr, contents + addr + count,
+               (size_t) (toaddr - addr - count));
+      did_shrink = TRUE;
+    }
   if (prop_record == NULL)
-    sec->size -= count;
+    {
+      sec->size -= count;
+      did_shrink = TRUE;
+    }
   else
     {
       /* Use the property record to fill in the bytes we've opened up.  */
@@ -1889,6 +1896,11 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
           prop_record->data.align.preceding_deleted += count;
           break;
         };
+      /* If toaddr == (addr + count), then we didn't delete anything, yet
+         we fill count bytes backwards from toaddr. This is still ok - we
+         end up overwriting the bytes we would have deleted. We just need
+         to remember we didn't delete anything i.e. don't set did_shrink,
+         so that we don't corrupt reloc offsets or symbol values.*/
       memset (contents + toaddr - count, fill, count);
 
       /* Adjust the TOADDR to avoid moving symbols located at the address
@@ -1896,6 +1908,9 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
       toaddr -= count;
     }
 
+  if (!did_shrink)
+    return TRUE;
+
   /* Adjust all the reloc addresses.  */
   for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
     {
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 7594fac..e784216 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,12 @@
+2016-06-13  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
+
+	Backport from master
+	2016-06-08  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
+
+	PR ld/20221
+	* testsuite/ld-avr/avr-prop-5.d: New.
+	* testsuite/ld-avr/avr-prop-5.s: New.
+
 2016-06-11  H.J. Lu  <hongjiu.lu@intel.com>
 
 	Backport from master
diff --git a/ld/testsuite/ld-avr/avr-prop-5.d b/ld/testsuite/ld-avr/avr-prop-5.d
new file mode 100644
index 0000000..5f62ba3
--- /dev/null
+++ b/ld/testsuite/ld-avr/avr-prop-5.d
@@ -0,0 +1,10 @@
+#name: AVR .avr.prop, single .align proper sym val test.
+#as: -mmcu=avrxmega2 -mlink-relax
+#ld: -mavrxmega2 --relax
+#source: avr-prop-5.s
+#objdump: -S
+#target: avr-*-*
+
+#...
+   0:	00 d0\s+rcall\s+\.\+0\s+; 0x2 <dest>
+#...
\ No newline at end of file
diff --git a/ld/testsuite/ld-avr/avr-prop-5.s b/ld/testsuite/ld-avr/avr-prop-5.s
new file mode 100644
index 0000000..6a3359a
--- /dev/null
+++ b/ld/testsuite/ld-avr/avr-prop-5.s
@@ -0,0 +1,7 @@
+        .text
+        .global _start, dest
+_start:
+        CALL    dest
+        .align  1
+dest:
+        NOP


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