ld: aarch64: fix TLS relaxation where TCB_SIZE is used
authorYury Norov <ynorov@caviumnetworks.com>
Sat, 3 Dec 2016 13:20:43 +0000 (18:50 +0530)
committerYury Norov <ynorov@caviumnetworks.com>
Wed, 14 Dec 2016 06:30:59 +0000 (12:00 +0530)
TCB_SIZE is 2*sizeof(void *), which is 0x10 for lp64, and 0x8 for
ilp32. During relaxation, ld goes to do a replace:
bl   __tls_get_addr => add R0, R0, TCB_SIZE

But actual implementation is:
bfd_putl32 (0x91004000, contents + rel->r_offset + 4);

Which is equivalent of add x0, x0, 0x10. This is wrong for ilp32.

The possible fix for it is:
bfd_putl32 (0x91000000 | (TCB_SIZE<<10), contents + rel->r_offset + 4);

But ilp32 also needs w-registers, so it's simpler to put proper
instruction in #if/#else condition.

There are 2 such relaxations in elfNN_aarch64_tls_relax(), and so 2 new
tests added for ilp32 mode to test it.

Yury

* bfd/elfnn-aarch64.c: fix TLS relaxations for ilp32 where
TCB_SIZE is used.
* ld/testsuite/ld-aarch64/aarch64-elf.exp: Add tests for the case.
* ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d: New file.
* ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d: New file.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
bfd/ChangeLog
bfd/elfnn-aarch64.c
ld/ChangeLog
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d [new file with mode: 0644]

index 26d4084baae14db077409d8ce8a885ac897398e6..21cbcac95e5051b897ded2886a89390502081647 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-14  Yury Norov <ynorov@caviumnetworks.com>
+
+         * bfd/elfnn-aarch64.c: fix TLS relaxations for ilp32 where
+         TCB_SIZE is used.
+
 2016-12-13  Alan Modra  <amodra@gmail.com>
 
        * elf64-hppa.c (elf64_hppa_modify_segment_map): Don't add PHDR
index ffa8e6a9970317414bf2464f04b9dff25ce83d70..d6cc2a0f542dffb9cdd404cb4a80e6dd1ee712d4 100644 (file)
@@ -5951,8 +5951,9 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
     case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
       /* LD->LE relaxation (tiny):
         adr  x0, :tlsldm:x  => mrs x0, tpidr_el0
-        bl   __tls_get_addr => add x0, x0, TCB_SIZE
-       */
+        bl   __tls_get_addr => add R0, R0, TCB_SIZE
+
+        Where R is x for lp64 mode, and w for ilp32 mode.  */
       if (is_local)
        {
          BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
@@ -5960,7 +5961,11 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
          /* No need of CALL26 relocation for tls_get_addr.  */
          rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
          bfd_putl32 (0xd53bd040, contents + rel->r_offset + 0);
+#if ARCH_SIZE == 64
          bfd_putl32 (0x91004000, contents + rel->r_offset + 4);
+#else
+         bfd_putl32 (0x11002000, contents + rel->r_offset + 4);
+#endif
          return bfd_reloc_ok;
        }
       return bfd_reloc_continue;
@@ -5978,17 +5983,22 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 
     case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
       /* LD->LE relaxation (small):
-        add   x0, #:tlsldm_lo12:x => add x0, x0, TCB_SIZE
+        add   x0, #:tlsldm_lo12:x => add R0, R0, TCB_SIZE
         bl   __tls_get_addr       => nop
-       */
+
+        Where R is x for lp64 mode, and w for ilp32 mode.  */
       if (is_local)
        {
          BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
          BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
          /* No need of CALL26 relocation for tls_get_addr.  */
          rel[1].r_info = ELFNN_R_INFO (STN_UNDEF, R_AARCH64_NONE);
+#if ARCH_SIZE == 64
          bfd_putl32 (0x91004000, contents + rel->r_offset + 0);
-         bfd_putl32 (0xd503201f, contents + rel->r_offset + 4);
+#else
+         bfd_putl32 (0x11002000, contents + rel->r_offset + 0);
+#endif
+         bfd_putl32 (INSN_NOP, contents + rel->r_offset + 4);
          return bfd_reloc_ok;
        }
       return bfd_reloc_continue;
index e910acc8cec551103ed190a8dd49b49120350e1c..086434aa3bbb72d1fe94e741ed217d5d86197bab 100644 (file)
@@ -1,3 +1,10 @@
+2016-12-14  Yury Norov <ynorov@caviumnetworks.com>
+
+       * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add tests for tiny and
+       small ld-le relaxations in ilp32 mode.
+       * ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d: New file.
+       * ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d: New file.
+
 2016-12-13  Jiong Wang  <jiong.wang@arm.com>
 
        * testsuite/ld-aarch64/aarch64-elf.exp (aarch64_choose_lp64_emul): New
index de158fe1d1a5cd04fbe2b7b81f086b43dc768d19..8fba2311e2a5124be496e735865a476711d8649c 100644 (file)
@@ -228,7 +228,9 @@ run_dump_test_lp64 "tls-relax-large-desc-le-be"
 run_dump_test "tls-relax-gdesc-ie"
 run_dump_test "tls-relax-ie-le"
 run_dump_test "tls-relax-ld-le-small"
+run_dump_test "tls-relax-ld-le-small-ilp32"
 run_dump_test "tls-relax-ld-le-tiny"
+run_dump_test "tls-relax-ld-le-tiny-ilp32"
 run_dump_test "tls-desc-ie"
 run_dump_test "tls-relax-gdesc-ie-2"
 run_dump_test "tls-relax-gdesc-le-2"
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d
new file mode 100644 (file)
index 0000000..0f86d93
--- /dev/null
@@ -0,0 +1,14 @@
+#source: tls-relax-ld-le-small.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#objdump: -dr
+#...
+ +10000:       910003fd        mov     x29, sp
+ +10004:       d53bd040        mrs     x0, tpidr_el0
+ +10008:       11002000        add     w0, w0, #0x8
+ +1000c:       d503201f        nop
+ +10010:       d503201f        nop
+ +10014:       91400001        add     x1, x0, #0x0, lsl #12
+ +10018:       91000021        add     x1, x1, #0x0
+ +1001c:       90000000        adrp    x0, 10000 <.*>
+ +10020:       d65f03c0        ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d
new file mode 100644 (file)
index 0000000..e2a4250
--- /dev/null
@@ -0,0 +1,13 @@
+#source: tls-relax-ld-le-tiny.s
+#as: -mabi=ilp32
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#objdump: -dr
+#...
+ +10000:       910003fd        mov     x29, sp
+ +10004:       d53bd040        mrs     x0, tpidr_el0
+ +10008:       11002000        add     w0, w0, #0x8
+ +1000c:       d503201f        nop
+ +10010:       91400001        add     x1, x0, #0x0, lsl #12
+ +10014:       91000021        add     x1, x1, #0x0
+ +10018:       90000000        adrp    x0, 10000 <main>
+ +1001c:       d65f03c0        ret
This page took 0.035665 seconds and 4 git commands to generate.