Commit Graph

368 Commits

Author SHA1 Message Date
Alan Modra a127494f2d Use dynamic text relocs for protected vars
Rather than reporting a link error on attempting to use dynbss for
protected vars, use dynamic text relocs.

	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Heed -z nocopyreloc.
	Use text relocs rather than giving an error on trying to use
	.dynbss for protected shared lib vars.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
2015-02-26 14:09:50 +10:30
Alan Modra 2ec55de302 Properly place the NULL STT_FILE symbol revistited
I was having a little closer look at what is going on here and noticed
that HJ unconditionally emits a NULL STT_FILE symbol before emitting
forced local symbols.  That means we really don't need a second pass
over forced local symbols.  The only reason for two passes is when
some forced local symbol can be emitted before the NULL STT_FILE.  So
I set about removing the second pass, updating the testsuite all over
again.  It's also unnecessary to emit the NULL STT_FILE when no
previous file symbol has been emitted.

bfd/
	PR ld/17975
	* elflink.c (struct elf_outext_info): Remove need_second_pass
	and second_pass.
	(elf_link_output_extsym): Delete code handling second forced
	local pass.  Move code emitting NULL STT_FILE symbol later, so
	that it can be omitted if forced local is stripped.  Don't
	emit the NULL STT_FILE if no file symbols have been output.
	(bfd_elf_final_link): Remove second forced local pass.
	* elf32-ppc.c (add_stub_sym): Set linker_def on linker syms.
	(ppc_elf_size_dynamic_sections): Likewise.
	* elf64-ppc.c (ppc_build_one_stub): Likewise.
	(build_global_entry_stubs): Likewise.
	(ppc64_elf_build_stubs): Likewise.
ld/testsuite/
	PR ld/17975
	* ld-aarch64/gc-tls-relocs.d, * ld-alpha/tlspic.rd,
	* ld-cris/libdso-2.d, * ld-i386/tlsdesc-nacl.rd, * ld-i386/tlsdesc.rd,
	* ld-i386/tlsnopic-nacl.rd, * ld-i386/tlsnopic.rd,
	* ld-i386/tlspic-nacl.rd, * ld-i386/tlspic.rd, * ld-ia64/tlspic.rd,
	* ld-powerpc/tlsexe.r, * ld-powerpc/tlsexetoc.r,
	* ld-powerpc/tlsso.r, * ld-powerpc/tlstocso.r,
	* ld-s390/tlspic.rd, * ld-s390/tlspic_64.rd,
	* ld-sparc/tlssunnopic32.rd, * ld-sparc/tlssunnopic64.rd,
	* ld-sparc/tlssunpic32.rd, * ld-sparc/tlssunpic64.rd,
	* ld-tic6x/shlib-1.rd, * ld-tic6x/shlib-1b.rd, * ld-tic6x/shlib-1r.rd,
	* ld-tic6x/shlib-1rb.rd, * ld-tic6x/shlib-noindex.rd,
	* ld-x86-64/tlsdesc-nacl.rd, * ld-x86-64/tlsdesc.rd,
	* ld-x86-64/tlspic-nacl.rd, * ld-x86-64/tlspic.rd: Update.
2015-02-18 00:31:52 +10:30
Alan Modra 989f98793c Don't segfault or assert on NULL tls_sec
Real code won't hit these, but it's possible to contrive a testcase..

	* elf32-ppc.c (ppc_elf_relocate_section): Don't segfault on NULL
	tls_sec.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elflink.c (elf_link_output_extsym): Don't assert on NULL tls_sec.
2015-02-09 14:06:27 +10:30
Nick Clifton 64d2901806 More fixes for illegal memory accesses triggered by running objdump on fuzzed binaries.
PR binutils/17512
	* objdump.c (display_any_bfd): Fail if archives nest too deeply.

	* ecoff.c: Use bfd_alloc2 to allocate space for structure arrays.
	(_bfd_ecoff_slurp_symbol_table): Check for a negative symbol
	index or an out of range fdr index.
	* elf-m10300.c (mn10300_info_to_howto): Fix typo in error message.
	* elf32-arc.c (arc_info_to_howto_rel): Likewise.
	* elf32-avr.c (avr_info_to_howto_rela): Likewise.
	* elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
	* elf32-cr16c.c (elf_cr16c_info_to_howto_rel): Likewise.
	* elf32-cris.c (cris_info_to_howto_rela): Likewise.
	* elf32-crx.c (elf_crx_info_to_howto): Likewise.
	* elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
	* elf32-d30v.c (d30v_info_to_howto_rel): Likewise.
	* elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
	* elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
	* elf32-frv.c (frv_info_to_howto_rela): Likewise.
	* elf32-i370.c (i370_elf_info_to_howto): Likewise.
	* elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
	* elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
	* elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
	* elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
	* elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
	* elf32-m32r.c (m32r_info_to_howto_rel): Likewise.
	* elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
	* elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
	* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
	* elf32-mep.c (mep_info_to_howto_rela): Likewise.
	* elf32-metag.c (metag_info_to_howto_rela): Likewise.
	* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
	* elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
	* elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
	* elf32-mt.c (mt_info_to_howto_rela): Likewise.
	* elf32-nds32.c (nds32_info_to_howto_rel): Likewise.
	* elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
	* elf32-pj.c (pj_elf_info_to_howto): Likewise.
	* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
	* elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
	* elf32-rx.c (rx_info_to_howto_rela): Likewise.
	* elf32-sh.c (sh_elf_info_to_howto): Likewise.
	* elf32-spu.c (spu_elf_info_to_howto): Likewise.
	* elf32-v850.c (v850_elf_perform_relocation): Likewise.
	* elf32-vax.c (rtype_to_howto): Likewise.
	* elf32-visium.c (visium_info_to_howto_rela): Likewise.
	* elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
	* elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
	* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
	* elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
	* mach-o.c: Use bfd_alloc2 to allocate space for structure arrays.
	(bfd_mach_o_canonicalize_one_reloc): Fix check on out
	of range symbol indicies.
	(bfd_mach_o_canonicalize_relocs): Check for out of range alloc.
	(bfd_mach_o_canonicalize_dynamic_reloc): Likewise.
	(bfd_mach_o_build_dysymtab): Likewise.
	(bfd_mach_o_write_symtab_content): Set the string table size to
	zero upon error.
	(bfd_mach_o_read_symtab_symbols): Reset the nsyms value if the
	read fails.
	* peXXigen.c (pe_print_edata):  Check for numeric overflow in edt
	fields.
	* tekhex.c (first_phase): Check for src pointer reaching end of
	buffer.
2015-02-03 14:34:54 +00:00
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 6346d5ca43 Fallout from recent bfd_reloc_outofrange changes
Commit ec93045b and cd21f5da introduced a large number of tic4x and
tic54x regressions, due to the new checks being wrong for targets
with octets_per_byte != 1.  To fix that I introduced a new
bfd_get_section_limit_octets and performed the check on octets rather
than byte adresses, reducing the number of bfd_octets_per_byte calls.
bfd_octets_per_byte is rather expensive..

I then wondered why the same bfd_reloc_outofrange check added to
bfd_perform_relocation wasn't also added to bfd_install_relocation.
The two functions are virtually identical and ought to remain that
way.  However, adding the same check to bfd_install_relocation
resulted in ld-elf "FAIL Link eh-group.o to eh-group" on many ELF
targets, including x64_64-linux.  The reason being that eh-group.o
has NONE relocs at the end of a section, and most targets give NONE
relocs a non-zero size.  So if we are to keep the new outofrange
check it appears that NONE relocs must have a zero size.

	* bfd-in.h (bfd_get_section_limit_octets): New define, extracted from..
	(bfd_get_section_limit): ..here.
	* reloc.c (bfd_perform_relocation): Correct bfd_reloc_outofrange check.
	(bfd_install_relocation, _bfd_final_link_relocate): Add same check here.
	* elf32-sh.c (sh_elf_reloc): Correct bfd_reloc_outofrange check.
	* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Remove duplicated
	bfd_reloc_outofrange check.
	* bfd-in2.h: Regenerate.

	* cpu-ns32k.c (_bfd_do_ns32k_reloc_contents): Return bfd_reloc_ok
	on zero size relocs.
	* ecoff.c (ecoff_reloc_link_order): Likewise.
	* elf32-nds32.c (nds32_relocate_contents): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_put_addend): Likewise.

	* reloc.c (_bfd_relocate_contents): Don't bomb on zero size relocs.
	(_bfd_clear_contents): Likewise.
	* elfxx-mips.c (mips_elf_obtain_contents): Likewise.
	(mips_elf_perform_relocation): Likewise.

	* aoutx.h (aout_link_reloc_link_order): Allow for NULL return
	from malloc on zero size alloc.
	* cofflink.c (_bfd_coff_reloc_link_order): Likewise.
	* elflink.c (elf_reloc_link_order): Likewise.
	* linker.c (_bfd_generic_reloc_link_order): Likewise.
	* pdp11.c (aout_link_reloc_link_order): Likewise.
	* xcofflink.c (xcoff_reloc_link_order): Likewise.

	* aoutx.h (howto_table_ext): Ensure NONE relocs have size 3,
	bitsize 0, and complain_overflow_dont.
	* coff-sparc.c (coff_sparc_howto_table): Likewise.
	* elf-hppa.h (elf_hppa_howto_table): Likewise.
	* elf-m10200.c (elf_mn10200_howto_table): Likewise.
	* elf-m10300.c (elf_mn10300_howto_table): Likewise.
	* elf32-arc.c (elf_arc_howto_table): Likewise.
	* elf32-arm.c (elf32_arm_howto_table_1): Likewise.
	* elf32-avr.c (elf_avr_howto_table): Likewise.
	* elf32-bfin.c (bfin_howto_table): Likewise.
	* elf32-cr16.c (cr16_elf_howto_table): Likewise.
	* elf32-cris.c (cris_elf_howto_table): Likewise.
	* elf32-crx.c (crx_elf_howto_table): Likewise.
	* elf32-d10v.c (elf_d10v_howto_table): Likewise.
	* elf32-d30v.c (elf_d30v_howto_table): Likewise.
	* elf32-dlx.c (dlx_elf_howto_table): Likewise.
	* elf32-epiphany.c (epiphany_elf_howto_table): Likewise.
	* elf32-fr30.c (fr30_elf_howto_table): Likewise.
	* elf32-frv.c (elf32_frv_howto_table): Likewise.
	* elf32-h8300.c (h8_elf_howto_table): Likewise.
	* elf32-i370.c (i370_elf_howto_raw): Likewise.
	* elf32-i386.c (elf_howto_table): Likewise.
	* elf32-i860.c (elf32_i860_howto_table): Likewise.
	* elf32-i960.c (elf32_i960_relocate): Likewise.
	* elf32-ip2k.c (ip2k_elf_howto_table): Likewise.
	* elf32-iq2000.c (iq2000_elf_howto_table): Likewise.
	* elf32-lm32.c (lm32_elf_howto_table): Likewise.
	* elf32-m32c.c (m32c_elf_howto_table): Likewise.
	* elf32-m32r.c (m32r_elf_howto_table): Likewise.
	* elf32-m68hc11.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68hc12.c (elf_m68hc11_howto_table): Likewise.
	* elf32-m68k.c (howto_table): Likewise.
	* elf32-mcore.c (mcore_elf_howto_raw): Likewise.
	* elf32-mep.c (mep_elf_howto_table): Likewise.
	* elf32-metag.c (elf_metag_howto_table): Likewise.
	* elf32-microblaze.c (microblaze_elf_howto_raw): Likewise.
	* elf32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elf32-moxie.c (moxie_elf_howto_table): Likewise.
	* elf32-msp430.c (elf_msp430_howto_table): Likewise.
	* elf32-mt.c (mt_elf_howto_table): Likewise.
	* elf32-nds32.c (nds32_elf_howto_table): Likewise.
	* elf32-nios2.c (elf_nios2_howto_table_rel): Likewise.
	* elf32-or1k.c (or1k_elf_howto_table): Likewise.
	* elf32-pj.c (pj_elf_howto_table): Likewise.
	* elf32-ppc.c (ppc_elf_howto_raw): Likewise.
	* elf32-rl78.c (rl78_elf_howto_table): Likewise.
	* elf32-rx.c (rx_elf_howto_table): Likewise.
	* elf32-s390.c (elf_howto_table): Likewise.
	* elf32-score.c (elf32_score_howto_table): Likewise.
	* elf32-score7.c (elf32_score_howto_table): Likewise.
	* elf32-sh-relocs.h (R_SH_NONE): Likewise.
	* elf32-spu.c (elf_howto_table): Likewise.
	* elf32-tic6x.c (elf32_tic6x_howto_table): Likewise.
	* elf32-tilepro.c (tilepro_elf_howto_table): Likewise.
	* elf32-v850.c (v850_elf_howto_table): Likewise.
	* elf32-vax.c (howto_table): Likewise.
	* elf32-visium.c (visium_elf_howto_table): Likewise.
	* elf32-xc16x.c (xc16x_elf_howto_table): Likewise.
	* elf32-xgate.c (elf_xgate_howto_table): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_howto_table): Likewise.
	* elf32-xtensa.c (elf_howto_table): Likewise.
	* elf64-alpha.c (elf64_alpha_howto_table): Likewise.
	* elf64-mips.c (mips_elf64_howto_table_rel): Likewise.
	* elf64-mmix.c (elf_mmix_howto_table): Likewise.
	* elf64-ppc.c (ppc64_elf_howto_raw): Likewise.
	* elf64-s390.c (elf_howto_table): Likewise.
	* elf64-sh64.c (sh_elf64_howto_table): Likewise.
	* elf64-x86-64.c (x86_64_elf_howto_table): Likewise.
	* elfn32-mips.c (elf_mips_howto_table_rel): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_howto_table): Likewise.
	(elfNN_aarch64_howto_none): Likewise.
	* elfxx-ia64.c (ia64_howto_table): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_howto_table): Likewise.
	* elfxx-tilegx.c (tilegx_elf_howto_table): Likewise.
	* nlm32-sparc.c (nlm32_sparc_howto_table): Likewise.
2015-01-19 19:37:45 +10:30
Nick Clifton cd21f5daad Fix memory access violations triggered by running objdump on fuzzed binaries.
PR binutils/17512
	* elf-m10300.c (mn10300_info_to_howto): Replace assertion with an
	error message.  Never return an invalid howto pointer.
	* elf32-cr16.c (cr16_info_to_howto): Likewise.
	* elf32-crx.c (elf_crx_info_to_howto): Likewise.
	* elf32-i370.c (i370_elf_info_to_howto): Likewise.
	* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
	* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
	* elf32-mips.c (mips_elf32_rtype_to_howto): Likewise.
	* elf32-pj.c (pj_elf_info_to_howto): Likewise.
	* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
	* elf32-spu.c (spu_elf_info_to_howto): Likewise.
	* elf32-v850.c (v850_elf_info_to_howto_rela): Likewise.
	* elf32-vax.c (rtype_to_howto): Likewise.
	* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
	* elf64-mips.c (mips_elf64_rtype_to_howto): Likewise.
	* elfn32-mips.c (sh_elf_info_to_howto): Likewise.
	* elf32-sh.c (sh_elf_info_to_howto): Likewise.
	(sh_elf_reloc): Check that the reloc is in range.
	* reloc.c (bfd_perform_relocation): Check that the section is big
	enough for the entire reloc.
	(bfd_generic_get_relocated_section_contents): Report unexpected
	return values from perform_reloc.
2015-01-15 16:22:55 +00:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Richard Henderson 04c6a44c7c Set ppc COMMONPAGESIZE to 64k
bfd/
	* elf32-ppc.c (ELF_COMMONPAGESIZE): Set to 64k.
	* elf64-ppc.c (ELF_COMMONPAGESIZE): Likewise.
2014-12-18 15:40:25 -06:00
Alan Modra 6cabe1ea46 Copy relocations against protected symbols
Copy relocs are used in a scheme to avoid dynamic text relocations in
non-PIC executables that refer to variables defined in shared
libraries.  The idea is to have the linker define any such variable in
the executable, with a copy reloc copying the initial value, then have
both the executable and shared library refer to the executable copy.
If the shared library defines the variable as protected then we have
two copies of the variable being used.

	PR 15228
	* elflink.c (_bfd_elf_adjust_dynamic_copy): Add "info" param.
	Error on copy relocs against protected symbols.
	(elf_merge_st_other): Set h->protected_def.
	* elf-bfd.h (struct elf_link_hash_entry): Add "protected_def".
	(_bfd_elf_adjust_dynamic_copy): Update prototype.
	* elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Update
	_bfd_elf_adjust_dynamic_copy call.
	* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise.
	* elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise.
	* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise.
	* elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise.
	* elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise.
	* elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise.
	* elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise.
	* elf32-metag.c (elf_metag_adjust_dynamic_symbol): Likewise.
	* elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Likewise.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise.
	* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise.
	* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise.
	* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise.
	* elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
	* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise.
	* elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise.
	* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise.
2014-12-12 23:35:50 +10:30
Alan Modra 1e269e9b8f ppc476 workaround sizing
* elf32-ppc.c (ppc_elf_relax_section): Correct ppc476 workaround
	alignment calculation.
2014-11-20 21:37:02 +10:30
Alan Modra f1885d1e59 Fix 17492, ld segfault with --oformat=binary
PR 17492
	* elf32-arm.c (elf32_arm_add_symbol_hook): Only set has_gnu_symbols
	on ELF output bfd.
	* elf32-i386.c (elf_i386_add_symbol_hook): Likewise.
	* elf32-m68k.c (elf_m68k_add_symbol_hook): Likewise.
	* elf32-ppc.c (ppc_elf_add_symbol_hook): Likewise.
	* elf32-sparc.c (elf32_sparc_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_add_symbol_hook): Likewise.
	* elf64-x86-64.c (elf_x86_64_add_symbol_hook): Likewise.
	* elfxx-aarch64.c (_bfd_aarch64_elf_add_symbol_hook): Likewise.
	* elf-s390-common.c (elf_s390_add_symbol_hook): Likewise.  Handle
	STB_GNU_UNIQUE too.
2014-10-16 21:18:16 +10:30
Alan Modra 6128f9cf2b ppc476 patch area size miscalculation
ppc476 sections that end exactly on a page boundary need the
workaround applied when a function ends in "bctr", or when pasting
together code from multiple sections.  The space allocated for the
patch area didn't allow for this case, while the code in
relocate_section performing the patches did, leading to an assertion
failure.

	* elf32-ppc.c (ppc_elf_relax_section): Fix off by one error.
2014-08-30 10:12:44 +09:30
Alan Modra 1009ef284f PowerPC fix for ifunc broken by d1eca1e4
This probably could be fixed by making changes in relocate_section for
ifunc, but it's simpler to disable the optimisation for ifunc.

	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Don't attempt to
	use dynrelocs for ifunc.
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Similarly.
2014-08-18 21:00:46 +09:30
Alan Modra d1eca1e41d Taking an undefined function's address in an executable
doesn't always mean you need to define a function symbol on plt code.
If all references are in read-write sections, then using dynamic relocs
is OK.

bfd/
	* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Clear
	pointer_equality_needed when !readonly_dynrelocs.
	* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise.
ld/testsuite/
	* ld-powerpc/ambiguousv1.d: Match symbol table too.
	* ld-powerpc/ambiguousv2.d: Likewise.
	* ld-powerpc/ambiguousv1b.d: New.
	* ld-powerpc/ambiguousv2b.d: New.
	* ld-powerpc/powerpc.exp: Run new tests.
2014-07-02 18:16:14 +09:30
Alan Modra afb933145e Set DF_STATIC_TLS for PIEs
If we can dlopen an object then DF_STATIC_TLS is relevant.

	* elf32-ppc.c (ppc_elf_check_relocs): Set DF_STATIC_TLS for PIEs too.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
2014-07-02 14:04:21 +09:30
Alan Modra 15bfcc7768 Don't strip section defining _SDA_BASE_
Prior to 93d1b056 _SDA_BASE_ used to be defined in a linker script
output section.  Now _SDA_BASE_ is defined in an input section that is
subject to being stripped.  If the section is stripped we don't output
the symbol, which results in --emit-relocs trying to emit relocs with
dangling references to _SDA_BASE_.

	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Arrange to keep
	.sdata/.sdata2 when _SDA_BASE_/_SDA2_BASE_ should be output
	for --emit-relocs.
2014-06-24 13:39:04 +09:30
Alan Modra c72f2fb2bb Make bfd.link_next field a union
This field of struct bfd is currently only used to chain together
linker input files.  This patch prepares to use the field to stash
the linker hash table, which is always created on the linker output
file.

bfd/
	* bfd.c (struct bfd): Replace link_next with a union.
	* aoutx.h, * bfd.c, * coff-ppc.c, * coff-rs6000.c, * cofflink.c,
	* ecoff.c, * elf-m10300.c, * elf32-arm.c, * elf32-avr.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c, * elf32-m32c.c,
	* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-metag.c,
	* elf32-microblaze.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-or1k.c, * elf32-ppc.c, * elf32-rl78.c, * elf32-s390.c,
	* elf32-score.c, * elf32-score7.c, * elf32-sh.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilepro.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c,
	* elf64-mmix.c, * elf64-ppc.c, * elf64-s390.c, * elf64-x86-64.c,
	* elflink.c, * elfnn-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
	* elfxx-tilegx.c, * linker.c, * pdp11.c, * peXXigen.c, * simple.c,
	* sunos.c, * vms-alpha.c, * xcofflink.c: Update for above.
	* bfd-in2.h: Regenerate.
include/
	* bfdlink.h: Update for bfd.link_next change.
ld/
	* emultempl/cr16elf.em, * emultempl/elf32.em, * emultempl/genelf.em,
	* emultempl/m68kcoff.em, * emultempl/m68kelf.em,
	* emultempl/nds32elf.em, * emultempl/pe.em, * emultempl/pep.em,
	* ldlang.c, * ldmain.c, * pe-dll.c: Update for bfd.link_next change.
2014-06-13 19:10:57 +09:30
Alan Modra a47622ac1b 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.
2014-06-07 14:55:11 +09:30
Alan Modra 93d1b056cb Rewrite ppc32 backend .sdata and .sdata2 handling
1) _SDA_BASE_ and _SDA2_BASE_ and defined automatically, in a similar
   manner to the way _GLOBAL_OFFSET_TABLE_ is handled.  It's a little
   more complicated to remove the symbols because _SDA_BASE_ needs to
   be there if either .sdata or .sbss is present, and similarly for
   _SDA2_BASE.
2) The linker created .sdata and .sdata2 sections used for
   R_PPC_EMB_SDAI16 and R_PPC_EMB_SDA2I16 pointers are created early.
   Nowadays we strip unneeded sections from the output, so it isn't
   necessary to delay creating the sections.
3) The output section for targets of various SDA relocs is now checked
   as per the ABI(s).  We previously allowed .sdata.foo and similar,
   most likely because at some stage we were checking input sections.

Also, the patch fixes a long-standing bug in size_input_sections
that affects the values of symbols defined in stripped input
sections.

	PR 16952
bfd/
	* elf32-ppc.c (ppc_elf_create_linker_section): Move earlier.
	Remove redundant setting of htab->elf.dynobj.  Don't align.
	Define .sdata symbols using _bfd_elf_define_linkage_sym.
	(ppc_elf_create_glink): Call ppc_elf_create_linker_section.
	(create_sdata_sym): Delete.
	(elf_allocate_pointer_linker_section): Rename from
	elf_create_pointer_linker_section.  Align section.
	(ppc_elf_check_relocs): Don't call ppc_elf_creat_linker_section
	directly here, or create_sdata_sym.  Set ref_regular on _SDA_BASE_
	and _SDA2_BASE_.
	(ppc_elf_size_dynamic_sections): Remove ATTRIBUTE_UNUSED on param.
	Remove unnecessary tests on _SDA_BASE_ sym.
	(maybe_strip_sdasym, ppc_elf_maybe_strip_sdata_syms): New functions.
	(ppc_elf_relocate_section): Tighten SDA reloc symbol section checks.
	* elf32-ppc.h (ppc_elf_set_sdata_syms): Delete.
	(ppc_elf_maybe_strip_sdata_syms): Declare.
ld/
	* emulparams/elf32ppccommon.sh (_SDA_BASE_, _SDA2_BASE_): Delete.
	* emultempl/ppc32elf.em (ppc_before_allocation): Call
	ppc_elf_maybe_strip_sdata_syms.
	* ldlang.c (size_input_section): Correct output_offset value
	for excluded input sections.
2014-05-20 13:13:23 +09:30
Alan Modra 6d00b59031 bfd target vector rationalisation
This renames the bfd targets to <cpu>_<format>_<other>_<endian>_vec.
So for example, bfd_elf32_ntradlittlemips_vec becomes
mips_elf32_ntrad_le_vec and hp300bsd_vec becomes m68k_aout_hp300bsd_vec.

bfd/
	* aix386-core.c, * aout-adobe.c, * aout-arm.c, * aout-ns32k.c,
	* aout-sparcle.c, * aout0.c, * aoutx.h, * armnetbsd.c, * bout.c,
	* cf-i386lynx.c, * cf-sparclynx.c, * cisco-core.c, * coff-alpha.c,
	* coff-apollo.c, * coff-arm.c, * coff-aux.c, * coff-go32.c,
	* coff-h8300.c, * coff-h8500.c, * coff-i386.c, * coff-i860.c,
	* coff-i960.c, * coff-m68k.c, * coff-m88k.c, * coff-mips.c,
	* coff-rs6000.c, * coff-sh.c, * coff-sparc.c, * coff-stgo32.c,
	* coff-svm68k.c, * coff-tic80.c, * coff-u68k.c, * coff-w65.c,
	* coff-we32k.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c,
	* coff64-rs6000.c, * config.bfd, * configure.com, * configure.in,
	* demo64.c, * elf-m10200.c, * elf-m10300.c, * elf32-am33lin.c,
	* elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-bfin.c,
	* elf32-cr16.c, * elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c,
	* elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c,
	* elf32-fr30.c, * elf32-frv.c, * elf32-gen.c, * elf32-h8300.c,
	* elf32-hppa.c, * elf32-i370.c, * elf32-i386.c, * elf32-i860.c,
	* elf32-i960.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c,
	* elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c,
	* elf32-m68k.c, * elf32-m88k.c, * elf32-mcore.c, * elf32-mep.c,
	* elf32-metag.c, * elf32-microblaze.c, * elf32-mips.c, * elf32-moxie.c,
	* elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-nios2.c,
	* elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c, * elf32-rl78.c,
	* elf32-rx.c, * elf32-s390.c, * elf32-score.c, * elf32-sh-symbian.c,
	* elf32-sh.c, * elf32-sh64.c, * elf32-sparc.c, * elf32-spu.c,
	* elf32-tic6x.c, * elf32-tilegx.c, * elf32-tilepro.c, * elf32-v850.c,
	* elf32-vax.c, * elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c,
	* elf32-xtensa.c, * elf64-alpha.c, * elf64-gen.c, * elf64-hppa.c,
	* elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c, * elf64-ppc.c,
	* elf64-s390.c, * elf64-sh64.c, * elf64-sparc.c, * elf64-tilegx.c,
	* elf64-x86-64.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c,
	* epoc-pe-arm.c, * epoc-pei-arm.c, * hp300bsd.c, * hp300hpux.c,
	* hppabsd-core.c, * hpux-core.c, * i386aout.c, * i386bsd.c,
	* i386dynix.c, * i386freebsd.c, * i386linux.c, * i386lynx.c,
	* i386mach3.c, * i386msdos.c, * i386netbsd.c, * i386os9k.c,
	* irix-core.c, * m68k4knetbsd.c, * m68klinux.c, * m68knetbsd.c,
	* m88kmach3.c, * m88kopenbsd.c, * mach-o-i386.c, * mach-o-x86-64.c,
	* makefile.vms, * mipsbsd.c, * mmo.c, * netbsd-core.c, * newsos3.c,
	* nlm32-alpha.c, * nlm32-i386.c, * nlm32-ppc.c, * nlm32-sparc.c,
	* ns32knetbsd.c, * osf-core.c, * pc532-mach.c, * pe-arm-wince.c,
	* pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-mips.c, * pe-ppc.c,
	* pe-sh.c, * pe-x86_64.c, * pei-arm-wince.c, * pei-arm.c,
	* pei-i386.c, * pei-ia64.c, * pei-mcore.c, * pei-mips.c, * pei-ppc.c,
	* pei-sh.c, * pei-x86_64.c, * ppcboot.c, * ptrace-core.c, * riscix.c,
	* sco5-core.c, * som.c, * sparclinux.c, * sparclynx.c,
	* sparcnetbsd.c, * sunos.c, * targets.c, * trad-core.c,
	* vax1knetbsd.c, * vaxbsd.c, * vaxnetbsd.c, * versados.c,
	* vms-alpha.c, * vms-lib.c: Rename bfd targets to
	<cpu>_<format>_<other>_<endian>_vec.  Adjust associated MY macros
	on aout targets.
	* configure: Regenerate.
binutils/
	* emul_aix.c: Update bfd target vector naming.
	* testsuite/binutils-all/objcopy.exp: Likewise.
ld/
	* emultempl/metagelf.em: Update bfd target vector naming.
	* emultempl/nios2elf.em: Likewise.
	* emultempl/spuelf.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
2014-05-02 20:09:40 +09:30
Alan Modra 40fd06d188 fill ppc476 fixup area
Stops false positive warnings from scanner.

	* elf32-ppc.c (ppc_elf_relocate_section): Fill 476 fixup area
	with "ba 0" rather than zeros.
2014-04-16 11:50:30 +09:30
Alan Modra da3a208854 ppc476 plt call stubs
Fuss over bctr in call stubs.

	* elf32-ppc.c (BA): Define
	(ppc_elf_link_hash_table_create): Correct default_params.
	(write_glink_stub): Pad small plt call stub with "ba 0" rather
	than "nop" for ppc476_workaround.
	(ppc_elf_finish_dynamic_sections): Likewise for branch table
	and __glink_PLTresolve.  Ensure plt call stub at end of page
	doesn't allow fall-thru prefetch.
2014-04-14 18:17:13 +09:30
Alan Modra b4ab436423 ppc476 icache workaround fix for bctr
I got the ppc476 workaround wrong.  bctr (and bctrl) as the last
instruction in a page can hit the icache bug if the preceding mtctr
insn is close by, and the destination is in the first few instructions
on the next page.  This scenario can occur with code generated by gcc
to implement switch statements, or in code generated to call by
function pointer.

To prevent the bctr problem it is also necessary to remove other
instructions that otherwise would be safe.

bfd/
	* elf32-ppc.c (ppc_elf_relocate_section): Remove bctr from list
	of safe ppc476 insns at end of page.  Also remove non-branch insns.
	Expand comments.
ld/
	* emultempl/ppc32elf.em (no_zero_padding, ppc_finish): New functions.
	(LDEMUL_FINISH): Define.
2014-04-09 07:07:06 +09:30
Alan Modra c3301df1da 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.
2014-03-14 15:01:53 +10:30
Alan Modra 86c9573369 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.
2014-03-08 16:30:43 +10:30
Alan Modra db434ba03e Fix ELF ppc32 targets that don't use ppc32elf.em
5446cbdf82 broke powerpc-lynxos,
powerpc-netware, powerpc-windiss and powerpc-vxworks.

bfd/
	* elf32-ppc.c (ppc_elf_link_hash_table_create): Provide default
	params for targets that don't use ppc32elf.em.
ld/
	* emulparams/elf32ppcvxworks.sh: Source plt_unwind.sh and
	use ppc32elf.em.
	* emultempl/ppc32elf.em (ppc_after_open): Don't compile for
	vxworks.
	(LDEMUL_AFTER_OPEN): Don't set for vxworks.
	(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS): Exclude
	-secure-plt, -bss-plt and -sdata-got when vxworks.
2014-02-27 23:39:01 +10:30
Alan Modra 668e22e51b ppc476 workaround for ld -r fixes
This fixes the glaring error that the ppc476 workaround wasn't
actually enabled for ld -r, and adjusts relocations to match moved
code.

bfd/
	* elf32-ppc.c (ppc_elf_relocate_section): Move relocs on insns
	patched for ppc476 workaround.  Reapply branch taken/not taken
	relocs.
ld/
	* emultempl/ppc32elf.em (ppc_after_open_output): Really enable
	ppc476 workaround for ld -r.
2014-02-17 17:00:19 +10:30
Alan Modra 9f7552cff4 Fix bad interaction between --relax and tls optimisation
Adding long-branch stubs for __tls_get_addr calls that are optimised
away is silly.  It also causes assertion failures on newer object files
that use R_PPC_TLSGD and R_PPC_TLSLD marker relocs, and half-optimised
(ie. broken) code for older object files.

	PR 16546
	* elf32-ppc.c (ppc_elf_relax_section): Don't build long-branch
	stubs for calls to __tls_get_addr that we know will later be
	optimised away.
2014-02-12 22:10:09 +10:30
Alan Modra 795bc6b3ea Enable ppc476 workaround for ld -r.
The Linux kernel builds modules using ld -r.  These might need the
ppc476 workaround, so enable it for ld -r if sections have sufficient
alignment to tell location within a page.

bfd/
	* elf32-ppc.c (ppc_elf_relax_section): Enable ppc476 workaround
	for ld -r, when code sections are sufficiently aligned.
	* elf32-ppc.h (struct ppc_elf_params): Delete pagesize.  Add
	pagesize_p2.
ld/
	* emultempl/ppc32elf.em (pagesize): New static var.
	(ppc_after_open_output): Set params.pagesize_p2 from pagesize.
	(PARSE_AND_LIST_ARGS_CASES): Adjust to use pagesize.
2014-02-12 22:10:09 +10:30
Alan Modra 53291d1f16 powerpc relax_section and section contents cache
This patch provides a means for backend relax_section support to
increase the size of a section without needing to reallocate
section contents.  This helps reduce memory usage when the added space
does not need to be written in relax_section, as is the case for
powerpc.  Writing the stubs later means a few tweaks are needed in the
powerpc relocate_section function, but also removes some code
duplication since the extra ld -r relocs can be written there too.

	* elf-bfd.h (struct elf_backend_data): Add caches_rawsize.
	* elfxx-target.h (elf_backend_caches_rawsize): Define.
	(elfNN_bed): Init new field.
	* elflink.c (elf_link_input_bfd): Handle caches_rawsize.
	* elf32-ppc.c (shared_stub_entry): Zero addi offset.
	(ppc_elf_relax_section): Don't reallocate section here, write
	stubs, or write out relocs for ld -r here..
	(ppc_elf_relocate_section): ..instead write stubs here, and use
	existing code to write out relocs for ld -r.  Fix offset
	adjustment on reloc for little-endian.
	(elf_backend_caches_rawsize): Define.
2014-02-09 23:25:14 +10:30
Alan Modra 5446cbdf82 ppc476 icache bug workaround
This implements a work-around for an icache bug on 476 that can cause
execution of stale instructions when control falls through from one
page to the next.  The idea is to prevent such fall-through by
replacing the last instruction on a page with a branch to a patch
area containing the instruction, then branch to the next page.

The patch also fixes a number of bugs in the existing support for long
branch trampolines.

bfd/
	* elf32-ppc.c (struct ppc_elf_link_hash_table): Add params.
	Delete emit_stub_syms, no_tls_get_addr_opt.  Update all uses.
	(ppc_elf_link_params): New function.
	(ppc_elf_create_glink): Align .glink to 64 bytes for ppc476
	workaround.
	(ppc_elf_select_plt_layout): Remove plt_style and emit_stub_syms
	parameters.  Use htab->params instead.
	(ppc_elf_tls_setup): Remove no_tls_get_addr_opt parameter.
	(ppc_elf_size_dynamic_sections): Align __glink_PLTresolve to
	64 bytes for ppc476 workaround.
	(struct ppc_elf_relax_info): New.
	(ppc_elf_relax_section): Exclude linker created sections and
	those too small to hold one instruction.  Don't add another
	branch 	around trampolines on later relax passes.  Don't
	generate trampolines for undefined symbols when !relocatable,
	nor for plugin symbols.  Allocate space for ppc476 workaround
	patch area.  Free fixups on error return path.
	(ppc_elf_relocate_section): Handle ppc476 workaround patching.
	* elf32-ppc.h (struct ppc_elf_params): New.
	(ppc_elf_select_plt_layout, ppc_elf_tls_setup): Update prototype.
	(ppc_elf_link_params): Declare.
	* section.c (SEC_INFO_TYPE_TARGET): Define.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/ppc32elf.em (no_tls_get_addr_opt, emit_stub_syms)
	plt_style): Delete.  Adjust all refs to instead use..
	(params): ..this.  New variable.
	(ppc_after_open_output): New function.  Tweak params and pass to
	ppc_elf_link_params.
	(ppc_after_open): Adjust ppc_elf_select_plt_layout call.
	(ppc_before_allocation): Adjust ppc_elf_tls_setup call.  Enable
	relaxation for ppc476 workaround.
	(PARSE_AND_LIST_*): Add --{no-,}ppc476-workaround support.
	(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): Define.
2014-02-03 20:24:20 +10:30
Alan Modra c7e17e05b6 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.
2014-01-13 15:04:15 +10:30
H.J. Lu 782450358d Default elf_backend_post_process_headers to set OSABI
* elf-bfd.h (_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf.c (_bfd_elf_compute_section_file_positions): Always
	call elf_backend_post_process_headers.
	(_bfd_elf_set_osabi): Renamed to ...
	(_bfd_elf_post_process_headers): This.
	* elf32-hppa.c (elf_backend_post_process_headers): Removed.
	* elf32-i370.c (elf_backend_post_process_headers): Likewise.
	* elf32-msp430.c (elf_backend_post_process_headers): Likewise.
	* elf32-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf32-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-hppa.c (elf_backend_post_process_headers): Likewise.
	* elf64-ppc.c (elf_backend_post_process_headers): Likewise.
	* elf64-sparc.c (elf_backend_post_process_headers): Likewise.
	* elf64-x86-64.c (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	*  (elf_backend_post_process_headers): Likewise.
	* elf32-i386.c (elf_backend_post_process_headers): Don't
	define as _bfd_elf_set_osabi.
	(elf_i386_fbsd_post_process_headers): Updated.
	* elf32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf32-tic6x.c (elf32_tic6x_set_osabi): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elf64-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfn32-mips.c (elf_fbsd_post_process_headers): Removed.
	(elf_backend_post_process_headers): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_post_process_headers): Updated.
	* elfxx-target.h (elf_backend_post_process_headers): Default
	to _bfd_elf_post_process_headers.
2013-12-17 13:41:17 -08:00
H.J. Lu 62d887d406 Pass ignored unresolved relocations to ld backend
bfd/

	PR ld/4409
	* elf-bfd.h (RELOC_FOR_GLOBAL_SYMBOL): Add an argument for
	error ignored.
	* elf-m10200.c (mn10200_elf_relocate_section): Updated.
	* elf-m10300.c (mn10300_elf_relocate_section): Likewise.
	* elf32-arm.c (elf32_arm_relocate_section): Likewise.
	* elf32-avr.c (elf32_avr_relocate_section): Likewise.
	* elf32-bfin.c (bfinfdpic_relocate_section): Likewise.
	(bfin_relocate_section): Likewise.
	* elf32-cr16.c (elf32_cr16_relocate_section): Likewise.
	* elf32-cr16c.c (elf32_cr16c_relocate_section): Likewise.
	* elf32-cris.c (cris_elf_relocate_section): Likewise.
	* elf32-crx.c (elf32_crx_relocate_section): Likewise.
	* elf32-d10v.c (elf32_d10v_relocate_section): Likewise.
	* elf32-epiphany.c (epiphany_elf_relocate_section): Likewise.
	* elf32-fr30.c (fr30_elf_relocate_section): Likewise.
	* elf32-frv.c (elf32_frv_relocate_section): Likewise.
	* elf32-h8300.c (elf32_h8_relocate_section): Likewise.
	* elf32-hppa.c (elf32_hppa_relocate_section): Likewise.
	* elf32-i386.c (elf_i386_relocate_section): Likewise.
	* elf32-i860.c (elf32_i860_relocate_section): Likewise.
	* elf32-ip2k.c (ip2k_elf_relocate_section): Likewise.
	* elf32-iq2000.c (iq2000_elf_relocate_section): Likewise.
	* elf32-lm32.c (lm32_elf_relocate_section): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_relocate_section): Likewise.
	* elf32-m68k.c (elf_m68k_relocate_section): Likewise.
	* elf32-metag.c (elf_metag_relocate_section): Likewise.
	* elf32-microblaze.c (microblaze_elf_relocate_section): Likewise.
	* elf32-mcore.c (mcore_elf_relocate_section): Likewise.
	* elf32-mep.c (mep_elf_relocate_section): Likewise.
	* elf32-moxie.c (moxie_elf_relocate_section): Likewise.
	* elf32-msp430.c (elf32_msp430_relocate_section): Likewise.
	* elf32-mt.c (mt_elf_relocate_section): Likewise.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-openrisc.c (openrisc_elf_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_relocate_section): Likewise.
	* elf32-rl78.c (rl78_elf_relocate_section): Likewise.
	* elf32-rx.c (rx_elf_relocate_section): Likewise.
	* elf32-tic6x.c (elf32_tic6x_relocate_section): Likewise.
	* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
	* elf32-s390.c (elf_s390_relocate_section): Likewise.
	* elf32-v850.c (v850_elf_relocate_section): Likewise.
	* elf32-vax.c (elf_vax_relocate_section): Likewise.
	* elf32-xc16x.c (elf32_xc16x_relocate_section): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_relocate_section): Likewise.
	* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
	* elf64-alpha.c (elf64_alpha_relocate_section): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_relocate_section): Likewise.
	* elf64-mmix.c (mmix_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
	* elf64-s390.c (elf_s390_relocate_section): Likewise.
	* elf64-x86-64.c (elf64_x86_64_relocate_section): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Likewise.
	* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.

	* elfnn-ia64.c (elfNN_ia64_relocate_section): Skip if error
	from RELOC_FOR_GLOBAL_SYMBOL in executable is ignored.

ld/testsuite/

	PR ld/4409
	* ld-ia64/error1.d: New file.
	* ld-ia64/error1.s: Likewise.
	* ld-ia64/error2.d: Likewise.
	* ld-ia64/error3.d: Likewise.
2013-11-05 10:29:44 -08:00
Alan Modra e8910a83af Replace DT_PPC_TLSOPT with DT_PPC_OPT.
This removes the DT_PPC_TLSOPT/DT_PPC64_TLSOPT dynamic tag and replaces
it with DT_PPC_OPT/DT_PPC64_OPT tag to provide the same functionality
and more.  This isn't backwards compatible, but the TLSOPT tag hasn't
been used since the tls optimisation support was never submitted to
glibc.

/include/elf/
	* ppc.h (DT_PPC_TLSOPT): Delete.
	(DT_PPC_OPT, PPC_OPT_TLS): Define.
	* ppc64.h (DT_PPC64_TLSOPT): Delete.
	(DT_PPC64_OPT, PPC64_OPT_TLS, PPC64_OPT_MULTI_TOC): Define.
bfd/
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Use new DT_PPC_OPT
	tag to specify tls optimisation.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	(ppc64_elf_finish_dynamic_sections): Specify whether multiple
	toc pointers are used via DT_PPC64_OPT.
binutils/
	* readelf.c (get_ppc_dynamic_type): Replace PPC_TLSOPT with PPC_OPT.
	(get_ppc64_dynamic_type): Replace PPC64_TLSOPT with PPC64_OPT.
2013-10-30 13:43:32 +10:30
Alan Modra 198f1157c9 * elf32-ppc.c (ppc_elf_check_relocs): Use SYMBOLIC_BIND.
* elf64-ppc.c (ppc64_elf_check_relocs, dec_dynrel_count): Likewise.
2013-04-06 06:44:45 +00:00
Alan Modra 81fbe831fe PR ld/15323
bfd/
	* elf-m10300.c (mn10300_elf_check_relocs): Set non_ir_ref for
	global symbols referenced by relocs.
	* elf32-arm.c (elf32_arm_check_relocs): Likewise.
	* elf32-bfin.c (bfin_check_relocs): Likewise.
	* elf32-cr16.c (cr16_elf_check_relocs): Likewise.
	* elf32-cris.c (cris_elf_check_relocs): Likewise.
	* elf32-d10v.c (elf32_d10v_check_relocs): Likewise.
	* elf32-dlx.c (elf32_dlx_check_relocs): Likewise.
	* elf32-fr30.c (fr30_elf_check_relocs): Likewise.
	* elf32-frv.c (elf32_frv_check_relocs): Likewise.
	* elf32-hppa.c (elf32_hppa_check_relocs): Likewise.
	* elf32-i370.c (i370_elf_check_relocs): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_check_relocs): Likewise.
	* elf32-m32c.c (m32c_elf_check_relocs): Likewise.
	* elf32-m32r.c (m32r_elf_check_relocs): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_check_relocs): Likewise.
	* elf32-m68k.c (elf_m68k_check_relocs): Likewise.
	* elf32-mcore.c (mcore_elf_check_relocs): Likewise.
	* elf32-metag.c (elf_metag_check_relocs): Likewise.
	* elf32-microblaze.c (microblaze_elf_check_relocs): Likewise.
	* elf32-moxie.c (moxie_elf_check_relocs): Likewise.
	* elf32-msp430.c (elf32_msp430_check_relocs): Likewise.
	* elf32-mt.c (mt_elf_check_relocs): Likewise.
	* elf32-nios2.c (nios2_elf32_check_relocs): Likewise.
	* elf32-openrisc.c (openrisc_elf_check_relocs): Likewise.
	* elf32-ppc.c (ppc_elf_check_relocs): Likewise.
	* elf32-rl78.c (rl78_elf_check_relocs): Likewise.
	* elf32-s390.c (elf_s390_check_relocs): Likewise.
	* elf32-score.c (s3_bfd_score_elf_check_relocs): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_check_relocs): Likewise.
	* elf32-sh.c (sh_elf_check_relocs): Likewise.
	* elf32-tic6x.c (elf32_tic6x_check_relocs): Likewise.
	* elf32-tilepro.c (tilepro_elf_check_relocs): Likewise.
	* elf32-v850.c (v850_elf_check_relocs): Likewise.
	* elf32-vax.c (elf_vax_check_relocs): Likewise.
	* elf32-xstormy16.c (xstormy16_elf_check_relocs): Likewise.
	* elf32-xtensa.c (elf_xtensa_check_relocs): Likewise.
	* elf64-aarch64.c (elf64_aarch64_check_relocs): Likewise.
	* elf64-alpha.c (elf64_alpha_check_relocs): Likewise.
	* elf64-hppa.c (elf64_hppa_check_relocs): Likewise.
	* elf64-ia64-vms.c (elf64_ia64_check_relocs): Likewise.
	* elf64-mmix.c (mmix_elf_check_relocs): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Likewise.
	* elf64-s390.c (elf_s390_check_relocs): Likewise.
	* elf64-sh64.c (sh_elf64_check_relocs): Likewise.
	* elfnn-ia64.c (elfNN_ia64_check_relocs): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Likewise.
	* elfxx-tilegx.c (tilegx_elf_check_relocs): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.  Don't
	test indirect/warning links for NULL.
ld/testsuite/
	* ld-plugin/lto.exp (pr15323a.c): Compile without -flto rather
	than using -r to effectively strip out lto info.
2013-03-30 10:14:15 +00:00
Alan Modra f95f8542c5 * elf32-ppc.c (struct ppc_dyn_relocs): New.
(ppc_elf_check_relocs): Separate dynrel counts for local syms
	into ifunc and non-ifunc.
	(allocate_dynrelocs): Always put ifunc relocs into reliplt.
	(ppc_elf_size_dynamic_sections): Likewise.
	(ppc_elf_relocate_section): Likewise.
2013-03-28 07:07:25 +00:00
Alan Modra 7e612e9848 * elf-bfd.h (enum elf_reloc_type_class): Add reloc_class_ifunc.
(struct elf_backend_data <elf_backed_reloc_type_class>): Add
	bfd_link_info* and asection* params.
	(_bfd_elf_reloc_type_class): Likewise.
	* elf.c (_bfd_elf_reloc_type_class): Likewise.
	* elflink.c (elf_link_sort_cmp2): Sort first on reloc class.
	(elf_link_sort_relocs): Update elf_backed_reloc_type_class call.
	* elf32-ppc.c (ppc_elf_reloc_type_class): Return reloc_class_ifunc
	for any reliplt reloc.  Don't return reloc_class_plt for
	R_PPC_REL24 and R_PPC_ADDR24.
	* elf64-ppc.c (allocate_got): Formatting.
	(ppc64_elf_reloc_type_class): Return reloc_class_ifunc for any
	reliplt reloc.
	* elf-m10300.c, * elf32-arm.c, * elf32-bfin.c, * elf32-cr16.c,
	* elf32-cris.c, * elf32-hppa.c, * elf32-i386.c, * elf32-lm32.c,
	* elf32-m32r.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c,
	* elf32-s390.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilepro.c,
	* elf32-vax.c, * elf32-xtensa.c, * elf64-aarch64.c, * elf64-alpha.c,
	* elf64-hppa.c, * elf64-ia64-vms.c, * elf64-s390.c, * elf64-sparc.c,
	* elf64-x86-64.c, * elfnn-ia64.c, * elfxx-tilegx.c, * elfxx-tilegx.h:
	Add extra params to the various reloc_type_class functions.
2013-03-27 13:37:51 +00:00
Alan Modra 0bed072fb1 * elf32-ppc.c (ppc_elf_check_relocs): Set PLT_IFUNC in local got
masks for all local ifunc syms.
	(allocate_dynrelocs): Don't use htab->relgot for ifunc.
	(ppc_elf_size_dynamic_sections): Likewise.
	(ppc_elf_relocate_section): Likewise.
2013-03-27 13:25:48 +00:00
Alan Modra f75e0e336f * elf32-ppc.c (ppc_elf_relocate_section <R_PPC_PLTREL24>): Adjust
non-zero addends when relocatable, rather than addends >= 32768.
	Always zero "addend" before applying relocation.
2013-03-04 12:12:11 +00:00
Alan Modra 228e534f16 * elf-bfd.h (struct core_elf_obj_tdata): New.
(struct elf_obj_tdata): Delete core_signal, core_pid, core_lwpid,
	core_program, and core_command.  Add "core".
	* elf.c (bfd_elf_mkcorefile): Allocate "core" struct.
	Update all refs to tdata core fields.
	* elf32-am33lin.c, * elf32-arm.c, * elf32-cris.c, * elf32-frv.c,
	* elf32-hppa.c, * elf32-i386.c, * elf32-m68k.c, * elf32-mips.c,
	* elf32-nios2.c, * elf32-ppc.c, * elf32-s390.c, * elf32-score.c,
	* elf32-score7.c, * elf32-sh.c, * elf32-sparc.c, * elf32-tilegx.c,
	* elf32-tilepro.c, * elf32-xtensa.c, * elf64-aarch64.c,
	* elf64-hppa.c, * elf64-mips.c, * elf64-ppc.c, * elf64-tilegx.c,
	* elf64-x86-64.c, * elfcore.h, * elfn32-mips.c: Update all refs
	to tdata core fields.
2013-02-21 03:02:30 +00:00
Alan Modra 12bd695738 bfd/
* elf-bfd.h (struct elf_obj_tdata): Rename segment_map to seg_map.
	Delete num_locals and num_globals.
	(elf_num_locals, elf_num_globals): Don't define.
	(elf_seg_map, elf_next_file_pos, elf_eh_frame_hdr, elf_linker,
	elf_stack_flags, elf_strtab_sec, elf_shstrtab_sec): Define.
	* bfd.c, * elf-eh-frame.c, * elf-nacl.c, * elf-vxworks.c, * elf.c,
	* elf32-arm.c, * elf32-lm32.c, * elf32-ppc.c, * elf32-rx.c,
	* elf32-spu.c, * elf64-hppa.c, * elfcode.h, * elflink.c,
	* elfnn-ia64.c, * elfxx-mips.c: Use newly defined elf_obj_tdata
	accessor macros.
	* elf.c (elf_map_symbols): Add pnum_locals param.  Return
	number of locals syms via new param.
	(swap_out_syms): Adjust to suit elf_map_symbols change.
ld/
	* emultempl/elf-generic.em: Use newly defined elf_obj_tdata
	accessor macros.
2013-02-21 02:29:11 +00:00
Sergio Durigan Junior 70a38d42c5 2013-02-04 Sergio Durigan Junior <sergiodj@redhat.com>
Pedro Alves  <palves@redhat.com>

	* Makefile.in (SOURCE_HFILES): Add `elf-linux-psinfo.h'.
	* elf-bfd.h (elf_internal_linux_prpsinfo): New structure
	declaration.
	(elfcore_write_linux_prpsinfo32, elfcore_write_linux_prpsinfo64)
	(elfcore_write_ppc32_linux_prpsinfo32): New declarations.
	* elf-linux-psinfo.h: New file.
	* elf.c: Include elf-linux-psinfo.h.
	(elfcore_write_linux_prpsinfo32, elfcore_write_linux_prpsinfo64):
	New functions.
	* elf32-ppc.c: Include `elf-linux-psinfo.h'.
	(elf_external_ppc_linux_prpsinfo32): New structure declaration.
	(PPC_LINUX_PRPSINFO32_SWAP_FIELDS): New macro.
	(elfcore_write_ppc_linux_prpsinfo32): New function.
2013-02-04 18:26:34 +00:00
H.J. Lu 68ffbac672 Remove trailing white spaces in bfd
* aout0.c: Remove trailing white spaces.
	* archive.c: Likewise.
	* archures.c: Likewise.
	* bfd-in.h: Likewise.
	* bfd-in2.h: Likewise.
	* coff-alpha.c: Likewise.
	* coff-i860.c: Likewise.
	* coff-mips.c: Likewise.
	* coff-ppc.c: Likewise.
	* coff-tic80.c: Likewise.
	* coff-x86_64.c: Likewise.
	* coff-z80.c: Likewise.
	* coffcode.h: Likewise.
	* coffgen.c: Likewise.
	* cofflink.c: Likewise.
	* compress.c: Likewise.
	* corefile.c: Likewise.
	* cpu-arm.c: Likewise.
	* cpu-avr.c: Likewise.
	* cpu-bfin.c: Likewise.
	* cpu-cr16.c: Likewise.
	* cpu-cr16c.c: Likewise.
	* cpu-crx.c: Likewise.
	* cpu-h8300.c: Likewise.
	* cpu-i386.c: Likewise.
	* cpu-lm32.c: Likewise.
	* cpu-m68k.c: Likewise.
	* cpu-moxie.c: Likewise.
	* cpu-msp430.c: Likewise.
	* cpu-sh.c: Likewise.
	* cpu-xc16x.c: Likewise.
	* dwarf2.c: Likewise.
	* ecofflink.c: Likewise.
	* ecoffswap.h: Likewise.
	* elf-ifunc.c: Likewise.
	* elf-m10300.c: Likewise.
	* elf-vxworks.c: Likewise.
	* elf32-avr.c: Likewise.
	* elf32-avr.h: Likewise.
	* elf32-cr16.c: Likewise.
	* elf32-cr16c.c: Likewise.
	* elf32-cris.c: Likewise.
	* elf32-crx.c: Likewise.
	* elf32-frv.c: Likewise.
	* elf32-hppa.c: Likewise.
	* elf32-i860.c: Likewise.
	* elf32-ip2k.c: Likewise.
	* elf32-iq2000.c: Likewise.
	* elf32-m32c.c: Likewise.
	* elf32-m68hc1x.c: Likewise.
	* elf32-msp430.c: Likewise.
	* elf32-mt.c: Likewise.
	* elf32-ppc.c: Likewise.
	* elf32-rl78.c: Likewise.
	* elf32-s390.c: Likewise.
	* elf32-score.h: Likewise.
	* elf32-sh-symbian.c: Likewise.
	* elf32-sh.c: Likewise.
	* elf32-spu.c: Likewise.
	* elf32-tic6x.c: Likewise.
	* elf32-v850.c: Likewise.
	* elf32-xc16x.c: Likewise.
	* elf32-xtensa.c: Likewise.
	* elf64-alpha.c: Likewise.
	* elf64-hppa.c: Likewise.
	* elf64-ppc.c: Likewise.
	* elf64-s390.c: Likewise.
	* elfcore.h: Likewise.
	* elflink.c: Likewise.
	* elfxx-mips.c: Likewise.
	* elfxx-sparc.c: Likewise.
	* elfxx-tilegx.c: Likewise.
	* ieee.c: Likewise.
	* libcoff.h: Likewise.
	* libpei.h: Likewise.
	* libxcoff.h: Likewise.
	* linker.c: Likewise.
	* mach-o-i386.c: Likewise.
	* mach-o-target.c: Likewise.
	* mach-o.c: Likewise.
	* mach-o.h: Likewise.
	* mmo.c: Likewise.
	* opncls.c: Likewise.
	* pdp11.c: Likewise.
	* pe-x86_64.c: Likewise.
	* peXXigen.c: Likewise.
	* pef-traceback.h: Likewise.
	* pei-x86_64.c: Likewise.
	* peicode.h: Likewise.
	* plugin.c: Likewise.
	* reloc.c: Likewise.
	* riscix.c: Likewise.
	* section.c: Likewise.
	* som.c: Likewise.
	* syms.c: Likewise.
	* tekhex.c: Likewise.
	* ticoff.h: Likewise.
	* vaxbsd.c: Likewise.
	* xcofflink.c: Likewise.
	* xtensa-isa.c: Likewise.
2013-01-10 20:03:55 +00:00
Alan Modra bdaacd3a1c * elf32-ppc.c (ppc_elf_howto_raw): Correct dst_mask in
R_PPC_VLE_LO16A, R_PPC_VLE_HI16A, R_PPC_VLE_HA16A,
	R_PPC_VLE_SDAREL_LO16A, R_PPC_VLE_SDAREL_HI16A,
	R_PPC_VLE_SDAREL_HA16A reloc howtos.
2012-10-29 09:51:10 +00:00
Alan Modra 1fe532cf60 PR target/14758
bfd/
	* elf32-ppc.c (ppc_elf_reloc_type_lookup): Decode ppc64 _DS
	bfd_reloc values.  Map to corresponding D-form relocs.
	(is_insn_ds_form, is_insn_qs_form): New functions.
	(ppc_elf_relocate_section): Validate insn with DS-form or DQ-form
	fields using D-form reloc.
gas/
	* config/tc-ppc.c (ppc_setup_opcodes): Fix comment.
	(md_assemble): Translate to _DS relocs for ppc32 as well as ppc64.
	(tc_gen_reloc): Handle _DS relocs in ppc32 mode.
2012-10-26 03:40:37 +00:00
Maciej W. Rozycki 14acf4dcae * elf32-ppc.c (ppc_elf_relocate_section): Assert that dynindx is
not minus one.
	* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
2012-08-28 20:17:56 +00:00
Alan Modra a86852103b typo fixes 2012-08-17 02:43:21 +00:00