From 5c5a4843ec385a60954fbbc4bcf5b64763639bd3 Mon Sep 17 00:00:00 2001 From: Christophe Lyon Date: Tue, 20 Mar 2018 10:55:29 +0100 Subject: [ARM] Add TLS relocations for FDPIC. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and handle TLS relocations for FDPIC in BFD and gas. In gas, the new relocations are rejected if the --fdpic option was not specified. We also define the __tdata_start symbol to mark the start of the .tdata section. This allows FDPIC static binaries to find the start of .tdata section, since phdr->p_vaddr of TLS segment is not a valid value for FDPIC. 2018-04-25 Christophe Lyon Mickaël Guêné bfd/: * bfd-in2.h (BFD_RELOC_ARM_TLS_GD32_FDPIC) (BFD_RELOC_ARM_TLS_LDM32_FDPIC, BFD_RELOC_ARM_TLS_IE32_FDPIC): New relocations. * elf32-arm.c (elf32_arm_howto_table_2): Add R_ARM_TLS_GD32_FDPIC, R_ARM_TLS_LDM32_FDPIC, R_ARM_TLS_IE32_FDPIC relocations. (elf32_arm_reloc_map): Add R_ARM_TLS_GD32_FDPIC, R_ARM_TLS_LDM32_FDPIC, R_ARM_TLS_IE32_FDPIC. (struct elf32_arm_link_hash_table): Update comment. (elf32_arm_final_link_relocate): Handle TLS FDPIC relocations. (IS_ARM_TLS_RELOC): Likewise. (elf32_arm_check_relocs): Likewise. (allocate_dynrelocs_for_symbol): Likewise. (elf32_arm_size_dynamic_sections): Update comment. * reloc.c: Add BFD_RELOC_ARM_TLS_GD32_FDPIC, BFD_RELOC_ARM_TLS_LDM32_FDPIC, BFD_RELOC_ARM_TLS_IE32_FDPIC. gas/ * config/tc-arm.c (reloc_names): Add TLSGD_FDPIC, TLSLDM_FDPIC, GOTTPOFF_FDIC relocations. (md_apply_fix): Handle the new TLS FDPIC relocations. (tc_gen_reloc): Likewise. (arm_fix_adjustable): Likewise. include/ * elf/arm.h: Add R_ARM_TLS_GD32_FDPIC, R_ARM_TLS_LDM32_FDPIC, R_ARM_TLS_IE32_FDPIC. ld/ * scripttempl/elf.sc: Define __tdata_start for .tdata section. --- gas/ChangeLog | 9 +++++++++ gas/config/tc-arm.c | 26 +++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'gas') diff --git a/gas/ChangeLog b/gas/ChangeLog index 122daaa..ce832e9 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,6 +1,15 @@ 2018-04-25 Christophe Lyon Mickaël Guêné + * config/tc-arm.c (reloc_names): Add TLSGD_FDPIC, TLSLDM_FDPIC, + GOTTPOFF_FDIC relocations. + (md_apply_fix): Handle the new TLS FDPIC relocations. + (tc_gen_reloc): Likewise. + (arm_fix_adjustable): Likewise. + +2018-04-25 Christophe Lyon + Mickaël Guêné + * config/tc-arm.c (reloc_names): Add gotfuncdesc, gotofffuncdesc, funcdesc. (md_apply_fix): Support the new relocations. diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c index 33a88bb..760afab 100644 --- a/gas/config/tc-arm.c +++ b/gas/config/tc-arm.c @@ -19309,7 +19309,10 @@ static struct reloc_entry reloc_names[] = { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC }, { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC }, { "funcdesc", BFD_RELOC_ARM_FUNCDESC }, - { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC } + { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC }, + { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC }, + { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, + { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC }, }; #endif @@ -23982,6 +23985,21 @@ md_apply_fix (fixS * fixP, S_SET_THREAD_LOCAL (fixP->fx_addsy); break; + /* Same handling as above, but with the arm_fdpic guard. */ + case BFD_RELOC_ARM_TLS_GD32_FDPIC: + case BFD_RELOC_ARM_TLS_IE32_FDPIC: + case BFD_RELOC_ARM_TLS_LDM32_FDPIC: + if (arm_fdpic) + { + S_SET_THREAD_LOCAL (fixP->fx_addsy); + } + else + { + as_bad_where (fixP->fx_file, fixP->fx_line, + _("Relocation supported only in FDPIC mode")); + } + break; + case BFD_RELOC_ARM_GOT32: case BFD_RELOC_ARM_GOTOFF: break; @@ -24783,9 +24801,12 @@ tc_gen_reloc (asection *section, fixS *fixp) case BFD_RELOC_ARM_TLS_GOTDESC: case BFD_RELOC_ARM_TLS_GD32: + case BFD_RELOC_ARM_TLS_GD32_FDPIC: case BFD_RELOC_ARM_TLS_LE32: case BFD_RELOC_ARM_TLS_IE32: + case BFD_RELOC_ARM_TLS_IE32_FDPIC: case BFD_RELOC_ARM_TLS_LDM32: + case BFD_RELOC_ARM_TLS_LDM32_FDPIC: /* BFD will include the symbol's address in the addend. But we don't want that, so subtract it out again here. */ if (!S_IS_COMMON (fixp->fx_addsy)) @@ -25051,9 +25072,12 @@ arm_fix_adjustable (fixS * fixP) || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 + || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 + || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 + || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL -- cgit v1.1