Fixed AArch64 TLS relocation resolution.
authorYufeng Zhang <yufeng.zhang@arm.com>
Tue, 16 Oct 2012 16:36:50 +0000 (16:36 +0000)
committerYufeng Zhang <yufeng.zhang@arm.com>
Tue, 16 Oct 2012 16:36:50 +0000 (16:36 +0000)
bfd/

* elf64-aarch64.c (elf64_aarch64_tls_howto_table): Fix shift value for
R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, R_AARCH64_TLSLE_MOVW_TPREL_G2,
R_AARCH64_TLSLE_MOVW_TPREL_G1, R_AARCH64_TLSLE_MOVW_TPREL_G1_NC,
R_AARCH64_TLSLE_ADD_TPREL_HI12.
(elf64_aarch64_tlsdesc_howto_table): Fix shift value for
R_AARCH64_TLSDESC_LD64_PREL19 and R_AARCH64_TLSDESC_OFF_G1.
(elf64_aarch64_final_link_relocate): Add signed_addend when resolving
AARCH64_TLSLE_*_TPREL_* relocations.

ld/testsuite/

* ld-aarch64/tlsle-symbol-offset.s: New file.
* ld-aarch64/tlsle-symbol-offset.d: New file.
* ld-aarch64/aarch64-elf.exp: Add tlsle-symbol-offset test.

bfd/ChangeLog
bfd/elf64-aarch64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/tlsle-symbol-offset.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/tlsle-symbol-offset.s [new file with mode: 0644]

index 7033bac8560fa43c64b654bf41e826aeca5f7c07..29cb5c679760564ce9b5e250d312810a82bd27f0 100644 (file)
@@ -1,3 +1,14 @@
+2012-10-16  Sofiane Naci  <sofiane.naci@arm.com>
+
+       * elf64-aarch64.c (elf64_aarch64_tls_howto_table): Fix shift value for
+       R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, R_AARCH64_TLSLE_MOVW_TPREL_G2,
+       R_AARCH64_TLSLE_MOVW_TPREL_G1, R_AARCH64_TLSLE_MOVW_TPREL_G1_NC,
+       R_AARCH64_TLSLE_ADD_TPREL_HI12.
+       (elf64_aarch64_tlsdesc_howto_table): Fix shift value for
+       R_AARCH64_TLSDESC_LD64_PREL19 and R_AARCH64_TLSDESC_OFF_G1.
+       (elf64_aarch64_final_link_relocate): Add signed_addend when resolving
+       AARCH64_TLSLE_*_TPREL_* relocations.
+
 2012-10-16  Alan Modra  <amodra@gmail.com>
 
        * elf32-xtensa.c (free_section_cache): Renamed from
index 0607b3aba44f853ad63b6b83cc22abce2b0cbdf9..423fb9b31e858ead7d0dca79f4dafff52fdbbc40 100644 (file)
@@ -1076,7 +1076,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSIE_LD_GOTTPREL_PREL19,   /* type */
-        0,                     /* rightshift */
+        2,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         21,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -1090,7 +1090,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G2,        /* type */
-        8,                     /* rightshift */
+        32,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         12,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -1104,7 +1104,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G1,        /* type */
-        4,                     /* rightshift */
+        16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         12,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -1118,7 +1118,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSLE_MOVW_TPREL_G1_NC,     /* type */
-        4,                     /* rightshift */
+        16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         12,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -1160,7 +1160,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSLE_ADD_TPREL_HI12,       /* type */
-        3,                     /* rightshift */
+        12,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         12,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -1205,7 +1205,7 @@ static reloc_howto_type elf64_aarch64_tls_howto_table[] =
 static reloc_howto_type elf64_aarch64_tlsdesc_howto_table[] =
 {
   HOWTO (R_AARCH64_TLSDESC_LD64_PREL19,        /* type */
-        0,                     /* rightshift */
+        2,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         21,                    /* bitsize */
         TRUE,                  /* pc_relative */
@@ -1279,7 +1279,7 @@ static reloc_howto_type elf64_aarch64_tlsdesc_howto_table[] =
         FALSE),                /* pcrel_offset */
 
   HOWTO (R_AARCH64_TLSDESC_OFF_G1,     /* type */
-        4,                     /* rightshift */
+        16,                    /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         12,                    /* bitsize */
         FALSE,                 /* pc_relative */
@@ -4054,7 +4054,7 @@ elf64_aarch64_final_link_relocate (reloc_howto_type *howto,
     case R_AARCH64_TLSLE_MOVW_TPREL_G1_NC:
     case R_AARCH64_TLSLE_MOVW_TPREL_G2:
       value = aarch64_resolve_relocation (r_type, place, value,
-                                         - tpoff_base (info), weak_undef_p);
+                                         signed_addend - tpoff_base (info), weak_undef_p);
       *unresolved_reloc_p = FALSE;
       break;
 
index 8e829615fec9ebcbfd0262c8bdf68730df4faa52..a27d274426c6c78ea2a7f01d634b27fe5079d364 100644 (file)
@@ -1,3 +1,9 @@
+2012-10-16  Sofiane Naci  <sofiane.naci@arm.com>
+
+       * ld-aarch64/tlsle-symbol-offset.s: New file.
+       * ld-aarch64/tlsle-symbol-offset.d: New file.
+       * ld-aarch64/aarch64-elf.exp: Add tlsle-symbol-offset test.
+
 2012-10-08  Joe Seymour  <jseymour@codesourcery.com>
 
        * ld-scripts/sane1.d: Sort output from nm. Allow for other symbols in
index 7e5d73e5997e51864e3b8780ab56ac7318aaffd7..e85d1dba7b14d075f1b1268a6b3355e5467f9ee6 100644 (file)
@@ -108,3 +108,4 @@ run_dump_test "tls-relax-gdesc-ie-2"
 run_dump_test "tls-relax-gdesc-le-2"
 run_dump_test "tls-relax-ie-le-2"
 run_dump_test "tls-relax-ie-le-3"
+run_dump_test "tlsle-symbol-offset"
diff --git a/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d b/ld/testsuite/ld-aarch64/tlsle-symbol-offset.d
new file mode 100644 (file)
index 0000000..cf61691
--- /dev/null
@@ -0,0 +1,11 @@
+#source: tlsle-symbol-offset.s
+#ld: -shared -T relocs.ld -e0
+#objdump: -dr
+#...
+Disassembly of section .text:
+
+0000000000010000 <.text>:
+ +10000:       d53bd040        mrs     x0, tpidr_el0
+ +10004:       91400400        add     x0, x0, #0x1, lsl #12
+ +10008:       91010000        add     x0, x0, #0x40
+ +1000c:       d65f03c0        ret
diff --git a/ld/testsuite/ld-aarch64/tlsle-symbol-offset.s b/ld/testsuite/ld-aarch64/tlsle-symbol-offset.s
new file mode 100644 (file)
index 0000000..41088ef
--- /dev/null
@@ -0,0 +1,17 @@
+       .global p
+       .global a
+       .section        .tbss,"awT",%nobits
+p:
+       .zero   4096
+a:
+       .zero   52
+
+       .text
+
+# Compute the address of an integer within structure a, padded
+# by an array of size 48
+
+       mrs     x0, tpidr_el0
+       add     x0, x0, #:tprel_hi12:a+48
+       add     x0, x0, #:tprel_lo12_nc:a+48
+       ret