From 7ba71655a425ac44721f97cc0ad7922ca15bce43 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 28 Feb 2017 08:32:36 +1030 Subject: PowerPC addpcis fix This came up because I was looking at ld/tmpdir/addpcis.o and noticed the odd addends on REL16DX_HA. They ought to both be -4. The error crept in due REL16DX_HA howto being pc-relative (as indeed it should be), and code at gas/write.c:1001 after this comment /* Make it pc-relative. If the back-end code has not selected a pc-relative reloc, cancel the adjustment we do later on all pc-relative relocs. */ *not* cancelling the pc-relative adjustment. So I've made a dummy non-relative split reloc so that the generic code handles this, rather than attempting to add hacks later in md_apply_fix which would not be very robust. Having the new internal reloc also makes it easy to support addpcis rx,sym@ha as an equivalent to addpcis rx,(sym-0f)@ha 0: The patch also fixes overflow checking, which must test whether the addi will overflow too since @l relocs don't have any overflow check. Lastly, since I was poking at md_apply_fix, I arranged to have the generic gas/write.c code emit errors for subtraction expressions where we lack reloc support. include/ * elf/ppc64.h (R_PPC64_16DX_HA): New. Expand fake reloc comment. * elf/ppc.h (R_PPC_16DX_HA): Likewise. bfd/ * reloc.c (BFD_RELOC_PPC_16DX_HA): New. * elf64-ppc.c (ppc64_elf_howto_raw ): New howto. (ppc64_elf_reloc_type_lookup): Translate new bfd reloc. (ppc64_elf_ha_reloc): Correct overflow test on REL16DX_HA. (ppc64_elf_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_howto_raw ): New howto. (ppc_elf_reloc_type_lookup): Translate new bfd reloc. (ppc_elf_check_relocs): Handle R_PPC_16DX_HA to pacify gcc. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. gas/ * config/tc-ppc.c (md_assemble): Use BFD_RELOC_PPC_16DX_HA for addpcis. (md_apply_fix): Remove fx_subsy check. Move code converting to pcrel reloc earlier and handle BFD_RELOC_PPC_16DX_HA. Remove code emiiting errors on seeing fx_pcrel set on unexpected relocs, as that is done now by the generic code via.. * config/tc-ppc.h (TC_FORCE_RELOCATION_SUB_LOCAL): ..this. Define. (TC_VALIDATE_FIX_SUB): Define. ld/ * testsuite/ld-powerpc/addpcis.d: Define ext1 and ext2 at limits of addpcis range. --- include/elf/ppc.h | 6 +++++- include/elf/ppc64.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include/elf') diff --git a/include/elf/ppc.h b/include/elf/ppc.h index 21ed671..6790cd7 100644 --- a/include/elf/ppc.h +++ b/include/elf/ppc.h @@ -73,10 +73,14 @@ START_RELOC_NUMBERS (elf_ppc_reloc_type) RELOC_NUMBER (R_PPC_ADDR30, 37) #ifndef RELOC_MACROS_GEN_FUNC -/* Fake relocations for branch stubs, only used internally by ld. */ +/* Relocations only used internally by ld. If you need to use these + reloc numbers, you can change them to some other unused value + without affecting the ABI. They will never appear in object files. */ RELOC_NUMBER (R_PPC_RELAX, 48) RELOC_NUMBER (R_PPC_RELAX_PLT, 49) RELOC_NUMBER (R_PPC_RELAX_PLTREL24, 50) +/* Reloc only used internally by gas. As above, value is unimportant. */ + RELOC_NUMBER (R_PPC_16DX_HA, 51) #endif /* Relocs added to support TLS. */ diff --git a/include/elf/ppc64.h b/include/elf/ppc64.h index 307d4c2..43090dd 100644 --- a/include/elf/ppc64.h +++ b/include/elf/ppc64.h @@ -155,8 +155,12 @@ START_RELOC_NUMBERS (elf_ppc64_reloc_type) RELOC_NUMBER (R_PPC64_ENTRY, 118) #ifndef RELOC_MACROS_GEN_FUNC -/* Fake relocation only used internally by ld. */ +/* Relocation only used internally by ld. If you need to use these + reloc numbers, you can change them to some other unused value + without affecting the ABI. They will never appear in object files. */ RELOC_NUMBER (R_PPC64_LO_DS_OPT, 128) +/* Reloc only used internally by gas. As above, value is unimportant. */ + RELOC_NUMBER (R_PPC64_16DX_HA, 129) #endif /* Power9 split rel16 for addpcis. */ -- cgit v1.1