Add ADR :tlsgd: directive and TLSGD_ADR_PREL21 support.
authorMarcus Shawcroft <marcus.shawcroft@arm.com>
Fri, 13 Feb 2015 07:13:57 +0000 (07:13 +0000)
committerMarcus Shawcroft <marcus.shawcroft@arm.com>
Thu, 26 Feb 2015 22:23:09 +0000 (22:23 +0000)
bfd/ChangeLog
bfd/elfnn-aarch64.c
bfd/elfxx-aarch64.c
bfd/reloc.c
gas/ChangeLog
gas/config/tc-aarch64.c
include/elf/ChangeLog
include/elf/aarch64.h

index 4d347f4..3132320 100644 (file)
@@ -1,5 +1,17 @@
 2015-02-26  Marcus Shawcroft  <marcus.shawcroft@arm.com>
 
+       * elfnn-aarch64.c (IS_AARCH64_TLS_RELOC)
+       (elfNN_aarch64_howto_table, aarch64_tls_transition_without_check)
+       (aarch64_reloc_got_type, elfNN_aarch64_final_link_relocate)
+       (elfNN_aarch64_tls_relax, elfNN_aarch64_relocate_section)
+       (elfNN_aarch64_gc_sweep_hook, elfNN_aarch64_check_relocs): Handle
+       BFD_RELOC_AARCH64_TLSGD_ADR_PREL21.
+       * elfxx-aarch64.c (_bfd_aarch64_elf_put_addend)
+       (_bfd_aarch64_elf_resolve_relocation): Likewise.
+       * reloc.c (BFD_RELOC_AARCH64_TLSGD_ADR_PREL21): Define.
+
+2015-02-26  Marcus Shawcroft  <marcus.shawcroft@arm.com>
+
        * elfnn-aarch64.c: (TLSIE_LD_GOTTREL_PREL19): Fix HOWTO bit field width.
        (aarch64_tls_transition_without_check, aarch64_reloc_got_type)
        (elfNN_aarch64_final_link_relocate, elfNN_aarch64_tls_relax)
index 3d9c383..1ff1865 100644 (file)
 
 #define IS_AARCH64_TLS_RELOC(R_TYPE)                           \
   ((R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21              \
+   || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADR_PREL21           \
    || (R_TYPE) == BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC          \
    || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1     \
    || (R_TYPE) == BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC  \
@@ -863,6 +864,20 @@ static reloc_howto_type elfNN_aarch64_howto_table[] =
         0x1fffff,              /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
+  HOWTO (AARCH64_R (TLSGD_ADR_PREL21), /* type */
+        0,                     /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        21,                    /* bitsize */
+        TRUE,                  /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_dont,        /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        AARCH64_R_STR (TLSGD_ADR_PREL21),      /* name */
+        FALSE,                 /* partial_inplace */
+        0x1fffff,              /* src_mask */
+        0x1fffff,              /* dst_mask */
+        TRUE),                 /* pcrel_offset */
+
   /* ADD: GOT offset G(S) & 0xff8 [no overflow check] */
   HOWTO (AARCH64_R (TLSGD_ADD_LO12_NC),        /* type */
         0,                     /* rightshift */
@@ -3750,6 +3765,11 @@ aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
       return r_type;
 
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
+      return (is_local
+             ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
+             : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
+
     case BFD_RELOC_AARCH64_TLSDESC_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSDESC_CALL:
       /* Instructions with these relocations will become NOPs.  */
@@ -3774,6 +3794,7 @@ aarch64_reloc_got_type (bfd_reloc_code_real_type r_type)
       return GOT_NORMAL;
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
       return GOT_TLS_GD;
 
@@ -4489,6 +4510,7 @@ elfNN_aarch64_final_link_relocate (reloc_howto_type *howto,
       break;
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
     case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
@@ -4596,6 +4618,51 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
          return bfd_reloc_continue;
        }
 
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
+      if (is_local)
+       {
+         /* Tiny GD->LE relaxation:
+            adr x0, :tlsgd:var      =>   mrs  x1, tpidr_el0
+             bl   __tls_get_addr     =>   add  x0, x1, #:tprel_hi12:x, lsl #12
+             nop                     =>   add  x0, x0, #:tprel_lo12_nc:x
+          */
+
+         /* First kill the tls_get_addr reloc on the bl instruction.  */
+         BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
+
+         bfd_putl32 (0xd53bd041, contents + rel->r_offset + 0);
+         bfd_putl32 (0x91400020, contents + rel->r_offset + 4);
+         bfd_putl32 (0x91000000, contents + rel->r_offset + 8);
+
+         rel[1].r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
+                                       AARCH64_R (TLSLE_ADD_TPREL_LO12_NC));
+         rel[1].r_offset = rel->r_offset + 8;
+
+         /* Move the current relocation to the second instruction in
+            the sequence.  */
+         rel->r_offset += 4;
+         rel->r_info = ELFNN_R_INFO (ELFNN_R_SYM (rel->r_info),
+                                     AARCH64_R (TLSLE_ADD_TPREL_HI12));
+         return bfd_reloc_continue;
+       }
+      else
+       {
+         /* Tiny GD->IE relaxation:
+            adr x0, :tlsgd:var      =>   ldr  x0, :gottprel:var
+            bl   __tls_get_addr     =>   mrs  x1, tpidr_el0
+            nop                     =>   add  x0, x0, x1
+          */
+
+         /* First kill the tls_get_addr reloc on the bl instruction.  */
+         BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
+         rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
+
+         bfd_putl32 (0x58000000, contents + rel->r_offset);
+         bfd_putl32 (0xd53bd041, contents + rel->r_offset + 4);
+         bfd_putl32 (0x8b000020, contents + rel->r_offset + 8);
+         return bfd_reloc_continue;
+       }
+
     case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
       return bfd_reloc_continue;
 
@@ -4884,6 +4951,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
       switch (elfNN_aarch64_bfd_reloc_from_type (r_type))
        {
        case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+       case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
        case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
          if (! symbol_got_offset_mark_p (input_bfd, h, r_symndx))
            {
@@ -5396,6 +5464,7 @@ elfNN_aarch64_gc_sweep_hook (bfd *abfd,
        case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
        case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
        case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+       case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
        case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
        case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
        case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
@@ -5865,6 +5934,7 @@ elfNN_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
        case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
        case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+       case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
        case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
        case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
        case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
index 328743d..b5a9334 100644 (file)
@@ -252,6 +252,7 @@ _bfd_aarch64_elf_put_addend (bfd *abfd,
     case BFD_RELOC_AARCH64_TLSDESC_CALL:
       break;
 
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
@@ -377,6 +378,7 @@ _bfd_aarch64_elf_resolve_relocation (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_NONE:
       break;
 
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
     case BFD_RELOC_AARCH64_ADR_LO21_PCREL:
     case BFD_RELOC_AARCH64_BRANCH19:
index 547c1a1..8c4a88a 100644 (file)
@@ -6769,6 +6769,10 @@ ENUMDOC
   relative value.  Used in conjunction with
   BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC.
 ENUM
+  BFD_RELOC_AARCH64_TLSGD_ADR_PREL21
+ENUMDOC
+  AArch64 TLS General Dynamic
+ENUM
   BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC
 ENUMDOC
   Unsigned 12 bit byte offset to global offset table entry for a symbols
index ba92ff9..b4eadfb 100644 (file)
@@ -1,6 +1,13 @@
 2015-02-19  Marcus Shawcroft  <marcus.shawcroft@arm.com>
 
        * config/tc-aarch64.c (reloc_table_entry): Generate
+       BFD_RELOC_AARCH64_TLSGD_ADR_PREL21.
+       (md_apply_fix, aarch64_force_relocation): Handle
+       BFD_RELOC_AARCH64_TLSGD_ADR_PREL21.
+
+2015-02-19  Marcus Shawcroft  <marcus.shawcroft@arm.com>
+
+       * config/tc-aarch64.c (reloc_table_entry): Generate
        BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19.
        (md_apply_fix, aarch64_force_relocation): Handle
        BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19.
index 02122ef..bcd6f4f 100644 (file)
@@ -2456,7 +2456,7 @@ static struct reloc_table_entry reloc_table[] = {
 
   /* Get to the page containing GOT TLS entry for a symbol */
   {"tlsgd", 0,
-   0,                          /* adr_type */
+   BFD_RELOC_AARCH64_TLSGD_ADR_PREL21, /* adr_type */
    BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21,
    0,
    0,
@@ -6712,6 +6712,7 @@ md_apply_fix (fixS * fixP, valueT * valP, segT seg)
     case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
     case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
     case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
@@ -6912,6 +6913,7 @@ aarch64_force_relocation (struct fix *fixp)
     case BFD_RELOC_AARCH64_TLSDESC_LD64_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
+    case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
     case BFD_RELOC_AARCH64_TLSIE_LD32_GOTTPREL_LO12_NC:
     case BFD_RELOC_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
index 69151cb..056aaf5 100644 (file)
@@ -1,3 +1,7 @@
+2015-02-19  Marcus Shawcroft  <marcus.shawcroft@arm.com>
+
+       * aarch64.h (R_AARCH64_P32_TLSGD_ADR_PREL21): Add.
+
 2015-02-24  Nick Clifton  <nickc@redhat.com>
 
        * v850.h (EF_RH850_SIMD): Delete deprecated flag.
index 93a950f..b905f13 100644 (file)
@@ -125,7 +125,7 @@ RELOC_NUMBER (R_AARCH64_P32_GOT_LD_PREL19, 25)
 RELOC_NUMBER (R_AARCH64_P32_ADR_GOT_PAGE, 26)
 RELOC_NUMBER (R_AARCH64_P32_LD32_GOT_LO12_NC, 27)
 
-
+RELOC_NUMBER (R_AARCH64_P32_TLSGD_ADR_PREL21, 80)
 RELOC_NUMBER (R_AARCH64_P32_TLSGD_ADR_PAGE21, 81)
 RELOC_NUMBER (R_AARCH64_P32_TLSGD_ADD_LO12_NC, 82)
 RELOC_NUMBER (R_AARCH64_P32_TLSIE_ADR_GOTTPREL_PAGE21, 103)