When relaxing, update size of symbols.
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 27 Oct 2014 10:45:18 +0000 (10:45 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 3 Nov 2014 20:34:13 +0000 (20:34 +0000)
When performing linker relaxation, reduce the size of symbols that span
the deleted bytes.  This ensures that, for example, function symbols
will have the correct size.

bfd/ChangeLog:

* elf32-avr.c (elf32_avr_relax_delete_bytes): During linker
relaxation, reduce the size of symbols that span the deleted
bytes.

ld/ChangeLog:

* testsuite/ld-avr/relax-02.d: Update to check size of symbols has
changed.
* testsuite/ld-avr/relax-03.d: Likewise.

bfd/ChangeLog
bfd/elf32-avr.c
ld/ChangeLog
ld/testsuite/ld-avr/relax-02.d
ld/testsuite/ld-avr/relax-03.d

index 0da08bb0d698c1776de5a454ca568289bc166d8a..0222d323105c3b7142f5c7fdbab8e77d80536925 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-03  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * elf32-avr.c (elf32_avr_relax_delete_bytes): During linker
+       relaxation, reduce the size of symbols that span the deleted
+       bytes.
+
 2014-11-03  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * elf32-avr.c (elf32_avr_relax_delete_bytes): Modify symbols
index 8498d29493e80b7167a59404b42e8e0d306d98d9..5aa3cf6e13765ef0c3ea9fbf5686d761861381a0 100644 (file)
@@ -1881,10 +1881,22 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
       isymend = isym + symtab_hdr->sh_info;
       for (; isym < isymend; isym++)
        {
-         if (isym->st_shndx == sec_shndx
-             && isym->st_value > addr
-             && isym->st_value <= toaddr)
-           isym->st_value -= count;
+         if (isym->st_shndx == sec_shndx)
+            {
+             if (isym->st_value > addr
+                  && isym->st_value <= toaddr)
+                isym->st_value -= count;
+
+              if (isym->st_value <= addr
+                  && isym->st_value + isym->st_size > addr)
+                {
+                  /* If this assert fires then we have a symbol that ends
+                     part way through an instruction.  Does that make
+                     sense?  */
+                  BFD_ASSERT (isym->st_value + isym->st_size >= addr + count);
+                  isym->st_size -= count;
+                }
+            }
        }
     }
 
@@ -1898,11 +1910,22 @@ elf32_avr_relax_delete_bytes (bfd *abfd,
       struct elf_link_hash_entry *sym_hash = *sym_hashes;
       if ((sym_hash->root.type == bfd_link_hash_defined
            || sym_hash->root.type == bfd_link_hash_defweak)
-          && sym_hash->root.u.def.section == sec
-          && sym_hash->root.u.def.value > addr
-          && sym_hash->root.u.def.value <= toaddr)
+          && sym_hash->root.u.def.section == sec)
         {
-          sym_hash->root.u.def.value -= count;
+          if (sym_hash->root.u.def.value > addr
+              && sym_hash->root.u.def.value <= toaddr)
+            sym_hash->root.u.def.value -= count;
+
+          if (sym_hash->root.u.def.value <= addr
+              && (sym_hash->root.u.def.value + sym_hash->size > addr))
+            {
+              /* If this assert fires then we have a symbol that ends
+                 part way through an instruction.  Does that make
+                 sense?  */
+              BFD_ASSERT (sym_hash->root.u.def.value + sym_hash->size
+                          >= addr + count);
+              sym_hash->size -= count;
+            }
         }
     }
 
index 86258cb316fc51cecf6e2effec2c0cffd5b49a65..56b9bd8aed46e0969772e49213c3701819f0f1a9 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-03  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * testsuite/ld-avr/relax-02.d: Update to check size of symbols has
+       changed.
+       * testsuite/ld-avr/relax-03.d: Likewise.
+
 2014-11-03  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * testsuite/ld-avr/relax-02.d: New file.
index 64457098b035918335c7fe89cd52a009088becb3..c8d9b1037c5827cabfdff3c36333cc78d15cb1aa 100644 (file)
@@ -9,20 +9,20 @@
 
 SYMBOL TABLE:
 #...
-00000000 l     F \.text        [0-9a-f]+ local_start
-0000000a l     F \.text        [0-9a-f]+ local_func_1
-00000014 l     F \.text        [0-9a-f]+ local_func_2
-0000001e l     F \.text        [0-9a-f]+ local_func_3
+00000000 l     F \.text        0000000a local_start
+0000000a l     F \.text        0000000a local_func_1
+00000014 l     F \.text        0000000a local_func_2
+0000001e l     F \.text        0000000a local_func_3
 00000032 l       \.text        00000000 local_end_label
 00000028 g       \.text        00000000 dest
 #...
-00000014 g     F \.text        [0-9a-f]+ func_2
+00000014 g     F \.text        0000000a func_2
 #...
-00000000 g     F \.text        [0-9a-f]+ _start
+00000000 g     F \.text        0000000a _start
 00000032 g       \.text        00000000 end_label
-0000000a g     F \.text        [0-9a-f]+ func_1
+0000000a g     F \.text        0000000a func_1
 #...
-0000001e g     F \.text        [0-9a-f]+ func_3
+0000001e g     F \.text        0000000a func_3
 
 
 
index a538c0459add1d9c566f3e93d2c45e6c0e8cb2dc..3adc279306e3891f9afdb81644a4d1ba5529431b 100644 (file)
@@ -9,10 +9,10 @@
 
 SYMBOL TABLE:
 #...
-00000000 l     F .text [0-9a-f]+ local_start
+00000000 l     F .text 0000000a local_start
 0000000a l       .text 00000000 local_end_label
 #...
-00000000 g     F \.text        [0-9a-f]+ _start
+00000000 g     F \.text        0000000a _start
 0000000a g       \.text        00000000 end_label
 #...