From 3c12b0543695609d96f818b2a60c74b624fc0ffb Mon Sep 17 00:00:00 2001 From: Marcus Shawcroft Date: Fri, 13 Feb 2015 07:13:57 +0000 Subject: [PATCH] Add ADR :tlsgd: directive and TLSGD_ADR_PREL21 support. --- bfd/ChangeLog | 12 +++++++ bfd/elfnn-aarch64.c | 70 +++++++++++++++++++++++++++++++++++++++++ bfd/elfxx-aarch64.c | 2 ++ bfd/reloc.c | 4 +++ gas/ChangeLog | 7 +++++ gas/config/tc-aarch64.c | 4 ++- include/elf/ChangeLog | 4 +++ include/elf/aarch64.h | 2 +- 8 files changed, 103 insertions(+), 2 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 4d347f43854..3132320f08e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2015-02-26 Marcus Shawcroft + + * 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 * elfnn-aarch64.c: (TLSIE_LD_GOTTREL_PREL19): Fix HOWTO bit field width. diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 3d9c383f10d..1ff18651a42 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -166,6 +166,7 @@ #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: diff --git a/bfd/elfxx-aarch64.c b/bfd/elfxx-aarch64.c index 328743d8b12..b5a93341600 100644 --- a/bfd/elfxx-aarch64.c +++ b/bfd/elfxx-aarch64.c @@ -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: diff --git a/bfd/reloc.c b/bfd/reloc.c index 547c1a16b7f..8c4a88a33e2 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -6768,6 +6768,10 @@ ENUMDOC tls_index structure as part of an adrp instruction using a 21 bit PC 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 diff --git a/gas/ChangeLog b/gas/ChangeLog index ba92ff9b319..b4eadfb0cee 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,10 @@ +2015-02-19 Marcus Shawcroft + + * 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 * config/tc-aarch64.c (reloc_table_entry): Generate diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 02122efacca..bcd6f4fb270 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -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: diff --git a/include/elf/ChangeLog b/include/elf/ChangeLog index 69151cb7793..056aaf52362 100644 --- a/include/elf/ChangeLog +++ b/include/elf/ChangeLog @@ -1,3 +1,7 @@ +2015-02-19 Marcus Shawcroft + + * aarch64.h (R_AARCH64_P32_TLSGD_ADR_PREL21): Add. + 2015-02-24 Nick Clifton * v850.h (EF_RH850_SIMD): Delete deprecated flag. diff --git a/include/elf/aarch64.h b/include/elf/aarch64.h index 93a950f85d3..b905f131b08 100644 --- a/include/elf/aarch64.h +++ b/include/elf/aarch64.h @@ -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) -- 2.30.2