Fix assertion failure in the BFD library when linking with --emit-relocs enabled.
[deliverable/binutils-gdb.git] / bfd / elfxx-aarch64.c
index cae94d03e8453de0cceee1619668fff71a609edf..1495ade7550d9ebd746378ef18035aeae8064716 100644 (file)
@@ -1,5 +1,5 @@
 /* AArch64-specific support for ELF.
 /* AArch64-specific support for ELF.
-   Copyright (C) 2009-2019 Free Software Foundation, Inc.
+   Copyright (C) 2009-2020 Free Software Foundation, Inc.
    Contributed by ARM Ltd.
 
    This file is part of BFD, the Binary File Descriptor library.
    Contributed by ARM Ltd.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -395,10 +395,12 @@ _bfd_aarch64_elf_put_addend (bfd *abfd,
 }
 
 bfd_vma
 }
 
 bfd_vma
-_bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type,
+_bfd_aarch64_elf_resolve_relocation (bfd *input_bfd,
+                                    bfd_reloc_code_real_type r_type,
                                     bfd_vma place, bfd_vma value,
                                     bfd_vma addend, bfd_boolean weak_undef_p)
 {
                                     bfd_vma place, bfd_vma value,
                                     bfd_vma addend, bfd_boolean weak_undef_p)
 {
+  bfd_boolean tls_reloc = TRUE;
   switch (r_type)
     {
     case BFD_RELOC_AARCH64_NONE:
   switch (r_type)
     {
     case BFD_RELOC_AARCH64_NONE:
@@ -446,6 +448,8 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_MOVW_G2_NC:
     case BFD_RELOC_AARCH64_MOVW_G2_S:
     case BFD_RELOC_AARCH64_MOVW_G3:
     case BFD_RELOC_AARCH64_MOVW_G2_NC:
     case BFD_RELOC_AARCH64_MOVW_G2_S:
     case BFD_RELOC_AARCH64_MOVW_G3:
+      tls_reloc = FALSE;
+      /* fall-through.  */
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
@@ -466,6 +470,15 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12:
     case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12:
     case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12:
     case BFD_RELOC_AARCH64_TLSLE_LDST32_TPREL_LO12:
     case BFD_RELOC_AARCH64_TLSLE_LDST64_TPREL_LO12:
     case BFD_RELOC_AARCH64_TLSLE_LDST8_TPREL_LO12:
+      /* Weak Symbols and TLS relocations are implementation defined.  For this
+        case we choose to emit 0.  */
+      if (weak_undef_p && tls_reloc)
+       {
+         _bfd_error_handler (_("%pB: warning: Weak TLS is implementation "
+                               "defined and may not work as expected"),
+                               input_bfd);
+         value = place;
+       }
       value = value + addend;
       break;
 
       value = value + addend;
       break;
 
@@ -695,6 +708,7 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
   bfd *pbfd;
   bfd *ebfd = NULL;
   elf_property *prop;
   bfd *pbfd;
   bfd *ebfd = NULL;
   elf_property *prop;
+  unsigned align;
 
   uint32_t gnu_prop = *gprop;
 
 
   uint32_t gnu_prop = *gprop;
 
@@ -719,6 +733,11 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
       prop = _bfd_elf_get_property (ebfd,
                                    GNU_PROPERTY_AARCH64_FEATURE_1_AND,
                                    4);
       prop = _bfd_elf_get_property (ebfd,
                                    GNU_PROPERTY_AARCH64_FEATURE_1_AND,
                                    4);
+      if (gnu_prop & GNU_PROPERTY_AARCH64_FEATURE_1_BTI
+         && !(prop->u.number & GNU_PROPERTY_AARCH64_FEATURE_1_BTI))
+           _bfd_error_handler (_("%pB: warning: BTI turned on by -z force-bti "
+                                 "when all inputs do not have BTI in NOTE "
+                                 "section."), ebfd);
       prop->u.number |= gnu_prop;
       prop->pr_kind = property_number;
 
       prop->u.number |= gnu_prop;
       prop->pr_kind = property_number;
 
@@ -738,6 +757,11 @@ _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *info,
            info->callbacks->einfo (
              _("%F%P: failed to create GNU property section\n"));
 
            info->callbacks->einfo (
              _("%F%P: failed to create GNU property section\n"));
 
+          align = (bfd_get_mach (ebfd) & bfd_mach_aarch64_ilp32) ? 2 : 3;
+         if (!bfd_set_section_alignment (sec, align))
+           info->callbacks->einfo (_("%F%pA: failed to align section\n"),
+                                   sec);
+
          elf_section_type (sec) = SHT_NOTE;
        }
     }
          elf_section_type (sec) = SHT_NOTE;
        }
     }
@@ -863,3 +887,38 @@ _bfd_aarch64_elf_merge_gnu_properties (struct bfd_link_info *info
 
   return updated;
 }
 
   return updated;
 }
+
+/* Fix up AArch64 GNU properties.  */
+void
+_bfd_aarch64_elf_link_fixup_gnu_properties
+  (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+   elf_property_list **listp)
+{
+  elf_property_list *p, *prev;
+
+  for (p = *listp, prev = *listp; p; p = p->next)
+    {
+      unsigned int type = p->property.pr_type;
+      if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
+       {
+         if (p->property.pr_kind == property_remove)
+           {
+             /* Remove empty property.  */
+             if (prev == p)
+               {
+                 *listp = p->next;
+                 prev = *listp;
+               }
+             else
+                 prev->next = p->next;
+             continue;
+           }
+         prev = p;
+       }
+      else if (type > GNU_PROPERTY_HIPROC)
+       {
+         /* The property list is sorted in order of type.  */
+         break;
+       }
+    }
+}
This page took 0.027618 seconds and 4 git commands to generate.