Commit Graph

100 Commits

Author SHA1 Message Date
Nick Clifton 866fe07d8d Fix a problem with a few PowerPC linker tests when the .data section is retained.
* testsuite/ld-powerpc/powerpc.exp (ppcelftests): Use section name
	.PPC.EMB.apuinfo instead of section number 2 in apuinfo tests.
2020-07-20 14:59:39 +01:00
Alan Modra d349c8e245 Power10 stub selection
This patch better supports mixing of power10 and non-power10 code,
as might be seen in a cpu-optimized library using ifuncs to select
functions optimized for a given cpu.  Using -Wl,--no-power10-stubs
isn't that good in this situation since non-power10 notoc stubs are
slower and larger than the power10 variants, which you'd like to use
on power10 code paths.

With this change, power10 pc-relative code that makes calls marked
@notoc uses power10 stubs if stubs are necessary, and other calls use
non-power10 instructions in stubs.  This will mean that if gcc is
generating code for -mcpu=power10 but with pc-rel disabled then you'll
get the older stubs even on power10 (unless you force with
-Wl,--power10-stubs).  That shouldn't be too big a problem: stubs that
use r2 are reasonable.  It's just the ones that set up addressing
using "mflr 12; bcl 20,31,.+4; mflr 11; mtlr 12" that should be
avoided if possible.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add has_power10_relocs.
	(select_alt_stub): New function.
	(ppc_get_stub_entry): Use it here.
	(ppc64_elf_check_relocs): Set had_power10_relocs rather than
	power10_stubs.
	(ppc64_elf_size_stubs): Clear power10_stubs here instead.  Don't
	merge notoc stubs with other varieties when power10_stubs is "auto".
	Instead dup the stub hash table entry.
	(plt_stub_size, ppc_build_one_stub, ppc_size_one_stub): Adjust
	tests of power10_stubs.
ld/
	* emultempl/ppc64elf.em (power10-stubs): Accept optional "auto" arg.
	* ld.texi (power10-stubs): Update.
	* testsuite/ld-powerpc/callstub-1.d: Force --power10-stubs.
	* testsuite/ld-powerpc/callstub-2.d: Relax branch offset comparison.
	* testsuite/ld-powerpc/callstub-4.d: New test.
	* testsuite/ld-powerpc/notoc.d: Force --no-power10-stubs.
	* testsuite/ld-powerpc/notoc3.d,
	* testsuite/ld-powerpc/notoc3.s,
	* testsuite/ld-powerpc/notoc3.wf: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.  Pass
	--no-power10-stubs for notoc link.

(cherry picked from commit e10a07b32dc1faed25b5bbcbbc47d68e2ff537b9)
2020-07-19 12:31:15 +09:30
Alan Modra 8c1ec83fba PowerPC64 ld --no-power10-stubs
Needed for libraries that use ifuncs or other means to support
cpu-optimized versions of functions, some power10, some not, and those
functions make calls using linkage stubs.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add power10_stubs.
	* elf64-ppc.c (struct ppc_link_hash_table): Delete
	power10_stubs.
	(ppc64_elf_check_relocs): Adjust setting of power10_stubs.
	(plt_stub_size, ppc_build_one_stub, ppc_size_one_stub): Adjust
	uses of power10_stubs.
ld/
	* emultempl/ppc64elf.em (params): Init new field.
	(enum ppc64_opt): Add OPTION_POWER10_STUBS and OPTION_NO_POWER10_STUBS.
	(PARSE_AND_LIST_LONGOPTS): Support --power10-stubs and
	--no-power10-stubs.
	(PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Likewise.
	* testsuite/ld-powerpc/callstub-3.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.

(cherry picked from commit d3b10ee787216d304a858246656ed2fdaecdfd93)
2020-07-10 12:09:58 +09:30
Nick Clifton 0942c7ab94 Change readelf's display of symbol names (when not in --wide mode) so that if they are going to be truncated then "[...]" is displayed at the end. Add a comment line option to disable this enhancement and restore the old behaviour.
PR 26028
binutils* readelf.c (print_symbol): Handle truncation of symbol names.
	(options): Add -T/--silent-truncation option.
	(parse_args): Handle the option.
	(print_dynamic_symbol): Correct calculation of width available to
	display symbol name.
	* doc/binutils.texi: Document the -T option to readelf.
	* NEWS: Mention the new feature.

gas	* testsuite/gas/ia64/group-2.d: Add -T option to readelf
	command line.
	* testsuite/gas/ia64/unwind.d: Likewise.
	* testsuite/gas/mmix/bspec-1.d: Likewise.
	* testsuite/gas/mmix/bspec-2.d: Likewise.
	* testsuite/gas/mmix/comment-1.d: Likewise.
	* testsuite/gas/tic6x/scomm-directive-4.d: Likewise.

ld	* testsuite/ld-powerpc/powerpc.exp: Add -T option to readelf
	command line when running some tests.
	* testsuite/ld-arm/arm-elf.exp: Likewise.
	* testsuite/ld-mips-elf/mips-elf.exp: Likewise.
	* testsuite/ld-mmix/local1.d: Likewise.
	* testsuite/ld-mmix/local3.d: Likewise.
	* testsuite/ld-mmix/local5.d: Likewise.
	* testsuite/ld-mmix/local7.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
2020-07-02 11:30:52 +01:00
Alan Modra 7c1f422735 PowerPC Rename powerxx to power10
Now that ISA3.1 is out we can finish with the powerxx silliness.

bfd/
	* elf64-ppc.c: Rename powerxx to power10 throughout.
gas/
	* config/tc-ppc.c (md_assemble): Update for PPC_OPCODE_POWER10
	renaming.
	* testsuite/gas/ppc/prefix-align.d: Use -mpower10/-Mpower10 in
	place of -mfuture/-Mfuture.
	* testsuite/gas/ppc/prefix-pcrel.d: Likewise.
	* testsuite/gas/ppc/prefix-reloc.d: Likewise.
gold/
	* powerpc.cc: Rename powerxx to power10 throughout.
include/
	* elf/ppc64.h: Update comment.
	* opcode/ppc.h (PPC_OPCODE_POWER10): Rename from PPC_OPCODE_POWERXX.
ld/
	* testsuite/ld-powerpc/callstub-1.d: Use -mpower10/-Mpower10 in
	place of -mfuture/-Mfuture.
	* testsuite/ld-powerpc/notoc2.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
	* testsuite/ld-powerpc/tlsgd.d: Likewise.
	* testsuite/ld-powerpc/tlsie.d: Likewise.
	* testsuite/ld-powerpc/tlsld.d: Likewise.
opcodes/
	* ppc-dis.c (ppc_opts): Add "power10" entry.
	(print_insn_powerpc): Update for PPC_OPCODE_POWER10 renaming.
	* ppc-opc.c (POWER10): Rename from POWERXX.  Update all uses.
2020-05-11 21:08:36 +09:30
Christophe Lyon abf874aafe Add support for non-contiguous memory regions
2020-01-06  Christophe Lyon  <christophe.lyon@linaro.org>

	bfd/
	* bfd-in2.h: Regenerate.
	* section.c (asection): Add already_assigned field.
	(BFD_FAKE_SECTION): Add default initializer for it.
	* ecoff.c (bfd_debug_section): Initialize already_assigned field.
	* elf32-arm.c (arm_build_one_stub): Add support for
	non_contiguous_regions.
	* elf32-csky.c (csky_build_one_stub): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
	* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
	* elf32-metag.c (metag_build_one_stub): Likewise.
	* elf32-nios2.c (nios2_build_one_stub): Likewise.
	* elf64-ppc.c (ppc_build_one_stub): Likewise.
	(ppc_size_one_stub): Likewise.
	* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.
	* elflink.c (elf_link_input_bfd): Likewise.

	include/
	* bfdlink.h (bfd_link_info): Add non_contiguous_regions and
	non_contiguous_regions_warnings fields.

	ld/
	* ldlang.c (lang_add_section): Add support for
	non_contiguous_regions.
	(size_input_section): Likewise.
	(lang_size_sections_1): Likewise.
	(process_insert_statements): Likewise.
	* ldlex.h (option_values): Add OPTION_NON_CONTIGUOUS_REGIONS and
	OPTION_NON_CONTIGUOUS_REGIONS_WARNINGS.
	* lexsup.c (ld_options): Add entries for
	--enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings.
	(parse_args): Handle it.
	* NEWS: Add --enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings.
	* ld.texi: Add --enable-non-contiguous-regions and
	--enable-non-contiguous-regions-warnings documentation.
	* emultempl/armelf.em (elf32_arm_add_stub_section): Add
	SEC_LINKER_CREATED flag.
	* emultempl/xtensaelf.em (ld_build_required_section_dependence):
	Emit an error when --enable-non-contiguous-regions is used.
	* testsuite/ld-elf/non-contiguous.d: New.
	* testsuite/ld-elf/non-contiguous.ld: New.
	* testsuite/ld-elf/non-contiguous.s: New.
	* testsuite/ld-arm/arm-elf.exp: Run the new tests.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.s: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm2.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm3.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm4.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm4.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm5.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm5.ld: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm6.d: New.
	* testsuite/ld-arm/arm-elf/non-contiguous-arm6.ld: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/non-contiguous-powerpc.d: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.ld: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.sd: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc64.d: New.
2020-03-13 14:44:45 +00:00
Alan Modra a804e4760a PowerPC64 tls_get_addr_desc static support
This provides a linker generated __tls_get_addr_desc wrapper function
preserving registers around a __tls_get_addr call.  The idea being to
support __tls_get_addr_desc without requiring a glibc update.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add tga_group.
	(ppc64_elf_archive_symbol_lookup): Extract __tls_get_addr_opt for
	__tls_get_addr_desc.
	(ppc64_elf_size_stubs): Add section for linker generated
	__tls_get_addr_desc wrapper function.  Loop at least once if
	generating this function.
	(emit_tga_desc, emit_tga_desc_eh_frame): New functions.
	(ppc64_elf_build_stubs): Generate __tls_get_addr_desc.
ld/
	* testsuite/ld-powerpc/tlsdesc3.d,
	* testsuite/ld-powerpc/tlsdesc3.wf,
	* testsuite/ld-powerpc/tlsdesc4.d,
	* testsuite/ld-powerpc/tlsdesc4.s,
	* testsuite/ld-powerpc/tlsdesc4.wf: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2020-01-22 17:14:08 +10:30
Alan Modra 9e7028aa1e PowerPC64 __tls_get_addr_desc
This implements register saving and restoring in the __tls_get_addr
call stub, so that when glibc supports the optimized tls call stub gcc
can generate code that assumes only r0, r12 and of course r3 are
changed on a __tls_get_addr call.  When gcc expects __tls_get_addr
calls to preserve registers the call will be to __tls_get_addr_desc,
which will be translated by the linker to a call to __tls_get_addr_opt.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add no_tls_get_addr_regsave.
	* elf64-ppc.c (struct ppc_link_hash_table): Add tga_desc and
	tga_desc_fd.
	(is_tls_get_addr): Match tga_desc and tga_desc_df too.
	(STDU_R1_0R1, ADDI_R1_R1): Define.
	(tls_get_addr_prologue, tls_get_addr_epilogue): New functions.
	(ppc64_elf_tls_setup): Set up tga_desc and tga_desc_fd.  Indirect
	tga_desc_fd to opt_fd, and tga_desc to opt.  Set
	no_tls_get_addr_regsave.
	(branch_reloc_hash_match): Add hash3 and hash4.
	(ppc64_elf_tls_optimize): Handle tga_desc_fd and tga_desc too.
	(ppc64_elf_size_dynamic_sections): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	(plt_stub_size, build_plt_stub): Likewise.  Size regsave
	__tls_get_addr stub.
	(build_tls_get_addr_stub): Build regsave __tls_get_addr stub and
	eh_frame.
	(ppc_size_one_stub): Handle tga_desc_fd and tga_desc too.  Size
	eh_frame for regsave __tls_get_addr.
gas/
	* config/tc-ppc.c (parse_tls_arg): Handle tls arg for
	__tls_get_addr_desc and __tls_get_addr_opt.
ld/
	* emultempl/ppc64elf.em (ppc64_opt, PARSE_AND_LIST_LONGOPTS),
	(PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Support
	--tls-get-addr-regsave and --no-tls-get-addr-regsave.
	(params): Init new field.
	* ld.texi (--tls-get-addr-regsave, --no-tls-get-addr-regsave):
	Document.
	* testsuite/ld-powerpc/tlsdesc.s,
	* testsuite/ld-powerpc/tlsdesc.d,
	* testsuite/ld-powerpc/tlsdesc.wf,
	* testsuite/ld-powerpc/tlsdesc2.d,
	* testsuite/ld-powerpc/tlsdesc2.wf,
	* testsuite/ld-powerpc/tlsexenors.d,
	* testsuite/ld-powerpc/tlsexenors.r,
	* testsuite/ld-powerpc/tlsexers.d,
	* testsuite/ld-powerpc/tlsexers.r,
	* testsuite/ld-powerpc/tlsexetocnors.d,
	* testsuite/ld-powerpc/tlsexetocrs.d,
	* testsuite/ld-powerpc/tlsexetocrs.r,
	* testsuite/ld-powerpc/tlsopt6.d,
	* testsuite/ld-powerpc/tlsopt6.wf: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2020-01-22 17:14:08 +10:30
Alan Modra b3adc24a07 Update year range in copyright notice of binutils files 2020-01-01 18:42:54 +10:30
Alan Modra 6446511295 PowerPC local got test
This is the one that causes ld segfaults between 2019-10-04 and
2019-10-07.  Bug introduced with f749f26eea, fixed by 93370e8e7b.

	* testsuite/ld-powerpc/localgot.s,
	* testsuite/ld-powerpc/localgot.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2019-10-09 00:20:19 +10:30
Alan Modra c3614cffc8 PowerPC TLS tests
This patch adds some --no-tls-optimize tests and performs some of the
existing dynamic tests with tls markers in order to catch any
regression in PLT counting.

	* testsuite/ld-powerpc/tlsexe.r: Adjust for added TLSMARK symbol.
	* testsuite/ld-powerpc/tlsexe32.r: Likewise.
	* testsuite/ld-powerpc/tlsso.r: Likewise.
	* testsuite/ld-powerpc/tlsso32.r: Likewise.
	* testsuite/ld-powerpc/tls32no.d,
	* testsuite/ld-powerpc/tls32no.g: New test files.
	* testsuite/ld-powerpc/tlsexe32no.d,
	* testsuite/ld-powerpc/tlsexe32no.g,
	* testsuite/ld-powerpc/tlsexe32no.r: New test files.
	* testsuite/ld-powerpc/tlsexeno.d,
	* testsuite/ld-powerpc/tlsexeno.g,
	* testsuite/ld-powerpc/tlsexeno.r: New test files.
	* testsuite/ld-powerpc/tlsexetocno.d,
	* testsuite/ld-powerpc/tlsexetocno.g: New test files.
	* testsuite/ld-powerpc/tlsno.d,
	* testsuite/ld-powerpc/tlsno.g: New test files.
	* testsuite/ld-powerpc/tlstocno.d,
	* testsuite/ld-powerpc/tlstocno.g: New test files.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2019-10-07 13:34:40 +10:30
Alan Modra c213164ad2 [PowerPC64] pc-relative TLS relocations
This patch supports using pcrel instructions in TLS code sequences.  A
number of new relocations are needed, gas operand modifiers to
generate those relocations, and new TLS optimisation.  For
optimisation it turns out that the new pcrel GD and LD sequences can
be distinguished from the non-pcrel GD and LD sequences by there being
different relocations on the new sequence.  The final "add ra,rb,13"
on IE sequences similarly needs a new relocation, or as I chose, a
modification of R_PPC64_TLS.  On pcrel IE code, the R_PPC64_TLS points
one byte into the "add" instruction rather than being on the
instruction boundary.

GD:
 pla 3,z@got@tlsgd@pcrel	  # R_PPC64_GOT_TLSGD34
 bl __tls_get_addr@notoc(z@tlsgd) # R_PPC64_TLSGD and R_PPC64_REL24_NOTOC
  edited to IE
   pld 3,z@got@tprel@pcrel
   add 3,3,13
  edited to LE
   paddi 3,13,z@tprel
   nop

LD:
 pla 3,z@got@tlsld@pcrel	  # R_PPC64_GOT_TLSLD34
 bl __tls_get_addr@notoc(z@tlsld) # R_PPC64_TLSLD and R_PPC64_REL24_NOTOC
 ..
 paddi 9,3,z2@dtprel
 pld 10,z3@got@dtprel@pcrel
 add 10,10,3
  edited to LE
   paddi 3,13,0x1000
   nop

IE:
 pld 9,z@got@tprel@pcrel	  # R_PPC64_GOT_TPREL34
 add 3,9,z@tls@pcrel		  # R_PPC64_TLS at insn+1
 ldx 4,9,z@tls@pcrel
 lwax 5,9,z@tls@pcrel
 stdx 5,9,z@tls@pcrel
  edited to LE
  paddi 9,13,z@tprel
  nop
  ld 4,0(9)
  lwa 5,0(9)
  std 5,0(9)

LE:
 paddi 10,13,z@tprel

include/
	* elf/ppc64.h (R_PPC64_TPREL34, R_PPC64_DTPREL34),
	(R_PPC64_GOT_TLSGD34, R_PPC64_GOT_TLSLD34),
	(R_PPC64_GOT_TPREL34, R_PPC64_GOT_DTPREL34): Define.
	(IS_PPC64_TLS_RELOC): Include new tls relocs.
bfd/
	* reloc.c (BFD_RELOC_PPC64_TPREL34, BFD_RELOC_PPC64_DTPREL34),
	(BFD_RELOC_PPC64_GOT_TLSGD34, BFD_RELOC_PPC64_GOT_TLSLD34),
	(BFD_RELOC_PPC64_GOT_TPREL34, BFD_RELOC_PPC64_GOT_DTPREL34),
	(BFD_RELOC_PPC64_TLS_PCREL): New pcrel tls relocs.
	* elf64-ppc.c (ppc64_elf_howto_raw): Add howtos for pcrel tls relocs.
	(ppc64_elf_reloc_type_lookup): Translate pcrel tls relocs.
	(must_be_dyn_reloc, dec_dynrel_count): Add R_PPC64_TPREL64.
	(ppc64_elf_check_relocs): Support pcrel tls relocs.
	(ppc64_elf_tls_optimize, ppc64_elf_relocate_section): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
gas/
	* config/tc-ppc.c (ppc_elf_suffix): Map "tls@pcrel", "got@tlsgd@pcrel",
	"got@tlsld@pcrel", "got@tprel@pcrel", and "got@dtprel@pcrel".
	(fixup_size, md_assemble): Handle pcrel tls relocs.
	(ppc_force_relocation, ppc_fix_adjustable): Likewise.
	(md_apply_fix, tc_gen_reloc): Likewise.
ld/
	* testsuite/ld-powerpc/tlsgd.d,
	* testsuite/ld-powerpc/tlsgd.s,
	* testsuite/ld-powerpc/tlsie.d,
	* testsuite/ld-powerpc/tlsie.s,
	* testsuite/ld-powerpc/tlsld.d,
	* testsuite/ld-powerpc/tlsld.s: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2019-07-19 18:01:25 +09:30
Alan Modra 7a70898417 [PowerPC] Rename testcase
Just making room for a new tlsld test.

	* testsuite/ld-powerpc/tlsldopt.d: Rename from tlsld.d.
	* testsuite/ld-powerpc/tlsldopt.s: Rename from tlsld.s.
	* testsuite/ld-powerpc/tlsldopt32.d: Rename from tlsld32.d.
	* testsuite/ld-powerpc/tlsldopt32.s: Rename from tlsld32.s.
	* testsuite/ld-powerpc/powerpc.exp: Update.
2019-07-19 18:01:25 +09:30
Alan Modra 60d53d7f03 PowerPC notoc call stub tests
* testsuite/ld-powerpc/callstub-1.d,
	* testsuite/ld-powerpc/callstub-1.s: New test.
	* testsuite/ld-powerpc/callstub-2.d,
	* testsuite/ld-powerpc/callstub-2.s: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2019-06-28 10:16:17 +09:30
Alan Modra 04bdff6a76 PowerPC notoc linkage stubs
Use pcrel addressing instructions in linkage stubs.

bfd/
	* elf64-ppc.c: Comment on powerxx _notoc stub variants.
	(LI_R11_0, LIS_R11, ORI_R11_R11_0, SLDI_R11_R11_34): Define.
	(PADDI_R12_PC, PLD_R12_PC, D34, HA34): Define.
	(struct ppc_link_hash_table): Add powerxx_stubs.
	(ppc64_elf_check_relocs): Set powerxx_stubs.
	(build_powerxx_offset, size_powerxx_offset),
	(num_relocs_for_powerxx_offset),
	(emit_relocs_for_powerxx_offset): New functions.
	(plt_stub_size): Size powerxx stubs.
	(ppc_build_one_stub): Emit powerxx stubs.
	(ppc_size_one_stub): Size powerxx stubs.  Omit .eh_frame for
	powerxx stubs.
ld/
	* testsuite/ld-powerpc/notoc2.d,
	* testsuite/ld-powerpc/notoc2.s: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2019-05-24 10:28:07 +09:30
Alan Modra 4a421c53cf PowerPC GOT_PCREL34 optimisation
bfd/
	* elf64-ppc.c (ppc64_elf_check_relocs): Set has_gotrel for
	R_PPC64_GOT_PCREL34.
	(xlate_pcrel_opt): New function.
	(ppc64_elf_edit_toc): Handle R_PPC64_GOT_PCREL34.
	(ppc64_elf_relocate_section): Edit GOT indirect to GOT relative
	for R_PPC64_GOT_PCREL34.  Implement R_PPC64_PCREL_OPT optimisation.
ld/
	* testsuite/ld-powerpc/pcrelopt.s,
	* testsuite/ld-powerpc/pcrelopt.d,
	* testsuite/ld-powerpc/pcrelopt.sec: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2019-05-24 10:27:53 +09:30
Alan Modra 827041555a Update year range in copyright notice of binutils files 2019-01-01 22:06:53 +10:30
Alan Modra ba85c15dab PR23937, powerpc64le local ifunc IRELATIVE relocs are wrong
IFUNC resolvers must always be called via their global entry point.
They will be called from ld.so rather than from the local executable.

	PR 23937
bfd/
	* elf64-ppc.c (write_plt_relocs_for_local_syms): Don't add local
	entry offset for ifuncs.
ld/
	* testsuite/ld-powerpc/pr23937.d,
	* testsuite/ld-powerpc/pr23937.s: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2018-11-30 16:18:58 +10:30
Alan Modra df136d64fa PowerPC64 EH info for _notoc linkage stubs
This patch generates EH info for the new _notoc linkage stubs, to
support unwinding from asynchronous signal handlers.  Unwinding
through the __tls_get_addr_opt stub was already supported, but that
was just a single stub.  With multiple stubs the EH opcodes need to be
emitted and sized when iterating over stubs, so this is done when
emitting and sizing the stub code.  Emitting the CIEs and FDEs is done
when sizing the stubs, as we did before in order to have the linker
generated FDEs indexed in .eh_frame_hdr.  I moved the final tweaks to
FDEs from ppc64_elf_finish_dynamic_sections to ppc64_elf_build_stubs
simply because it's tidier to be done with them at that point.

bfd/
	* elf64-ppc.c (struct map_stub): Delete tls_get_addr_opt_bctrl.
	Add lr_restore, eh_size and eh_base.
	(eh_advance, eh_advance_size): New functions.
	(build_tls_get_addr_stub): Emit EH info for stub.
	(ppc_build_one_stub): Likewise for _notoc stubs.
	(ppc_size_one_stub): Size EH info for stub.
	(group_sections): Init new map_stub fields.
	(stub_eh_frame_size): Delete.
	(ppc64_elf_size_stubs): Size EH info for stubs.  Set up dummy EH
	program for stubs.
	(ppc64_elf_build_stubs): Reinit new map_stub fields.  Set FDE
	offset to stub section here..
	(ppc64_elf_finish_dynamic_sections): ..rather than here.
ld/
	* testsuite/ld-powerpc/notoc.s: Generate some cfi.
	* testsuite/ld-powerpc/notoc.d: Adjust.
	* testsuite/ld-powerpc/notoc.wf: New file.
	* testsuite/ld-powerpc/powerpc.exp: Run "ext" and "notoc" tests
	as run_ld_link_tests rather than run_dump_test.
2018-08-07 18:43:55 +09:30
Alan Modra 05d0e962f0 R_PPC64_REL24_NOTOC support
R_PPC64_REL24_NOTOC is used on calls like "bl foo@notoc" to tell the
linker that linkage stubs for PLT calls or long branches can't use r2
for pic addressing.  Instead, new stubs that generate pc-relative
addresses are used.  One complication is that pc-relative offsets to
the PLT may need to be 64-bit in large programs, in contrast to the
toc-relative addressing used by older PLT linkage stubs where a 32-bit
offset is sufficient until the PLT itself exceeds 2G in size.

.eh_frame info to cover the _notoc stubs is yet to be implemented.

bfd/
	* elf64-ppc.c (ADDI_R12_R11, ADDI_R12_R12, LIS_R12),
	(ADDIS_R12_R11, ORIS_R12_R12_0, ORI_R12_R12_0),
	(SLDI_R12_R12_32, LDX_R12_R11_R12, ADD_R12_R11_R12): Define.
	(ppc64_elf_howto_raw): Add R_PPC64_REL24_NOTOC entry.
	(ppc64_elf_reloc_type_lookup): Support R_PPC64_REL24_NOTOC.
	(ppc_stub_type): Add ppc_stub_long_branch_notoc,
	ppc_stub_long_branch_both, ppc_stub_plt_branch_notoc,
	ppc_stub_plt_branch_both, ppc_stub_plt_call_notoc, and
	ppc_stub_plt_call_both.
	(is_branch_reloc): Add R_PPC64_REL24_NOTOC.
	(build_offset, size_offset): New functions.
	(plt_stub_size): Support plt_call_notoc and plt_call_both.
	(ppc_build_one_stub, ppc_size_one_stub): Support new stubs.
	(toc_adjusting_stub_needed): Handle R_PPC64_REL24_NOTOC.
	(ppc64_elf_size_stubs): Likewise, and new stubs.
	(ppc64_elf_build_stubs, ppc64_elf_relocate_section): Likewise.
	* reloc.c: Add BFD_RELOC_PPC64_REL24_NOTOC.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
gas/
	* config/tc-ppc.c (ppc_elf_suffix): Support @notoc.
	(ppc_force_relocation, ppc_fix_adjustable): Handle REL24_NOTOC.
ld/
	* testsuite/ld-powerpc/ext.d,
	* testsuite/ld-powerpc/ext.s,
	* testsuite/ld-powerpc/ext.lnk,
	* testsuite/ld-powerpc/notoc.d,
	* testsuite/ld-powerpc/notoc.s: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2018-08-05 12:11:51 +09:30
Alan Modra a67ae9b01a Re: PowerPC64 __tls_get_addr_opt stub .eh_frame fix
The modified test failed on some powerpc targets due to differences in
default hash style.  If the default hash style is both, then more
sections are created, bumping section ids.  Section id is used in stub
symbols and although the test is careful to not depend on id in
labels, the stub hash traversal order changes when stub names change.
That lead to the stubs being emitted in a different order and thus not
matching expected output.

	* testsuite/ld-powerpc/powerpc.exp: Run tlsopt5 with hash-style
	specified.
2018-08-01 19:06:37 +09:30
Alan Modra 1aa4214141 PowerPC64 __tls_get_addr_opt stub .eh_frame fix
This patch sets stub_offset in ppc_size_one_stub rather than in
ppc_build_one_stub.  That allows the plt stub alignment to be done in
just ppc_size_one_stub rather than both functions.  The patch also
corrects the place where the alignment was done, fixing a possible
error in .eh_frame data, and tidies some offset calculations.

bfd/
	* elf64-ppc.c (plt_stub_pad): Delay plt_stub_size call until needed.
	(ppc_build_one_stub): Don't set stub_offset, instead assert that
	it is sane.  Don't adjust stub_offset for alignment.  Adjust size
	calculation.  Use "targ" temp when calculating offsets.
	(ppc_size_one_stub): Set stub_offset here.  Use "targ" temp when
	calculating offsets.  Adjust for alignment before setting
	tls_get_addr_opt_bctrl.
ld/
	* testsuite/ld-powerpc/powerpc.exp: Run tlsopt5 with plt alignment.
	* testsuite/ld-powerpc/tlsopt5.s: Add extra call.
	* testsuite/ld-powerpc/tlsopt5.wf: Adjust expected output.
	* testsuite/ld-powerpc/tlsopt5.d: Likewise.
2018-08-01 12:14:22 +09:30
Alan Modra 491993044b Enhance powerpc ld -r --relax
One of the ill effects of ld -r is to mash together sections.  That
can result in reduced icache performance at runtime due to unexpected
movement of code.  Another problem is that sections can become too
large to link on targets that have limited relative addressing.  ld -r
--relax attempts to overcome the large section problem for branches by
inserting trampolines, but the powerpc support added lots of
unnecessary trampolines.  This patch trims them somewhat.

bfd/
	* elf32-ppc.c (ppc_elf_relax_section): Ignore common or undef locals.
	Avoid trashing toff with added when used as a symbol index.
	Ignore R_PPC_PLTREL24 addends in unused example code.  Avoid
	creating unnecessary fixups when relocatable.
ld/
	* testsuite/ld-powerpc/big.s: New file.
	* testsuite/ld-powerpc/relaxrl.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run new test.
	* testsuite/ld-powerpc/relaxr.d: Adjust.
2018-07-25 16:52:58 +09:30
Alan Modra b4b594e304 Remove netware support
include/
	* nlm/ChangeLog-9315: Delete.
	* nlm/alpha-ext.h: Delete.
	* nlm/common.h: Delete.
	* nlm/external.h: Delete.
	* nlm/i386-ext.h: Delete.
	* nlm/internal.h: Delete.
	* nlm/ppc-ext.h: Delete.
	* nlm/sparc32-ext.h: Delete.
bfd/
	* Makefile.am: Remove netware support.
	* bfd-in.h: Likewise.
	* bfd.c: Likewise.
	* config.bfd: Likewise.
	* configure.ac: Likewise.
	* doc/bfdint.texi: Likewise.
	* ecoff.c: Likewise.
	* targets.c: Likewise.
	* libnlm.h: Delete.
	* nlm-target.h: Delete.
	* nlm.c: Delete.
	* nlm32-alpha.c: Delete.
	* nlm32-i386.c: Delete.
	* nlm32-ppc.c: Delete.
	* nlm32-sparc.c: Delete.
	* nlm32.c: Delete.
	* nlm64.c: Delete.
	* nlmcode.h: Delete.
	* nlmswap.h: Delete.
	* Makefile.in: Regenerate.
	* bfd-in2.h: Regenerate.
	* configure: Regenerate.
	* po/SRC-POTFILES.in: Regenerate.
binutils/
	* .gitignore: Remove netware support.
	* Makefile.am: Likewise.
	* configure.ac: Likewise.
	* doc/Makefile.am: Likewise.
	* doc/binutils.texi: Likewise.
	* testsuite/binutils-all/nm.exp: Likewise.
	* nlmconv.c: Delete.
	* nlmconv.h: Delete.
	* nlmheader.y: Delete.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* doc/Makefile.in: Regenerate.
	* po/POTFILES.in: Regenerate.
gas/
	* Makefile.am: Remove netware support.
	* config/tc-i386.c: Likewise.
	* configure.tgt: Likewise.
	* config/te-netware.h: Delete.
	* Makefile.in: Regenerate.
	* po/POTFILES.in: Regenerate.
gprof/
	* corefile.c: Remove netware support.
ld/
	* Makefile.am: Remove netware support.
	* configure.tgt: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
	* emulparams/i386nw.sh: Delete.
	* emulparams/ppcnw.sh: Delete.
	* scripttempl/nw.sc: Delete.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
2018-04-16 15:11:22 +09:30
Alan Modra 407aa07cee Revert "PowerPC PLT speculative execution barriers"
This reverts most of commit 1be5d8d3bb.
Left in place are addition of --no-plt-align to some ppc32 ld tests
and the ld.texinfo --no-plt-thread-safe fix.
2018-02-07 14:23:08 +10:30
Alan Modra 1be5d8d3bb PowerPC PLT speculative execution barriers
Spectre variant 2 mitigation for PowerPC and PowerPC64.

bfd/
	* elf32-ppc.c (GLINK_ENTRY_SIZE): Handle speculation barrier.
	(CRSETEQ, BEQCTRM): Define.
	(is_nonpic_glink_stub): Don't check bctr.
	(ppc_elf_link_hash_table_create): Init new ppc_elf_params field.
	(ppc_elf_relax_section): Size speculation barrier.
	(output_bctr): New function.
	(write_glink_stub): Use output_bctr.
	(ppc_elf_relocate_section): Use output_bctr for long branch stub.
	(ppc_elf_finish_dynamic_symbol): Likewise.
	(ppc_elf_finish_dynamic_sections): Use output_bctr.
	* elf32-ppc.h (struct ppc_elf_params): Add speculate_indirect_jumps.
	* elf64-ppc.c (CRSETEQ, BEQCTRM, BEQCTRLM): Define.
	(GLINK_PLTRESOLVE_SIZE): Size speculation barrier.
	(size_global_entry_stubs): Handle speculation barrier sizing.
	(plt_stub_size): Likewise.
	(output_bctr): New function.
	(build_plt_stub, build_tls_get_addr_stub): Output speculation
	barrier.
	(ppc_build_one_stub): Likewise for ppc_stub_plt_branch.
	(ppc_size_one_stub): Size speculation barrier in ppc_stub_plt_branch.
	(build_global_entry_stubs): Output speculation barrier.
	(ppc64_elf_build_stubs): Likewise in __glink_PLTresolve stub.
	* elf64-ppc.h (struct ppc64_elf_params): Add speculate_indirect_jumps.
gold/
	* options.h (speculate_indirect_jumps): New option.
	* powerpc.cc (beqctrm, beqctrlm, crseteq): New insn constants.
	(output_bctr): New function.
	(Stub_table::plt_call_size): Add space for speculation barrier.
	(Stub_table::branch_stub_size): Likewise.
	(Output_data_glink::pltresolve_size): Likewise.
	(Stub_table::do_write): Output speculation barriers.
ld/
	* emultempl/ppc32elf.em (params): Init new field.
	(OPTION_SPECULATE_INDIRECT_JUMPS): Define.
	(OPTION_NO_SPECULATE_INDIRECT_JUMPS): Define.
	(PARSE_AND_LIST_LONGOPTS): Handle new options.
	(PARSE_AND_LIST_ARGS_CASES): Likewise.
	(PARSE_AND_LIST_OPTIONS): Likewise.
	* emultempl/ppc64elf.em (params): Init new field.
	(OPTION_SPECULATE_INDIRECT_JUMPS): Define.
	(OPTION_NO_SPECULATE_INDIRECT_JUMPS): Define.
	(PARSE_AND_LIST_LONGOPTS): Handle --speculate-indirect-jumps.
	(PARSE_AND_LIST_OPTIONS): Likewise.
	(PARSE_AND_LIST_ARGS_CASES): Likewise.
	* ld.texinfo (--no-plt-thread-safe): Correct itemx.
	(--speculate-indirect-jumps): Document.
	* testsuite/ld-powerpc/elfv2exe.d,
	* testsuite/ld-powerpc/elfv2so.d,
	* testsuite/ld-powerpc/relbrlt.d,
	* testsuite/ld-powerpc/powerpc.exp: Disable plt alignment and
	speculation barriers on various tests.
2018-01-17 18:52:57 +10:30
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Alan Modra 97d4213f68 Modify ppceabi ld tests to run on all powerpc ELF targets
* testsuite/ld-powerpc/powerpc.exp (ppceabitests): Add -a32 -mbig
	to assembler options, and -melf32ppc to linker options.  Always
	run these tests.
2017-12-04 10:23:57 +10:30
Alan Modra 2420fff633 PowerPC64 --plt-align
This changes the PowerPC64 --plt-align option to perform the usual
alignment of code as suggested by its name, as well as the previous
behaviour of padding so as to reduce boundary crossing.  The old
behaviour is had by using a negative parameter.

The default is also changed to align plt stub code by default to 32
byte boundaries, the point being to get better bctr branch prediction
on power8 and power9 hardware.

bfd/
	* elf64-ppp.c (plt_stub_pad): Handle positive and negative
	plt_stub_align.
ld/
	* ld.texinfo (--plt-align): Describe new behaviour of option.
	* emultempl/ppc64elf.em (params): Default plt_stub_align to 5.
	* testsuite/ld-powerpc/powerpc.exp: Pass --no-plt-align for
	selected tests.
	* testsuite/ld-powerpc/relbrlt.d: Pass --no-plt-align.
	* testsuite/ld-powerpc/elfv2so.d: Adjust expected output.
2017-09-10 01:55:16 +09:30
Alan Modra 9a23f96e91 PowerPC TPREL16_HA/LO reloc optimization
In the TLS GD/LD to LE optimization, ld replaces a sequence like

 addi 3,2,x@got@tlsgd		R_PPC64_GOT_TLSGD16	x
 bl __tls_get_addr(x@tlsgd)	R_PPC64_TLSGD		x
				R_PPC64_REL24		__tls_get_addr
 nop

with

 addis 3,13,x@tprel@ha		R_PPC64_TPREL16_HA	x
 addi 3,3,x@tprel@l		R_PPC64_TPREL16_LO	x
 nop

When the tprel offset is small, this can be further optimized to

 nop
 addi 3,13,x@tprel
 nop

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add do_tls_opt.
	(ppc64_elf_tls_optimize): Set it.
	(ppc64_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO and TPREL16_LO_DS relocs to use r13 when
	addis would add zero.
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Add do_tls_opt.
	(ppc_elf_tls_optimize): Set it.
	(ppc_elf_relocate_section): Nop addis on TPREL16_HA, and convert
	insn on TPREL16_LO relocs to use r2 when addis would add zero.
gold/
	* powerpc.cc (Target_powerpc::Relocate::relocate): Nop addis on
	TPREL16_HA, and convert insn on TPREL16_LO and TPREL16_LO_DS
	relocs to use r2/r13 when addis would add zero.
ld/
	* testsuite/ld-powerpc/tls.s: Add calls with tls markers.
	* testsuite/ld-powerpc/tls32.s: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Run tls marker tests.
	* testsuite/ld-powerpc/tls.d: Adjust for TPREL16_HA/LO optimization.
	* testsuite/ld-powerpc/tlsexe.d: Likewise.
	* testsuite/ld-powerpc/tlsexetoc.d: Likewise.
	* testsuite/ld-powerpc/tlsld.d: Likewise.
	* testsuite/ld-powerpc/tlsmark.d: Likewise.
	* testsuite/ld-powerpc/tlsopt4.d: Likewise.
	* testsuite/ld-powerpc/tlstoc.d: Likewise.
2017-08-30 20:43:31 +09:30
Alan Modra bab55c0522 Support different ld --hash-style in the ld testsuite
When ld is running with something other than --hash-style=sysv by
default, numerous tests need tweaking.  Most of the changes just add
--hash-style=sysv.  I didn't want to make --hash-style=sysv global as
that means --hash-style=gnu isn't well tested.

	* testsuite/ld-alpha/alpha.exp: Add --hash-style=sysv to various
	test's ld options.
	* testsuite/ld-arm/arm-elf.exp: Likewise.
	* testsuite/ld-elf/elf.exp: Likewise.
	* testsuite/ld-elf/readelf.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-i386/i386.exp: Likewise.
	* testsuite/ld-ia64/ia64.exp: Likewise.
	* testsuite/ld-m68k/m68k.exp: Likewise.
	* testsuite/ld-metag/metag.exp: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
	* testsuite/ld-s390/s390.exp: Likewise.
	* testsuite/ld-sh/sh-vxworks.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-sparc/sparc.exp: Likewise.
	* testsuite/ld-tic6x/tic6x.exp: Likewise.
	* testsuite/ld-vax-elf/vax-elf.exp: Likewise.
	* testsuite/ld-x86-64/mpx.exp: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-xtensa/xtensa.exp: Likewise.

	* testsuite/ld-elf/comm-data2.ld: Add .gnu.hash output section.
	* testsuite/ld-elf/pr20828-v.ld: Likewise.
	* testsuite/ld-elf/pr20828.ld: Likewise.
	* testsuite/ld-elf/pr21233.ld: Likewise.
	* testsuite/ld-elf/pr21384.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-1.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-2.ld: Likewise.
	* testsuite/ld-elf/provide-hidden-s.ld: Likewise.
	* testsuite/ld-scripts/cross1.t: Likewise.

	* testsuite/ld-elf/stab.d: Adjust allowed section indices.

	* testsuite/ld-i386/pie1.d: Don't match addresses.
	* testsuite/ld-i386/plt-pic2.dd: Likewise.
	* testsuite/ld-i386/pr19636-1d.d: Likewise.
	* testsuite/ld-i386/pr19636-2c.d: Likewise.
	* testsuite/ld-powerpc/elfv2so.d: Likewise.
	* testsuite/ld-powerpc/tlsopt5.d: Likewise.
	* testsuite/ld-powerpc/tlsopt5.wf: Likewise.
	* testsuite/ld-powerpc/tlsopt5_32.d: Likewise.

	* testsuite/ld-i386/pr19636-2b.d: Don't match _start.

	* testsuite/ld-powerpc/ambiguousv1.d: Relax symbol count, index
	and address match.
	* testsuite/ld-powerpc/ambiguousv1b.d: Likewise.
	* testsuite/ld-powerpc/ambiguousv2.d: Likewise.
	* testsuite/ld-powerpc/ambiguousv2b.d: Likewise.

	* testsuite/ld-aarch64/gc-plt-relocs.d: Run ld with --hash-style=sysv.
	* testsuite/ld-aarch64/ifunc-1.d: Likewise.
	* testsuite/ld-aarch64/ifunc-2.d: Likewise.
	* testsuite/ld-aarch64/ifunc-21.d: Likewise.
	* testsuite/ld-aarch64/relasz.d: Likewise.
	* testsuite/ld-aarch64/tls-small-ld.d: Likewise.
	* testsuite/ld-aarch64/tls-tiny-ld.d: Likewise.
	* testsuite/ld-arc/tls_gd-01.d: Likewise.
	* testsuite/ld-cris/libdso-10.d: Likewise.
	* testsuite/ld-cris/libdso-2.d: Likewise.
	* testsuite/ld-cris/pic-gc-72.d: Likewise.
	* testsuite/ld-cris/pic-gc-73.d: Likewise.
	* testsuite/ld-cris/tls-gd-1.d: Likewise.
	* testsuite/ld-cris/tls-gd-1h.d: Likewise.
	* testsuite/ld-cris/tls-gd-2.d: Likewise.
	* testsuite/ld-cris/tls-gd-2h.d: Likewise.
	* testsuite/ld-cris/tls-ie-10.d: Likewise.
	* testsuite/ld-cris/tls-ie-11.d: Likewise.
	* testsuite/ld-cris/tls-ie-8.d: Likewise.
	* testsuite/ld-cris/tls-ie-9.d: Likewise.
	* testsuite/ld-cris/tls-ld-4.d: Likewise.
	* testsuite/ld-cris/tls-ld-5.d: Likewise.
	* testsuite/ld-cris/tls-ld-6.d: Likewise.
	* testsuite/ld-cris/tls-ld-7.d: Likewise.
	* testsuite/ld-cris/tls-ldgd-14.d: Likewise.
	* testsuite/ld-cris/tls-ldgd-15.d: Likewise.
	* testsuite/ld-cris/tls-ldgdx-14.d: Likewise.
	* testsuite/ld-cris/tls-ldgdx-15.d: Likewise.
	* testsuite/ld-cris/tls-local-54.d: Likewise.
	* testsuite/ld-cris/tls-local-60.d: Likewise.
	* testsuite/ld-cris/tls-local-61.d: Likewise.
	* testsuite/ld-cris/weakhiddso.d: Likewise.
	* testsuite/ld-elf/linkinfo1a.d: Likewise.
	* testsuite/ld-elf/linkinfo1b.d: Likewise.
	* testsuite/ld-elf/pr19617a.d: Likewise.
	* testsuite/ld-elfvsb/hidden2.d: Likewise.
	* testsuite/ld-frv/fdpic-pie-6.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-2.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-5.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-6.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-8.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-local-2.d: Likewise.
	* testsuite/ld-frv/fdpic-shared-local-8.d: Likewise.
	* testsuite/ld-frv/tls-dynamic-2.d: Likewise.
	* testsuite/ld-i386/ibt-plt-1.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-2c.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3a.d: Likewise.
	* testsuite/ld-i386/ibt-plt-3c.d: Likewise.
	* testsuite/ld-i386/pr20830.d: Likewise.
	* testsuite/ld-ia64/merge1.d: Likewise.
	* testsuite/ld-ia64/merge2.d: Likewise.
	* testsuite/ld-ia64/merge3.d: Likewise.
	* testsuite/ld-ia64/merge4.d: Likewise.
	* testsuite/ld-ia64/merge5.d: Likewise.
	* testsuite/ld-ifunc/ifunc-1-local-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-1-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-3a-x86.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-i386.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
	* testsuite/ld-m68k/got-1.d: Likewise.
	* testsuite/ld-m68k/got-multigot-12-13-14-34-35-ok.d: Likewise.
	* testsuite/ld-m68k/got-multigot-14-ok.d: Likewise.
	* testsuite/ld-m68k/got-multigot-15-er.d: Likewise.
	* testsuite/ld-m68k/got-negative-12-13-14-34-ok.d: Likewise.
	* testsuite/ld-m68k/got-negative-12-13-14-35-er.d: Likewise.
	* testsuite/ld-m68k/got-negative-14-ok.d: Likewise.
	* testsuite/ld-m68k/got-negative-15-er.d: Likewise.
	* testsuite/ld-m68k/got-single-12-ok.d: Likewise.
	* testsuite/ld-m68k/got-single-13-er.d: Likewise.
	* testsuite/ld-m68k/got-xgot-12-13-14-15-34-35-ok.d: Likewise.
	* testsuite/ld-m68k/got-xgot-15-ok.d: Likewise.
	* testsuite/ld-m68k/tls-gd-1.d: Likewise.
	* testsuite/ld-m68k/tls-gd-2.d: Likewise.
	* testsuite/ld-m68k/tls-gd-ie-1.d: Likewise.
	* testsuite/ld-m68k/tls-ie-1.d: Likewise.
	* testsuite/ld-m68k/tls-ld-1.d: Likewise.
	* testsuite/ld-m68k/tls-ld-2.d: Likewise.
	* testsuite/ld-sh/shared-2.d: Likewise.
	* testsuite/ld-sh/tlsbin-2.d: Likewise.
	* testsuite/ld-sh/tlspic-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-1.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise.
	* testsuite/ld-x86-64/bnd-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-1.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ilp32-4-nacl.d: Likewise.
	* testsuite/ld-x86-64/ilp32-4.d: Likewise.
	* testsuite/ld-x86-64/load1c-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1c.d: Likewise.
	* testsuite/ld-x86-64/load1d-nacl.d: Likewise.
	* testsuite/ld-x86-64/load1d.d: Likewise.
	* testsuite/ld-x86-64/pie3-nacl.d: Likewise.
	* testsuite/ld-x86-64/pie3.d: Likewise.
	* testsuite/ld-x86-64/pr14207.d: Likewise.
	* testsuite/ld-x86-64/pr19162.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d-nacl.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1d.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1f.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1j.d: Likewise.
	* testsuite/ld-x86-64/pr20253-1l.d: Likewise.
	* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830b.d: Likewise.
	* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2017-08-07 22:10:51 +09:30
Alan Modra d4aaa2a074 __tls_get_addr_opt stub eh_frame info
Since the __tls_get_addr_opt stub saves LR and makes a call, eh_frame
info should be generated to describe how to unwind through the stub.

The patch also changes the way the backend iterates over stubs, from
looking at all sections in stub_bfd to which all dynamic sections are
attached as well, to iterating over the group list, which gets just
the stub sections.  Most binaries will have just one or two stub
groups, so this is a little faster.

bfd/
	* elf64-ppc.c (struct map_stub): Add tls_get_addr_opt_bctrl.
	(stub_eh_frame_size): New function.
	(ppc_size_one_stub): Set group tls_get_addr_opt_bctrl.
	(group_sections): Init group tls_get_addr_opt_bctrl.
	(ppc64_elf_size_stubs): Update sizing and initialization of
	.eh_frame.  Iteration over stubs via group list.
	(ppc64_elf_build_stubs): Iterate over stubs via group list.
	(ppc64_elf_finish_dynamic_sections): Update finalization of
	.eh_frame.
ld/
	* testsuite/ld-powerpc/tlsopt5.s: Add cfi.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
	* testsuite/ld-powerpc/tlsopt5.wf: New file.
	* testsuite/ld-powerpc/powerpc.exp: Perform new tlsopt5 test.
2017-07-25 15:14:39 +09:30
Alan Modra 86038de0d8 ppc32 tlsopt tests
These all were odd in that they used r13 as the GOT pointer.  That
didn't matter for the purpose of testing, but would never occur in
practice.  Also, the tlsopt5 tests could have their global dynamic
sequences optimized to initial exec, so link with -shared.

	* testsuite/ld-powerpc/powerpc.exp: Add -shared to tlsop5 tests.
	* testsuite/ld-powerpc/tlsopt5.d: Adjust.
	* testsuite/ld-powerpc/tlsopt1_32.s: Use r30 as GOT pointer.
	* testsuite/ld-powerpc/tlsopt2_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt3_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt4_32.s: Likewise.
	* testsuite/ld-powerpc/tlsopt5_32.s: Rewrite.
	* testsuite/ld-powerpc/tlsopt1_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt2_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt3_32.d: Adjust.
	* testsuite/ld-powerpc/tlsopt5_32.d: Adjust.
2017-07-14 22:51:01 +09:30
Alan Modra 81209eff90 PowerPC64 tocsave testcases
* testsuite/ld-powerpc/powerpc.exp: Run TOCSAVE tests.
	* testsuite/ld-powerpc/tocsave1.s,
	* testsuite/ld-powerpc/tocsave1a.d,
	* testsuite/ld-powerpc/tocsave1s.d,
	* testsuite/ld-powerpc/tocsave2.s,
	* testsuite/ld-powerpc/tocsave2a.d,
	* testsuite/ld-powerpc/tocsave2s.d,
	* testsuite/ld-powerpc/tocsavelib.s: New files.
2017-06-21 22:45:15 +09:30
Alan Modra f378ab099d PPC64_OPT_LOCALENTRY
ELFv2 functions with localentry:0 are those with a single entry point,
ie. global entry == local entry, and that have no requirement on r2 or
r12, and guarantee r2 is unchanged on return.  Such an external
function can be called via the PLT without saving r2 or restoring it
on return, avoiding a common load-hit-store for small functions.   The
optimization is attractive.  The TOC pointer load-hit-store is a major
reason why calls to small functions that need no register saves, or
with shrink-wrap, no register saves on a fast path, are slow on
powerpc64le.

To be safe, this optimization needs ld.so support to check that the
run-time matches link-time function implementation.  If a function
in a shared library with st_other localentry non-zero is called
without saving and restoring r2, r2 will be trashed on return, leading
to segfaults.  For that reason the optimization does not happen for
weak functions since a weak definition is a fairly solid hint that the
function will likely be overridden.  I'm also not enabling the
optimization by default unless glibc-2.26 is detected, which should
have the ld.so checks implemented.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add has_plt_localentry0.
	(ppc64_elf_merge_symbol_attribute): Merge localentry bits from
	dynamic objects.
	(is_elfv2_localentry0): New function.
	(ppc64_elf_tls_setup): Default params->plt_localentry0.
	(plt_stub_size): Adjust size for tls_get_addr_opt stub.
	(build_tls_get_addr_stub): Use a simpler stub when r2 is not saved.
	(ppc64_elf_size_stubs): Leave stub_type as ppc_stub_plt_call for
	optimized localentry:0 stubs.
	(ppc64_elf_build_stubs): Save r2 in ELFv2 __glink_PLTresolve.
	(ppc64_elf_relocate_section): Leave nop unchanged for optimized
	localentry:0 stubs.
	(ppc64_elf_finish_dynamic_sections): Set PPC64_OPT_LOCALENTRY in
	DT_PPC64_OPT.
	* elf64-ppc.h (struct ppc64_elf_params): Add plt_localentry0.
include/
	* elf/ppc64.h (PPC64_OPT_LOCALENTRY): Define.
ld/
	* emultempl/ppc64elf.em (params): Init plt_localentry0 field.
	(enum ppc64_opt): New, replacing OPTION_* defines.  Add
	OPTION_PLT_LOCALENTRY, and OPTION_NO_PLT_LOCALENTRY.
	(PARSE_AND_LIST_*): Support --plt-localentry and --no-plt-localentry.
	* testsuite/ld-powerpc/elfv2so.d: Update.
	* testsuite/ld-powerpc/powerpc.exp (TLS opt 5): Use --no-plt-localentry.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
2017-06-01 22:47:32 +09:30
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra 39eeab2534 PowerPC64 toc optimisation for power9
Recognize power9 and a few other insns from older machines.  Fixes
linker complaints like "toc optimization is not supported for
0xf4090002 instruction".  0xf4090002 is stxsd v0,0(r9)

bfd/
	* elf64-ppc.c (ok_lo_toc_insn): Add r_type param.  Recognize
	lq,lfq,lxv,lxsd,lxssp,lfdp,stq,stfq,stxv,stxsd,stxssp,stfdp.
	Don't match lmd and stmd.
ld/
	* testsuite/ld-powerpc/tocopt7.s,
	* testsuite/ld-powerpc/tocopt7.out,
	* testsuite/ld-powerpc/tocopt7.d: New test.
	* testsuite/ld-powerpc/tocopt8.s,
	* testsuite/ld-powerpc/tocopt8.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2016-12-06 18:25:14 +10:30
Alan Modra 8c5b4e5228 PowerPC64 dot-symbol compatibility bugfixes
Lots of fixes for the compatibility code that handles linking of
-mcall-aixdesc code (or that generated by 12 year old gcc) with
current ELFv1 ABI code.

1) A reference to a dot-symbol in an object file wasn't satisfied by a
   function descriptor in later object files.
2) The as-needed code had bit-rotted;  Shared libs now need a strong
   reference to be counted as needed.
3) --gc-sections involving dot-symbols was broken, needing
   func_desc_adjust to be run early and lots of other fixes.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_entry): Delete "was_undefined".
	(struct ppc_link_hash_table): Delete "twiddled_syms".  Add
	"need_func_desc_adj".
	(lookup_fdh): Link direct fdh sym via oh field and set flags.
	(make_fdh): Make strong and weak undefined function descriptor
	symbols.
	(ppc64_elf_merge_symbol): New function.
	(elf_backend_merge_symbol): Define.
	(ppc64_elf_archive_symbol_lookup): Don't test undefweak for fake
	function descriptors.
	(add_symbol_adjust): Don't twiddle symbols to undefweak.
	Propagate more ref flags to function descriptor symbol.  Make
	some function descriptor symbols dynamic.
	(ppc64_elf_before_check_relocs): Only run add_symbol_adjust for
	ELFv1.  Set need_func_desc_adj.  Don't fix undefs list.
	(ppc64_elf_check_relocs): Set non_ir_ref for descriptors.
	Don't call lookup_fdh here.
	(ppc64_elf_gc_sections): New function.
	(bfd_elf64_bfd_gc_sections): Define.
	(ppc64_elf_gc_mark_hook): Mark descriptor.
	(func_desc_adjust): Don't make fake function descriptor syms strong
	here.  Exit earlier on non-dotsyms.  Take note of elf.dynamic
	flag when deciding whether a dynamic function descriptor might
	be needed.  Transfer elf.dynamic and set elf.needs_plt.  Move
	plt regardless of visibility.  Make descriptor dynamic if
	entry sym is dynamic, not for other cases.
	(ppc64_elf_func_desc_adjust): Don't run func_desc_adjust if
	already done.
	(ppc64_elf_edit_opd): Use oh field rather than lookup_fdh.
	(ppc64_elf_size_stubs): Likewise.
	(ppc_build_one_stub): Don't clear was_undefined.  Only set sym
	undefweak if stub symbol is defined.
	(undo_symbol_twiddle, ppc64_elf_restore_symbols): Delete.
	* elf64-ppc.h (ppc64_elf_restore_symbols): Don't declare.
ld/
	* emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Don't call
	ppc64_elf_restore_symbols.
	* testsuite/ld-powerpc/dotsym1.d: New.
	* testsuite/ld-powerpc/dotsym2.d: New.
	* testsuite/ld-powerpc/dotsym3.d: New.
	* testsuite/ld-powerpc/dotsym4.d: New.
	* testsuite/ld-powerpc/dotsymref.s: New.
	* testsuite/ld-powerpc/nodotsym.s: New.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2016-12-03 21:00:01 +10:30
Alan Modra 005d79fd61 PowerPC .gnu.attributes
This patch extends Tag_GNU_Power_ABI_FP to cover long double ABIs,
makes the assembler warn about undefined tag values, and removes
similar warnings from the linker.  I think it is better to not
warn in the linker about undefined tag values as future extensions to
the tags then won't result in likely bogus warnings.  This is
consistent with the fact that an older linker won't warn on an
entirely new tag.

include/
	* elf/ppc.h (Tag_GNU_Power_ABI_FP): Comment.
bfd/
	* elf-bfd.h (_bfd_elf_ppc_merge_fp_attributes): Declare.
	* elf32-ppc.c (_bfd_elf_ppc_merge_fp_attributes): New function.
	(ppc_elf_merge_obj_attributes): Use it.  Don't copy first file
	attributes, merge them.  Don't warn about undefined tag bits,
	or copy unknown values to output.
	* elf64-ppc.c (ppc64_elf_merge_private_bfd_data): Call
	_bfd_elf_ppc_merge_fp_attributes.
binutils/
	* readelf.c (display_power_gnu_attribute): Catch truncated section
	for all powerpc attributes.  Display long double ABI.  Don't
	capitalize words, except for names.  Show known bits of tag values
	when some unknown bits are present.  Whitespace fixes.
gas/
	* config/tc-ppc.c (ppc_elf_gnu_attribute): New function.
	(md_pseudo_table <ELF>): Handle "gnu_attribute".
ld/
	* testsuite/ld-powerpc/attr-gnu-4-4.s: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-14.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-24.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-34.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-41.d: Delete.
	* testsuite/ld-powerpc/attr-gnu-4-32.d: Adjust expected warning.
	* testsuite/ld-powerpc/attr-gnu-8-23.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-01.d: Adjust expected output.
	* testsuite/ld-powerpc/attr-gnu-4-02.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-03.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-10.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-11.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-20.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-22.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-4-33.d: Likewise.
	* testsuite/ld-powerpc/attr-gnu-8-11.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Don't run deleted tests.
2016-09-26 18:04:57 +09:30
Alan Modra 14b57c7c6a PowerPC VLE
VLE is an encoding, not a particular processor architecture, so it
isn't really proper to select insns based on PPC_OPCODE_VLE.  For
example
{"evaddw",  VX (4, 512), VX_MASK, PPCSPE|PPCVLE, PPCNONE, {RS, RA, RB}},
{"vaddubs", VX (4, 512), VX_MASK, PPCVEC|PPCVLE, PPCNONE, {VD, VA, VB}},
shows two insns that have the same encoding, both available with VLE.
Enabling both with VLE means we can't disassemble the second variant
even if -Maltivec is given rather than -Mspe.  Also, we don't check
user assembly against the processor type as well as we could.

Another problem is that when using the VLE encoding, insns from the
main ppc opcode table are not available, except those using opcode 4
and 31.  Correcting this revealed two errors in the ld testsuite,
use of "nop" and "rfmci" when -mvle.

This patch fixes those problems in the opcode table, and removes
PPCNONE.  I find a plain 0 distracts less from other values.

In addition, I've implemented code to recognize some machine values
from the apuinfo note present in ppc32 objects.  It's not a complete
disambiguation since we're lacking info to detect newer chips, but
what we have should help with disassembly.

include/
	* elf/ppc.h (APUINFO_SECTION_NAME, APUINFO_LABEL, PPC_APUINFO_ISEL,
	PPC_APUINFO_PMR, PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK,
	PPC_APUINFO_SPE, PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK,
	PPC_APUINFO_VLE: Define.
opcodes/
	* ppc-dis.c (ppc_opts): Delete extraneous parentheses.  Default
	cpu for "vle" to e500.
	* ppc-opc.c (ALLOW8_SPRG): Remove PPC_OPCODE_VLE.
	(NO371, PPCSPE, PPCISEL, PPCEFS, MULHW, DCBT_EO): Likewise.
	(PPCNONE): Delete, substitute throughout.
	(powerpc_opcodes): Remove PPCVLE from "flags".  Add to "deprecated"
	except for major opcode 4 and 31.
	(vle_opcodes <se_rfmci>): Add PPCRFMCI to flags.
bfd/
	* cpu-powerpc.c (powerpc_compatible): Allow bfd_mach_ppc_vle entry
	to match other 32-bit archs.
	* elf32-ppc.c (_bfd_elf_ppc_set_arch): New function.
	(ppc_elf_object_p): Call it.
	(ppc_elf_special_sections): Use APUINFO_SECTION_NAME.  Fix
	overlong line.
	(APUINFO_SECTION_NAME, APUINFO_LABEL): Don't define here.
	* elf64-ppc.c (ppc64_elf_object_p): Call _bfd_elf_ppc_set_arch.
	* bfd-in.h (_bfd_elf_ppc_at_tls_transform,
	_bfd_elf_ppc_at_tprel_transform): Move to..
	* elf-bfd.h: ..here.
	(_bfd_elf_ppc_set_arch): Declare.
	* bfd-in2.h: Regenerate.
gas/
	* config/tc-ppc.c (PPC_APUINFO_ISEL, PPC_APUINFO_PMR,
	PPC_APUINFO_RFMCI, PPC_APUINFO_CACHELCK, PPC_APUINFO_SPE,
	PPC_APUINFO_EFS, PPC_APUINFO_BRLOCK, PPC_APUINFO_VLE): Don't define.
	(ppc_setup_opcodes): Check vle disables powerpc_opcodes overridden
	by vle_opcodes, and that vle flag doesn't enable opcodes.  Don't
	add vle_opcodes twice.
	(ppc_cleanup): Use APUINFO_SECTION_NAME and APUINFO_LABEL.
ld/
	* testsuite/ld-powerpc/apuinfo1.s: Delete nop.
	* testsuite/ld-powerpc/apuinfo-vle2.s: New.
	* testsuite/ld-powerpc/powerpc.exp: Use apuinfo-vle2.s.
2016-06-07 22:04:38 +09:30
Alan Modra 3bd43ebcb6 ld --gc-sections fail with __tls_get_addr_opt
When --gc-sections is active, __tls_get_addr_opt is marked as not
needed and forced local before ppc*_elf_tls_setup is run.

bfd/
	PR 20060
	* elf64-ppc.c (ppc64_elf_tls_setup): Clear forced_local.
	* elf32-ppc.c (ppc_elf_tls_setup): Likewise.
ld/
	PR 20060
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
	* testsuite/ld-powerpc/tlsdll.s: New.
	* testsuite/ld-powerpc/tlsdll.ver: New.
	* testsuite/ld-powerpc/tlsdll_32.s: New.
	* testsuite/ld-powerpc/tlsopt5.d: New.
	* testsuite/ld-powerpc/tlsopt5.s: New.
	* testsuite/ld-powerpc/tlsopt5_32.d: New.
	* testsuite/ld-powerpc/tlsopt5_32.s: New.
2016-05-11 22:40:09 +09:30
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Peter Bergner a680de9a98 Add assembler, disassembler and linker support for power9.
include/opcode/
	* ppc.h (PPC_OPCODE_POWER9): New define.
	(PPC_OPCODE_VSX3): Likewise.

opcodes/
	* ppc-dis.c (ppc_opts): Add "power9" and "pwr9" entries.
	Add PPC_OPCODE_VSX3 to the vsx entry.
	(powerpc_init_dialect): Set default dialect to power9.
        * ppc-opc.c (insert_dcmxs, extract_dcmxs, insert_dxd, extract_dxd,
        insert_dxdn, extract_dxdn, insert_l0, extract_l0, insert_l1,
        extract_l1 insert_xtq6, extract_xtq6): New static functions.
        (insert_esync): Test for illegal L operand value.
	(DCMX, DCMXS, DXD, NDXD, L0, L1, RC, FC, UIM6, X_R, RIC, PRS, XSQ6,
	XTQ6, LRAND, IMM8, DQX, DQX_MASK, DX, DX_MASK, VXVAPS_MASK, VXVA,XVA,
	XX2VA, XVARC, XBF_MASK, XX2UIM4_MASK, XX2BFD_MASK, XX2DCMXS_MASK,
	XVA_MASK, XRLA_MASK, XBFRARB_MASK, XLRAND_MASK, POWER9, PPCVEC3,
	PPCVSX3): New defines.
	(powerpc_opcodes) <ps_cmpu0, ps_cmpo0, ps_cmpu1, ps_cmpo1, fcmpu,
	fcmpo, ftdiv, ftsqrt>: Use XBF_MASK.
	<mcrxr>: Use XBFRARB_MASK.
	<addpcis, bcdcfn., bcdcfsq., bcdcfz., bcdcpsgn., bcdctn., bcdctsq.,
	bcdctz., bcds., bcdsetsgn., bcdsr., bcdtrunc., bcdus., bcdutrunc.,
	cmpeqb, cmprb, cnttzd, cnttzd., cnttzw, cnttzw., copy, copy_first,
	cp_abort, darn, dtstsfi, dtstsfiq, extswsli, extswsli., ldat, ldmx,
	lwat, lxsd, lxsibzx, lxsihzx, lxssp, lxv, lxvb16x, lxvh8x, lxvl, lxvll,
	lxvwsx, lxvx, maddhd, maddhdu, maddld, mcrxrx, mfvsrld, modsd, modsw,
	modud, moduw, msgsync, mtvsrdd, mtvsrws, paste, paste., paste_last,
	rmieg, setb, slbieg, slbsync, stdat, stop, stwat, stxsd, stxsibx,
	stxsihx, stxssp, stxv, stxvb16x, stxvh8x, stxvl, stxvll, stxvx,
	subpcis, urfid, vbpermd, vclzlsbb, vcmpneb, vcmpneb., vcmpneh,
	vcmpneh., vcmpnew, vcmpnew., vcmpnezb, vcmpnezb., vcmpnezh, vcmpnezh.,
	vcmpnezw, vcmpnezw., vctzb, vctzd, vctzh, vctzlsbb, vctzw, vextractd,
	vextractub, vextractuh, vextractuw, vextsb2d, vextsb2w, vextsh2d,
	vextsh2w, vextsw2d, vextublx, vextubrx, vextuhlx, vextuhrx, vextuwlx,
	vextuwrx, vinsertb, vinsertd, vinserth, vinsertw, vmul10cuq,
	vmul10ecuq, vmul10euq, vmul10uq, vnegd, vnegw, vpermr, vprtybd,
	vprtybq, vprtybw, vrldmi, vrldnm, vrlwmi, vrlwnm, vslv, vsrv, wait,
	xsabsqp, xsaddqp, xsaddqpo, xscmpeqdp, xscmpexpdp, xscmpexpqp,
	xscmpgedp, xscmpgtdp, xscmpnedp, xscmpoqp, xscmpuqp, xscpsgnqp,
	xscvdphp, xscvdpqp, xscvhpdp, xscvqpdp, xscvqpdpo, xscvqpsdz,
	xscvqpswz, xscvqpudz, xscvqpuwz, xscvsdqp, xscvudqp, xsdivqp,
	xsdivqpo, xsiexpdp, xsiexpqp, xsmaddqp, xsmaddqpo, xsmaxcdp,
	xsmaxjdp, xsmincdp, xsminjdp, xsmsubqp, xsmsubqpo, xsmulqp, xsmulqpo,
	xsnabsqp, xsnegqp, xsnmaddqp, xsnmaddqpo, xsnmsubqp, xsnmsubqpo,
	xsrqpi, xsrqpix, xsrqpxp, xssqrtqp, xssqrtqpo, xssubqp, xssubqpo,
	xststdcdp, xststdcqp, xststdcsp, xsxexpdp, xsxexpqp, xsxsigdp,
	xsxsigqp, xvcmpnedp, xvcmpnedp., xvcmpnesp, xvcmpnesp., xvcvhpsp,
	xvcvsphp, xviexpdp, xviexpsp, xvtstdcdp, xvtstdcsp, xvxexpdp,
	xvxexpsp, xvxsigdp, xvxsigsp, xxbrd, xxbrh, xxbrq, xxbrw, xxextractuw,
	xxinsertw, xxperm, xxpermr, xxspltib>: New instructions.
	<doze, nap, sleep, rvwinkle, waitasec, lxvx, stxvx>: Disable on POWER9.
	<tlbiel, tlbie, sync, slbmfev, slbmfee>: Add additional operands.

include/elf/
	* ppc.h (R_PPC_REL16DX_HA): New reloction.
	* ppc64.h (R_PPC64_REL16DX_HA): Likewise.

bfd/
	* elf32-ppc.c (ppc_elf_howto_raw): Add R_PPC_REL16DX_HA.
	(ppc_elf_reloc_type_lookup): Handle R_PPC_REL16DX_HA.
	(ppc_elf_addr16_ha_reloc): Likewise.
	(ppc_elf_check_relocs): Likewise.
	(ppc_elf_relocate_section): Likewise.
	(is_insn_dq_form): Handle lxv and stxv instructions.
	* elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_REL16DX_HA.
	(ppc64_elf_reloc_type_lookup): Handle R_PPC64_REL16DX_HA.
	(ppc64_elf_ha_reloc): Likewise.
	(ppc64_elf_check_relocs): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Likewise.
	* reloc.c (BFD_RELOC_PPC_REL16DX_HA): New.

elfcpp/
	* powerpc.h (R_POWERPC_REL16DX_HA): Define.

gas/
	* doc/as.texinfo (Target PowerPC): Document -mpower9 and -mpwr9.
	* doc/c-ppc.texi (PowerPC-Opts):  Likewise.
	* config/tc-ppc.c (md_show_usage): Likewise.
	(md_assemble): Handle BFD_RELOC_PPC_REL16DX_HA.
	(md_apply_fix): Likewise.
	(ppc_handle_align): Handle power9's group ending nop.

gas/testsuite/
	* gas/ppc/altivec3.s: New test.
	* gas/ppc/altivec3.d: Likewise.
	* gas/ppc/vsx3.s: Likewise.
	* gas/ppc/vsx3.d: Likewise.
	* gas/ppc/power9.s: Likewise.
	* gas/ppc/power9.d: Likewise.
	* gas/ppc/ppc.exp: Run them.
	* gas/ppc/power8.s <lxvx, lxvd2x, stxvx, stxvd2x>: Add new tests.
	* gas/ppc/power8.d: Likewise.
	* gas/ppc/vsx.s: <lxvx, stxvx>: Rename invalid mnemonics ...
	<lxvd2x, stxvd2x>: ...to this.
	* gas/ppc/vsx.d: Likewise.

gold/
	* gold/powerpc.cc (Powerpc_relocate_functions::addr16_dq): New function.
	(Powerpc_relocate_functions::addr16dx_ha): Likewise.
	(Target_powerpc::Scan::local): Handle R_POWERPC_REL16DX_HA.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.

ld/testsuite/
	* ld-powerpc/addpcis.d: New test.
	* ld-powerpc/addpcis.s: New test.
	* ld-powerpc/powerpc.exp: Run it.
2015-11-11 19:52:52 -06:00
Alan Modra 1cb0b71f5a Add reloc sort test
* ld-powerpc/relocsort.s, * ld-powerpc/relocsort.d: New test.
	* ld-powerpc/powerpc.exp: Run it.
2015-08-27 23:21:21 +09:30
Richard Sandiford 92a9c616e4 Fix an opd->append index in elf64-ppc.c
bfd/
	* elf64-ppc.c (toc_adjusting_stub_needed): Use the symbol value
	plus addend rather than the original st_value when looking up
	entries in opd->adjust.

ld/testsuite/
	* ld-powerpc/tocopt6-inc.s, ld-powerpc/tocopt6a.s,
	ld-powerpc/tocopt6b.s, ld-powerpc/tocopt6c.s,
	ld-powerpc/tocopt6.d: New test.
	* ld-powerpc/powerpc.exp (ppc64elftests): Add it.
2015-07-05 19:57:07 +01:00
Alan Modra f8b447819b ppc476 linker workaround shared lib fixes
When building a shared lib from non-PIC objects, we'll get dynamic
text relocations.  These need to move with any insns we move.
Otherwise the dynamic reloc will modify the branch, resulting in
crashes and other unpleasant behaviour.

Also, ld -r --ppc476-workaround used with sufficiently aligned PIC
objects needs a fix for emitted REL16 relocs.

bfd/
	* elf64-ppc.c (ppc_elf_relocate_section): Move dynamic text
	relocs with insns moved by --ppc476-workaround.  Correct
	output of REL16 relocs.
ld/testsuite/
	* ld-powerpc/ppc476-shared.s,
	* ld-powerpc/ppc476-shared.lnk,
	* ld-powerpc/ppc476-shared.d,
	* ld-powerpc/ppc476-shared2.d: New tests.
	* ld-powerpc/powerpc.exp: Run them.
2015-06-05 20:12:11 +09:30
Alan Modra b86ac8e3a5 Correct PowerPC64 local-dynamic TLS linker optimization
The linker hardcoded r3 into a local-dynamic to local-exec TLS
optimization sequence.  This is normally the case since r3 is required
as a parameter to (the optimized out) __tls_get_addr call.  However,
it is possible for a compiler, LLVM in this case, to set up the
parameter value in another register then copy it to r3 before the
call.

When fixing this problem, I noticed that ppc32 had another bug when
optimizing away one of the TLS insns to a nop.

The patch also tidies a mask used by global-dynamic to initial-exec
TLS optimization, to just select the fields needed.  Leaving the
offset in the instruction wasn't a bug since it will be overwritten
anyway.

bfd/
	* elf64-ppc.c (ppc64_elf_relocate_section): Correct GOT_TLSLD
	optimization.  Tidy mask for GOT_TLSGD optimization.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.  Correct
	location of nop zapping high insn too.
ld/testsuite/
	* ld-powerpc/tlsld.d, * ld-powerpc/tlsld.s: New test.
	* ld-powerpc/tlsld32.d, * ld-powerpc/tlsld32.s: New test.
	* ld-powerpc/powerpc.exp: Run them.  Move tocvar and tocnovar.
2015-01-29 13:13:02 +10:30
Alan Modra dbd1e97e32 PowerPC64 changes for xlc
The changes to reorder sections for better relro protection on powerpc64,
3e2b0f31, 23283c1b, and 5ad18f16, run into a problem with xlc.
xlc -qdatalocal puts global variables into .toc, which means that .toc
must be writable.  The simplest way to accomplish this is to edit the
linker script to remove .toc sections from .got on detecting xlc object
files.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add "object_in_toc".
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Assume that global symbols
	in .toc indicate xlc compiled code that might require a rw .toc.
ld/
	* emulparams/elf64ppc.sh (INITIAL_READWRITE_SECTIONS): Define.
	* emultempl/ppc64elf.em (params): Init new field.
	(ppc_after_open): New function.
	(LDEMUL_AFTER_OPEN): Define.
	* ldlang.c (lang_final): Whitespace fix.
ld/testsuite/
	* ld-powerpc/tocvar.d, * ld-powerpc/tocvar.s: New test.
	* ld-powerpc/tocnovar.d, * ld-powerpc/tocnovar.s: New test.
	* ld-powerpc/powerpc.exp: Run tocvar and tocnovar.
2015-01-28 18:30:54 +10:30
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Alan Modra 12b2843a6b Use a symbol flag bit to mark linker defined symbols
Trying to use the SEC_LINKER_CREATED section flag to determine whether
a symbol is linker defined fails to work on targets like alpha that
define special SEC_COMMON sections.  These might contain symbols that
originated in an object file.

include/
	* bfdlink.h (struct bfd_link_hash_entry): Comment non_ir_ref.  Add
	linker_def.
bfd/
	* elflink.c (_bfd_elf_define_linkage_sym): Set linker_def.
	* linker.c (_bfd_generic_link_add_one_symbol): Clear linker_def
	for CDEF, DEF, DEFW, COM.
ld/
	* ldexp.c (exp_fold_tree_1 <etree_provide>): Test linker_def.
ld/testsuite/
	* ld-powerpc/sdabase.s,
	* ld-powerpc/sdabase.t,
	* ld-powerpc/sdabase.d: New test.
	* ld-powerpc/sdabase2.t,
	* ld-powerpc/sdabase2.d: New test.
	* ld-powerpc/powerpc.exp: Run them.
2014-12-23 23:36:50 +10:30