[GAS][ARM][2/3]Add SE_H shape to represent fp16 type.
[deliverable/binutils-gdb.git] / bfd / elfnn-aarch64.c
index aa22c3e7e7b3bfab505cd1f230759441ff6eecb3..af7b78989173e0ee802e3b6e0e4eb80a306835f5 100644 (file)
@@ -1,5 +1,5 @@
 /* AArch64-specific support for NN-bit ELF.
-   Copyright (C) 2009-2015 Free Software Foundation, Inc.
+   Copyright (C) 2009-2016 Free Software Foundation, Inc.
    Contributed by ARM Ltd.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -2639,34 +2639,21 @@ aarch64_select_branch_stub (bfd_vma value, bfd_vma place)
 /* Determine the type of stub needed, if any, for a call.  */
 
 static enum elf_aarch64_stub_type
-aarch64_type_of_stub (struct bfd_link_info *info,
-                     asection *input_sec,
+aarch64_type_of_stub (asection *input_sec,
                      const Elf_Internal_Rela *rel,
                      asection *sym_sec,
                      unsigned char st_type,
-                     struct elf_aarch64_link_hash_entry *hash,
                      bfd_vma destination)
 {
   bfd_vma location;
   bfd_signed_vma branch_offset;
   unsigned int r_type;
-  struct elf_aarch64_link_hash_table *globals;
   enum elf_aarch64_stub_type stub_type = aarch64_stub_none;
-  bfd_boolean via_plt_p;
 
   if (st_type != STT_FUNC
-      && (sym_sec != bfd_abs_section_ptr))
+      && (sym_sec == input_sec))
     return stub_type;
 
-  globals = elf_aarch64_hash_table (info);
-  via_plt_p = (globals->root.splt != NULL && hash != NULL
-              && hash->root.plt.offset != (bfd_vma) - 1);
-  /* Make sure call to plt stub can fit into the branch range.  */
-  if (via_plt_p)
-    destination = (globals->root.splt->output_section->vma
-                  + globals->root.splt->output_offset
-                  + hash->root.plt.offset);
-
   /* Determine where the call point is.  */
   location = (input_sec->output_offset
              + input_sec->output_section->vma + rel->r_offset);
@@ -4142,8 +4129,8 @@ elfNN_aarch64_size_stubs (bfd *output_bfd,
                    }
 
                  /* Determine what (if any) linker stub is needed.  */
-                 stub_type = aarch64_type_of_stub
-                   (info, section, irela, sym_sec, st_type, hash, destination);
+                 stub_type = aarch64_type_of_stub (section, irela, sym_sec,
+                                                   st_type, destination);
                  if (stub_type == aarch64_stub_none)
                    continue;
 
@@ -4174,7 +4161,7 @@ elfNN_aarch64_size_stubs (bfd *output_bfd,
                      goto error_ret_free_internal;
                    }
 
-                 stub_entry->target_value = sym_value;
+                 stub_entry->target_value = sym_value + irela->r_addend;
                  stub_entry->target_section = sym_sec;
                  stub_entry->stub_type = stub_type;
                  stub_entry->h = hash;
@@ -4996,6 +4983,9 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
 
+#if ARCH_SIZE == 64
+       case BFD_RELOC_AARCH64_32:
+#endif
        case BFD_RELOC_AARCH64_NN:
          if (rel->r_addend != 0)
            {
@@ -5168,6 +5158,9 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
       *unresolved_reloc_p = FALSE;
       return bfd_reloc_ok;
 
+#if ARCH_SIZE == 64
+    case BFD_RELOC_AARCH64_32:
+#endif
     case BFD_RELOC_AARCH64_NN:
 
       /* When generating a shared object or relocatable executable, these
@@ -5280,15 +5273,28 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
        /* Check if a stub has to be inserted because the destination
           is too far away.  */
        struct elf_aarch64_stub_hash_entry *stub_entry = NULL;
-       if (! aarch64_valid_branch_p (value, place))
+
+       /* If the branch destination is directed to plt stub, "value" will be
+          the final destination, otherwise we should plus signed_addend, it may
+          contain non-zero value, for example call to local function symbol
+          which are turned into "sec_sym + sec_off", and sec_off is kept in
+          signed_addend.  */
+       if (! aarch64_valid_branch_p (via_plt_p ? value : value + signed_addend,
+                                     place))
          /* The target is out of reach, so redirect the branch to
             the local stub for this function.  */
        stub_entry = elfNN_aarch64_get_stub_entry (input_section, sym_sec, h,
                                                   rel, globals);
        if (stub_entry != NULL)
-         value = (stub_entry->stub_offset
-                  + stub_entry->stub_sec->output_offset
-                  + stub_entry->stub_sec->output_section->vma);
+         {
+           value = (stub_entry->stub_offset
+                    + stub_entry->stub_sec->output_offset
+                    + stub_entry->stub_sec->output_section->vma);
+
+           /* We have redirected the destination to stub entry address,
+              so ignore any addend record in the original rela entry.  */
+           signed_addend = 0;
+         }
       }
       value = _bfd_aarch64_elf_resolve_relocation (bfd_r_type, place, value,
                                                   signed_addend, weak_undef_p);
@@ -5320,9 +5326,6 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
        }
 
     case BFD_RELOC_AARCH64_16:
-#if ARCH_SIZE == 64
-    case BFD_RELOC_AARCH64_32:
-#endif
     case BFD_RELOC_AARCH64_ADD_LO12:
     case BFD_RELOC_AARCH64_BRANCH19:
     case BFD_RELOC_AARCH64_LDST128_LO12:
@@ -6392,10 +6395,6 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
          break;
        }
 
-      if (!save_addend)
-       addend = 0;
-
-
       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
          because such sections are not SEC_ALLOC and thus ld.so will
          not process them.  */
@@ -6435,6 +6434,34 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
                     name, input_bfd, input_section, rel->r_offset);
                  return FALSE;
                }
+             /* Overflow can occur when a variable is referenced with a type
+                that has a larger alignment than the type with which it was
+                declared. eg:
+                  file1.c: extern int foo; int a (void) { return foo; }
+                  file2.c: char bar, foo, baz;
+                If the variable is placed into a data section at an offset
+                that is incompatible with the larger alignment requirement
+                overflow will occur.  (Strictly speaking this is not overflow
+                but rather an alignment problem, but the bfd_reloc_ error
+                enum does not have a value to cover that situation).
+
+                Try to catch this situation here and provide a more helpful
+                error message to the user.  */
+             if (addend & ((1 << howto->rightshift) - 1)
+                 /* FIXME: Are we testing all of the appropriate reloc
+                    types here ?  */
+                 && (real_r_type == BFD_RELOC_AARCH64_LD_LO19_PCREL
+                     || real_r_type == BFD_RELOC_AARCH64_LDST16_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST32_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST64_LO12
+                     || real_r_type == BFD_RELOC_AARCH64_LDST128_LO12))
+               {
+                 info->callbacks->warning
+                   (info, _("One possible cause of this error is that the \
+symbol is being referenced in the indicated code as if it had a larger \
+alignment than was declared where it was defined."),
+                    name, input_bfd, input_section, rel->r_offset);
+               }
              break;
 
            case bfd_reloc_undefined:
@@ -6469,6 +6496,9 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
              break;
            }
        }
+
+      if (!save_addend)
+       addend = 0;
     }
 
   return TRUE;
@@ -6770,6 +6800,9 @@ elfNN_aarch64_gc_sweep_hook (bfd *abfd,
        case BFD_RELOC_AARCH64_MOVW_G1_NC:
        case BFD_RELOC_AARCH64_MOVW_G2_NC:
        case BFD_RELOC_AARCH64_MOVW_G3:
+#if ARCH_SIZE == 64
+       case BFD_RELOC_AARCH64_32:
+#endif
        case BFD_RELOC_AARCH64_NN:
          if (h != NULL && bfd_link_executable (info))
            {
@@ -7075,6 +7108,9 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
            case BFD_RELOC_AARCH64_LD64_GOT_LO12_NC:
            case BFD_RELOC_AARCH64_MOVW_GOTOFF_G0_NC:
            case BFD_RELOC_AARCH64_MOVW_GOTOFF_G1:
+#if ARCH_SIZE == 64
+           case BFD_RELOC_AARCH64_32:
+#endif
            case BFD_RELOC_AARCH64_NN:
              if (htab->root.dynobj == NULL)
                htab->root.dynobj = abfd;
@@ -7090,6 +7126,9 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       switch (bfd_r_type)
        {
+#if ARCH_SIZE == 64
+       case BFD_RELOC_AARCH64_32:
+#endif
        case BFD_RELOC_AARCH64_NN:
 
          /* We don't need to handle relocs into sections not going into
@@ -9336,3 +9375,22 @@ const struct elf_size_info elfNN_aarch64_size_info =
 #define elf_backend_obj_attrs_section          ".ARM.attributes"
 
 #include "elfNN-target.h"
+
+/* CloudABI support.  */
+
+#undef TARGET_LITTLE_SYM
+#define        TARGET_LITTLE_SYM       aarch64_elfNN_le_cloudabi_vec
+#undef TARGET_LITTLE_NAME
+#define        TARGET_LITTLE_NAME      "elfNN-littleaarch64-cloudabi"
+#undef TARGET_BIG_SYM
+#define        TARGET_BIG_SYM          aarch64_elfNN_be_cloudabi_vec
+#undef TARGET_BIG_NAME
+#define        TARGET_BIG_NAME         "elfNN-bigaarch64-cloudabi"
+
+#undef ELF_OSABI
+#define        ELF_OSABI               ELFOSABI_CLOUDABI
+
+#undef elfNN_bed
+#define        elfNN_bed               elfNN_aarch64_cloudabi_bed
+
+#include "elfNN-target.h"
This page took 0.030217 seconds and 4 git commands to generate.