Error on shared lib call to @local ifunc

On powerpc32, making ifuncs have non-default visibility in shared
libraries or pies can result in runtime failures.  The problem is that
if gcc is told that a given function has non-default visibility, then
calls to that function are assumed to be local (which is true) and
thus need not go via a plt call stub (which is false for ifunc).  If
the caller has no other reason to set up the got pointer (r30), code
won't be emitted to do so.  However, a pic plt call stub makes use of
r30 to load the plt entry.  So a call to an ifunc, which always needs
a plt entry, will fail.

This patch makes ld emit an error for the problem case, and allows
calls to non-default visibility ifuncs to work in normal executables.
I also fix some cases where ifuncs fail when using the old bss-plt.

	* elf32-ppc.c (ppc_elf_check_relocs): For @local call to ifunc,
	error when shared and force a plt call otherwise.
	(ppc_elf_size_dynamic_sections): Don't emit DT_PPC_GOT unless
	plt_type == PLT_NEW.
	(ppc_elf_relocate_section): Add missing test to resolve ifuncs to
	the appropriate call stub.
Mark symbol in executables if it matches dynamic_list

bfd/

	PR gold/16530
	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Mark symbol in
	executables if it matches dynamic_list.

ld/testsuite/

	PR gold/16530
	* ld-elf/dynamic-1.c: New file.
	* ld-elf/dynamic-1.rd: Likewise.
	* ld-elf/dynamic-1.syms: Likewise.

	* ld-elf/shared.exp (build_tests): Add dynamic-1.
PR15530, mark symbol in executables if it matches dynamic_list

For powerpc64 as HJ did earlier for other ELF targets, and a tidy.

	PR gold/15530
	* elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Support
	--export-dynamic and --dynamic-list marking of symbols.
	* elflink.c (bfd_elf_gc_mark_dynamic_ref_symbol): Reorder
	cheap tests first.
Consolidate ppc64 ld/bfd communication

Moves assorted variables used to communicate between ld and bfd into
a struct, hooks it into the bfd link_hash_table early, and removes
all other places where such variables were passed piecemeal.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Define.
	(ppc64_elf_init_stub_bfd, ppc64_elf_edit_opd, ppc64_elf_tls_setup,
	ppc64_elf_setup_section_lists, ppc64_elf_size_stubs,
	ppc64_elf_build_stubs): Update prototype.
	* elf64-ppp.c (struct ppc_link_hash_table): Add params, delete other
	fields now in params.  Adjust code throughout file.
	(ppc64_elf_init_stub_bfd): Delete "abfd" parameter, add "params".
	Save params pointer in htab.
	(ppc64_elf_edit_opd, ppc64_elf_tls_setup,
	ppc64_elf_setup_section_lists, ppc64_elf_size_stubs,
	ppc64_elf_build_stubs): Remove parameters now in "params".
ld/
	* emultemps/ppc64elf.em (params): New static struct replacing
	various other static vars.  Adjust code throughout file.
Control powerpc64-ld provision of register save/restore

This patch allows the user to override powerpc64-ld's default for
providing linker generated register save and restore functions as used
by gcc -Os code.  Normally these are not provided by ld -r, so Linux
kernel modules have needed to include their own copies.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add save_restore_funcs.
	* elf64-ppc.c (ppc64_elf_func_desc_adjust): Use it to control
	provision of out-of-line register save/restore routines.
ld/
	* emultempl/ppc64elf.em (params): Init new field.
	(ppc_create_output_section_statements): Set params.save_restore_funcs
	default.
	(PARSE_AND_LIST_*): Add support for --save-restore-funcs and
	--no-save-restore-funcs.
Better overflow checking for powerpc64 relocations

R_PPC64_ADDR16 is used in three contexts:
- .short data relocation
- 16-bit signed insn fields, eg. addi
- 16-bit unsigned insn fields, eg. ori
In the first case we want to allow both signed and unsigned 16-bit
values, the latter two ought to error if the field exceeds the range
of values allowed for 16-bit signed and unsigned integers
respectively.  These conflicting requirements meant that ld had to
choose the least restrictive overflow checks, and thus it is possible
to construct testcases where an addi field overflows but is not
reported by ld.  Many relocations dealing with 16-bit insn fields have
this problem.  What's more, some relocations that are only ever used
for signed fields of instructions woodenly copied the lax overflow
checking of R_PPC64_ADDR16.

bfd/
	* elf64-ppc.c (ppc64_elf_howto_raw): Use complain_overflow_signed
	for R_PPC64_ADDR14, R_PPC64_ADDR14_BRTAKEN, R_PPC64_ADDR14_BRNTAKEN,
	R_PPC64_SECTOFF, R_PPC64_ADDR16_DS, R_PPC64_SECTOFF_DS,
	R_PPC64_REL16 entries.  Use complain_overflow_dont for R_PPC64_TOC.
	(ppc64_elf_relocate_section): Modify overflow test for 16-bit
	fields in instructions to signed/unsigned according to whether
	the field takes a signed or unsigned value.
gold/
	* powerpc.cc (Powerpc_relocate_functions::Overflow_check): Add
	CHECK_UNSIGNED, CHECK_LOW_INSN, CHECK_HIGH_INSN.
	(Powerpc_relocate_functions::has_overflow_unsigned): New function.
	(Powerpc_relocate_functions::has_overflow_bitfield,
	overflowed): Use the above.
	(Target_powerpc::Relocate::relocate): Correct overflow checking
	for a number of relocations.  Modify overflow test for 16-bit
	fields in instructions to signed/unsigned according to whether
	the field takes a signed or unsigned value.
Better overflow checking for powerpc32 relocations

Similar to the powerpc64 patch, this improves overflow checking in
elf32-ppc.c.  Many reloc "howto" entries needed fixes, some just
cosmetic.

The patch also fixes the R_PPC_VLE_SDA21 reloc application code, which
was horribly broken.  In fact, it may still be broken since Power ISA
2.07 says e_li behaves as
   RT <- EXTS(li20 1:4 || li20 5:8 || li20 0 || li20 9:19)
where li20 is a field taken from bits 17..20, 11..15, 21..31 of the
instruction.  Freescale VLEPEM says differently, and I assume
correctly, that
   RT <- EXTS(li20 0:3 || li20 4:8 || li20 9:19)
The VLE_SDA21 relocation description matches this too.

Now the VLE_SDA21 relocation specifies in the case where e_addi16 is
converted to e_li for symbols in .PPC.EMB.sdata0 or .PPC.EMB.sbss0
(no base register), that the field is restricted to 16 bits, with the
sign bit being propagated to the top 4 bits.  I don't see the sense in
restricting the value like this, so have allowed the full 20 bit
signed value.  This of course is compatible with the reloc description
in that values in the 16 bit signed range will result in exactly the
same insn field as when the reloc description is followed to the
letter.

	* elf32-ppc.c (ppc_elf_howto_raw): Correct overflow check for
	many relocations.  Correct bitsize and rightshift too for a number
	of VLE relocs.  Describe R_PPC_VLE_SDA21 and R_PPC_VLE_SDA21_LO.
	Correct dst_mask on R_PPC_VLE_SDA21_LO.
	(ppc_elf_vle_split16): Tidy, delete unnecessary prototype.
	(ppc_elf_relocate_section): Modify overflow test for 16-bit
	fields in instructions to signed/unsigned according to whether
	the field takes a signed or unsigned value.  Tidy vle split16 code.
	Correct R_PPC_VLE_SDA21 and R_PPC_VLE_SDA21_LO handling.
Fix overflow handling of VLE_SDA21

bfd/
	* elf32-ppc.c (ppc_elf_relocate_section): Correct overflow
	handling for VLE_SDA21 relocs.
ld/testsuite/
	* ld-powerpc/vle.ld: Place .PPC.EMB.sdata0 within 32k of 0.
	* ld-powerpc/vle-reloc-3.d: Update.
Referencing a function's address on PowerPC64 ELFv2

ELFv2 needs to create plt entries in a non-PIC executable for an
address reference to a function defined in a shared object.  It's
possible that an object file has no features that distinguish it as
ELFv1 or ELFv2, eg. an object only containing data.  Such files need
to be handled like those that are known to be ELFv2.
However, this unnecessarily creates plt entries for the analogous
ELFv1 case, so arrange to set output abi version earlier, and use the
output abi version to further distinguish ambiguous input files.

bfd/
	* elf64-ppc.c (ppc64_elf_check_relocs): Account for possibly
	needed plt entries when taking the address of functions for
	abiversion == 0 (ie. unknown) as well as abiversion == 2.
	Move opd setup and abiversion checks to..
	(ppc64_elf_before_check_relocs): ..here.  Renamed from
	ppc64_elf_process_dot_syms.  Set output abiversion from input and
	input abiversion from output, if either is not set.
	(ppc64_elf_merge_private_bfd_data): Don't merge flags here.
	(elf_backend_check_directives): Update.
ld/testsuite/
	* ld-powerpc/startv1.s, * ld-powerpc/startv2.s, * ld-powerpc/funref.s,
	* ld-powerpc/funv1.s, * ld-powerpc/funv2.s,
	* ld-powerpc/ambiguousv1.d, * ld-powerpc/ambiguousv2.d: New test files.
	* ld-powerpc/powerpc.exp: Run new tests.
Fix "overflow in PLT unwind data" warning

When linking statically, it's possible to hit this warning with IFUNC
or very large executables, due to .glink being unused.

	* powerpc.cc (do_plt_fde_location): Handle zero length .glink.
	Compare FDE contents with DW_CFA_nop rather than 0.
Fix testsuite to use newly-built linker for ehdr_start_test_4, and fix
check script to look for the right binding.

gold/
	* testsuite/Makefile.am (ehdr_start_test_4): Fix typo in -B option.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ehdr_start_test_4.sh: Look for "U" instead of "w".
Fix PowerPC64 ELFv2 icf_safe failures

ELFv2 doesn't use .opd, so folding function code can't be allowed
in safe mode if a function's address might be taken.

	* powerpc.cc (Target_powerpc::local_reloc_may_be_function_pointer):
	Only ignore relocs on ELFv1.
	(Target_powerpc::global_reloc_may_be_function_pointer): Likewise.
Fix gold plugin_test failures on PowerPC64 ELFv2

readelf output for ELFv2 includes st_other bits specifying a
function's local entry offset.

	* testsuite/plugin_test.c (parse_readelf_line): Skip non-visibility
	st_other output.
Support fusion for ELFv2 stubs

Power8 fuses addis,addi and addis,ld sequences when the target of the
addis is the same as the addi/ld.  Thus
    addis r12,r2,xxx@ha
    addi r12,r12,xxx@l / ld r12,xxx@l(r12)
is faster than
    addis r11,r2,xxx@ha
    addi r12,r11,xxx@l / ld r12,xxx@l(r11)
So use the form that allows fusion in plt call and branch stubs.

bfd/
	* elf64-ppc.c (ADDIS_R12_R2): Define.
	(build_plt_stub): Support fusion on ELFv2 stub.
	(ppc_build_one_stub): Likewise for plt branch stubs.
gold/
	* powerpc.cc (addis_12_2): Define.
	(Stub_table::do_write): Support fusion on ELFv2 stubs.
ld/testsuite/
	* ld-powerpc/elfv2exe.d: Update for changed plt call stubs.
Allow both signed and unsigned fields in PowerPC cmpli insn

There are legitimate reasons to allow a signed value in a cmpli insn
field, for example to test for a "stw r1,lock@sdarel(r13)" instruction
in user code, a kernel might use
	subis r3,r3,STW_R1_0R13@ha	# subtract off high part
	cmplwi r3,lock@sdarel		# is low part accessing lock?
Since the lock@sdarel may take a range of -32768 to 32767,
the allowed range of cmpli immediate must be at least [-32768,65535].

bfd/
	* elf32-ppc.c (ppc_elf_relocate_section): Treat field of cmpli
	insn as a bitfield; Use complain_overflow_bitfield.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
opcodes/
	* ppc-opc.c (UISIGNOPT): Define and use with cmpli.
gas/
	* config/tc-ppc.c (ppc_insert_operand): Handle PPC_OPERAND_SIGNOPT
	on unsigned fields.  Comment on PPC_OPERAND_SIGNOPT signed fields
	in 64-bit mode.
gold/
	* powerpc.cc (relocate): Treat field of cmpli insn as a bitfield.
PROVIDE in linker script vs. built-in symbols

	* ldexp.c (exp_fold_tree_1 <etree_provide>): Make PROVIDEd
	linker script symbol value override a built-in linker symbol.
Regenerate msp430 file to pick up cosmetic changes

	* msp430-decode.c: Regenerate.
daily update