[ARC] Allow non-instruction relocations within .text sections
[deliverable/binutils-gdb.git] / bfd / elf32-arc.c
index ab2512d11d0cc6db7f1ce5847562c01d5093ee25..4090b7a77176bbbf7924d7912df29d5265570443 100644 (file)
@@ -252,32 +252,11 @@ is_reloc_for_TLS (reloc_howto_type *howto)
 
 #define arc_bfd_get_8(A,B,C) bfd_get_8(A,B)
 #define arc_bfd_get_16(A,B,C) bfd_get_16(A,B)
+#define arc_bfd_get_32(A,B,C) bfd_get_32(A,B)
 #define arc_bfd_put_8(A,B,C,D) bfd_put_8(A,B,C)
 #define arc_bfd_put_16(A,B,C,D) bfd_put_16(A,B,C)
+#define arc_bfd_put_32(A,B,C,D) bfd_put_32(A,B,C)
 
-static long
-arc_bfd_get_32 (bfd * abfd, void *loc, asection * input_section)
-{
-  long insn = bfd_get_32 (abfd, loc);
-
-  if (!bfd_big_endian (abfd)
-      && input_section
-      && (input_section->flags & SEC_CODE))
-    insn = ((0x0000fffff & insn) << 16) | ((0xffff0000 & insn) >> 16);
-
-  return insn;
-}
-
-static void
-arc_bfd_put_32 (bfd * abfd, long insn, void *loc, asection * input_section)
-{
-  if (!bfd_big_endian (abfd)
-      && input_section
-      && (input_section->flags & SEC_CODE))
-    insn = ((0x0000fffff & insn) << 16) | ((0xffff0000 & insn) >> 16);
-
-  bfd_put_32 (abfd, insn, loc);
-}
 
 static bfd_reloc_status_type
 arc_elf_reloc (bfd *abfd ATTRIBUTE_UNUSED,
@@ -344,9 +323,15 @@ static void arc_elf_howto_init (void)
 #define ARC_RELOC_HOWTO(TYPE, VALUE, SIZE, BITSIZE, RELOC_FUNCTION, OVERFLOW, FORMULA) \
   elf_arc_howto_table[TYPE].pc_relative = \
     (strstr (#FORMULA, " P ") != NULL || strstr (#FORMULA, " PDATA ") != NULL); \
-  elf_arc_howto_table[TYPE].dst_mask = RELOC_FUNCTION(0, ~0);
+  elf_arc_howto_table[TYPE].dst_mask = RELOC_FUNCTION(0, ~0); \
+  /* Only 32 bit data relocations should be marked as ME.  */ \
+  if (strstr (#FORMULA, " ME ") != NULL) \
+    { \
+      BFD_ASSERT (SIZE == 2); \
+    }
 
 #include "elf/arc-reloc.def"
+
 }
 #undef ARC_RELOC_HOWTO
 
@@ -771,14 +756,23 @@ debug_arc_reloc (struct arc_relocation_data reloc_data)
     }
 }
 
-static ATTRIBUTE_UNUSED bfd_vma
-get_middle_endian_relocation (bfd_vma reloc)
+static bfd_vma
+middle_endian_convert (bfd_vma insn, bfd_boolean do_it)
 {
-  bfd_vma ret = ((reloc & 0xffff0000) >> 16) |
-               ((reloc & 0xffff) << 16);
-  return ret;
+  if (do_it)
+    {
+      insn =
+       ((insn & 0xffff0000) >> 16) |
+       ((insn & 0xffff) << 16);
+    }
+  return insn;
 }
 
+#define ME(reloc) (reloc)
+
+#define IS_ME(FORMULA,BFD) ((strstr (FORMULA, "ME") != NULL) \
+                           && (!bfd_big_endian (BFD)))
+
 #define S (reloc_data.sym_value                                                \
           + (reloc_data.sym_section->output_section != NULL ?          \
              (reloc_data.sym_section->output_offset                    \
@@ -818,8 +812,6 @@ get_middle_endian_relocation (bfd_vma reloc)
 #define TLS_TBSS (8)
 #define TCB_SIZE (8)
 
-#define NON_ME(VALUE) (reverse_me (reloc_data, VALUE))
-
 #define none (0)
 
 #define PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA) \
@@ -870,20 +862,13 @@ get_middle_endian_relocation (bfd_vma reloc)
       bfd_vma bitsize ATTRIBUTE_UNUSED = BITSIZE; \
       relocation = FORMULA  ; \
       PRINT_DEBUG_RELOC_INFO_BEFORE(FORMULA) \
+      insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
       insn = RELOC_FUNCTION (insn, relocation); \
+      insn = middle_endian_convert (insn, IS_ME (#FORMULA, abfd)); \
       PRINT_DEBUG_RELOC_INFO_AFTER \
     } \
     break;
 
-static bfd_vma
-reverse_me (struct arc_relocation_data reloc_data, bfd_vma reloc)
-{
-  if (reloc_data.input_section && reloc_data.input_section->flags & SEC_CODE)
-    return ((0x0000fffff & reloc) << 16) | ((0xffff0000 & reloc) >> 16);
-  else
-    return reloc;
-}
-
 static bfd_reloc_status_type
 arc_do_relocation (bfd_byte * contents,
                   struct arc_relocation_data reloc_data,
@@ -892,6 +877,7 @@ arc_do_relocation (bfd_byte * contents,
   bfd_vma relocation = 0;
   bfd_vma insn;
   bfd_vma orig_insn ATTRIBUTE_UNUSED;
+  bfd * abfd = reloc_data.input_section->owner;
   struct elf_link_hash_table *htab ATTRIBUTE_UNUSED = elf_hash_table (info);
 
   if (reloc_data.should_relocate == FALSE)
@@ -900,13 +886,17 @@ arc_do_relocation (bfd_byte * contents,
   switch (reloc_data.howto->size)
     {
       case 2:
-       insn = arc_bfd_get_32 (reloc_data.input_section->owner,
+       insn = arc_bfd_get_32 (abfd,
                               contents + reloc_data.reloc_offset,
                               reloc_data.input_section);
        break;
       case 1:
+       insn = arc_bfd_get_16 (abfd,
+                              contents + reloc_data.reloc_offset,
+                              reloc_data.input_section);
+       break;
       case 0:
-       insn = arc_bfd_get_16 (reloc_data.input_section->owner,
+       insn = arc_bfd_get_8 (abfd,
                               contents + reloc_data.reloc_offset,
                               reloc_data.input_section);
        break;
@@ -934,7 +924,7 @@ arc_do_relocation (bfd_byte * contents,
       flag = bfd_check_overflow (reloc_data.howto->complain_on_overflow,
                                 reloc_data.howto->bitsize,
                                 reloc_data.howto->rightshift,
-                                bfd_arch_bits_per_address (reloc_data.input_section->owner),
+                                bfd_arch_bits_per_address (abfd),
                                 relocation);
 
 #undef  DEBUG_ARC_RELOC
@@ -960,13 +950,17 @@ arc_do_relocation (bfd_byte * contents,
   switch (reloc_data.howto->size)
     {
       case 2:
-       arc_bfd_put_32 (reloc_data.input_section->owner, insn,
+       arc_bfd_put_32 (abfd, insn,
                       contents + reloc_data.reloc_offset,
                       reloc_data.input_section);
        break;
       case 1:
+       arc_bfd_put_16 (abfd, insn,
+                      contents + reloc_data.reloc_offset,
+                      reloc_data.input_section);
+       break;
       case 0:
-       arc_bfd_put_16 (reloc_data.input_section->owner, insn,
+       arc_bfd_put_8 (abfd, insn,
                       contents + reloc_data.reloc_offset,
                       reloc_data.input_section);
        break;
This page took 0.037255 seconds and 4 git commands to generate.