Commit Graph

239 Commits

Author SHA1 Message Date
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
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
Alan Modra 407aa07cee Revert "PowerPC PLT speculative execution barriers"
This reverts most of commit 1be5d8d3bb.
Left in place are addition of --no-plt-align to some ppc32 ld tests
and the ld.texinfo --no-plt-thread-safe fix.
2018-02-07 14:23:08 +10:30
Alan Modra 1be5d8d3bb PowerPC PLT speculative execution barriers
Spectre variant 2 mitigation for PowerPC and PowerPC64.

bfd/
	* elf32-ppc.c (GLINK_ENTRY_SIZE): Handle speculation barrier.
	(CRSETEQ, BEQCTRM): Define.
	(is_nonpic_glink_stub): Don't check bctr.
	(ppc_elf_link_hash_table_create): Init new ppc_elf_params field.
	(ppc_elf_relax_section): Size speculation barrier.
	(output_bctr): New function.
	(write_glink_stub): Use output_bctr.
	(ppc_elf_relocate_section): Use output_bctr for long branch stub.
	(ppc_elf_finish_dynamic_symbol): Likewise.
	(ppc_elf_finish_dynamic_sections): Use output_bctr.
	* elf32-ppc.h (struct ppc_elf_params): Add speculate_indirect_jumps.
	* elf64-ppc.c (CRSETEQ, BEQCTRM, BEQCTRLM): Define.
	(GLINK_PLTRESOLVE_SIZE): Size speculation barrier.
	(size_global_entry_stubs): Handle speculation barrier sizing.
	(plt_stub_size): Likewise.
	(output_bctr): New function.
	(build_plt_stub, build_tls_get_addr_stub): Output speculation
	barrier.
	(ppc_build_one_stub): Likewise for ppc_stub_plt_branch.
	(ppc_size_one_stub): Size speculation barrier in ppc_stub_plt_branch.
	(build_global_entry_stubs): Output speculation barrier.
	(ppc64_elf_build_stubs): Likewise in __glink_PLTresolve stub.
	* elf64-ppc.h (struct ppc64_elf_params): Add speculate_indirect_jumps.
gold/
	* options.h (speculate_indirect_jumps): New option.
	* powerpc.cc (beqctrm, beqctrlm, crseteq): New insn constants.
	(output_bctr): New function.
	(Stub_table::plt_call_size): Add space for speculation barrier.
	(Stub_table::branch_stub_size): Likewise.
	(Output_data_glink::pltresolve_size): Likewise.
	(Stub_table::do_write): Output speculation barriers.
ld/
	* emultempl/ppc32elf.em (params): Init new field.
	(OPTION_SPECULATE_INDIRECT_JUMPS): Define.
	(OPTION_NO_SPECULATE_INDIRECT_JUMPS): Define.
	(PARSE_AND_LIST_LONGOPTS): Handle new options.
	(PARSE_AND_LIST_ARGS_CASES): Likewise.
	(PARSE_AND_LIST_OPTIONS): Likewise.
	* emultempl/ppc64elf.em (params): Init new field.
	(OPTION_SPECULATE_INDIRECT_JUMPS): Define.
	(OPTION_NO_SPECULATE_INDIRECT_JUMPS): Define.
	(PARSE_AND_LIST_LONGOPTS): Handle --speculate-indirect-jumps.
	(PARSE_AND_LIST_OPTIONS): Likewise.
	(PARSE_AND_LIST_ARGS_CASES): Likewise.
	* ld.texinfo (--no-plt-thread-safe): Correct itemx.
	(--speculate-indirect-jumps): Document.
	* testsuite/ld-powerpc/elfv2exe.d,
	* testsuite/ld-powerpc/elfv2so.d,
	* testsuite/ld-powerpc/relbrlt.d,
	* testsuite/ld-powerpc/powerpc.exp: Disable plt alignment and
	speculation barriers on various tests.
2018-01-17 18:52:57 +10:30
Alan Modra 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
Alan Modra 219d1afa89 Update year range in copyright notice of binutils files 2018-01-03 17:49:56 +10:30
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
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 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 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
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 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 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 590b87ffa3 PR21503, Gold doesn't create linker stub symbols on ppc64
PR 21503
	* options.h: Add --emit-stub-syms option.
	* powerpc.cc (object_id): New.
	(Powerpc_relobj): Add uniq_ and accessor.  Sort variables for
	better packing.
	(Powerpc_dynobj): Sort variables for better packing.
	(Target_powerpc::define_local): New function.
	(Target_powerpc::group_sections): Pass stub table size to
	Stub_table constructor.
	(Target_powerpc::do_relax): Define stub and glink symbols.
	(Stub_table): Add uniq_ variable, and id param to constructor.
	(Stub_table::Plt_stub_ent): Add indx_ variable.
	(Stub_table::Branch_stub_entries): Move typedef earlier.
	(Stub_table::branch_stub_size): Replace "to" parameter with a
	Branch_stub_entries iterator.
	(Stub_table::add_long_branch_entry): Adjust to suit.
	(Stub_table::add_plt_call_entry): Set indx_.
	(Stub_table::define_stub_syms): New function.
2017-05-23 21:49:33 +09:30
Alan Modra f159cdb611 [GOLD] Add --secure-plt option for ppc32
Added just to accept, and ignore.  gcc since 2015-10-21, when
configured with --enable-secureplt passes this option to the linker.
As powerpc gold cannot link --bss-plt code successfully, gold needs to
accept the option or the gcc specs file needs to be changed.

The patch also make gold detect --bss-plt code and error out rather
than producing a binary that crashes.

	* options.h: Add --secure-plt option.
	* powerpc.cc (Target_powerpc::Scan::local): Detect and error
	on -fPIC -mbss-plt code.
	(Target_powerpc::Scan::global): Likewise.
2017-01-10 11:50:07 +10:30
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Cary Coutant 7a0c0a1475 Add -z bndplt support (for Intel MPX).
gold/
	PR gold/17643
	* options.h (-z bndplt): New option.
	* x86_64.cc (Output_data_plt_x86_64::regular_count): New method.
	(Output_data_plt_x86_64::address_for_global): Move implementation into
	virtual method.
	(Output_data_plt_x86_64::address_for_local): Likewise.
	(Output_data_plt_x86_64::got): New method.
	(Output_data_plt_x86_64::got_plt): New method.
	(Output_data_plt_x86_64::got_irelative): New method.
	(Output_data_plt_x86_64::do_address_for_global): New virtual method.
	(Output_data_plt_x86_64::do_address_for_local): New virtual method.
	(class Output_data_plt_x86_64_bnd): New class.
	(Target_x86_64::do_make_data_plt): Move out of line and specialize
	for each size (both overloads).
	(Output_data_plt_x86_64::set_final_data_size): Cosmetic changes.
	* testsuite/Makefile.am (bnd_plt_1): New test case.
	(bnd_ifunc_1): New test case.
	(bnd_ifunc_2): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/bnd_ifunc_1.s: New source file.
	* testsuite/bnd_ifunc_1.sh: New shell script.
	* testsuite/bnd_ifunc_2.s: New source file.
	* testsuite/bnd_ifunc_2.sh: New shell script.
	* testsuite/bnd_plt_1.s: New source file.
	* testsuite/bnd_plt_1.sh: New shell script.
2016-12-22 20:07:23 -08:00
Cary Coutant 591be3e4a8 Add --orphan-handling option.
gold/
	PR gold/20749
	* options.h (--orphan-handling): New option.
	(General_options::Orphan_handling): New enum.
	(General_options::orphan_handling_enum): New method.
	(General_options::set_orphan_handling_enum): New method.
	(General_options::orphan_handling_enum_): New data member.
	* options.cc (General_options::General_options): Initialize new member.
	(General_options::finalize): Convert --orphan-handling argument to enum.
	* script-sections.cc (Script_sections::output_section_name): Check it.
2016-12-13 13:01:26 -08:00
Alan Modra 69a2af1016 [GOLD] fix typo in --stub-group-multi help
* options.h (--stub-group-multi): Fix typo.
2016-12-08 21:35:11 +10:30
Alan Modra 1c3a5fbe15 [GOLD] PowerPC --stub-group-multi
Adds a new option, defaulting to off, that allows a group of stubs to
serve multiple output sections.  Prior to this patch powerpc gold
allowed this unconditionally, which is a little unsafe with clever
code that discards/reuses sections at runtime.

	* options.h (--stub-group-multi): New PowerPC option.
	* powerpc.cc (Stub_control): Add multi_os_ var and param
	to constructor.  Sort start_ var later.  Comment State.
	(Stub_control::can_add_to_stub_group): Heed multi_os_.
	(Target_powerpc::group_sections): Update.
2016-12-07 14:15:59 +10:30
Alan Modra a5018ae555 [GOLD] powerpc64le-linux fails to link large Linux kernel
Gold attaches stubs to an existing section in contrast to ld.bfd which
inserts a new section for stubs.  If we want stubs before branches,
then the stubs must be added to the previous section.  Adding to the
previous section is a disaster if there is a large gap between the
previous section and the group.

	PR gold/20878
	* powerpc.cc (Stub_control): Replace stubs_always_before_branch_
	with stubs_always_after_branch_, group_end_addr_ with
	group_start_addr_.
	(Stub_control::can_add_to_stub_group): Rewrite to suit scanning
	sections by increasing address.
	(Target_powerpc::group_sections): Scan that way.  Delete corner
	case.
	* options.h (--stub-group-size): Update help string.
2016-12-07 14:15:44 +10:30
Cary Coutant 376c3ecd17 Implement --push-state/--pop-state.
gold/
	PR gold/18989
	* options.cc (General_options::object_format_to_string): New function.
	(General_options::copy_from_posdep_options): New function.
	(General_options::parse_push_state): New function.
	(General_options::parse_pop_state): New function.
	* options.h (--push-state, --pop-state): New options.
	(General_options::object_format_to_string): New method.
	(General_options::set_incremental_disposition): New method.
	(General_options::copy_from_posdep_options): New method.
	(General_options::options_stack_): New data member.
2016-12-01 16:33:08 -08:00
Cary Coutant 358a971863 Print the default for all binary options; clean up --help output.
gold/
	PR gold/20346
	* options.cc (One_option::print): Print "(default)" when appropriate.
	* options.h: Clean up and re-sort options.
	(One_option::is_default): New data member.
	(One_option::One_option): Add is_default parameter; adjust all calls.
	(DEFINE_var): Add is_default__ parameter; adjust all calls.
	(DEFINE_bool): Set is_default based on default_value__.
	(DEFINE_bool_ignore): New macro.
	(--no-eh-frame-hdr): New option.
	(--enable-new-dtags): Remove mention of DT_FLAGS.
2016-11-22 15:46:34 -08:00
Doug Kwan bc99685c73 Handle ARM-specific --target1-abs, --target1-rel and --target2 options 2016-09-02 15:51:59 -07:00
Roland McGrath 1130c90ed7 [gold] Implement -z stack-size option
gold/
	* options.h (General_options): Grok -z stack-size.
	* output.h (Output_segment::set_size): New method.
	* layout.cc (Layout::create_executable_stack_info): Renamed to ...
	(Layout::create_stack_segment): ... this.  Always create the
	segment if -z stack-size was used.
	(Layout::set_segment_offsets): Don't call ->set_offset on the
	PT_GNU_STACK segment.
2016-08-23 17:15:53 -07:00
Bharathi Seshadri 9f84726cd5 Add --be8 option to gold.
gold/
	* options.h (General_options): Add --be8 option.
	* arm.cc (Arm_relobj::do_relocate_sections): Add code to swap for be8.
	(Output_data_plt_arm_standard::do_fill_first_plt_entry): Likewise.
	(Output_data_plt_arm_short::do_fill_plt_entry): Likewise.
	(Output_data_plt_arm_long::do_fill_plt_entry): Likewise.
	(Target_arm::do_adjust_elf_header): Do EF_ARM_BE8 adjustment.
2016-08-23 14:50:48 -07:00
H.J. Lu 6b1edb94fe gold: Add a linker configure option --enable-relro
Add a configure option --enable-relro to decide whether -z relro should
be enabled by default.  Default to yes.

	PR ld/20283
	* NEWS: Mention --enable-relro.
	* configure.ac: Add --enable-relro.
	(DEFAULT_LD_Z_RELRO): New.  Set by --enable-relro and default
	to 1.
	* config.in: Regenerated.
	* configure: Likewise.
	* options.h (General_options::relro): Default to
	DEFAULT_LD_Z_RELRO.
2016-06-22 05:39:39 -07:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Peter Collingbourne ce3e49806d Implement --long-plt flag (ARM only).
gold/
    PR gold/18780
    * arm.cc (Target_arm::do_make_data_plt): Choose PLT generator based
    on value of --long-plt flag.
    (Output_data_plt_arm_standard::do_get_plt_entry_size): Moved to
    Output_data_plt_arm_short.
    (Output_data_plt_arm_standard::do_fill_plt_entry): Likewise.
    (Output_data_plt_arm_standard::plt_entry): Likewise.
    (Output_data_plt_arm_standard::do_fill_first_plt_entry): Fix
    variable reference.
    (Output_data_plt_arm_short): New class.
    (Output_data_plt_arm_short::do_fill_plt_entry): Error out on too large
    PLT offsets instead of asserting.
    (Output_data_plt_arm_long): New class.
    * options.h (General_options): Define --long-plt flag.
2015-12-17 16:52:12 -08:00
Cary Coutant 96f9814df2 Revert patch for PR 19119, which led to PR 19172 and 19197.
Gold does not support all the emulations that Gnu ld does, and supports
only one spelling per target. The -m option is used only in the rare case
where there are no ELF input files, and we produce an empty output file.
In those cases, users are expected to supply a -m option naming one of
the supported emulations. In the many cases where a build script provides
an unnecessary -m option naming an emulation that gold does not support,
we will simply ignore the option, as we did before the reverted patch.

gold/
	PR gold/19119
	PR gold/19172
	PR gold/19197
	Revert commit 6457197210144f50a696097c0d308d81d46d5510:

	2015-10-16  H.J. Lu  <hongjiu.lu@intel.com>

		* options.h (General_options): Remove "obsolete" from -m.
		* parameters.cc (set_parameters_target): Check if input target
		is compatible with output emulation set by "-m emulation".
2015-11-05 12:59:19 -08:00
Cary Coutant 0eccf19f96 Add aarch64-specific --no-apply-dynamic-relocs option.
With --no-apply-dynamic-relocs on aarch64 targets, gold will not apply
link-time values for absolute relocations that become dynamic relocations.
This provides a workaround for broken Android dynamic linkers that use
the link-time value as an extra addend to the relocation.

gold/
	PR gold/19163
	* aarch64.cc (Target_aarch64::Relocate::relocate): Don't apply
	certain relocations if --no-apply-dynamic-relocs is set.
	* options.h (--apply-dynamic-relocs): New aarch64-specific option.
2015-11-05 12:24:14 -08:00
H.J. Lu 6457197210 Don't ignore "-m emulation" command line option
Gold shouldn't ignore "-m emulation" command line option, which may
lead to incorrect output.

	PR gold/19119
	* options.h (General_options): Remove "obsolete" from -m.
	* parameters.cc (set_parameters_target): Check if input target
	is compatible with output emulation set by "-m emulation".
2015-10-16 08:05:09 -07:00
Han Shen cdb061674c 2015-07-23 Ian Coolidge <icoolidge@google.com>
Plumb --pic-veneer option for gold.

gold/ChangeLog:
	* arm.cc (Reloc_stub::stub_type_for_reloc): Plumb to stub generation.
	* options.h (General_options): Add --pic-veneer option.
2015-07-23 15:56:33 -07:00
H.J. Lu fb8b9dbc14 Extend --compress-debug-sections in gold
This patch extends --compress-debug-sections= with [zlib-gnu|zlib-gabi]
in gold.

	PR gold/18322
	* compressed_output.cc (zlib_compress): Add argument for
	compression header size.  Set header size to compression header
	size if it isn't 0.  Don't write out the zlib header here.
	(Output_compressed_section::set_final_data_size): Support
	zlib-gnu and zlib-gabi compressions.  Pass compression header
	size to zlib_compress and write out compression header.  Set
	the SHF_COMPRESSED bit for zlib-gabi compression.  Otherwise
	clear the SHF_COMPRESSED bit
	* options.h (compress_debug_sections): Add zlib-gnu and
	zlib-gabi.
	* output.h (Output_section::set_flags): New.
	* testsuite/Makefile.am (check_PROGRAMS): Add
	flagstest_compress_debug_sections_none,
	flagstest_compress_debug_sections_gnu and
	flagstest_compress_debug_sections_gabi.
	(check_DATA): Add flagstest_compress_debug_sections_none.stdout.
	flagstest_compress_debug_sections.stdout,
	flagstest_compress_debug_sections.cmp,
	flagstest_compress_debug_sections.check,
	flagstest_compress_debug_sections_gnu.stdout,
	flagstest_compress_debug_sections_gnu.cmp,
	flagstest_compress_debug_sections_gnu.check,
	flagstest_compress_debug_sections_gabi.stdout,
	flagstest_compress_debug_sections_gabi.cmp and
	flagstest_compress_debug_sections_gabi.check.
	(flagstest_compress_debug_sections_none): New.
	(flagstest_compress_debug_sections_none.stdout): Likewise.
	(flagstest_compress_debug_sections.stdout): Likewise.
	(flagstest_compress_debug_sections.check): Likewise.
	(flagstest_compress_debug_sections.cmp): Likewise.
	(flagstest_compress_debug_sections_gnu): Likewise.
	(flagstest_compress_debug_sections_gnu.stdout): Likewise.
	(flagstest_compress_debug_sections_gnu.check): Likewise.
	(flagstest_compress_debug_sections_gnu.cmp): Likewise.
	(flagstest_compress_debug_sections_gabi): Likewise.
	(flagstest_compress_debug_sections_gabi.stdout): Likewise.
	(flagstest_compress_debug_sections_gnu.check): Likewise.
	(flagstest_compress_debug_sections_gnu.cmp): Likewise.
	* testsuite/Makefile.in: Regenerated.
2015-07-12 10:56:58 -07:00
Han Shen 2f0c79aa61 [gold][aarch64] Fix erratum 835769.
gold/ChangeLog:

	* aarch64.cc (AArch64_insn_utilities::BYTES_PER_INSN): Move
	defintion outside class definition.
	(AArch64_insn_utilities::AARCH64_ZR): New static constant.
	(AArch64_insn_utilities::aarch64_op31): New member.
	(AArch64_insn_utilities::aarch64_ra): New member.
	(AArch64_insn_utilities::aarch64_mac): New member.
	(AArch64_insn_utilities::aarch64_mlxl): New member.
	(ST_E_835769): New global enum member.
	(Stub_table::relocate_stubs): Add 835769 handler.
	(Stub_template_repertoire::Stub_template_repertoire): Install new
	stub type.
	(AArch64_relobj::scan_errata): This func is renamed from
	scan_erratum_843419.
	(AArch64_relobj::do_count_local_symbols): Add 835769 handler.
	(AArch64_relobj::do_relocate_sections): Add 835769 handler.
	(AArch64_relobj::scan_sections_for_stubs): Add 835769 handler.
	(Target_aarch64::scan_erratum_835769_span): New method.
	(Target_aarch64::create_erratum_stub): New method.
	(Target_aarch64::is_erratum_835769_sequence): New method.
	(Target_aarch64::scan_erratum_843419_sequence): Move part of the
	code into create_erratum_stub.
	* options.h (fix_cortex_a53_835769): New option.
2015-06-12 14:34:14 -07:00
Cary Coutant cd3c333f43 Change default to discard temporary local symbols in merge sections.
Add --discard-none to keep all local symbols.

gold/
	PR gold/17498
	* object.cc (Sized_relobj_file::do_count_local_symbols): Discard
	temporary locals in merge sections.
	* options.cc (General_options::parse_discard_all): New method.
	(General_options::parse_discard_locals): New method.
	(General_options::parse_discard_none): New method.
	(General_options::General_options): Initialize discard_locals_.
	* options.h (--discard-all): Convert to special option.
	(--discard-locals): Likewise.
	(--discard-none): New option.
	(General_options::discard_all): New method.
	(General_options::discard_locals): New method.
	(General_options::discard_sec_merge): New method.
	(General_options::Discard_locals): New enum.
	(General_options::discard_locals_): New data member.
2015-06-04 20:58:08 -07:00
Han Shen 7a2a1c7935 [gold] Rename '--fix-cortex-a53' to '--fix-cortex-a53-843419'.
Keep gold consistent with bfd erratum-fixing option names, so as to
ease life in Makefile/scripts.

gold/

	* options.h (--fix-cortex-a53-843419): Rename option.
	* aarch64.cc (AArch64_relobj::do_count_local_symbols): Use renamed
	option.
	(AArch64_relobj::scan_sections_for_stubs): Use renamed option.
2015-04-27 15:49:41 -07:00
Sriraman Tallam a100d66fb4 Add option --weak-unresolved-symbols to treat unresolved symbols as weak ref.
This patch adds option --weak-unresolved-symbols to treat unresolved symbols as
weak references.  This is helpful when we want the link to succeed with unresolved
symbols and the dynamic loader to not complain at run-time.  Option
--warn-unresolved-symbols lets the link succeed but could fail at run-time with
unresolved symbol warnings especially when the unresolved symbols have GOT entries
and dynamic relocations against them, like when -fPIE is used.
2015-04-23 13:56:40 -07:00
Han Shen 5019d64a1f [gold] The first patch to address cortex-a53 erratum-843419.
It implemented scanning the binary and reporting occurrences to users
when '--fix-cortex-a53' is turned on. With this, gold users will be
able to see if or not there are such erratum occurrences in the output
binary. Also included in the CL is reading/recording mapping symbols,
which is needed during scan.

gold/ChangeLog:
    * aarch64.cc (AArch64_insn_utilities): New utility class.
    (AArch64_relobj::Mapping_symbol_position): New struct.
    (AArch64_relobj::Mapping_symbol_info): New typedef.
    (AArch64_relobj::do_count_local_symbols): New function overriding
    parent's implementation.
    (AArch64_relobj::mapping_symbol_info_): New member
    (AArch64_relobj::scan_erratum_843419): New method.
    (Target_aarch64::scan_erratum_843419_span): New method.
    (Target_aarch64::is_erratum_843419_sequence): New method.
    * options.h (fix_cortex_a53): New option.
2015-04-16 15:26:34 -07:00
H.J. Lu 918357b955 Regenerate configure in gold
Regenerate configure for zlib.m4 change, which adds --with-system-zlib and
removes --with-zlib in gold.  zlib is enabled unconditionally with builtin
zlib imported from GCC.

	* Makefile.am (ZLIB): New.
	(ZLIBINC): Likewise.
	(AM_CFLAGS): Add $(ZLIBINC).
	(AM_CXXFLAGS): Likewise.
	(ldadd_varldadd_var): Add $(ZLIB).
	(incremental_dump_LDADD): Likewise.
	(dwp_LDADD): Likewise.
	* compressed_output.cc: Don't check HAVE_ZLIB_H to include
	<zlib.h>.
	(zlib_compress): Don't check HAVE_ZLIB_H.
	(zlib_decompress): Likewise.
	* options.h (compress_debug_sections): Likewise.
	* configure.ac (AM_CONDITIONAL): Removed.
	* testsuite/Makefile.am (ZLIB): New.
	(LDADD): Add $(ZLIB).
	Don't check HAVE_ZLIB.
	* Makefile.in: Regenerated.
	* config.in: Likewise.
	* configure: Likewise.
	* testsuite/Makefile.in: Likewise.
2015-04-01 06:40:35 -07:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Dmitriy Ivanov fb25783533 Add support for -z global.
gold/
	* layout.cc (Layout::finish_dynamic_section): When '-z global'
	is specified set DF_1_GLOBAL in DT_FLAGS_1 flags.
	* options.h (General_options): New -z option (global).
2014-12-01 13:37:38 -08:00
Sriraman Tallam 5f77241211 2014-09-29 Sriraman Tallam <tmsriram@google.com>
* options.h (--pic-executable): Add negative to alias to -no-pie.
2014-09-29 17:30:54 -07:00
Sriraman Tallam 8123365312 Add option -no-pie. 2014-08-13 18:40:19 -07:00
Alan Modra 4b95cf5c0c Update copyright years 2014-03-05 22:16:15 +10:30
Cary Coutant fd834e57ff Fix problems with the --dynamic-list option.
PR gold/13577 complains that even though symbols listed in
the --dynamic-list script are exported, they are still bound symbolically
if -Bsymbolic is also used. There are two underlying problems here.
First, -Bsymbolic should be overridden by --dynamic-list, since the
dynamic list provides an explicit list of symbols that are not bound
within the library, and if we go ahead and set DT_SYMBOLIC, then the
dynamic loader will bind it within the library anyway. Second, gold
did not properly identify the symbols listed in the file as preemptible.

PR gold/16530 complains that symbols listed in the --dynamic-list script
can still be garbage collected. I've fixed this by checking the symbols
as they're added to the symbol table. (Unlike the --export-dynamic-symbol
option, we can't iterate over the list, because the --dynamic-list script
can have wildcards in it.)

gold/

2014-02-05  Cary Coutant  <ccoutant@google.com>

	PR gold/13577
	* options.cc (General_options::parse_dynamic_list):
	Set have_dynamic_list_.
	(General_options::General_options): Initialize have_dynamic_list_.
	(General_options::finalize): Turn off -Bsymbolic and
	-Bsymbolic-functions if --dynamic-list provided.
	* options.h (General_options::have_dynamic_list): New function.
	(General_options::have_dynamic_list_): New data member.
	* symtab.h (Symbol::is_preemptible): Handle --dynamic-list
	correctly.

	PR gold/16530
	* symtab.cc (Symbol_table::add_from_relobj): If symbol is named
	in --dynamic-list, mark it.

	* testsuite/Makefile.am (gc_dynamic_list_test.sh): New test case.
	(dynamic_list_2): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/dynamic_list_2.cc: New file.
	* testsuite/dynamic_list_2.t: New file.
	* testsuite/dynamic_list_lib1.cc: New file.
	* testsuite/dynamic_list_lib2.cc: New file.
	* testsuite/gc_dynamic_list_test.c: New file.
	* testsuite/gc_dynamic_list_test.sh: New file.
	* testsuite/gc_dynamic_list_test.t: New file.
2014-02-05 18:01:47 -08:00