Commit Graph

2127 Commits

Author SHA1 Message Date
Cary Coutant 890d155592 Fix internal error caused by conflicting default version definitions.
gold/
	PR gold/16504
	* dynobj.cc (Versions::symbol_section_contents): Don't set
	VERSYM_HIDDEN flag for undefined symbols.
	* symtab.cc (Symbol_table::add_from_object): Don't override default
	version definition with a different default version.
	* symtab.h (Symbol::from_dyn): New method.
	* testsuite/plugin_test.c (struct sym_info): Add ver field.
	(claim_file_hook): Pass symbol version to plugin API.
	(parse_readelf_line): Parse symbol version.
	* testsuite/Makefile.am (ver_test_pr16504): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ver_test_pr16504.sh: New test script.
	* testsuite/ver_test_pr16504_a.c: New source file.
	* testsuite/ver_test_pr16504_a.script: New version script.
	* testsuite/ver_test_pr16504_b.c: New source file.
	* testsuite/ver_test_pr16504_b.script: New version script.
2018-04-24 13:51:24 -07:00
Cary Coutant d83d540335 Fix second bug where --icf=safe triggers segfault when linking ARM.
When checking a R_ARM_TARGET[12] relocation, we need a valid target
pointer, but the garbage collection code was passing a NULL instead.
The previous fix for this bug fixed the call to
scan.global_reloc_may_be_function_pointer, but missed the similar
call to scan.local_reloc_may_be_function_pointer.

gold/
	PR gold/23046
	* gc.h (gc_process_relocs): Pass target to
	scan.local_reloc_may_be_function_pointer.
2018-04-19 10:20:08 -07:00
Nick Clifton f792cedd00 Updated Spanish translations for the gold and gprof sub-directories 2018-04-18 10:48:56 +01:00
Cary Coutant aae8280935 Fix bug where --icf=safe triggers segfault when linking ARM.
When checking a R_ARM_TARGET[12] relocation, we need a valid target
pointer, but the garbage collection code was passing a NULL instead.

gold/
	PR gold/23046
	* gc.h (gc_process_relocs): Pass target to
	scan.global_reloc_may_be_function_pointer.
2018-04-14 15:58:07 -07:00
Alan Modra c4a614e239 Regenerate some files
The gold change is to pick up HJ's PR22318 AC_PLUGINS update.  The
ld change is to correct a file I generated from a modified tree.

gold/
	* configure: Regenerate.
ld/
	* po/BLD-POTFILES.in: Regenerate.
2018-04-10 00:20:19 +09:30
Alan Modra 23cedd1dc9 PowerPC inline PLT call support
In addition to the existing relocs we need two more to mark all
instructions in the call sequence, PLTCALL on the call itself (plus
the toc restore insn for ppc64), and PLTSEQ on others.  All
relocations in a particular sequence have the same symbol.

Example ppc64 ELFv2 assembly:
 .reloc .,R_PPC64_PLTSEQ,puts
	std 2,24(1)
	addis 12,2,puts@plt@ha	# .reloc .,R_PPC64_PLT16_HA,puts
	ld 12,puts@plt@l(12)	# .reloc .,R_PPC64_PLT16_LO_DS,puts
 .reloc .,R_PPC64_PLTSEQ,puts
	mtctr 12
 .reloc .,R_PPC64_PLTCALL,puts
	bctrl
	ld 2,24(1)

Example ppc32 -fPIC assembly:
	addis 12,30,puts+32768@plt@ha # .reloc .,R_PPC_PLT16_HA,puts+0x8000
	lwz 12,12,puts+32768@plt@l    # .reloc .,R_PPC_PLT16_LO,puts+0x8000
 .reloc .,R_PPC_PLTSEQ,puts+32768
	mtctr 12
 .reloc .,R_PPC_PLTCALL,puts+32768
	bctrl

Marking sequences like this allows the linker to convert them to nops
and a direct call if the target symbol turns out to be local.

When the call is __tls_get_addr, each relocation shown above is paired
with an R_PPC*_TLSLD or R_PPC*_TLSGD reloc to additionally mark the
sequence for possible TLS optimization.  The TLSLD or TLSGD relocs are
emitted first.

include/
	* elf/ppc.h (R_PPC_PLTSEQ, R_PPC_PLTCALL): Define.
	* elf/ppc64.h (R_PPC64_PLTSEQ, R_PPC64_PLTCALL): Define.
bfd/
	* elf32-ppc.c (ppc_elf_howto_raw): Add PLTSEQ and PLTCALL howtos.
	(is_plt_seq_reloc): New function.
	(ppc_elf_check_relocs): Handle PLTSEQ and PLTCALL relocs.
	(ppc_elf_tls_optimize): Handle inline plt call sequence.
	(ppc_elf_relax_section): Handle PLTCALL reloc.
	(ppc_elf_relocate_section): Nop out inline plt call sequence when
	resolving locally.
	* elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_PLTSEQ and
	R_PPC64_PLTCALL entries.  Comment R_PPC64_TOCSAVE.
	(has_tls_get_addr_call): Correct comment.
	(is_branch_reloc): Add PLTCALL.
	(is_plt_seq_reloc): New function.
	(ppc64_elf_check_relocs): Handle PLT16_LO_DS reloc.  Set
	has_tls_reloc for R_PPC64_TLSGD and R_PPC64_TLSLD.  Create plt
	entry for R_PPC64_PLTCALL.
	(ppc64_elf_tls_optimize): Handle inline plt call sequence.
	(ppc_type_of_stub): Handle PLTCALL reloc.
	(toc_adjusting_stub_needed): Likewise.
	(ppc64_elf_relocate_section): Set "can_plt_call" for PLTCALL
	reloc insn.  Nop out inline plt call sequence when resolving
	locally.  Handle __tls_get_addr inline plt call optimization.
elfcpp/
	* powerpc.h (R_POWERPC_PLTSEQ, R_POWERPC_PLTCALL): Define.
gold/
	* powerpc.cc (Target_powerpc::Track_tls::maybe_skip_tls_get_addr_call):
	Handle inline plt sequence relocs.
	(Stub_table::Plt_stub_key::Plt_stub_key): Likewise.
	(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.
2018-04-09 17:25:20 +09:30
Alan Modra 2d7ad24e87 Support PLT16 relocs against local symbols
Necessary if gcc is to use PLT16 relocs to implement -mlongcall, and
there isn't a good technical reason why local symbols should be
excluded from PLT16 support.  Non-ifunc local symbol PLT entries go in
a separate section to other PLT entries.  In a fixed position
executable they won't need to be relocated, and in a PIE or shared
library I chose to not implement lazy relocation.

bfd/
	* elf64-ppc.c (LOCAL_PLT_ENTRY_SIZE): Define.
	(struct ppc_stub_hash_entry): Add symtype field.
	(PLT_KEEP): Define.
	(struct ppc_link_hash_table): Add pltlocal and relpltlocal.
	(create_linkage_sections): Create pltlocal and relpltlocal.
	(ppc64_elf_check_relocs): Allow PLT relocs on local symbols.
	Set PLT_KEEP.
	(ppc64_elf_adjust_dynamic_symbol): Keep PLT entries for inline calls.
	(allocate_dynrelocs): Allocate pltlocal and relpltlocal.
	(ppc64_elf_size_dynamic_sections): Size pltlocal and relpltlocal.
	Keep PLT entries for inline calls against locals.
	(ppc_build_one_stub): Use pltlocal as appropriate.
	(ppc_size_one_stub): Likewise.
	(ppc64_elf_size_stubs): Set symtype.
	(build_global_entry_stubs_and_plt): Init pltlocal and write
	relpltlocal for globals.
	(write_plt_relocs_for_local_syms): Likewise for local syms.
	(ppc64_elf_relocate_section): Support PLT for local syms.
	* elf32-ppc.c (PLT_KEEP): Define.
	(struct ppc_elf_link_hash_table): Add pltlocal and relpltlocal.
	(ppc_elf_create_glink): Create pltlocal and relpltlocal.
	(ppc_elf_check_relocs): Allow PLT relocs on local symbols.
	Set PLT_KEEP.  Adjust update_local_sym_info call.
	(ppc_elf_adjust_dynamic_symbol): Keep PLT entries for inline calls.
	(allocate_dynrelocs): Allocate pltlocal and relpltlocal.
	(ppc_elf_size_dynamic_sections): Size pltlocal and relpltlocal.
	(ppc_elf_relocate_section): Support PLT16 relocs for local syms.
	(write_global_sym_plt): Init pltlocal and write relpltlocal.
	(ppc_finish_symbols): Likewise for locals.
ld/
	* emulparams/elf32ppc.sh (OTHER_RELRO_SECTIONS_2): Add .branch_lt.
	(OTHER_GOT_RELOC_SECTIONS): Add .rela.branch_lt.
	* testsuite/ld-powerpc/elfv2so.d: Update for symbol/stub reordering.
	* testsuite/ld-powerpc/relbrlt.d: Likewise.
	* testsuite/ld-powerpc/relbrlt.s: Likewise.
	* testsuite/ld-powerpc/tlsso.r: Likewise.
	* testsuite/ld-powerpc/tlstocso.r: Likewise.
gold/
	* powerpc.cc (Target_powerpc::lplt_): New variable.
	(Target_powerpc::lplt_section): Associated accessor.
	(Target_powerpc::plt_off): Handle local non-ifunc symbols.
	(Target_powerpc::make_lplt_section): New function.
	(Target_powerpc::make_local_plt_entry): New function.
	(Powerpc_relobj::do_relocate_sections): Write out lplt.
	(Output_data_plt_powerpc::first_plt_entry_offset): Zero for lplt.
	(Output_data_plt_powerpc::add_local_entry): New function.
	(Output_data_plt_powerpc::do_write): Ignore lplt.
	(Target_powerpc::make_iplt_section): Make lplt first.
	(Target_powerpc::make_brlt_section): Make .branch_lt relro.
	(Target_powerpc::Scan::local): Handle PLT16 relocs.
2018-04-09 17:05:09 +09:30
Alan Modra 08be322439 PowerPC PLT16 relocations
The PowerPC64 ELFv2 ABI and the PowerPC SysV ABI support a number of
relocations that can be used to create and access a PLT entry.
However, the relocs are not well defined.  The PLT16 family of relocs
talk about "the section offset or address of the procedure linkage
table entry".  It's plain that we do need a relative address when PIC
as otherwise we'd have dynamic text relocations, but "section offset"
doesn't specify which section.  The most obvious one, ".plt", isn't
that useful because there is no readily available way of addressing
the start of the ".plt" section.  Much more useful would be "the
GOT/TOC-pointer relative offset of the procedure linkage table entry",
and I suppose you could argue that is a "section offset" of sorts.
For PowerPC64 it is better to use the same TOC-pointer relative
addressing even when non-PIC, since ".plt" may be located outside the
range of a 32-bit address.  However, for ppc32 we do want an absolute
address when non-PIC as a GOT pointer may not be set up.  Also, for
ppc32 PIC we have a similar situation to R_PPC_PLTREL24 in that the
GOT pointer is set to a location in the .got2 section and we need to
specify the .got2 offset in the PLT16 reloc addend.

This patch supports PLT16 relocations using these semantics.  This is
not an ABI change for ppc32 since the relocations were not previously
supported by GNU ld, but is for ppc64 where some of the PLT16 relocs
were supported.  I'm not particularly concerned since the old ppc64
PLT16 reloc semantics made them almost completely useless.

bfd/
	* elf32-ppc.c (ppc_elf_check_relocs): Handle PLT16 relocs.
	(ppc_elf_relocate_section): Likewise.
	* elf64-ppc.c (ppc64_elf_check_relocs): Handle PLT16_LO_DS.
	(ppc64_elf_relocate_section): Likewise.  Correct PLT16
	resolution to plt entry relative to toc pointer.
gold/
	* powerpc.cc (Target_powerpc::plt_off): New functions.
	(is_plt16_reloc): New function.
	(Stub_table::plt_off): Use Target_powerpc::plt_off.
	(Stub_table::plt_call_size): Use plt_off.
	(Stub_table::do_write): Likewise.
	(Target_powerpc::Scan::get_reference_flags): Return RELATIVE_REF
	for PLT16 relocations.
	(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Return true
	for PLT16 relocations.
	(Target_powerpc::Scan::global): Make a PLT entry for PLT16 relocations.
	(Target_powerpc::Relocate::relocate): Support PLT16 relocations.
	(Powerpc_scan_relocatable_reloc::global_strategy): Return RELOC_SPECIAL
	for ppc32 plt16 relocs.
2018-04-09 16:56:35 +09:30
Cary Coutant 43193fe9fc Further improve warnings for relocations referring to discarded sections.
Relocations referring to discarded sections are now treated as errors
instead of warnings.

Also with this patch, we will now print the section group signature and the
object file with the prevailing definition of that group along with the
name of the symbol that the relocation is referring to. This additional
information should be much more useful to anyone trying to track down
the source of such errors.

To do so, we now map each discarded section to the Kept_section info in
the Layout class, and defer the logic that maps a discarded section to
its counterpart in the kept group. This gives us the information we need
to identify the signature symbol given the discarded section, and the
name of the object file that provided the prevailing (i.e., first)
definition of that group.

gold/
	* object.cc (Sized_relobj_file::include_section_group): Store
	reference to Kept_section info for discarded comdat sections
	regardless of size.  Move size checking to map_to_kept_section.
	(Sized_relobj_file::include_linkonce_section): Likewise.
	(Sized_relobj_file::map_to_kept_section): Add section name parameter.
	Insert size checking logic from above functions.
	(Sized_relobj_file::find_kept_section_object): New method.
	(Sized_relobj_file::get_symbol_name): New method.
	* object.h (Sized_relobj_file::map_to_kept_section): Add section_name
	parameter.  Adjust all callers.
	(Sized_relobj_file::find_kept_section_object): New method.
	(Sized_relobj_file::get_symbol_name): New method.
	(Sized_relobj_file::Kept_comdat_section): Replace object and shndx
	fields with sh_size, kept_section, symndx, and is_comdat fields.
	(Sized_relobj_file::set_kept_comdat_section): Replace kept_object
	and kept_shndx parameters with is_comdat, symndx, sh_size, and
	kept_section.
	(Sized_relobj_file::get_kept_comdat_section): Likewise.
	* target-reloc.h (enum Comdat_behavior): Change CB_WARNING to CB_ERROR.
	Adjust all references.
	(issue_undefined_symbol_error): New function template.
	(relocate_section): Pass section name to map_to_kept_section.
	Move discarded section code to new function above.
	* aarch64.cc (Target_aarch64::scan_reloc_section_for_stubs): Move
	declaration for gsym out one level.  Call issue_discarded_error.
	* arm.cc (Target_arm::scan_reloc_section_for_stubs): Likewise.
	* powerpc.cc (Relocate_comdat_behavior): Change CB_WARNING to CB_ERROR.
2018-04-06 22:50:14 -07:00
Cary Coutant c54b27d1c0 Improve warnings for relocations referring to discarded sections.
gold/
	* target-reloc.h (relocate_section): Add local symbol index or global
	symbol name to warning about relocation that refers to discarded
	section.
2018-04-05 14:51:45 -07:00
Cary Coutant 494e49c985 Revert previous patch and apply revised patch.
Revert:

2018-04-05  James Cowgill  <james.cowgill@mips.com>

	PR gold/22770
	* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
	page entries for the object's GOT.

Apply:

	PR gold/22770
	* mips.cc (Mips_got_info::record_got_page_entry): Don't insert
	Got_page_entry for object's GOT.
	(Mips_got_info::add_got_page_entries): Add all pages from from's GOT.
	Rename to add_got_page_count.
	(Got_page_entry): Remove num_pages.
2018-04-05 09:45:07 -07:00
James Cowgill 67faf1f4c2 MIPS: Fix GOT page counter in multi-got links
The record_got_page_entry function records and updates the maximum
number of GOT page entries which may be required by an object. In the
case where an existing GOT page entry was expanded, only the entry
belonging to output GOT would have its page count updated. This leaves
the entry belonging to the object GOT with the num_pages count of 1 it
was originally initialized with. Later on when GOTs are being merged in a
multi-got link, this causes the value of entry->num_pages in
add_got_page_entries to always be 1 and underestimates the number of pages
required for the new entry. This in turn leads to an assertion failure in
get_got_page_offset where we run out of pages.

Fix by obtaining the object's GOT entry unconditionally and not just
the first time it gets created. Now that entry2 is always valid, remove
the useless NULL checks.

gold/
	PR gold/22770
	* mips.cc (Mips_got_info::record_got_page_entry): Fetch existing
	page entries for the object's GOT.
2018-04-05 08:47:53 -07:00
Alan Modra 544838989a [GOLD] Make powerpc64 .branch_lt relro
Better security beats better placement for code optimization.

	* powerpc.cc (Target_powerpc::make_brlt_section): Make .branch_lt relro.
2018-04-05 08:26:10 +09:30
Nick Clifton 4fb0d2b912 Update Spanish translations for ld/ opcodes/ and gold/ sub-directories 2018-04-04 09:00:18 +01:00
Cary Coutant bce5a025d2 Fix problem where mixed section types can cause internal error during a -r link.
During a -r (or --emit-relocs) link, if two sections had the same name but
different section types, gold would put relocations for both sections into
the same relocation section even though the data sections remained separate.

For .eh_frame sections, when one section is PROGBITS and another is
X86_64_UNWIND, we really should be using the UNWIND section type and
combining the sections anyway.  For other sections, we should be
creating one relocation section for each output data section.

gold/
	PR gold/23016
	* incremental.cc (can_incremental_update): Check for unwind section
	type.
	* layout.h (Layout::layout): Add sh_type parameter.
	* layout.cc (Layout::layout): Likewise.
	(Layout::layout_reloc): Create new output reloc section if data
	section does not already have one.
	(Layout::layout_eh_frame): Check for unwind section type.
	(Layout::make_eh_frame_section): Use unwind section type for .eh_frame
	and .eh_frame_hdr.
	* object.h (Sized_relobj_file::Shdr_write): New typedef.
	(Sized_relobj_file::layout_section): Add sh_type parameter.
	(Sized_relobj_file::Deferred_layout::Deferred_layout): Add sh_type
	parameter.
	* object.cc (Sized_relobj_file::check_eh_frame_flags): Check for
	unwind section type.
	(Sized_relobj_file::layout_section): Add sh_type parameter; pass it
	to Layout::layout.
	(Sized_relobj_file::do_layout): Make local copy of sh_type.
	Force .eh_frame sections to unwind section type.
	Pass sh_type to layout_section.
	(Sized_relobj_file<size, big_endian>::do_layout_deferred_sections):
	Pass sh_type to layout_section.
	* output.cc (Output_section::Output_section): Initialize reloc_section_.
	* output.h (Output_section::reloc_section): New method.
	(Output_section::set_reloc_section): New method.
	(Output_section::reloc_section_): New data member.
	* target.h (Target::unwind_section_type): New method.
	(Target::Target_info::unwind_section_type): New data member.

	* aarch64.cc (aarch64_info): Add unwind_section_type.
	* arm.cc (arm_info, arm_nacl_info): Likewise.
	* i386.cc (i386_info, i386_nacl_info, iamcu_info): Likewise.
	* mips.cc (mips_info, mips_nacl_info): Likewise.
	* powerpc.cc (powerpc_info): Likewise.
	* s390.cc (s390_info): Likewise.
	* sparc.cc (sparc_info): Likewise.
	* tilegx.cc (tilegx_info): Likewise.
	* x86_64.cc (x86_64_info, x86_64_nacl_info): Likewise.

	* testsuite/Makefile.am (pr23016_1, pr23016_2): New test cases.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/testfile.cc: Add unwind_section_type.
	* testsuite/pr23016_1.sh: New test script.
	* testsuite/pr23016_1a.s: New source file.
	* testsuite/pr23016_1b.s: New source file.
	* testsuite/pr23016_2.sh: New test script.
	* testsuite/pr23016_2a.s: New source file.
	* testsuite/pr23016_2b.s: New source file.
2018-04-02 19:07:04 -07:00
Cary Coutant 24538276c6 Use top-level config support for enabling plugins.
Also recognizes --plugin options when plugins are disabled.

2018-03-28  Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/21423
	PR gold/22500
	* configure.ac: Call AC_USE_SYSTEM_EXTENSIONS.
	Replace check for --enable-plugins with AC_PLUGINS.
	* options.cc (parse_plugin, parse_plugin_opt): Remove #ifdef.
	(General_options::finalize): Check if plugins enabled.
	* options.h (--plugin, --plugin-opt): Define even if plugins not
	enabled.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.in: Regenerate.
2018-03-28 14:02:41 -07:00
Cary Coutant e82e6b2b19 Add support for R_AARCH64_TLSLE_LDST8_TPREL_LO12, etc.
elfcpp/
	PR gold/22969
	* aarch64.h: Fix spelling of R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC.
gold/
	PR gold/22969
	* aarch64-reloc.def: Add TLSLE_LDST* relocations.
	* aarch64.cc (Target_aarch64::optimize_tls_reloc): Likewise.
	(Target_aarch64::Scan::local): Likewise.
	(Target_aarch64::Scan::global): Likewise.
	(Target_aarch64::Relocate::relocate): Likewise.
	(Target_aarch64::Relocate::relocate_tls): Likewise.
2018-03-28 09:10:25 -07:00
Roland McGrath 9c75b45645 gold/testsuite: Fix bad regexp in split_x86_64.sh
gold/
	* testsuite/split_x86_64.sh: Fix bad regexp.
2018-03-27 18:51:22 -07:00
Cary Coutant 0b7a4aa6ba Fix case where IR file provides symbol visibility but replacement file does not.
In PR 22868, two IR files provide conflicting visibility for a symbol.
When a def with PROTECTED visibility is seen after a def with DEFAULT
visibility, gold does not override the visibility. Later, if the
replacement object define the symbol with DEFAULT visibility, the symbol
remains DEFAULT. This was caused by a recent change to allow multiply-defined
absolute symbols, combined with the fact that the plugin framework was using
SHN_ABS as the section index for placeholder symbols. The solution is to
use a real (but arbitrary) section index.

gold/
	PR gold/22868
	* plugin.cc (Sized_pluginobj::do_add_symbols): Use a real section
	index instead of SHN_ABS for defined symbols.
	* testsuite/Makefile.am (plugin_pr22868): New test case.
	* testsuite/Makefile.in: Regenerate
	* testsuite/plugin_pr22868.sh: New test script.
	* testsuite/plugin_pr22868_a.c: New source file.
	* testsuite/plugin_pr22868_b.c: New source file.
2018-03-26 10:54:45 -07:00
Cary Coutant 8da9a904f4 Fix warn-unused-return message.
gold/
	* plugin.cc (link_or_copy_file): Remove newlines from warning messages.
	Add pedantic check for return value from ::write.
2018-03-23 23:34:13 -07:00
Cary Coutant 3215deaaa6 Add missing ChangeLog entry for last commit. 2018-03-23 23:34:13 -07:00
Cary Coutant 291158a341 Add --debug=plugin option to record plugin actions.
With --debug=plugin, gold will log all plugin actions to a log file,
and make copies of plugin-supplied replacement files in a temporary
directory created under the current working directory.

gold/
	* debug.h (DEBUG_PLUGIN): New constant.
	(DEBUG_ALL): Add DEBUG_PLUGIN.
	(debug_string_to_enum): Likewise.
	* plugin.cc (make_sized_plugin_object): Add filename parameter.
	(Plugin_recorder): New class.
	(Plugin_manager::~Plugin_manager): Delete recorder_.
	(Plugin_manager::load_plugins): Create and initialize recorder_.
	(Plugin_manager::claim_file): Record claimed and unclaimed files.
	(Plugin_manager::make_plugin_object): Use object name as name for
	plugin object, if available.
	(Plugin_manager::add_input_file): Record replacement files.
	(Sized_pluginobj::do_add_symbols): Record plugin symbols.
	(Plugin_finish::run): Call Plugin_recorder::finish().
	(make_sized_plugin_object): Add filename parameter and pass to
	Sized_pluginobj constructor.
	* plugin.h (Plugin::filename): New method.
	(Plugin::recorder): New method.
	(Plugin::recorder_): New data member.
2018-03-23 10:05:38 -07:00
Sriraman Tallam 779bdadbea New option -z,keep-text-section prefix.
This option does not merge certain text sections with prefixes
.text.hot, .text.unlikely, .text.startup and .text.exit.

	* layout.cc (Layout::default_section_order): Check for text section
	prefixes.
	(Layout::text_section_name_mapping): New static member.
	(Layout::text_section_name_mapping_count): New static member.
	(Layout::match_section_name): New static function.
	(Layout::output_section_name): Check for text section prefixes.
	* layout.h (Output_section_order::ORDER_TEXT_HOT): New enum value.
	(Output_section_order::ORDER_TEXT_STARTUP): New enum value.
	(Output_section_order::ORDER_TEXT_EXIT): New enum value.
	(Output_section_order::ORDER_TEXT_UNLIKELY): New enum value.
	(Layout::text_section_name_mapping): New static member.
	(Layout::text_section_name_mapping_count): New static member.
	(Layout::match_section_name): New static function.
	* options.h (keep_text_section_prefix): New -z option.
	* testsuite/Makefile.am (keep_text_section_prefix): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/keep_text_section_prefix.cc: New test source.
	* testsuite/keep_text_section_prefix.sh: New test script.
2018-03-07 12:15:49 -08:00
Sriraman Tallam 0b65c07b97 New plugin interface to get list of symbols wrapped with --wrap option.
2018-02-22  Sriraman Tallam  <tmsriram@google.com>

	* plugin.cc (get_wrap_symbols): New plugin interface.
	(load): Add get_wrap_symbols to transfer vector.
	* plugin-api.h (ld_plugin_get_wrap_symbols): New plugin interface.
	* testsuite/plugin_test.c (onload): Call and check get_wrap_symbols
	interface.
	* testsuite/plugin_test_wrap_symbols.sh: New test script.
	* testsuite/plugin_test_wrap_symbols_1.cc: New file.
	* testsuite/plugin_test_wrap_symbols_2.cc: New file.
	* testsuite/Makefile.am (plugin_test_wrap_symbols): New test.
	* testsuite/Makefile.in: Regenerate.
2018-02-22 13:56:46 -08:00
Sriraman Tallam 3281b315c8 Fix symbol resolution with linker plugins for defsym symbols.
2018-02-07  Sriraman Tallam  <tmsriram@google.com>

	* expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
	New method.
	(Unary_expression::set_expr_sym_in_real_elf): New method.
	(Binary_expression::set_expr_sym_in_real_elf): New method.
	(Trinary_expression::set_expr_sym_in_real_elf): New method.
	* plugin.cc (get_symbol_resolution_info): Fix symbol resolution if
	defined or used in defsyms.
	* plugin.h (Plugin_manager::is_defsym_def): New method.
	(Plugin_manager::Plugin_manager): Initialize defsym_defines_set_.
	(Plugin_manager::defsym_defines_set_): New member.
	(Plugin_manager::Defsym_defines_set): New typedef.
	* script.cc (Script_options::set_defsym_uses_in_real_elf): New method.
	(Script_options::find_defsym_defs): New method.
	* script.h (Expression::set_expr_sym_in_real_elf): New method.
	(Symbol_assignment::is_defsym): New method.
	(Symbol_assignment::value): New method.
	(Script_options::find_defsym_defs): New method.
	(Script_options::set_defsym_uses_in_real_elf): New method.
	* testsuite/Makefile.am (plugin_test_defsym): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/plugin_test.c: Check for new symbol resolution.
	* testsuite/plugin_test_defsym.sh: New script.
	* testsuite/plugin_test_defsym.c: New test source.
2018-02-15 17:35:16 -08:00
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
Cary Coutant c833445823 Add support for DWARF-4 line number tables.
Reads the maximum_operations_per_instruction field, added in DWARF-4 to the
line number program header.

gold/
	* PR gold/22776
	* dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog): Add
	support for DWARF-4 line number tables.
	* dwarf_reader.h (Sized_dwarf_line_info::max_ops_per_insn): New field.
2018-02-02 17:44:27 -08:00
Alan Modra 691d2e9af2 PowerPC PLT stub alignment fixes
Asking for ppc32 plt call stubs to be aligned at 32 byte boundaries
didn't quite work.  For ld.bfd they were spaced 32 bytes apart, but
only started on a 16 byte boundary.  ld.gold also didn't get it right.

Finding that bug made me check over the ppc64 plt stub alignment,
where I found that negative values for alignment (meaning align to
minimize boundary crossing) were not accepted.  Since no one has
complained about that, I guess I could have removed the feature from
ld.bfd documentation, but I've opted instead to correct the code.

I've also added an optional alignment paramenter for ppc32
--plt-align, for some consistency with gold and ppc64 ld.bfd.

bfd/
	* elf32-ppc.c (ppc_elf_create_glink): Correct alignment of .glink.
	* elf64-ppc.c (ppc64_elf_size_stubs): Handle negative plt_stub_align.
	(ppc64_elf_build_stubs): Likewise.
gold/
	* powerpc.cc (param_plt_align): New function supplying default
	--plt-align values.  Use it..
	(Stub_table::plt_call_align): ..here, and..
	(Output_data_glink::global_entry_align): ..here.
	(Stub_table::stub_align): Correct 32-bit minimum alignment.
ld/
	* emultempl/ppc32elf.em: Support optional --plt-align arg.
	* emultempl/ppc64elf.em: Support negative --plt-align arg.
2018-01-18 22:25:21 +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 9e390558ce PowerPC PLT stub tidy
This is in preparation for the next patch adding Spectre variant 2
mitigation for PowerPC and PowerPC64.  Besides tidying code involved
in stub output (to reduce the number of places where bctr is output),
the patch adds some user visible features:

1) PowerPC64 ELFv2 global entry stubs now are aligned under the
   control of --plt-align, with a default alignment of 32 bytes.
2) PowerPC64 __glink_PLTresolve is no longer padded out with nops.
3) PowerPC32 PLT stubs are aligned under the control of --plt-align,
   with the default alignment being 16 bytes as before.
4) The PowerPC32 branch/nop table emitted before __glink_PLTresolve
   is now smaller in many cases.  It was sized incorrectly when the
   __tls_get_addr_opt stub was used, and unnecessarily included space
   for local ifuncs.

bfd/
	* elf32-ppc.c (GLINK_ENTRY_SIZE): Add parameters, handle
	__tls_get_addr_opt, and alignment sizing.
	(TLS_GET_ADDR_GLINK_SIZE): Delete.
	(is_nonpic_glink_stub): Don't use GLINK_ENTRY_SIZE.
	(ppc_elf_get_synthetic_symtab): Recognize stubs spaced at 4, 6,
	or 8 insns.
	(ppc_elf_link_hash_table_create): Init new ppc_elf_params field.
	(allocate_dynrelocs): Use new GLINK_ENTRY_SIZE.
	(ppc_elf_size_dynamic_sections): Likewise.  Size branch table
	by PLT reloc count.
	(write_glink_stub): Handle __tls_get_addr_opt stub.
	Pad out to size given by GLINK_ENTRY_SIZE.
	(ppc_elf_relocate_section): Adjust write_glink_stub call.
	(ppc_elf_finish_dynamic_symbol): Likewise.
	(ppc_elf_finish_dynamic_sections): Write PLTresolve without using
	insn array since so many need rewriting.
	* elf32-ppc.h (struct ppc_elf_params): Add plt_stub_align.
	* elf64-ppc.c (GLINK_PLTRESOLVE_SIZE): Rename from
	GLINK_CALL_STUB_SIZE.  Add htab param and evaluate to size without
	nops.  Adjust all uses.
	(ppc64_elf_get_synthetic_symtab): Don't use GLINK_CALL_STUB_SIZE
	in glink_vma calculation.
	(struct ppc_link_hash_table): Add global_entry section pointer.
	(create_linkage_sections): Create separate section for global
	entry stubs.
	(PPC_LO, PPC_HI, PPC_HA): Move earlier.
	(size_global_entry_stubs): Handle sizing for aligned stubs.
	(ppc64_elf_size_dynamic_sections): Handle global_entry alloc,
	and don't stash end of glink branch table in rawsize.
	(ppc_build_one_stub): Rewrite stub size calculations.
	(build_global_entry_stubs): Use new section.
	(ppc64_elf_build_stubs): Don't pad __glink_PLTresolve with nops.
	Build lazy link stubs out to end of section.  Build global entry
	stubs in new section.
gold/
	* options.h (plt_align): Support for PowerPC32 too.
	* powerpc.cc (Stub_table::stub_align): Heed --plt-align for 32-bit.
	(Stub_table::plt_call_size, branch_stub_size): Tidy.
	(Stub_table::plt_call_align): Implement using stub_align.
	(Output_data_glink::global_entry_align): New function.
	(Output_data_glink::global_entry_off): New function.
	(Output_data_glink::global_entry_address): Use global_entry_off.
	(Output_data_glink::pltresolve_size): New function, replacing
	pltresolve_size_ constant.  Update all uses.
	(Output_data_glink::add_global_entry): Align offset.
	(Output_data_glink::set_final_data_size): Use global_entry_align.
	(Stub_table::do_write): Don't pad __glink_PLTrelsolve with nops.
	Tidy stub output.  Use global_entry_off.
ld/
	* emultempl/ppc32elf.em (params): Init new field.
	(enum ppc32_opt): New enum to define OPTION_* values.  Add
	OPTION_PLT_ALIGN and OPTION_NO_PLT_ALIGN.
	(PARSE_AND_LIST_LONGOPTS): Handle new options.
	(PARSE_AND_LIST_ARGS_CASES): Likewise.
	(PARSE_AND_LIST_OPTIONS): Likewise.  Break up help output.
	* emultempl/ppc64elf.em (ppc_add_stub_section): Init alignment
	correctly for negative --plt-stub-align.
	* testsuite/ld-powerpc/elfv2exe.d,
	* testsuite/ld-powerpc/elfv2so.d,
	* testsuite/ld-powerpc/relbrlt.d,
	* testsuite/ld-powerpc/relbrlt.s,
	* testsuite/ld-powerpc/tlsexe.d,
	* testsuite/ld-powerpc/tlsexe.r,
	* testsuite/ld-powerpc/tlsexe32.d,
	* testsuite/ld-powerpc/tlsexe32.g,
	* testsuite/ld-powerpc/tlsexe32.r,
	* testsuite/ld-powerpc/tlsexetoc.d,
	* testsuite/ld-powerpc/tlsexetoc.r,
	* testsuite/ld-powerpc/tlsopt5_32.d,
	* testsuite/ld-powerpc/tlsso.d,
	* testsuite/ld-powerpc/tlstocso.d: Update for changed stub order.
2018-01-17 18:51:04 +10:30
Cary Coutant 930b5f8bfb Fix -fuse-ld option to accept string argument.
PR 22042 complained that garbage text was being printed in the help
for the -fuse-ld option; this was caused by passing an empty string
to the gettext() function, which sometimes returns garbage when passed
an empty string. The quick fix was to replace "" with NULL as the helparg,
but that changed the parsing of the option, as gold uses the helparg to
determine whether an option takes an argument. This patch adds a
non-empty helparg string to fix both problems.

gold/
	PR gold/22694
	* options.h (-fuse-ld): Add correct helparg.
2018-01-15 10:07:11 -08:00
Nick Clifton 616dcb87ab Update Ukranian translations for bfd, binutils, gas, gold, ld and opcodes 2018-01-15 12:09:11 +00:00
Nick Clifton 3957a4963f Update pot files 2018-01-13 13:56:48 +00:00
Nick Clifton faf766e317 Add note about 2.30 branch creation to changelogs 2018-01-13 13:26:38 +00:00
Cary Coutant 27f7b092c2 Update gold version number to 1.15.
gold/
	* NEWS: Add new features in 1.15.
	* version.cc (version_string): Bump to 1.15.
2018-01-12 18:38:11 -08:00
Eric Christopher b4b07ef1d1 Apply:
2018-01-12 Sterling Augustine <saugustine@google.com>

	   * cref.cc (Cref_inputs::Cref_table_compare::operator): Add
	   conditionals and calls to is_forwarder.
2018-01-12 11:05:58 -08:00
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
Alan Modra 1e56386871 ChangeLog rotation 2018-01-03 17:49:42 +10:30
Alan Modra 2778747c56 [GOLD] PR22602, handle __tls_get_addr forwarders properly
We never need to resolve_forwards() a symbol found by hash table lookup
such as target->tls_get_addr_opt() but we do potentially need to do so
for random symbols seen on relocs.  So these calls were in the wrong
order, resulting in missing stubs and an assertion failure.

	PR 22602
	* powerpc.cc (Target_powerpc::Branch_info::mark_pltcall): Resolve
	forwards before replacing __tls_get_addr.
	(Target_powerpc::Branch_info::make_stub): Likewise.
2017-12-15 15:09:15 +10:30
Stephen Crane c4e648430f Add plugin API for processing plugin-added input files
Gold plugins may wish to further process an input file added by a plugin. For
example, the plugin may need to assign a unique segment for sections in a
plugin-generated input file. This patch adds a plugin callback that the linker
will call when reading symbols from a new input file added after the
all_symbols_read event (i.e. an input file added by a plugin).

2017-12-11  Stephen Crane  <sjc@immunant.com>

	* plugin-api.h: Add new plugin hook to allow processing of input
	files added by a plugin.
	(ld_plugin_new_input_handler): New function hook type.
	(ld_plugin_register_new_input): New interface.
	(LDPT_REGISTER_NEW_INPUT_HOOK): New enum val.
	(tv_register_new_input): New member.

	* plugin.cc (Plugin::load): Include hooks for register_new_input
	in transfer vector.
	(Plugin::new_input): New function.
	(register_new_input): New function.
	(Plugin_manager::claim_file): Call Plugin::new_input if in
	replacement phase.
	* plugin.h (Plugin::set_new_input_handler): New function.
	* testsuite/plugin_new_section_layout.c: New plugin to test
	new_input plugin API.
	* testsuite/plugin_final_layout.sh: Add new input test.
	* testsuite/Makefile.am (plugin_layout_new_file): New test case.
	* testsuite/Makefile.in: Regenerate.
2017-12-11 14:58:38 -08:00
Cary Coutant 222b39c283 Handle case where posix_fallocate is not supported for a filesystem.
2017-12-02  Vladimir Kondratyev  <vladimir@kondratyev.su>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/22540
	* output.cc (gold_fallocate): Trivial return for len == 0.
	Add fallback options when posix_fallocate and fallocate return
	not-supported errors.
2017-12-02 09:56:40 -08:00
Cary Coutant 158600eb98 Disallow --incremental with -pie and force -no-pie for incremental tests.
This is a partial fix for the gold testsuite failures documented in
PR 21090. The use of -fpie triggers some mov-to-lea optimizations that
are not compatible with incremental linking, so those optimizations need
to be disabled. We also diagnose the attempt to use -pie with incremental
linking, and force -no-pie for the incremental tests in case the build has
been configured to have GCC pass -pie all the time.

We still have a problem where compiling with -fpie results in some GOT
entries even when linking with -no-pie. This combination still causes test
failures because we are not updating the GOT entries in an incremental update
link.

gold/
	PR gold/21090
	* incremental.cc (Sized_relobj_incr::do_relocate): Fix comment.
	* options.cc (General_options::finalize): Disallow -pie with
	incremental linking.
	* x86_64.cc (Target_x86_64::Scan::local): Don't do mov-to-lea
	or callq-to-direct optimizations for incremental links.
	(Target_x86_64::Scan::global): Likewise.
	(Target_x86_64::Relocate::relocate): Likewise.
	* testsuite/Makefile.am (incremental_test): Force -no-pie.
	(incremental_test_2): Likewise.
	(incremental_test_3): Likewise.
	(incremental_test_4): Likewise.
	(incremental_test_5): Likewise.
	(incremental_test_6): Likewise.
	(incremental_copy_test): Likewise.
	(incremental_common_test_1): Likewise.
	(incremental_comdat_test_1):  Likewise.
	* testsuite/Makefile.in: Regenerate.
2017-12-01 23:46:03 -08:00
Cary Coutant 0af4ccfc5b Workaround GCC 7 bug with debug line numbers causing debug_msg.sh failure.
gold/
	PR gold/21841
	* testsuite/debug_msg.sh: Adjust expected line numbers.
	* testsuite/odr_violation2.cc (DummyFunction): New function.
2017-12-01 22:53:08 -08:00
Cary Coutant 059256c746 Fix incremental linking failure with GCC 7+.
With the new compiler, we're running out of patch space for the .eh_frame
section. To workaround that issue, we compile the before and after versions
both with no unwind tables.

gold/
	PR gold/22309
	* testsuite/Makefile.am (two_file_test_1_v1_ndebug.o): Compile with
	no EH information.
	(two_file_test_1_ndebug.o): Likewise.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/two_file_test_1.cc: Touch to force recompilation with new
	flags.
	* testsuite/two_file_test_1_v1.cc: Likewise.
2017-12-01 22:03:09 -08:00
Cary Coutant 7ef67ba533 Fix localized help string output for -fuse-ld.
gold/
	PR gold/22042
	* options.h (-fuse-ld): Use NULL instead of empty string.
2017-12-01 13:45:27 -08:00
Benjamin Peterson bd2e3511f7 Fix internal error from command line with unbalanced --start-lib/--end-lib.
The problem is that while the command line isn't trivially empty,
it contains no input files. As gold tries to configure the number
of threads to use based on the number of input files, this causes
the assertion failure above. Fix this problem by making the logic
in gold.cc more robust and also adding a better error message
about --start-lib to options.cc.

gold/
	PR gold/22406
	* gold.cc (queue_initial_tasks) Check for number of real input files.
	* options.cc (Command_line::process) Check for unterminated --start-lib
	options.
	* testsuite/Makefile.am: Add new test script.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/check_empty_command_lines.sh: New test script.
2017-12-01 12:59:36 -08:00
Stephen Crane 71739b698d Fix problem where undef can fail to trigger archive rescan.
If a shared library contains an undefined symbol and LTO adds
a new reference to that same undefined symbol, the reference in the new
object added by the plugin would not trigger a rescan of the archive
containing the symbol.

2017-11-17  Stephen Crane  <sjc@immunant.com>

gold/
	PR gold/22448
	* symtab.cc (Symbol_table::add_from_object): Only rescan for
	undefined symbols in regular, not dynamic, objects.
2017-12-01 12:10:02 -08:00
Peter Smith fd6798fa2d Fix internal error in fix_errata on aarch64.
The addresses of erratum stubs can be changed by relaxation passes, and
need to be updated.

gold/
	PR gold/20765
	* aarch64.cc (Aarch64_relobj::update_erratum_address): New method.
	(AArch64_relobj::scan_errata): Update addresses in stub table after
	relaxation pass.
2017-11-30 15:08:21 -08:00
Cary Coutant e0feb13342 Fix problem where erratum stubs are not always applied.
I checked over the results of applying --fix-cortex-a53-843419 to
a very large program (gitit) with two stub tables and thousands
of erratum fixes. I noticed that all the erratum_stubs were being
created but about 1/3 of them were being skipped over by
fix_errata_and_relocate_erratum_stubs(). By skipped over I mean
no branch relocation or adrp -> adr transformation was applied to
the erratum address, leaving the erratum_stub unreachable, and
with a branch with a 0 immediate.

The root cause of the skipped over erratum_stubs is
Erratum_stub::invalidate_erratum_stub() that is used to set
relobj_ to NULL when an erratum_stub has been processed.
Unfortunately relobj_ is used in operator<() so altering relobj
makes the results from erratum_stubs_.lower_bound() as used in
find_erratum_stubs_for_input_section() unreliable.

2017-11-30  Peter Smith  <peter.smith@linaro.org>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/20765
	* aarch64.cc (Erratum_stub::invalidate_erratum_stub): Use erratum_insn_
	instead of relobj_ to invalidate the stub.
	(Erratum_stub::is_invalidated_erratum_stub): Likewise.
2017-11-30 15:08:21 -08:00
Peter Smith 036aae7930 Fix segfault in relocate_erratum_stub on aarch64.
The fix for PR21868 (an internal error when --fix-cortex-a53-843419
is applied) has a small mistake in it. When the stub_owner section
needs an erratum fix an incorrect address for the stubs for the section
is given to relocate_erratum_stub. If we are lucky we will get a segfault;
if we aren't, an incorrect patch or data corruption is possible.
The error is visible in PR21868, but the side-effects aren't fatal.

gold/
	PR gold/22233
	* aarch64.cc (AArch64_relobj::fix_errata_and_relocate_erratum_stubs):
	Fix calculation of stub address.
2017-11-30 15:08:21 -08:00
Stefan Stroe ca39c2f4dd Support --localedir, --datarootdir and --datadir
bfd/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
binutils/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gas/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gold/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
gprof/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
ld/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
opcodes/
	* po/Make-in (datadir): Define as @datadir@.
	(localedir): Define as @localedir@.
	(gnulocaledir, gettextsrcdir): Use @datarootdir@.
2017-11-29 20:10:52 +10:30
Cary Coutant 5dc824ed42 Allow multiply-defined absolute symbols when they have the same value.
gold/
	* resolve.cc (Symbol_table::resolve): Allow multiply-defined absolute
	symbols when they have the same value.
2017-11-28 18:48:12 -08:00
Cary Coutant 8de0e07bf3 Allow multiple .eh_frame sections per object file.
LLVM is experimenting with placing .eh_frame sections in the COMDAT group
with the function's text. This triggers an internal error in gold because
we don't expect to see but one .eh_frame section in an object, and we use
a single data member in class Sized_relobj_file to keep track of that section.

This patch removes that data member, and instead checks the output section
and the input section offset to identify an optimized .eh_frame section.

gold/
	* object.h (class Sized_relobj_file): Remove discarded_eh_frame_shndx_.
	* object.cc (Sized_relobj_file::Sized_relobj_file): Likewise.
	(Sized_relobj_file::layout_eh_frame_section): Likewise.
	(Sized_relobj_file::do_count_local_symbols): Check for optimized
	.eh_frame section by other means.
	(Sized_relobj_file::compute_final_local_value_internal): Likewise.
2017-11-28 18:09:41 -08:00
H.J. Lu ff174d3ffa gold: Add a newline at end of pr22266_a.c
This patch fixes the build with GCC 4.2:

gold/testsuite/pr22266_a.c:13:2: error: no newline at end of file

	* testsuite/pr22266_a.c: Add a newline at end of file.
2017-11-28 09:00:44 -08:00
Cary Coutant 033bfb739b Fix symbol values and relocation addends for relocatable links.
The fix for PR 19291 broke some other cases where -r is used with scripts,
as reported in PR 22266. The original fix for PR 22266 ended up breaking
many cases for REL targets, where the addends are stored in the section data,
and are not being adjusted properly.

The problem was basically that in a relocatable output file (ET_REL),
symbol values are supposed to be relative to the start address of their
section. Usually in a relocatable file, all sections start at 0, so the
failure to get this right is often irrelevant, but with a linker script,
we occasionally see an output section whose starting address is not 0,
and gold would occasionally write a symbol with its relocated value instead
of its section-relative value.

This patch reverts the recent fix for PR 22266 as well as my original fix
for PR 19291. The original fix moved the symbol value adjustment to
write_local_symbols, but neglected to undo a few places where the adjustment
was also being applied, resulting in an occasional double adjustment. The
more recent fix removed those other adjustments, but then failed to
re-account for the adjustment when rewriting the relocations on REL targets.

With the old attempts reverted, we now apply the symbol value adjustment to
the one case that had been missed (non-section symbols in merge sections).
But now we also need to account for the adjustment when rewriting the addends
for RELA relocations.

gold/
	PR gold/19291
	PR gold/22266
	* object.cc (Sized_relobj_file::compute_final_local_value_internal):
	Revert changes from 2017-11-08 patch.  Adjust symbol value in
	relocatable links for non-section symbols.
	(Sized_relobj_file::compute_final_local_value): Revert changes from
	2017-11-08 patch.
	(Sized_relobj_file::do_finalize_local_symbols): Likewise.
	(Sized_relobj_file::write_local_symbols): Revert changes from
	2015-11-25 patch.
	* object.h (Sized_relobj_file::compute_final_local_value_internal):
	Revert changes from 2017-11-08 patch.
	* powerpc.cc (Target_powerpc::relocate_relocs): Adjust addend for
	relocatable links.
	* target-reloc.h (relocate_relocs): Adjust addend for relocatable links.
	* testsuite/pr22266_a.c (hello): New function.
	* testsuite/pr22266_main.c (main): Add test for merge sections.
	* testsuite/pr22266_script.t: Add rule for .rodata.
2017-11-27 17:32:55 -08:00
Cary Coutant 9c512d88c3 Fix typo in ChangeLog entry. 2017-11-19 18:02:31 -08:00
Cary Coutant 20dd9c210e Fix DWARF reader to use correct size for DW_FORM_ref_addr.
2017-11-19  Ian Lance Taylor  <iant@google.com>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	* gold/dwarf_reader.h (class Dwarf_info_reader): Add ref_addr_size
	method.
	* gold/dwarf_reader.cc (Dwarf_die::read_attributes): Use ref_addr_size
	for DW_FORM_ref_addr_size.
	(Dwarf_die::skip_attributes): Likewise.
2017-11-19 17:56:30 -08:00
H.J. Lu dc8d2d90da gold: Ignore def/ref from a dynamic object for special symbols
Since special symbol must be defined in a regular object, definition
from a dynamic object should be ignored.  If special symbol has the
hidden or internal visibility, reference from a dynamic object should
also be ignored.  Also __start and __stop symbols in a dynamic object
shouldn't be preempted.

	PR gold/22291
	* layout.cc (Layout::define_section_symbols): Use STV_PROTECTED
	for __start and __stop symbols.
	* symtab.cc (Symbol_table::define_special_symbol): Add an
	argument, visibility.  Ignore definition and reference from
	a dynamic object, depending on visibility.
	(Symbol_table::do_define_in_output_data): Pass visibility to
	define_special_symbol.
	(Symbol_table::do_define_in_output_segment): Likewise.
	(Symbol_table::do_define_as_constant): Likewise.
	(Symbol_table::add_undefined_symbol_from_command_line): Pass
	STV_DEFAULT to define_special_symbol.
	* symtab.h (Symbol_table::define_special_symbol): Add an
	argument, visibility.
2017-11-08 16:02:50 -08:00
James Clarke 333d0055f6 Fix problems with -r.
The fix committed for PR gold/19291 ended up breaking other cases. The
commit added adjustment code to write_local_symbols, but in many cases
compute_final_local_value_internal had already subtracted the output
section's address. To fix this, all other adjustments are now removed, so
only the one in write_local_symbols is left.

gold/
	PR gold/22266
	* object.cc (Sized_relobj_file::compute_final_local_value_internal):
	Drop relocatable parameter and stop adjusting output value based on
	it.
	(Sized_relobj_file::compute_final_local_value): Stop passing
	relocatable to compute_final_local_value_internal.
	(Sized_relobj_file::do_finalize_local_symbols): Ditto.
	* object.h (Sized_relobj_file::compute_final_local_value_internal):
	Drop relocatable parameter.
2017-11-08 15:13:53 -08:00
Eric Christopher 08228b1155 Apply:
2017-11-08  Kyle Butt  <iteratee@google.com>

        * object.cc (do_find_special_sections): Fix a thinko with memmem return
        values and check for != NULL rather than == 0.
2017-11-08 14:03:55 -08:00
Alan Modra 6003e27e76 ngettext support
binutils has lacked proper pluralization of output messages for a long
time, for example, readelf will display information about a section
that "contains 1 entries" or "There are 1 section headers".  Fixing
this properly requires us to use ngettext, because other languages
have different rules to English.

This patch defines macros for ngettext and friends to handle builds
with --disable-nls, and tidies the existing nls support.  I've
redefined gettext rather than just defining "_" as dgettext in bfd and
opcodes in case someone wants to use gettext there (which might
conceivably happen with generated code).

bfd/
	* sysdep.h: Formatting, comment fixes.
	(gettext, ngettext): Redefine when ENABLE_NLS.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
	(_): Define using gettext.
	(textdomain, bindtextdomain): Use safer "do nothing".
	* hosts/alphavms.h (textdomain, bindtextdomain): Likewise.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
opcodes/
	* opintl.h: Formatting, comment fixes.
	(gettext, ngettext): Redefine when ENABLE_NLS.
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
	(_): Define using gettext.
	(textdomain, bindtextdomain): Use safer "do nothing".
binutils/
	* sysdep.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
gas/
	* asintl.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
gold/
	* system.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
ld/
	* ld.h (textdomain, bindtextdomain): Use safer "do nothing".
	(ngettext, dngettext, dcngettext): Define when !ENABLE_NLS.
2017-11-07 15:52:52 +10:30
Alan Modra e601d38b7c Allow for __gnu_lto_slim prefixed with extra "_"
Some targets prefix global symbols with "_".

bfd/
	* archive.c (_bfd_compute_and_write_armap): Match "__gnu_lto_slim"
	optionally prefixed with "_".
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
binutils/
	* nm.c (filter_symbols): Match "__gnu_lto_slim" optionally prefixed
	with "_".
gold/
	* symtab.cc (Symbol_table::add_from_relobj): Match "__gnu_lto_slim"
	optionally prefixed with "_".
ld/
	* testsuite/ld-plugin/lto-3r.d: Match "__gnu_lto_v" optionally
	prefixed with "_".
	* testsuite/ld-plugin/lto-5r.d: Likewise.
2017-10-25 15:32:52 +10:30
Sriraman Tallam d63613596f Fix ChangeLog entry. 2017-10-20 11:21:45 -07:00
Sriraman Tallam 3b4190ccb3 New gold linker option -z,text-unlikely-segment.
2017-10-04  Sriraman Tallam  <tmsriram@google.com>

	* options.h (-z,text_unlikely_segment): New option.
	* layout.cc (Layout::layout): Create new output section
	for .text.unlikely sections with the new option.
	(Layout::segment_precedes): Check for the new option
	when segment flags match.
	* testsuite/text_unlikely_segment.cc: New test source.
	* testsuite/text_unlikely_segment.sh: New test script.
	* testsuite/Makefile.am (text_unlikely_segment): New test.
	* testsuite/Makefile.in: Regenerate.
2017-10-20 11:00:28 -07:00
Umesh Kalappa 36862fc052 Implement BE8 support for ARM.
gold/
	* arm.cc (Stub::do_fixed_endian_write):Far call stubs support for arm
	in the be8 mode.
	* testsuite/Makefile.am: New test cases.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/arm_farcall_arm_arm_be8.sh: New script for arm to arm far
	call stubs.
	* testsuite/arm_farcall_thumb_thumb_be8.sh: New script for thumb to
	thumb far call stubs.
2017-10-19 20:53:14 -07:00
Alan Modra 412294daf8 [GOLD] Fix powerpc64 optimization of TOC accesses
Fixes a thinko.  Given code that puts variables into the TOC (a bad
idea, but some see the TOC as a small data section) this bug could
result in an attempt to optimize a sequence that should not be
optimized.

	* powerpc.cc (Target_powerpc::Scan::local): Correct dst_off
	calculation for TOC16 relocs.
	(Target_powerpc::Scan::global): Likewise.
2017-10-18 08:48:17 +10:30
Cary Coutant 00956d3a8a Fix incorrect register mask.
PR gold/22213
	* sparc.cc (Target_sparc): Fix incorrect register mask.
2017-09-26 07:33:04 -07:00
Jim Wilson 0cf44ec826 [GOLD] Set non-exec stack for aarch64
GNU-stack notes added in 2004, aarch64 port added in 2012, so no old object
files with missing GNU-stack notes that we need to worry about.

	gold/
	* aarch64.cc (Target_aarch64::aarch64_info): Set
	is_default_stack_executable to false.
2017-09-22 07:58:28 -07:00
Alan Modra 7790bd6c74 [GOLD] clone assert breakage
* resolve.cc (clone): Fix got_offset_list test.
2017-09-22 15:20:12 +09:30
Alan Modra ec76901011 [GOLD] Set non-exec stack for ppc64
gcc doesn't emit stack notes for ELFv1, since ELFv1 never needs an
executable stack.  Note that ELFv1 is usually big-endian and ELFv2
little-endian, but the ABI is really orthogonal to endiannes.

	* powerpc.cc (Target_powerpc<64,*>::powerpc_info): Set
	is_default_stack_executable false.
2017-09-22 11:47:02 +09:30
Teresa Johnson ca464aac1b Check for export dynamic symbol options when doing symbol resolution in plugins.
2017-09-20  Teresa Johnson  <tejohnson@google.com>
	* plugin.cc (is_visible_from_outside): Check for export dynamic symbol
        option and list.
	* testsuite/Makefile.am (plugin_test_12): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/export_dynamic_plugin.cc: New test source.
	* testsuite/plugin_test_12.sh: New test script.
2017-09-20 15:45:04 -07:00
Alan Modra 64b5d6d785 [GOLD] PowerPC function address in non-PIC
ppc32, like many targets, defines the address of a function as the PLT
call stub code for functions referenced but not defined in a non-PIC
executable.  ppc32 gold, unlike other targets, inherits the ppc64
multiple stub capability for dealing with very large binaries where
one set of stubs can't be reached from all code locations.  This means
there can be multiple choices of address for a function, which might
cause function pointer comparison failures.  So for ppc32, make
non-branch references always use the first stub group.

(PowerPC64 ELFv1 is always PIC so doesn't need to define the address
of an external function as the PLT stub.  PowerPC64 ELFv2 needs a
special set of global entry stubs to serve as the address of external
functions, so it too is not affected by this bug.)

	* powerpc.cc (Target_powerpc::Branch_info::make_stub): Put
	stubs for ppc32 non-branch relocs in first stub table.
	(Target_powerpc::Relocate::relocate): Resolve similarly.
2017-09-20 09:56:19 +09:30
Alan Modra ab502e635e [GOLD, PowerPC] Add --no-stub-group-multi
The trouble with stubs per output section is that ppc32 uses a plt
stub as the address of a global function.  This needs to be unique,
otherwise we'll get multiple addresses for a function.

Obviously this is only a partial solution, since ppc32 will get
multiple stubs when code is larger than 33M.  A proper fix will
involve selecting a unique stub to use for non-branch relocs.

	* options.h (stub-group-multi): Default to true.  Add
	--no-stub-group-multi.
2017-09-19 11:45:51 +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 34e0882b83 [GOLD] PowerPC tls_get_addr_optimize
This implements the special __tls_get_addr_opt call stub for powerpc
gold that returns __thread variable addresses without actually making
a call to __tls_get_addr in most cases.  Shared libraries that are
loaded at program load time (ie. dlopen is not used) have a known
layout for their __thread variables, and thus DTPMOD64/DPTREL64 pairs
describing those variables can be set up by ld.so for the
__tls_get_addr_opt call stub fast exit.
Ref https://sourceware.org/ml/libc-alpha/2015-03/msg00626.html

I really, really wish I'd used a differently versioned __tls_get_addr
symbol than the base symbol to indicate glibc support for the
optimized call, rather than having glibc export __tls_get_addr_opt.  A
lot of the messing around here, flipping symbols from __tls_get_addr
to __tls_get_addr_opt, is caused by that decision.  About the only
benefit is that a user can see at a glance that their disassembled
code is calling __tls_get_addr via the fancy call stub..  Anyway, we
need references to __tls_get_addr to seem like they were to
__tls_get_addr_opt, and in cases like the tsan interceptor, a
definition of __tls_get_addr to seem like one of __tls_get_addr_opt
as well.  That's the reason for Symbol::clear_in_reg and
Symbol_table::clone, and why symbols are substituted in Scan::global
and other places dealing with dynamic linking.

elfcpp/
	* elfcpp.h (DT_PPC_OPT): Define.
	* powerpc.h (PPC_OPT_TLS): Define.
gold/
	* options.h (tls_get_addr_optimize): New option.
	* symtab.h (Symbol::clear_in_reg, clone): New functions.
	(Sized_symbol::clone): New function.
	(Symbol_table::clone): New function.
	* resolve.cc (Symbol::clone, Sized_symbol::clone): New functions.
	* powerpc.cc (Target_powerpc::has_tls_get_addr_opt_,
	tls_get_addr_, tls_get_addr_opt_): New vars.
	(Target_powerpc::tls_get_addr_opt, tls_get_addr,
	is_tls_get_addr_opt, replace_tls_get_addr,
	set_has_tls_get_addr_opt, stk_linker): New functions.
	(Target_powerpc::Track_tls::maybe_skip_tls_get_addr_call): Add
	target param.  Update callers.  Compare symbols rather than names.
	(Target_powerpc::do_define_standard_symbols): Init tls_get_addr_
	and tls_get_addr_opt_.
	(Target_powerpc::Branch_info::mark_pltcall): Translate tls_get_addr
	sym to tls_get_addr_opt.
	(Target_powerpc::Branch_info::make_stub): Likewise.
	(Stub_table::define_stub_syms): Likewise.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.
	(add_3_12_2, add_3_12_13, bctrl, beqlr, cmpdi_11_0, cmpwi_11_0,
	ld_11_1, ld_11_3, ld_12_3, lwz_11_3, lwz_12_3, mr_0_3, mr_3_0,
	mtlr_11, std_11_1): New constants.
	(Stub_table::eh_frame_added_): Delete.
	(Stub_table::tls_get_addr_opt_bctrl_, plt_fde_len_, plt_fde_): New vars.
	(Stub_table::init_plt_fde): New functions.
	(Stub_table::add_eh_frame, replace_eh_frame): Move definition out
	of line.  Init and use plt_fde_.
	(Stub_table::plt_call_size): Return size for tls_get_addr stub.
	Extract alignment code to..
	(Stub_table::plt_call_align): ..this new function.  Adjust all callers.
	(Stub_table::add_plt_call_entry): Set has_tls_get_addr_opt and
	tls_get_addr_opt_bctrl, and align after that.
	(Stub_table::do_write): Write out tls_get_addr stub.
	(Target_powerpc::do_finalize_sections): Emit DT_PPC_OPT
	PPC_OPT_TLS/PPC64_OPT_TLS bit.
	(Target_powerpc::Relocate::relocate): Don't check for or modify
	nop following bl for tls_get_addr stub.
2017-08-29 21:29:37 +09:30
Alan Modra 34ca2bd7ac [GOLD] Reduce size of class Symbol
On 64-bit targets there is a 32-bit hole in symbol->u_, and another
due to symbol flags exceeding 32 bits.  By splitting the union,
the total size of the class reduces by one 64-bit word.

	* symtab.h (Symbol): Split u_ into u1_ and u2_.  Adjust accessors
	to suit.  Move plt_offset_ before got_offsets_.
	* symtab.cc (Symbol::init_fields): Adjust for union change.
	(Symbol::init_base_output_data): Likewise.
	(Symbol::init_base_output_segment): Likewise.
	(Symbol::allocate_base_common): Likewise.
	(Symbol::output_section): Likewise.
	(Symbol::set_output_section): Likewise.
	(Symbol::set_output_segment): Likewise.
	* resolve.cc (Symbol::override_base): Likewise.
	(Symbol::override_base_with_special): Likewise.
2017-08-29 21:29:37 +09:30
Han Shen 972d8a18db 2017-08-28 James Clarke <jrtc27@jrtc27.com>
gold/ChangeLog:
	PR gold/21868
	* aarch64.cc (AArch64_relobj::try_fix_erratum_843419_optimized):
	Add extra view offset argument to function.
	(AArch64_relobj::fix_errata_and_relocate_erratum_stubs): Add
	extra view offset set to the output offset when the view has
	is_input_output_view set, since it has not already been
	included. Pass this to try_fix_erratum_843419_optimized.
2017-08-28 16:40:51 -07:00
Igor Kudrin cefdd1cd64 Fix bad offset calculation for R_AARCH64_TLSDESC_* relocs.
If a custom linker script with an unexpected relative layout of .got
and .got.plt sections was used, gold might produce a wrong offset
when applying R_AARCH64_TLSDESC_* relocations.
This patch fixes the issue by calculating "got_tlsdesc_offset"
in a more direct way.

gold/
	* aarch64.cc (Target_aarch64::Relocate::relocate_tls):
	Make got_tlsdesc_offset signed and fix its calculation.
	* testsuite/Makefile.am (aarch64_tlsdesc): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/aarch64_tlsdesc.s: New test source file.
	* testsuite/aarch64_tlsdesc.sh: New test script.
	* testsuite/aarch64_tlsdesc.t: New test linker script.
2017-08-28 08:03:00 -07:00
Alan Modra 565ed01a4e [GOLD] Symbol flag for PowerPC64 localentry:0 tracking
This patch provides a flag for PowerPC64 ELFv2 use in class Symbol,
and modifies Sized_target::resolve to return whether the symbol has
been resolved.  If not, normal processing continues.  I use this for
PowerPC64 ELFv2 to keep track of whether a symbol has any definition
with non-zero localentry, in order to disable --plt-localentry for
that symbol.

	PR 21847
	* powerpc.cc (Target_powerpc::is_elfv2_localentry0): Test
	non_zero_localentry.
	(Target_powerpc::resolve): New function.
	(powerpc_info): Set has_resolve for 64-bit.
	* target.h (Sized_target::resolve): Return bool.
	* resolve.cc (Symbol_table::resolve): Continue with normal
	processing when target resolve returns false.
	* symtab.h (Symbol::non_zero_localentry, set_non_zero_localentry):
	New accessors.
	(Symbol::non_zero_localentry_): New flag bit.
	* symtab.cc (Symbol::init_fields): Init non_zero_localentry_.
2017-08-28 16:27:33 +09:30
Romain Geissler 2760f24c49 Add configure flag to enable gnu hash style by default.
ld/
	* configure.ac: Add --enable-default-hash-style option.
	* ldmain.c (main): Set link_info.emit_hash to DEFAULT_EMIT_SYSV_HASH.
	Set link_info.emit_gnu_hash to DEFAULT_EMIT_GNU_HASH.
	* configure: Regenerate.
	* config.in: Regenerate.

gold/
	* configure.ac: Add --enable-default-hash-style option.
	* options.h (hash_style): Use DEFAULT_HASH_STYLE as default value.
	* configure: Regenerate.
	* config.in: Regenerate.
2017-08-08 07:25:39 +09:30
James Clarke 223b97ba9d Add --no-relax option.
gold/
	* options.h (General_options): Set a non-NULL second help string
	argument for relax to allow --no-relax.
2017-08-03 22:44:44 -07:00
Alan Modra be897fb774 [GOLD] PowerPC recreate eh_frame for stubs on each relax pass
There is a very small but non-zero probability that a stub group
contains stubs on one relax pass, but does not on the next.  In that
case we would get an FDE covering a zero length address range.
(Actually, it's even worse.  Alignment padding for stubs can mean the
address for the non-existent stubs is past the end of the original
section to which stubs are attached, and due to the way
do_plt_fde_location calculates the length we can get a negative
length.)  Fixing this properly requires removing the FDE.

Also, I have been implementing the __tls_get_addr_opt support for
gold, and that stub needs something other than the default FDE.  The
necessary FDE will depend on the offset to the __tls_get_addr_opt
stub, which of course can change during relaxation.  That means at the
very least, rewriting the FDE on each pass, possibly changing the FDE
size.  I think that is better done by completely recreating PLT
eh_frame FDEs.

	* ehframe.cc (Fde::operator==): New.
	(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): New.
	* ehframe.h (Fde::operator==): Declare.
	(Cie::remove_fde, Eh_frame::remove_ehframe_for_plt): Likewise.
	* layout.cc (Layout::remove_eh_frame_for_plt): New.
	* layout.h (Layout::remove_eh_frame_for_plt): Declare.
	* powerpc.cc (Target_powerpc::do_relax): Remove old eh_frame FDEs.
	(Stub_table::add_eh_frame): Delete eh_frame_added_ condition.
	Don't add eh_frame for empty stub section.
	(Stub_table::remove_eh_frame): New.
2017-08-01 14:08:53 +09:30
Alan Modra aacb3b6dfc [GOLD] PowerPC --no-tls-optimize
This adds a --no-tls-optimize option for people who want to keep
__tls_get_addr calls in an executable rather than optimizing such code
sequences to IE/LE.

Also tidy some formatting errors, rename a variable to better reflect
its use, and tweak two functions that create pairs of GOT entries to
first check whether the GOT entry already exists before potentially
inserting the header via reserve(2).  Without the check it is possible
to waste one GOT entry.

	* options.h (no_tls_optimize): New powerpc option.
	* powerpc.cc (Target_powerpc::abiversion, set_abiversion): Formatting.
	(Target_powerpc::stk_toc): Formatting, fix comment.
	(Target_powerpc::Track_tls::tls_get_addr_state): Rename from
	tls_get_addr.
	(Target_powerpc::optimize_tls_gd, optimize_tls_ld, optimize_tls_ie):
	Return TLSOPT_NONE when !tls_optimize.
	(Target_powerpc::add_global_pair_with_rel): Check
	for existing reloc before reserving.
	(Target_powerpc::add_local_tls_pair): Likewise.
2017-07-31 19:53:49 +09:30
Alan Modra d44c746aed PR 21847, PowerPC64 --plt-localentry again
This makes ld warn about --plt-localentry if a version of glibc
without the necessary ld.so checks is detected, and revises the
documentation.

bfd/
	* elf64-ppc.c (ppc64_elf_tls_setup): Warn on --plt-localentry
	without ld.so checks.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Warn on --plt-localentry
	without ld.so checks.
ld/
	* ld.texinfo (plt-localentry): Revise.
2017-07-31 13:20:44 +09:30
Alan Modra 8b5f1ed877 PR 21847, Don't default PowerPC64 to --plt-localentry
The big comment in ppc64_elf_tls_setup says why.  I've also added some
code to the bfd linker that catches the -lpthread -lc symbol
differences and disable generation of optimized call stubs even when
--plt-localentry is activated.  Gold doesn't yet have that.

	PR 21847
bfd/
	* elf64-ppc.c (struct ppc_link_hash_entry): Add non_zero_localentry.
	(ppc64_elf_merge_symbol): Set non_zero_localentry.
	(is_elfv2_localentry0): Test non_zero_localentry.
	(ppc64_elf_tls_setup): Default to --no-plt-localentry.
gold/
	* powerpc.cc (Target_powerpc::scan_relocs): Default to
	--no-plt-localentry.
ld/
	* ld.texinfo (plt-localentry): Document.
2017-07-29 13:02:27 +09:30
H.J. Lu 49ba15a23a gold: Add put_ch_reserved to 64-bit Chdr_write
The 64-bit ELF compression header has a reserved field.  It should be
cleared to avoid random bits in it.

elfcpp/

	PR gold/21857
	* elfcpp.h (Chdr_write): Add put_ch_reserved.
	(Chdr_write<64, true>::put_ch_reserved): New.
	(Chdr_write<64, false>::put_ch_reserved): Likewise.

gold/

	PR gold/21857
	* compressed_output.cc (Output_compressed_section::set_final_data_size):
	Call put_ch_reserved to clear the reserved field for 64-bit ELF.
2017-07-28 13:40:01 -07:00
H.J. Lu 104f0515d0 Gold: Fix mips.cc for GCC 4.2
GCC 4.2 fails to compile "(uint64_t) 0x800080008000" with

error: integer constant is too large for ‘long’ type

This patch adds "llu" suffix to 0x800080008000 for GCC 4.2.

	* mips.cc (Mips_relocate_functions): Add "llu" suffix to
	0x800080008000.
2017-07-26 10:43:36 -07:00
Alan Modra 15a3a14fdd Correct eh_frame info for __glink_PLTresolve
My PPC64_OPT_LOCALENTRY patch of June 1, git commit f378ab099d, and
the later gold change, git commit 7ee7ff7015, added an insn in
__glink_PLTresolve which needs a corresponding adjustment in the
eh_frame info for asynchronous exceptions to unwind correctly.

It would have been OK for both ABIs to use +5 for the advance before
restore of LR, since we can put the DW_CFA_restore_extended on any
insn after the actual restore and before the r12/r0 copy is clobbered,
but it's slightly better to delay as much as possible.  There are
then more addresses where fewer CFA program insns are executed.

bfd/
	* elf64-ppc.c (ppc64_elf_size_stubs): Correct advance to
	restore of LR.
gold/
	* powerpc.cc (glink_eh_frame_fde_64v2): Correct advance to
	restore of LR.
	(glink_eh_frame_fde_64v1): Advance to restore of LR at latest
	possible insn.
2017-07-23 20:40:39 +09:30
Yuri Chornovian de194d8575 Fix spelling typos. 2017-07-18 16:58:14 +01:00
Cary Coutant b7d7d4598c Add missing gold/ChangeLog entry. 2017-07-12 07:24:37 -07:00
Alan Modra 429d795d50 Update PO files
bfd/
	* po/es.po: Update from translationproject.org/latest/bfd/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/hr.po: New file from translationproject.org.
	* configure.ac (ALL_LINGUAS): Add hr.  Sort.
	* configure: Regenerate.

binutils/
	* po/bg.po: Update from translationproject.org/latest/binutils/.
	* po/ca.po: Likewise.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/hr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sk.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.

gas/
	* po/es.po: Update from translationproject.org/latest/gas/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/ja.po: Likewise.
	* po/ru.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/zh_CN.po: Likewise.

gold/
	* po/es.po: Update from translationproject.org/latest/gold/.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/ja.po: New file from translationproject.org.
	* po/sv.po: Likewise.
	* po/uk.po: Likewise.

gprof/
	* po/bg.po: Update from translationproject.org/latest/gprof/.
	* po/da.po: Likewise.
	* po/de.po: Likewise.
	* po/eo.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/ga.po: Likewise.
	* po/hu.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/ms.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/ru.po: Likewise.
	* po/sr.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.

ld/
	* po/bg.po: Update from translationproject.org/latest/ld/.
	* po/da.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/ja.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
	* po/zh_TW.po: Likewise.
	* po/de.po: New file from translationproject.org.
	* po/ru.po: Likewise.
	* configure.ac (ALL_LINGUAS): Add de, ru.  Sort.
	* configure: Regenerate.

opcodes/
	* po/da.po: Update from translationproject.org/latest/opcodes/.
	* po/de.po: Likewise.
	* po/es.po: Likewise.
	* po/fi.po: Likewise.
	* po/fr.po: Likewise.
	* po/id.po: Likewise.
	* po/it.po: Likewise.
	* po/nl.po: Likewise.
	* po/pt_BR.po: Likewise.
	* po/ro.po: Likewise.
	* po/sv.po: Likewise.
	* po/tr.po: Likewise.
	* po/uk.po: Likewise.
	* po/vi.po: Likewise.
	* po/zh_CN.po: Likewise.
2017-07-12 23:08:59 +09:30
Han Shen df2f63a6a0 Fixing for PR gold/21491 - Errata workaround can produce broken images.
The problem is caused by the fact that gold is relocating the stubs
for an entire output section when it processes the relocations for a
particular input section that happened to be designated as the stub
table "owner". The Relocate_task for that input section may or may not
run before the Relocate_task for another input section that contains
the code that needs the erratum fix, but doesn't "own" the stub
table. If it runs before (or might even race with) that other task, it
ends up with a copy of the unrelocated original instruction.

In other words - when calling fix_errata() from
do_relocate_sections(), gold is going through the list of errata stubs
that are associated only with that object. This routine updates the
stored original instruction and replaces it in the output view with a
branch to the stub. Later, as gold is going through the object file's
input sections, it then checks for stub tables "owned" by each input
section, and writes out all the stubs from that stub table, regardless
of what object file each stub is associated with.

Fixed by relocating the erratum stub only after the corresponding
errata spot is fixed. That is to have fix_errata() call
Stub_table::relocate_erratum_stub() for each stub.

gold/ChangeLog
2017-07-06  Han Shen  <shenhan@google.com>

	PR gold/21491

	* aarch64.cc (Erratum_stub::invalidate_erratum_stub): New method.
	(Erratum_stub::is_invalidated_erratum_stub): New method.
	(Stub_table::relocate_reloc_stub): Renamed from "relocate_stub".
	(Stub_table::relocate_reloc_stubs): Renamed from "relocate_stubs".
	(Stub_table::relocate_erratum_stub): New method.
	(AArch64_relobj::fix_errata_and_relocate_erratum_stubs): Renamed from
	"fix_errata".
	(Target_aarch64::relocate_reloc_stub): Renamed from "relocate_stub".
2017-07-11 11:17:56 -07:00
Alan Modra 7ee7ff7015 [GOLD] PowerPC64 localentry:0 plt call optimization
elfcpp/
	* elfcpp.h (DT_PPC64_OPT): Define.
	* powerpc.h (PPC64_OPT_TLS, PPC64_OPT_MULTI_TOC,
	PPC64_OPT_LOCALENTRY): Define.
gold/
	* options.h (General_options): Add plt_localentry.
	* powerpc.cc (Target_powerpc::st_other): New function.
	(Target_powerpc::plt_localentry0_, plt_localentry0_init_,
	has_localentry0_): New vars.
	(Target_powerpc::plt_localentry0, set_has_localentry0,
	is_elfv2_localentry0): New functions.
	(Target_powerpc::Branch_info::mark_pltcall): Don't set tocsave or
	return true for localentry:0 calls.
	(Stub_table::Plt_stub_ent::localentry0_): New var.
	(Stub_table::add_plt_call_entry): Set localentry0_ and has_localentry0_.
	Don't set r2save_ for localentry:0 calls.
	(Output_data_glink::do_write): Save r2 in __glink_PLTresolve for elfv2.
	(Target_powerpc::scan_relocs): Default plt_localentry0_.
	(Target_powerpc::do_finalize_sections): Set DT_PPC64_OPT.
	(Target_powerpc::Relocate::relocate): Don't require nop following
	calls for localentry:0 plt calls, and don't change nop.
2017-06-23 20:39:43 +09:30
Alan Modra 7e57d19e48 [GOLD] PowerPC64 tocsave
This adds support to gold for the tocsave relocs already supported by
ld.bfd.  R_PPC64_TOCSAVE relocs are part of a scheme to move r2 saves
to the prologue of a function rather than in each plt call stub.  We
don't want a compiler to always emit the r2 save, as this would be
wasted if the calls turned out to be local.  See the tocsave*.s in
ld/testsuite/ld-powerpc/.

	* powerpc.cc (Target_powerpc::tocsave_loc_): New var.
	(Target_powerpc::mark_pltcall, add_tocsave, tocsave_loc): New functions.
	(Target_powerpc::Branch_info::tocsave_): New var.
	(Target_powerpc::Branch_info::mark_pltcall): New function.
	(Target_powerpc::Branch_info::make_stub): Pass tocsave_ to
	add_plt_call_entry.
	(Stub_table::Plt_stub_ent): Make public.  Add r2save_.
	(Stub_table::add_plt_call_entry): Add bool tocsave_ param.  Set
	r2save_.
	(Stub_table::find_plt_call_entry): Return Plt_stub_ent*.  Adjust
	use throughout.
	(Stub_table::do_write): Conditionally output r2 save in plt stubs.
	(Target_powerpc::Scan::local): Handle R_PPC64_TOCSAVE.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Skip r2 save in plt call stub
	with tocsave reloc.  Replace header tocsave nop with r2 save.
	* symtab.h (struct Symbol_location_hash): Make public.
2017-06-23 20:37:34 +09:30
Alan Modra bdab445c82 [GOLD] PowerPC move plt indx_ out of unordered map key
I was lazy when adding indx_ to Plt_stub_ent.  The field isn't part of
the key, so ought to be part of the mapped type.  Make it so.

	* powerpc.cc (Plt_stub_key): Rename from Plt_stub_ent.  Remove indx_.
	(Plt_stub_key_hash): Rename from Plt_stub_ent_hash.
	(struct Plt_stub_ent): New.
	(Plt_stub_entries): Map from Plt_stub_key to Plt_stub_ent.  Adjust
	use throughout file.
2017-06-21 22:45:15 +09:30
Eric Christopher 69431babfb 2017-06-20 Eric Christopher <echristo@gmail.com>
* aarch64.cc (scan_reloc_for_stub): Use plt_address_for_global to
        calculate the symbol value.
        (scan_reloc_section_for_stubs): Allow stubs to be created for
        section symbols.
        (maybe_apply_stub): Handle creating stubs for weak symbols to
        match the code in scan_reloc_for_stub.
2017-06-20 16:18:58 -07:00
James Clarke 94de2a2c57 [GOLD] Avoid duplicate PLT stub symbols on ppc32
If two objects are compiled with -fPIC or -fPIE and call the same
function, two different PLT entries are created, one for each object,
but the same stub symbol name is used for both.

	* powerpc.cc (Stub_table::define_stub_syms): Always include object's
	uniq_ value.
2017-06-20 18:01:52 +09:30
Eric Christopher c092b67bf0 2017-06-15 Eric Christopher <echristo@gmail.com>
* aarch64.cc: Fix a few	typos and grammar-os.
2017-06-15 18:49:41 -07:00
Jiong Wang 37de058ab2 [GOLD] Don't install branch-to-stub for TLS relaxed ERRATUM 843419 sequences on AArch64
TLS relaxation may change erratum 843419 sequences that those offending ADRP
instructions actually transformed into other instructions in which case there
is erratum 843419 risk anymore that we should avoid installing unnecessary
branch-to-stub.

gold/
        * aarch64.cc (Insn_utilities::is_mrs_tpidr_el0): New method.
        (AArch64_relobj<size, big_endian>::try_fix_erratum_843419_optimized):
        Return ture for some TLS relaxed sequences.
2017-06-15 11:24:10 +01:00
Eric Christopher 81b6fe3bf9 2017-06-07 Eric Christopher <echristo@gmail.com>
* aarch64.cc (maybe_apply_stub): Add debug logging for looking
	up stubs to undefined symbols and early return rather than
	fail to look them up.
	(scan_reloc_for_stub): Add debug logging for no stub creation
	for undefined symbols.
2017-06-07 17:52:37 -07:00