From 976f16630b1f7421d6693011333cf0f51417c498 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Tue, 2 Aug 2022 12:10:01 +0100 Subject: [PATCH] ld: aarch64: Adjust TLS relaxation condition In aarch64_tls_transition_without_check and elfNN_aarch64_tls_relax we choose whether to perform a relaxation to an IE access model or an LE access model based on whether the symbol itself is marked as local (i.e. `h == NULL`). This is problematic in two ways. The first is that sometimes a global dynamic access can be relaxed to an initial exec access when creating a shared library, and if that happens on a local symbol then we currently relax it to a local exec access instead. This usually does not happen since we only relax an access if aarch64_can_relax_tls returns true and aarch64_can_relax_tls does not have the same problem. However, it can happen when we have seen both an IE and GD access on the same symbol. This case is exercised in the newly added testcase tls-relax-gd-ie-2. The second problem is that deciding based on whether the symbol is local misses the case when the symbol is global but is still non-interposable and known to be located in the executable. This happens on all global symbols in executables. This case is exercised in the newly added testcase tls-relax-ie-le-4. Here we adjust the condition we base our relaxation on so that we relax to local-exec if we are creating an executable and the relevant symbol we're accessing is stored inside that executable. -- Updating tests for new relaxation criteria Many of the tests added to check our relaxation to IE were implemented by taking advantage of the fact that we did not relax a global symbol defined in an executable. Since a global symbol defined in an executable is still not interposable, we know that a TLS version of such a symbol will be in the main TLS block. This means that we can perform a stronger relaxation on such symbols and relax their accesses to a local-exec access. Hence we have to update all tests that relied on the older suboptimal decision making. The two cases when we still would want to relax a general dynamic access to an initial exec one are: 1) When in a shared library and accessing a symbol which we have already seen accessed with an initial exec access sequence. 2) When in an executable and accessing a symbol defined in a shared library. Both of these require shared library support, which means that these tests are now only available on targets with that. I have chosen to switch the existing testcases from a plain executable to one dynamically linked to a shared object as that doesn't require changing the testcases quite so much (just requires accessing a different variable rather than requiring adding another code sequence). The tls-relax-all testcase was an outlier to the above approach, since it included a general dynamic access to both a local and global symbol and inspected for the difference accordingly. --- bfd/elfnn-aarch64.c | 70 ++++++++++--------- ld/testsuite/ld-aarch64/aarch64-elf.exp | 41 +++++++---- ld/testsuite/ld-aarch64/tls-gd-symbolic.d | 20 ++++++ ld/testsuite/ld-aarch64/tls-gd-symbolic.s | 27 +++++++ ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d | 8 +-- ld/testsuite/ld-aarch64/tls-relax-all.d | 8 +-- ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d | 27 +++++++ ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s | 34 +++++++++ ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d | 29 ++++++++ .../ld-aarch64/tls-relax-gd-ie-ilp32.d | 2 +- ld/testsuite/ld-aarch64/tls-relax-gd-ie.d | 2 +- ld/testsuite/ld-aarch64/tls-relax-gd-ie.s | 4 -- .../ld-aarch64/tls-relax-gdesc-ie-2.d | 2 +- .../ld-aarch64/tls-relax-gdesc-ie-2.s | 5 -- ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d | 2 +- ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s | 4 -- ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d | 20 ++++++ ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s | 22 ++++++ .../ld-aarch64/tls-relax-large-desc-ie.d | 2 +- .../ld-aarch64/tls-relax-large-desc-ie.s | 5 -- .../ld-aarch64/tls-relax-large-gd-ie.d | 2 +- .../ld-aarch64/tls-relax-large-gd-ie.s | 5 -- ld/testsuite/ld-aarch64/tls-sharedlib.s | 4 ++ .../ld-aarch64/tls-tiny-desc-ie-ilp32.d | 4 +- ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d | 4 +- ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s | 9 --- .../ld-aarch64/tls-tiny-gd-ie-ilp32.d | 4 +- ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d | 4 +- ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s | 9 --- 29 files changed, 269 insertions(+), 110 deletions(-) create mode 100644 ld/testsuite/ld-aarch64/tls-gd-symbolic.d create mode 100644 ld/testsuite/ld-aarch64/tls-gd-symbolic.s create mode 100644 ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d create mode 100644 ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s create mode 100644 ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d create mode 100644 ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d create mode 100644 ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s create mode 100644 ld/testsuite/ld-aarch64/tls-sharedlib.s diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index cf4db849282..ac48a175720 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -4898,60 +4898,62 @@ aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h, static bfd_reloc_code_real_type aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, - struct elf_link_hash_entry *h) + struct elf_link_hash_entry *h, + struct bfd_link_info *info) { - bool is_local = h == NULL; + bool local_exec = bfd_link_executable (info) + && SYMBOL_REFERENCES_LOCAL (info, h); switch (r_type) { case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21); case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type); case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); case BFD_RELOC_AARCH64_TLSDESC_LDR: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : BFD_RELOC_AARCH64_NONE); case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC); case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1); case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC); case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: - return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; + return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type; case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC: - return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; + return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type; case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19: return r_type; case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: - return (is_local + return (local_exec ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12 : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19); @@ -4964,16 +4966,16 @@ aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type, case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC: case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21: case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21: - return is_local ? BFD_RELOC_AARCH64_NONE : r_type; + return local_exec ? BFD_RELOC_AARCH64_NONE : r_type; #if ARCH_SIZE == 64 case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC: - return is_local + return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC; case BFD_RELOC_AARCH64_TLSGD_MOVW_G1: - return is_local + return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2 : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1; #endif @@ -5082,7 +5084,7 @@ aarch64_tls_transition (bfd *input_bfd, if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx)) return bfd_r_type; - return aarch64_tls_transition_without_check (bfd_r_type, h); + return aarch64_tls_transition_without_check (bfd_r_type, h, info); } /* Return the base VMA address which should be subtracted from real addresses @@ -6321,9 +6323,11 @@ static bfd_reloc_status_type elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, bfd *input_bfd, asection *input_section, bfd_byte *contents, Elf_Internal_Rela *rel, - struct elf_link_hash_entry *h) + struct elf_link_hash_entry *h, + struct bfd_link_info *info) { - bool is_local = h == NULL; + bool local_exec = bfd_link_executable (info) + && SYMBOL_REFERENCES_LOCAL (info, h); unsigned int r_type = ELFNN_R_TYPE (rel->r_info); unsigned long insn; @@ -6333,7 +6337,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, { case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21: case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21: - if (is_local) + if (local_exec) { /* GD->LE relaxation: adrp x0, :tlsgd:var => movz R0, :tprel_g1:var @@ -6362,7 +6366,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, break; case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19: - if (is_local) + if (local_exec) { /* Tiny TLSDESC->LE relaxation: ldr x1, :tlsdesc:var => movz R0, #:tprel_g1:var @@ -6404,7 +6408,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, } case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21: - if (is_local) + if (local_exec) { /* Tiny GD->LE relaxation: adr x0, :tlsgd:var => mrs x1, tpidr_el0 @@ -6456,7 +6460,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset); BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26)); - if (is_local) + if (local_exec) { /* Large GD->LE relaxation: movz x0, #:tlsgd_g1:var => movz x0, #:tprel_g2:var, lsl #32 @@ -6500,7 +6504,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, return bfd_reloc_continue; case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC: - if (is_local) + if (local_exec) { /* GD->LE relaxation: ldr xd, [x0, #:tlsdesc_lo12:var] => movk x0, :tprel_g0_nc:var @@ -6521,7 +6525,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, } case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC: - if (is_local) + if (local_exec) { /* GD->LE relaxation add x0, #:tlsgd_lo12:var => movk R0, :tprel_g0_nc:var @@ -6574,7 +6578,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, return bfd_reloc_ok; case BFD_RELOC_AARCH64_TLSDESC_LDR: - if (is_local) + if (local_exec) { /* GD->LE relaxation: ldr xd, [gp, xn] => movk R0, #:tprel_g0_nc:var @@ -6601,12 +6605,12 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var Where R is x for lp64 mode, and w for ILP32 mode. */ - if (is_local) + if (local_exec) bfd_putl32 (ldr_hw_R0, contents + rel->r_offset); return bfd_reloc_continue; case BFD_RELOC_AARCH64_TLSDESC_OFF_G1: - if (is_local) + if (local_exec) { /* GD->LE relaxation: movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32 @@ -6631,7 +6635,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, adrp xd, :gottprel:var => movz Rd, :tprel_g1:var Where R is x for lp64 mode, and w for ILP32 mode. */ - if (is_local) + if (local_exec) { insn = bfd_getl32 (contents + rel->r_offset); bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset); @@ -6646,7 +6650,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, ldr xd, [xm, #:gottprel_lo12:var] => movk Rd, :tprel_g0_nc:var Where R is x for lp64 mode, and w for ILP32 mode. */ - if (is_local) + if (local_exec) { insn = bfd_getl32 (contents + rel->r_offset); bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset); @@ -6659,7 +6663,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, bl __tls_get_addr => add R0, R0, TCB_SIZE Where R is x for lp64 mode, and w for ilp32 mode. */ - if (is_local) + if (local_exec) { BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); @@ -6676,7 +6680,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, /* LD->LE relaxation (small): adrp x0, :tlsldm:x => mrs x0, tpidr_el0 */ - if (is_local) + if (local_exec) { bfd_putl32 (0xd53bd040, contents + rel->r_offset); return bfd_reloc_ok; @@ -6689,7 +6693,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals, bl __tls_get_addr => nop Where R is x for lp64 mode, and w for ilp32 mode. */ - if (is_local) + if (local_exec) { BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset); BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26)); @@ -6863,7 +6867,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd, BFD_ASSERT (howto != NULL); r_type = howto->type; r = elfNN_aarch64_tls_relax (globals, input_bfd, input_section, - contents, rel, h); + contents, rel, h, info); unresolved_reloc = 0; } else diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index 3c45f87151f..337beadcbfe 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -273,17 +273,8 @@ run_dump_test "tls-relax-gd-le-ilp32" run_dump_test "tls-relax-gdesc-le" run_dump_test "tls-relax-gdesc-le-now" run_dump_test "tls-relax-gdesc-le-ilp32" -run_dump_test "tls-relax-gd-ie" -run_dump_test "tls-relax-gd-ie-ilp32" -run_dump_test_lp64 "tls-relax-large-gd-ie" -run_dump_test_lp64 "tls-relax-large-gd-ie-be" run_dump_test_lp64 "tls-relax-large-gd-le" run_dump_test_lp64 "tls-relax-large-gd-le-be" -run_dump_test_lp64 "tls-relax-large-desc-ie" -run_dump_test_lp64 "tls-relax-large-desc-ie-be" -run_dump_test_lp64 "tls-relax-large-desc-le" -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-ie-le-ilp32" run_dump_test "tls-relax-ld-le-small" @@ -292,7 +283,6 @@ 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-desc-ie-ilp32" -run_dump_test "tls-relax-gdesc-ie-2" run_dump_test "tls-relax-gdesc-le-2" run_dump_test "tls-relax-gdesc-le-2-ilp32" run_dump_test "tls-relax-ie-le-2" @@ -300,13 +290,9 @@ run_dump_test "tls-relax-ie-le-2-ilp32" run_dump_test "tls-relax-ie-le-3" run_dump_test "tls-relax-ie-le-3-ilp32" run_dump_test "tls-tiny-gd" -run_dump_test "tls-tiny-gd-ie" -run_dump_test "tls-tiny-gd-ie-ilp32" run_dump_test "tls-tiny-gd-le" run_dump_test "tls-tiny-gd-le-ilp32" run_dump_test "tls-tiny-desc" -run_dump_test "tls-tiny-desc-ie" -run_dump_test "tls-tiny-desc-ie-ilp32" run_dump_test "tls-tiny-desc-le" run_dump_test "tls-tiny-desc-le-ilp32" run_dump_test "tls-tiny-ie" @@ -331,6 +317,33 @@ run_dump_test "protected-data" run_dump_test_lp64 "pr22764" run_dump_test_lp64 "pr20402" +if {[check_shared_lib_support] + && [ld_assemble $as $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o] + && [ld_link $ld tmpdir/tls-sharedlib.so "-shared tmpdir/tls-sharedlib.o"] } { + run_dump_test "tls-relax-gd-ie" + run_dump_test_lp64 "tls-relax-large-gd-ie" + run_dump_test_lp64 "tls-relax-large-gd-ie-be" + run_dump_test_lp64 "tls-relax-large-desc-ie" + run_dump_test_lp64 "tls-relax-large-desc-ie-be" + run_dump_test_lp64 "tls-relax-large-desc-le" + run_dump_test_lp64 "tls-relax-large-desc-le-be" + run_dump_test "tls-relax-gdesc-ie" + run_dump_test "tls-relax-gdesc-ie-2" + run_dump_test "tls-tiny-gd-ie" + run_dump_test "tls-tiny-desc-ie" +} +if {[check_shared_lib_support] + && [ld_assemble_flags $as -mabi=ilp32 $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o] + && [ld_link $ld tmpdir/tls-sharedlib-ilp32.so "-shared tmpdir/tls-sharedlib.o -m [aarch64_choose_ilp32_emul]"] } { + run_dump_test "tls-relax-gd-ie-ilp32" + run_dump_test "tls-tiny-gd-ie-ilp32" + run_dump_test "tls-tiny-desc-ie-ilp32" +} +run_dump_test "tls-relax-gd-ie-2" +run_dump_test "tls-relax-gd-ie-3" +run_dump_test "tls-relax-ie-le-4" +run_dump_test "tls-gd-symbolic" + # ifunc tests run_dump_test "ifunc-1" run_dump_test "ifunc-1-local" diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.d b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d new file mode 100644 index 00000000000..d6732acdaf1 --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d @@ -0,0 +1,20 @@ +# Testcase to show that -Bsymbolic does not trigger any relaxation from general +# dynamic or initial exec for global symbols. +#target: [check_shared_lib_support] +#ld: -shared -Bsymbolic +#objdump: -d -j .text + +.*: file format .* + + +Disassembly of section \.text: + +[0-9a-f]+ <_test_tls_desc>: + +[0-9a-f]+: ........ adrp x0, .* + +[0-9a-f]+: ........ ldr x1, \[x0, #.*\] + +[0-9a-f]+: ........ add x0, x0, .* + +[0-9a-f]+: d63f0020 blr x1 + +[0-9a-f]+ <_test_tls_desc2>: + +[0-9a-f]+: ........ adrp x0, .* + +[0-9a-f]+: ........ ldr x0, \[x0, #.*\] diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.s b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s new file mode 100644 index 00000000000..d2ca5dac7be --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s @@ -0,0 +1,27 @@ + # Demonstrating TLS relaxation behavior for -Bsymbolic linking. + # (i.e. no extra relaxation when using -Bsymbolic). + .global tlsdescvar + .global tlsdescvar2 + .section .tbss,"awT",%nobits + .align 2 + .type tlsdescvar, %object + .size tlsdescvar, 4 +tlsdescvar: + .zero 4 + .type tlsdescvar2, %object + .size tlsdescvar2, 4 +tlsdescvar2: + .zero 4 +.text +_test_tls_desc: + + adrp x0, :tlsdesc:tlsdescvar + ldr x1, [x0, :tlsdesc_lo12:tlsdescvar] + add x0, x0, :tlsdesc_lo12:tlsdescvar + .tlsdesccall tlsdescvar + blr x1 + +_test_tls_desc2: + + adrp x0, :gottprel:tlsdescvar2 + ldr x0, [x0, #:gottprel_lo12:tlsdescvar2] diff --git a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d index 1cb4ef42613..62faed4b73a 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d +++ b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d @@ -5,8 +5,8 @@ #... +10000: a9bf7bfd stp x29, x30, \[sp, #-16\]! +10004: 910003fd mov x29, sp - +10008: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> - +1000c: b9400400 ldr w0, \[x0, #4\] + +10008: 52a00000 movz w0, #0x0, lsl #16 + +1000c: 72800100 movk w0, #0x8 +10010: d503201f nop +10014: d503201f nop +10018: d53bd041 mrs x1, tpidr_el0 @@ -20,8 +20,8 @@ +10038: 8b000040 add x0, x2, x0 +1003c: b9400000 ldr w0, \[x0\] +10040: 0b000021 add w1, w1, w0 - +10044: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> - +10048: b9400800 ldr w0, \[x0, #8\] + +10044: 52a00000 movz w0, #0x0, lsl #16 + +10048: 72800200 movk w0, #0x10 +1004c: d53bd041 mrs x1, tpidr_el0 +10050: 0b000020 add w0, w1, w0 +10054: b9400000 ldr w0, \[x0\] diff --git a/ld/testsuite/ld-aarch64/tls-relax-all.d b/ld/testsuite/ld-aarch64/tls-relax-all.d index 59421864f95..1262a99a6a0 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-all.d +++ b/ld/testsuite/ld-aarch64/tls-relax-all.d @@ -4,8 +4,8 @@ #... +10000: a9bf7bfd stp x29, x30, \[sp, #-16\]! +10004: 910003fd mov x29, sp - +10008: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> - +1000c: f9400400 ldr x0, \[x0, #8\] + +10008: d2a00000 movz x0, #0x0, lsl #16 + +1000c: f2800200 movk x0, #0x10 +10010: d503201f nop +10014: d503201f nop +10018: d53bd041 mrs x1, tpidr_el0 @@ -19,8 +19,8 @@ +10038: 8b000040 add x0, x2, x0 +1003c: b9400000 ldr w0, \[x0\] +10040: 0b000021 add w1, w1, w0 - +10044: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> - +10048: f9400800 ldr x0, \[x0, #16\] + +10044: d2a00000 movz x0, #0x0, lsl #16 + +10048: f2800300 movk x0, #0x18 +1004c: d53bd041 mrs x1, tpidr_el0 +10050: 8b000020 add x0, x1, x0 +10054: b9400000 ldr w0, \[x0\] diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d new file mode 100644 index 00000000000..f0281b77579 --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d @@ -0,0 +1,27 @@ +# The linker recognises that if we have one IE access to a TLS symbol then all +# accesses to that symbol could be IE. Here we are also interested to check +# the linker does not also decide that a second access to that symbol could be +# LE. +#target: [check_shared_lib_support] +#ld: -shared +#objdump: -dr + +.*: file format .* + + +Disassembly of section \.text: + +[0-9a-f]+ : + +[0-9a-f]+: d2800000 mov x0, #0x0 // #0 + +[0-9a-f]+: d53bd041 mrs x1, tpidr_el0 + +[0-9a-f]+: .* adrp x0, .* + +[0-9a-f]+: .* ldr x0, \[x0, #.*\] + +[0-9a-f]+: b8606820 ldr w0, \[x1, x0\] + +[0-9a-f]+: d53bd041 mrs x1, tpidr_el0 + +[0-9a-f]+: 910003fd mov x29, sp + +[0-9a-f]+: .* adrp x0, .* + +[0-9a-f]+: .* ldr x0, \[x0, #.*\] + +[0-9a-f]+: d503201f nop + +[0-9a-f]+: d503201f nop + +[0-9a-f]+: b8606820 ldr w0, \[x1, x0\] + +[0-9a-f]+: d65f03c0 ret diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s new file mode 100644 index 00000000000..568ceb4857c --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s @@ -0,0 +1,34 @@ + .section .tbss,"awT",@nobits + .align 2 + .type y, %object + .size y, 4 +y: + .zero 4 + + + + + .text + .global foo + .type foo, @function +foo: + # Access the local symbol with an IE access. + mov x0, 0 + mrs x1, tpidr_el0 + adrp x0, :gottprel:y + ldr x0, [x0, #:gottprel_lo12:y] + ldr w0, [x1, x0] + + # Also access the same symbol with a General Dynamic access. + # The linker should be able to recognise that if we're already + # accessing this symbol with an Initial Exec access then this General + # Dynamic access could be relaxed to an Initial Exec one too. + mrs x1, tpidr_el0 + mov x29, sp + adrp x0, :tlsdesc:y + ldr x2, [x0, #:tlsdesc_lo12:y] + add x0, x0, :tlsdesc_lo12:y + .tlsdesccall y + blr x2 + ldr w0, [x1, x0] + ret diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d new file mode 100644 index 00000000000..2e45ec90d1a --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d @@ -0,0 +1,29 @@ +# The linker recognises that if we have one IE access to a TLS symbol then all +# accesses to that symbol could be IE. Here we are also interested to check +# the linker does not also decide that a second access to that symbol could be +# LE. +#source: tls-relax-gd-ie-2.s +#target: [check_shared_lib_support] +#ld: -shared -Bsymbolic +#objdump: -dr + +.*: file format .* + + +Disassembly of section \.text: + +[0-9a-f]+ : + +[0-9a-f]+: d2800000 mov x0, #0x0 // #0 + +[0-9a-f]+: d53bd041 mrs x1, tpidr_el0 + +[0-9a-f]+: .* adrp x0, .* + +[0-9a-f]+: .* ldr x0, \[x0, #.*\] + +[0-9a-f]+: b8606820 ldr w0, \[x1, x0\] + +[0-9a-f]+: d53bd041 mrs x1, tpidr_el0 + +[0-9a-f]+: 910003fd mov x29, sp + +[0-9a-f]+: .* adrp x0, .* + +[0-9a-f]+: .* ldr x0, \[x0, #.*\] + +[0-9a-f]+: d503201f nop + +[0-9a-f]+: d503201f nop + +[0-9a-f]+: b8606820 ldr w0, \[x1, x0\] + +[0-9a-f]+: d65f03c0 ret + diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d index ab08c6161b9..340206a9e2b 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d @@ -1,6 +1,6 @@ #source: tls-relax-gd-ie.s #as: -mabi=ilp32 -#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 +#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so #objdump: -dr #... +10000: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d index f80bb907770..0c03290e0a9 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d @@ -1,5 +1,5 @@ #source: tls-relax-gd-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #objdump: -dr #... +10000: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s index 88c7eec73e4..afe076c8c82 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s +++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s @@ -1,7 +1,3 @@ - .global var - .section .tdata,"awT",%progbits -var: - .word 2 .text adrp x0, :tlsgd:var add x0, x0, :tlsgd_lo12:var diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d index 2b8e346fc66..f13263f201f 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d +++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d @@ -1,5 +1,5 @@ #source: tls-relax-gdesc-ie-2.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #objdump: -dr #... +10000: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s index 790b6c6eb8b..f7be57c3207 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s +++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s @@ -1,9 +1,5 @@ // Test TLS Desc to TLS IE relaxation when instructions are not consecutive. - .global var - .section .tdata -var: - .word 2 .text adrp x0, :tlsdesc:var nop @@ -20,5 +16,4 @@ var: mrs x1, tpidr_el0 add x0, x1, x0 ldr w0, [x0] - .global var .section .tdata diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d index 86277f82565..1ace84858a3 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d +++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d @@ -1,5 +1,5 @@ #source: tls-relax-gdesc-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #objdump: -dr #... +10000: 90000080 adrp x0, 20000 <_GLOBAL_OFFSET_TABLE_> diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s index 38b372132f4..089d36c9cc8 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s +++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s @@ -1,7 +1,3 @@ - .global var - .section .tdata -var: - .word 2 .text adrp x0, :tlsdesc:var ldr x17, [x0, #:tlsdesc_lo12:var] diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d new file mode 100644 index 00000000000..e2bc5f15304 --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d @@ -0,0 +1,20 @@ +# We already test that we relax an access to a local symbol, this testcase +# checks that we relax an access to a global-binding symbol if the static linker +# knows that the symbol will resolve to the executable local value. +# +# The access should be relaxed to a LE access. +#ld: +#objdump: -d + +.*: file format .* + + +Disassembly of section \.text: + +[0-9a-f]+ <_start>: + +[0-9a-f]+: d2800000 mov x0, #0x0 // #0 + +[0-9a-f]+: d53bd041 mrs x1, tpidr_el0 + +[0-9a-f]+: d2a00000 movz x0, #0x0, lsl #16 + +[0-9a-f]+: f2800200 movk x0, #0x10 + +[0-9a-f]+: b8606820 ldr w0, \[x1, x0\] + +[0-9a-f]+: d65f03c0 ret diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s new file mode 100644 index 00000000000..e151cd4efd6 --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s @@ -0,0 +1,22 @@ +# Test TLS IE to TLS LE relaxation for global symbols. + .section .tbss,"awT",@nobits + .global x + .align 2 + .type x, %object + .size x, 4 +x: + .zero 4 + + + + .text + .global _start + .type _start, @function +_start: + mov x0, 0 + mrs x1, tpidr_el0 + adrp x0, :gottprel:x + ldr x0, [x0, #:gottprel_lo12:x] + ldr w0, [x1, x0] + ret + diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d index 21ad5e5a18c..cb546ad74e6 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d +++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d @@ -1,5 +1,5 @@ #source: tls-relax-large-desc-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #notarget: aarch64_be-*-* #objdump: -dr #... diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s index a4d1e00086a..98dc2a571d5 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s +++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s @@ -1,8 +1,3 @@ - .global var - .section .tdata,"awT",%progbits -var: - .word 2 - .text test: ldr x1, .Lgot diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d index 2b398dbb9c6..740178d4610 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d +++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d @@ -1,5 +1,5 @@ #source: tls-relax-large-gd-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #notarget: aarch64_be-*-* #objdump: -dr #... diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s index 8e0310d6b3f..d35aace776e 100644 --- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s +++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s @@ -1,8 +1,3 @@ - .global var - .section .tdata,"awT",%progbits -var: - .word 2 - .text test: ldr x1, .Lgot diff --git a/ld/testsuite/ld-aarch64/tls-sharedlib.s b/ld/testsuite/ld-aarch64/tls-sharedlib.s new file mode 100644 index 00000000000..8838b9f2348 --- /dev/null +++ b/ld/testsuite/ld-aarch64/tls-sharedlib.s @@ -0,0 +1,4 @@ + .global var + .section .tdata,"awT",@progbits +var: + .word 2 diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d index ebbaf854baa..3dffa1b85e6 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d +++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d @@ -1,12 +1,12 @@ #source: tls-tiny-desc-ie.s #as: -mabi=ilp32 -#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 +#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so #objdump: -dr #... Disassembly of section .text: 00010000 \: - +10000: 18080020 ldr w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\> + +10000: 18080020 ldr w0, 20004 \ +10004: d503201f nop +10008: d503201f nop diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d index 0088539d6bf..e759ae94576 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d +++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d @@ -1,11 +1,11 @@ #source: tls-tiny-desc-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #objdump: -dr #... Disassembly of section .text: 0000000000010000 \: - +10000: 58080040 ldr x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\> + +10000: 58080040 ldr x0, 20008 \ +10004: d503201f nop +10008: d503201f nop diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s index 520cd4e85b2..fcc970f6d8f 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s +++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s @@ -1,12 +1,3 @@ - .global var - - .section .tbss,"awT",%nobits - .align 2 - .type var, %object - .size var, 4 -var: - .zero 4 - .text test: ldr x1, :tlsdesc:var diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d index 1ea61103b47..6317152eb1e 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d +++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d @@ -1,12 +1,12 @@ #source: tls-tiny-gd-ie.s #as: -mabi=ilp32 -#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 +#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so #objdump: -dr #... Disassembly of section .text: 00010000 \: - +10000: 18080020 ldr w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\> + +10000: 18080020 ldr w0, 20004 \ +10004: d53bd041 mrs x1, tpidr_el0 +10008: 0b000020 add w0, w1, w0 diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d index 629d90c942d..66b996e6f4a 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d +++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d @@ -1,11 +1,11 @@ #source: tls-tiny-gd-ie.s -#ld: -T relocs.ld -e0 +#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so #objdump: -dr #... Disassembly of section .text: 0000000000010000 \: - +10000: 58080040 ldr x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\> + +10000: 58080040 ldr x0, 20008 \ +10004: d53bd041 mrs x1, tpidr_el0 +10008: 8b000020 add x0, x1, x0 diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s index 4dc7e66bbdb..3ae4a0cc9fe 100644 --- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s +++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s @@ -1,12 +1,3 @@ - .global var - - .section .tbss,"awT",%nobits - .align 2 - .type var, %object - .size var, 4 -var: - .zero 4 - .text test: adr x0, :tlsgd:var -- 2.30.2