รจ
[deliverable/binutils-gdb.git] / bfd / elf32-sh.c
index ebbe352456ebbb0bb20752b3a9be04dd8a43b8df..0779e8ac091c945039767ad2e43c44243393db92 100644 (file)
@@ -1161,13 +1161,15 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
        case R_SH_SWITCH32:
          /* These relocs types represent
               .word L2-L1
-            The r_offset field holds the difference between the reloc
+            The r_addend field holds the difference between the reloc
             address and L1.  That is the start of the reloc, and
             adding in the contents gives us the top.  We must adjust
-            both the r_offset field and the section contents.  */
+            both the r_offset field and the section contents.
+            N.B. in gas / coff bfd, the elf bfd r_addend is called r_offset,
+            and the elf bfd r_offset is called r_vaddr.  */
 
-         start = irel->r_offset;
-         stop = (bfd_vma) ((bfd_signed_vma) start - (long) irel->r_addend);
+         stop = irel->r_offset;
+         start = (bfd_vma) ((bfd_signed_vma) stop - (long) irel->r_addend);
 
          if (start > addr
              && start < toaddr
@@ -1178,8 +1180,6 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
                   && (start <= addr || start >= toaddr))
            irel->r_addend -= count;
 
-         start = stop;
-
          if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH16)
            voff = bfd_get_signed_16 (abfd, contents + nraddr);
          else if (ELF32_R_TYPE (irel->r_info) == (int) R_SH_SWITCH8)
@@ -1307,6 +1307,56 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
        {
          Elf_Internal_Sym sym;
 
+         /* Dwarf line numbers use R_SH_SWITCH32 relocs.  */
+         if (ELF32_R_TYPE (irelscan->r_info) == (int) R_SH_SWITCH32)
+           {
+             bfd_vma start, stop;
+             bfd_signed_vma voff;
+
+             if (ocontents == NULL)
+               {
+                 if (elf_section_data (o)->this_hdr.contents != NULL)
+                   ocontents = elf_section_data (o)->this_hdr.contents;
+                 else
+                   {
+                     /* We always cache the section contents.
+                         Perhaps, if info->keep_memory is false, we
+                         should free them, if we are permitted to,
+                         when we leave sh_coff_relax_section.  */
+                     ocontents = (bfd_byte *) bfd_malloc (o->_raw_size);
+                     if (ocontents == NULL)
+                       return false;
+                     if (! bfd_get_section_contents (abfd, o, ocontents,
+                                                     (file_ptr) 0,
+                                                     o->_raw_size))
+                       return false;
+                     elf_section_data (o)->this_hdr.contents = ocontents;
+                   }
+               }
+
+             stop = irelscan->r_offset;
+             start
+               = (bfd_vma) ((bfd_signed_vma) stop - (long) irelscan->r_addend);
+
+             /* STOP is in a different section, so it won't change.  */
+             if (start > addr && start < toaddr)
+               irelscan->r_addend += count;
+
+             voff = bfd_get_signed_32 (abfd, ocontents + irelscan->r_offset);
+             stop = (bfd_vma) ((bfd_signed_vma) start + voff);
+
+             if (start > addr
+                 && start < toaddr
+                 && (stop <= addr || stop >= toaddr))
+               bfd_put_signed_32 (abfd, voff + count,
+                                  ocontents + irelscan->r_offset);
+             else if (stop > addr
+                      && stop < toaddr
+                      && (start <= addr || start >= toaddr))
+               bfd_put_signed_32 (abfd, voff - count,
+                                  ocontents + irelscan->r_offset);
+           }
+
          if (ELF32_R_TYPE (irelscan->r_info) != (int) R_SH_DIR32)
            continue;
 
@@ -2050,6 +2100,8 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
 #define elf_backend_relocate_section   sh_elf_relocate_section
 #define bfd_elf32_bfd_get_relocated_section_contents \
                                        sh_elf_get_relocated_section_contents
+#define bfd_elf32_bfd_merge_private_bfd_data \
+                                       _bfd_generic_verify_endian_match
 
 #define elf_backend_gc_mark_hook        sh_elf_gc_mark_hook
 #define elf_backend_gc_sweep_hook       sh_elf_gc_sweep_hook
This page took 0.02446 seconds and 4 git commands to generate.