Commit Graph

58 Commits

Author SHA1 Message Date
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
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
Yuri Chornovian de194d8575 Fix spelling typos. 2017-07-18 16:58:14 +01:00
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
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
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
Igor Kudrin 6bf56e7482 Fix misplacement of a relaxed section on AArch64.
gold/ChangeLog
	PR gold/21430
	* aarch64.cc
	(AArch64_relobj::convert_input_section_to_relaxed_section):
	Set the section offset to -1ULL.
	(Target_aarch64::relocate_section): Adjust the view in case
	of a relaxed input section.
	* testsuite/Makefile.am (pr21430): New test.
	* testsuite/Makefile.in: Regenerate
	* testsuite/pr21430.s: New test source file.
	* testsuite/pr21430.sh: New test script.
2017-05-12 15:24:32 -07:00
Nick Clifton a24df30571 Fix problem in aarch64 gold sources uncovered by Coverty - using sizeof on a pointer instead of an array.
* aarch64.cc (Stub_template_repertoire): Change ST_E_835769_INSNS
        from a pointer to an array.
2017-01-20 10:21:17 +00:00
Cary Coutant 98461510d3 Refactor Sized_relobj_file::do_relocate_sections.
gold/
	* aarch64.cc (AArch64_relobj::do_relocate_sections): Call
	Sized_relobj_file::relocate_section_range().
	* arm.cc (Arm_relobj::do_relocate_sections): Likewise.
	* object.h (Sized_relobj_file::relocate_section_range): New method.
	* reloc.cc (Sized_relobj_file::do_relocate_sections): Move
	implementation...
	(Sized_relobj_file::relocate_section_range): ...to new method.
2017-01-10 07:46:43 -08:00
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Cary Coutant 0f12543278 Fix internal error when relaxing branches to STT_SECTION symbols.
gold/
	PR gold/20807
	* aarch64.cc (Target_aarch64::scan_reloc_section_for_stubs): Handle
	section symbols correctly.
	* arm.cc (Target_arm): Likewise.
	* powerpc.cc (Target_powerpc): Likewise.
2016-12-01 12:53:54 -08:00
Ambrogino Modigliani 5c3024d2c1 Fix spelling in comments in C source files (gold)
* aarch64.cc: Fix spelling in comments.
	* arm.cc: Fix spelling in comments.
	* icf.cc: Fix spelling in comments.
	* layout.cc: Fix spelling in comments.
	* layout.h: Fix spelling in comments.
	* mips.cc: Fix spelling in comments.
	* output.h: Fix spelling in comments.
	* plugin.h: Fix spelling in comments.
	* script-sections.h: Fix spelling in comments.
	* script.h: Fix spelling in comments.
	* stringpool.h: Fix spelling in comments.
	* tilegx.cc: Fix spelling in comments.
2016-11-27 15:03:06 +10:30
Alan Modra d8e9025191 [GOLD] -Wimplicit-fallthrough warning fixes
* aarch64.cc: Spell fall through comments as "// Fall through.".
	* arm.cc: Likewise.
	* mips.cc: Likewise.
	* powerpc.cc: Likewise.
	* s390.cc: Likewise.
	* sparc.cc: Likewise.
	* x86_64.cc: Likewise.
	* powerpc.cc (Target_powerpc::Relocate::relocate): Add missing
	fall through comments.
	* sparc.cc: (Target_sparc::Scan::global): Likewise.
	(Target_sparc::Relocate::relocate): Likewise.
	* tilegx.cc (Target_tilegx::Relocate::relocate): Likewise.
	* resolve.cc (symbol_to_bits): Add missing break.
2016-10-06 09:36:33 +10:30
Alan Modra 2422813015 [GOLD] warning fixes
* aarch64.cc (Target_aarch64::is_erratum_835769_sequence): Avoid
	compiler warning.
	* output.cc (Output_segment::set_section_addresses): Likewise.
2016-09-26 18:04:18 +09:30
Han Shen 8769bc4bab [Gold, aarch64] Implement some AArch64 relocs.
This CL implemented the following relocs for AArch64 target.
  - R_AARCH64_MOVW_UABS_G*
  - R_AARCH64_MOVW_SABS_G* relocations

gold/ChangeLog

2016-07-26 Igor Kudrin  <ikudrin@accesssoftek.com>

    * aarch64-reloc-property.cc (Rvalue_bit_select_impl): New class.
    (rvalue_bit_select): Use Rvalue_bit_select_impl.
    * aarch64-reloc.def (MOVW_UABS_G0, MOVW_UABS_G0_NC,
    MOVW_UABS_G1,
    MOVW_UABS_G1_NC, MOVW_UABS_G2, MOVW_UABS_G2_NC, MOVW_UABS_G3,
    MOVW_SABS_G0, MOVW_SABS_G1, MOVW_SABS_G2): New relocations.
    * aarch64.cc (Target_aarch64::Scan::local): Add cases for new
    MOVW_UABS_* and MOVW_SABS_* relocations.
    (Target_aarch64::Scan::global): Likewise.
    (Target_aarch64::Relocate::relocate): Add cases and handlings
    for new MOVW_UABS_* and MOVW_SABS_* relocations.
    * testsuite/Makefile.am (aarch64_relocs): New test.
    * testsuite/Makefile.in: Regenerate.
    * testsuite/aarch64_globals.s: New test source file.
    * testsuite/aarch64_relocs.s: Likewise.
    * testsuite/aarch64_relocs.sh: New test script.
2016-07-26 08:55:14 -07:00
Igor Kudrin 5627d875bc Implement the R_AARCH64_NONE relocation.
According to "ELF for the ARM(r) 64-bit Architecture (AArch64)",
this relocation can be used "to prevent removal of sections that
might otherwise appear to be unused."

gold/
	* aarch64-reloc.def (NONE): New relocation.
	* aarch64.cc (Target_aarch64::Scan::local): Handle R_AARCH64_NONE.
	(Target_aarch64::Scan::global): Likewise.
	* testsuite/Makefile.am (aarch64_reloc_none): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/aarch64_reloc_none.s: New test source file.
	* testsuite/aarch64_reloc_none.sh: New test script.
2016-06-28 15:50:29 -07:00
Igor Kudrin 8032ac0339 Implement SORT_BY_INIT_PRIORITY.
2016-06-28  Igor Kudrin  <ikudrin@accesssoftek.com>

gold/
	PR gold/18098
	* script-c.h (Sort_wildcard): Add SORT_WILDCARD_BY_INIT_PRIORITY.
	* script-sections.cc (Input_section_sorter::get_init_priority): New method.
	(Input_section_sorter::operator()): Handle SORT_WILDCARD_BY_INIT_PRIORITY.
	(Output_section_element_input::print): Likewise.
	* script.cc (script_keyword_parsecodes): Add entry SORT_BY_INIT_PRIORITY.
	* yyscript.y (SORT_BY_INIT_PRIORITY): New token.
	(wildcard_section): Handle SORT_BY_INIT_PRIORITY.

	* testsuite/Makefile.am (script_test_14): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/script_test_14.s: New test source file.
	* testsuite/script_test_14.sh: New test script.
	* testsuite/script_test_14.t: New test linker script.
2016-06-28 15:34:11 -07:00
Han Shen 5c28a50381 Fix for PR gold/19987. 2016-05-09 14:22:15 -07:00
Han Shen e3dbf58233 Remove info message for every erratum 843419 found and fixed.
2016-02-11 Rahul Chaudhry  <rahulchaudhry@google.com>

	* aarch64.cc (Target_aarch64::scan_erratum_843419_span):
	Remove info message for every erratum 843419 found and fixed.
2016-02-11 09:47:49 -08:00
Han Shen 9a472eda40 [gold][aarch64] PR gold/19472 - DSOs need pc-relative stubs.
The stub generated during relaxation uses absolute addressing mode for
shared libraries, which is not correct. Use pc-relative addressing
instead.

gold/ChangeLog:

2016-01-15 Han Shen  <shenhan@google.com>

	PR gold/19472 - DSOs need pc-relative stubs.

	* aarch64.cc (Reloc_stub::stub_type_for_reloc): Return
	PC-relative stub type for DSOs and pie executables.
2016-01-15 17:10:04 -08:00
Cary Coutant d21f123b0e Fix internal error when applying TLSDESC relocations with no TLS segment.
gold/
	PR gold/19353
	* aarch64.cc (Target_aarch64::relocate_tls): Don't insist that
	we have a TLS segment for GD-to-IE optimization.
	* i386.cc (Target_i386::tls_gd_to_ie): Remove tls_segment parameter.
	Adjust all calls.
	(Target_i386::tls_desc_gd_to_ie): Likewise.
	(Target_i386::relocate_tls): Don't insist that we have a TLS segment
	for TLSDESC GD-to-IE optimizations.
	* x86_64.cc (Target_x86_64::tls_gd_to_ie): Remove tls_segment parameter.
	Adjust all calls.
	(Target_x86_64::tls_desc_gd_to_ie): Likewise.
	(Target_x86_64::relocate_tls): Don't insist that we have a TLS segment
	for TLSDESC GD-to-IE optimizations.
2016-01-11 23:58:28 -08:00
Cary Coutant 4d625b70fc Refactor gold to enable support for MIPS-64 relocation format.
For MIPS-64, the r_info field in the relocation format is
replaced by several individual fields, including r_sym and
r_type. To enable support for this format, I've refactored
target-independent code to remove almost all uses of the r_info
field. (I've left alone a couple of routines used only for
incremental linking, which I can update if/when the MIPS target
adds support for incremental linking.)

For routines that are already templated on a Classify_reloc class
(namely, gc_process_relocs, relocate_section, and
relocate_relocs), I've extended the Classify_reloc interface to
include sh_type (which no longer needs to be a separate template
parameter) as well as get_r_sym() and get_r_type() methods for
extracting the r_sym and r_type fields. For
scan_relocatable_relocs, I've extended the
Default_scan_relocatable_relocs class by converting it to a class
template with Classify_reloc as a template parameter. For the
remaining routines that need to access r_sym, I've added a
virtual Target::get_r_sym() method with an override for the MIPS
target.

In elfcpp, I've added Mips64_rel, etc., accessor classes and
corresponding internal data structures. The MIPS target uses
these new classes within its own Mips_classify_reloc class.
The Mips64_ accessor classes also expose the r_ssym, r_type2,
and r_type3 fields from the relocation.

These changes should be functionally the same for all but the
MIPS target.

elfcpp/
	* elfcpp.h (Mips64_rel, Mips64_rel_write): New classes.
	(Mips64_rela, Mips64_rela_write): New classes.
	* elfcpp_internal.h (Mips64_rel_data, Mips64_rela_data): New structs.

gold/
	* gc.h (get_embedded_addend_size): Remove sh_type parameter.
	(gc_process_relocs): Remove sh_type template parameter.
	Use Classify_reloc to access r_sym, r_type, and r_addend fields.
	* object.h (Sized_relobj_file::split_stack_adjust): Add target
	parameter.
	(Sized_relobj_file::split_stack_adjust_reltype): Likewise.
	* reloc-types.h (Reloc_types::copy_reloc_addend): (SHT_REL and SHT_RELA
	specializations) Remove.
	* reloc.cc (Emit_relocs_strategy): Rename and move to target-reloc.h.
	(Sized_relobj_file::emit_relocs_scan): Call Target::emit_relocs_scan().
	(Sized_relobj_file::emit_relocs_scan_reltype): Remove.
	(Sized_relobj_file::split_stack_adjust): Add target parameter.
	Adjust all callers.
	(Sized_relobj_file::split_stack_adjust_reltype): Likewise. Call
	Target::get_r_sym() to get r_sym field from relocations.
	(Track_relocs::next_symndx): Call Target::get_r_sym().
	* target-reloc.h (scan_relocs): Remove sh_type template parameter;
	add Classify_reloc template parameter.  Use for accessing r_sym and
	r_type.
	(relocate_section): Likewise.
	(Default_classify_reloc): New class (renamed and moved from reloc.cc).
	(Default_scan_relocatable_relocs): Remove sh_type template parameter.
	(Default_scan_relocatable_relocs::Reltype): New typedef.
	(Default_scan_relocatable_relocs::reloc_size): New const.
	(Default_scan_relocatable_relocs::sh_type): New const.
	(Default_scan_relocatable_relocs::get_r_sym): New method.
	(Default_scan_relocatable_relocs::get_r_type): New method.
	(Default_emit_relocs_strategy): New class.
	(scan_relocatable_relocs): Replace sh_type template parameter with
	Scan_relocatable_relocs class.  Use it to access r_sym and r_type
	fields.
	(relocate_relocs): Replace sh_type template parameter with
	Classify_reloc class.  Use it to access r_sym and r_type fields.
	* target.h (Target::is_call_to_non_split): Replace r_type parameter
	with pointer to relocation. Adjust all callers.
	(Target::do_is_call_to_non_split): Likewise.
	(Target::emit_relocs_scan): New virtual method.
	(Sized_target::get_r_sym): New virtual method.
	* target.cc (Target::do_is_call_to_non_split): Replace r_type parameter
	with pointer to relocation.

	* aarch64.cc (Target_aarch64::emit_relocs_scan): New method.
	(Target_aarch64::Relocatable_size_for_reloc): Remove.
	(Target_aarch64::gc_process_relocs): Use Default_classify_reloc.
	(Target_aarch64::scan_relocs): Likewise.
	(Target_aarch64::relocate_section): Likewise.
	(Target_aarch64::Relocatable_size_for_reloc::get_size_for_reloc):
	Remove.
	(Target_aarch64::scan_relocatable_relocs): Use Default_classify_reloc.
	(Target_aarch64::relocate_relocs): Use Default_classify_reloc.
	* arm.cc (Target_arm::Arm_scan_relocatable_relocs): Remove sh_type
	template parameter.
	(Target_arm::emit_relocs_scan): New method.
	(Target_arm::Relocatable_size_for_reloc): Replace with...
	(Target_arm::Classify_reloc): ...this.
	(Target_arm::gc_process_relocs): Use Classify_reloc.
	(Target_arm::scan_relocs): Likewise.
	(Target_arm::relocate_section): Likewise.
	(Target_arm::scan_relocatable_relocs): Likewise.
	(Target_arm::relocate_relocs): Likewise.
	* i386.cc (Target_i386::emit_relocs_scan): New method.
	(Target_i386::Relocatable_size_for_reloc): Replace with...
	(Target_i386::Classify_reloc): ...this.
	(Target_i386::gc_process_relocs): Use Classify_reloc.
	(Target_i386::scan_relocs): Likewise.
	(Target_i386::relocate_section): Likewise.
	(Target_i386::scan_relocatable_relocs): Likewise.
	(Target_i386::relocate_relocs): Likewise.
	* mips.cc (Mips_scan_relocatable_relocs): Remove sh_type template
	parameter.
	(Mips_reloc_types): New class template.
	(Mips_classify_reloc): New class template.
	(Target_mips::Reltype): New typedef.
	(Target_mips::Relatype): New typedef.
	(Target_mips::emit_relocs_scan): New method.
	(Target_mips::get_r_sym): New method.
	(Target_mips::Relocatable_size_for_reloc): Replace with
	Mips_classify_reloc.
	(Target_mips::copy_reloc): Use Mips_classify_reloc.
	(Target_mips::gc_process_relocs): Likewise.
	(Target_mips::scan_relocs): Likewise.
	(Target_mips::relocate_section): Likewise.
	(Target_mips::scan_relocatable_relocs): Likewise.
	(Target_mips::relocate_relocs): Likewise.
	(mips_get_size_for_reloc): New function, factored out from
	Relocatable_size_for_reloc::get_size_for_reloc.
	(Target_mips::Scan::local): Use Mips_classify_reloc.
	(Target_mips::Scan::global): Likewise.
	(Target_mips::Relocate::relocate): Likewise.
	* powerpc.cc (Target_powerpc::emit_relocs_scan): New method.
	(Target_powerpc::Relocatable_size_for_reloc): Remove.
	(Target_powerpc::gc_process_relocs): Use Default_classify_reloc.
	(Target_powerpc::scan_relocs): Likewise.
	(Target_powerpc::relocate_section): Likewise.
	(Powerpc_scan_relocatable_reloc): Convert to class template.
	(Powerpc_scan_relocatable_reloc::Reltype): New typedef.
	(Powerpc_scan_relocatable_reloc::reloc_size): New const.
	(Powerpc_scan_relocatable_reloc::sh_type): New const.
	(Powerpc_scan_relocatable_reloc::get_r_sym): New method.
	(Powerpc_scan_relocatable_reloc::get_r_type): New method.
	(Target_powerpc::scan_relocatable_relocs): Use
	Powerpc_scan_relocatable_reloc.
	(Target_powerpc::relocate_relocs): Use Default_classify_reloc.
	* s390.cc (Target_s390::emit_relocs_scan): New method.
	(Target_s390::Relocatable_size_for_reloc): Remove.
	(Target_s390::gc_process_relocs): Use Default_classify_reloc.
	(Target_s390::scan_relocs): Likewise.
	(Target_s390::relocate_section): Likewise.
	(Target_s390::Relocatable_size_for_reloc::get_size_for_reloc):
	Remove.
	(Target_s390::scan_relocatable_relocs): Use Default_classify_reloc.
	(Target_s390::relocate_relocs): Use Default_classify_reloc.
	* sparc.cc (Target_sparc::emit_relocs_scan): New method.
	(Target_sparc::Relocatable_size_for_reloc): Remove.
	(Target_sparc::gc_process_relocs): Use Default_classify_reloc.
	(Target_sparc::scan_relocs): Likewise.
	(Target_sparc::relocate_section): Likewise.
	(Target_sparc::Relocatable_size_for_reloc::get_size_for_reloc):
	Remove.
	(Target_sparc::scan_relocatable_relocs): Use Default_classify_reloc.
	(Target_sparc::relocate_relocs): Use Default_classify_reloc.
	* tilegx.cc (Target_tilegx::emit_relocs_scan): New method.
	(Target_tilegx::Relocatable_size_for_reloc): Remove.
	(Target_tilegx::gc_process_relocs): Use Default_classify_reloc.
	(Target_tilegx::scan_relocs): Likewise.
	(Target_tilegx::relocate_section): Likewise.
	(Target_tilegx::Relocatable_size_for_reloc::get_size_for_reloc):
	Remove.
	(Target_tilegx::scan_relocatable_relocs): Use Default_classify_reloc.
	(Target_tilegx::relocate_relocs): Use Default_classify_reloc.
	* x86_64.cc (Target_x86_64::emit_relocs_scan): New method.
	(Target_x86_64::Relocatable_size_for_reloc): Remove.
	(Target_x86_64::gc_process_relocs): Use Default_classify_reloc.
	(Target_x86_64::scan_relocs): Likewise.
	(Target_x86_64::relocate_section): Likewise.
	(Target_x86_64::Relocatable_size_for_reloc::get_size_for_reloc):
	Remove.
	(Target_x86_64::scan_relocatable_relocs): Use Default_classify_reloc.
	(Target_x86_64::relocate_relocs): Use Default_classify_reloc.

	* testsuite/testfile.cc (Target_test::emit_relocs_scan): New method.
2016-01-11 18:51:18 -08:00
Alan Modra 6f2750feaf Copyright update for binutils 2016-01-01 23:00:01 +10:30
Alan Modra 91a65d2fe8 [GOLD] Relocate::relocate() params
Some linker code editing needs to change multiple insns.  In some
cases multiple relocations are involved and it is not sufficient to
make the changes independently as relocations are processed, because
doing so might lead to a partial edit.  So in order to safely edit we
need all the relocations available in relocate().  Also, to emit
edited relocs corresponding to the edited code sequence we need some
way to pass information from relocate() to relocate_relocs(),
particularly if the edit depends on insns.  We can't modify input
relocs in relocate() as they are mmapped PROT_READ, nor it is
particularly clean to write relocs to the output at that stage.  So
add a Relocatable_relocs* field to relinfo to mark edited relocs.

Given that relocate is passed the raw reloc pointer, it makes sense to
remove the rel/rela parameter and r_type too.  However, that means the
mips relocate() needs to know whether SHT_REL or SHT_RELA relocs are
being processed.  So add a rel_type for mips, which also has the
benefit of removing relocate() overloading there.

This patch adds the infrastructure without making use of it.

Note that relinfo->rr will be NULL if not outputting relocations.

	* object.h (struct Relocate_info): Add "rr".
	* reloc.h (Relocatable_relocs::set_strategy): New accessor.
	* reloc.cc (Sized_relobj_file::do_relocate_sections): Init
	relinfo.rr for relocate_section and relocate_relocs.
	* powerpc.cc (relocate): Add rel_type and preloc parameters.
	Delete rela and r_type params, instead recalculate these from
	preloc.
	(relocate_relocs): Delete Relocatable_relocs* param, instead
	use relinfo->rr.
	* aarch64.cc: Likewise.
	* arm.cc: Likewise.
	* i386.cc: Likewise.
	* mips.cc: Likewise.
	* s390.cc: Likewise.
	* sparc.cc: Likewise.
	* target.h: Likewise.
	* tilegx.cc: Likewise.
	* x86_64.cc: Likewise.
	* testsuite/testfile.cc: Likewise.
	* target-reloc.h (relocate_section): Adjust to suit.
	(apply_relocation, relocate_relocs): Likewise.
2015-12-09 10:36:43 +10:30
Cary Coutant 859d79870d Remove unnecessary target dependencies on relocation format.
2015-11-09  Cary Coutant  <ccoutant@gmail.com>
	    Vladimir Radosavljevic <Vladimir.Radosavljevic@imgtec.com>

gold/
	* copy-relocs.h (Copy_relocs::copy_reloc): Replace reloc parameter
	with type, offset, addend.
	(Copy_relocs::save): Likewise.
	* copy-relocs.cc (Copy_relocs::copy_reloc): Likewise.
	(Copy_relocs::save): Likewise.
	* aarch64.cc (Target_aarch64::copy_reloc): Pass r_type, r_offset,
	and r_addend to Copy_relocs::copy_reloc.
	* arm.cc (Target_arm::copy_reloc): Likewise.
	* i386.cc (Target_i386::copy_reloc): Likewise.
	* mips.cc (Target_mips::copy_reloc): Likewise.
	* powerpc.cc (Target_powerpc::copy_reloc): Likewise.
	* s390.cc (Target_s390::copy_reloc): Likewise.
	* sparc.cc (Target_sparc::copy_reloc): Likewise.
	* tilegx.cc (Target_tilegx::copy_reloc): Likewise.
	* x86_64.cc (Target_x86_64::copy_reloc): Likewise.
2015-11-09 10:33:37 -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
Marcin Kościelnicki 8d9743bd43 Support 64-bit entry size in SHT_HASH (for s390).
gold/
	* dynobj.cc (Dynobj::create_elf_hash_table): Create hash table with
	target-specific entry size.
	(Dynobj::sized_create_elf_hash_table): Add size template parameter.
	* dynobj.h (Dynobj::sized_create_elf_hash_table): Likewise.
	* layout.cc (Layout::create_dynamic_symtab): Set entsize to
	hash_entry_size.
	* target.h (Target::hash_entry_size): New method.
	(Target::Target_info::hash_entry_size): New data member.

	* aarch64.cc (Target_aarch64::aarch64_info): Add hash_entry_size.
	* arm.cc (Target_arm::arm_info): Likewise.
	(Target_arm_nacl::arm_nacl_info): Likewise.
	* i386.cc (Target_i386::i386_info): Likewise.
	(Target_i386_nacl::i386_nacl_info): Likewise.
	(Target_iamcu::iamcu_info): Likewise.
	* mips.cc (Target_mips::mips_info): Likewise.
	(Target_mips_nacl::mips_nacl_info): Likewise.
	* powerpc.cc (Target_powerpc::powerpc_info): Likewise.
	* sparc.cc (Target_sparc::sparc_info): Likewise.
	* tilegx.cc (Target_tilegx::tilegx_info): Likewise.
	* x86_64.cc (Target_x86_64::x86_64_info): Likewise.
	(Target_x86_64_nacl::x86_64_nacl_info): Likewise.
	* testsuite/testfile.cc (Target_test::test_target_info): Likewise.
2015-10-28 16:45:37 -07:00
Han Shen 4d2f5d5824 Patch for PR gold/19042 - unsupported reloc 311/312.
gold/

	* aarch64.cc (Target_aarch64::Scan::local): Add support for
	reloc 311/312.
2015-10-27 15:22:41 -07:00
Andreas Schwab 3b0357dada gold: fix ABI pagesize for aarch64
* aarch64.cc (aarch64_info): Set abi_pagesize to 64K.
2015-10-07 10:57:37 +02:00
Alan Modra f945ba50bb GOLD aarch64 warning fix
aarch64.cc:2026:50: error: integer overflow in expression [-Werror=overflow]
       Insntype adr_insn = adrp_insn & ((1 << 31) - 1);

	* aarch64.cc (try_fix_erratum_843419_optimized): Warning fix.
2015-07-22 10:29:12 +09:30
Han Shen 0ef3814fe1 Optimize erratum 843419 fix.
gold/ChangeLog:
	* aarch64.cc (AArch64_insn_utilities::is_adr): New method.
	(AArch64_insn_utilities::aarch64_adr_encode_imm): New method.
	(AArch64_insn_utilities::aarch64_adrp_decode_imm): New method.
	(E843419_stub): New sub-class of Erratum_stub.
	(AArch64_relobj::try_fix_erratum_843419_optimized): New method.
	(AArch64_relobj::section_needs_reloc_stub_scanning): Try optimized fix.
	(AArch64_relobj::create_erratum_stub): Add 1 argument.
	(Target_aarch64::scan_erratum_843419_span): Pass in adrp insn offset.
2015-07-20 13:20:46 -07:00
Han Shen 73854cdd43 Use "gold_info" instead of "gold_warning" for erratum fix.
gold/ChangeLog:

	* aarch64.cc (Target_aarch64::scan_erratum_843419_span): Use 'gold_info'.
	(Target_aarch64::scan_erratum_835769_span): USe 'gold_info'.
2015-07-09 17:13:34 -07:00
Han Shen 61163dfaae Drop 'missing mapping symbols' warning for arm and aarch64.
The psABI (AAELF) says this about mapping symbols:

    4.6.5.1 Section-relative mapping symbols

    Mapping symbols defined in a section define a sequence of
    half-open address intervals that cover the address range of the
    section. Each interval starts at the address defined by the
    mapping symbol, and continues up to, but not including, the
    address defined by the next (in address order) mapping symbol or
    the end of the section. A section must have a mapping symbol
    defined at the beginning of the section; however, if the section
    contains only data then the mapping symbol may be omitted.

That makes it pretty clear that, in the absence of a mapping symbol,
the entire section can be treated as data.

gold/ChangeLog:
	* aarch64.cc (AArch64_relobj::scan_errata): Drop missing symbol warning.
	* arm.cc (Arm_relobj::scan_section_for_cortex_a8_erratum): Drop missing
	symbol warning.
2015-07-09 15:43:15 -07:00
Han Shen b91deca94e Make gold aarch64 accept long form of mapping symbols.
2015-07-07  Han Shen  <shenhan@google.com>

gold/ChangeLog:
	2015-07-06 Han Shen  <shenhan@google.com>
	* aarch64.cc (AArch64_relobj::do_count_local_symbols): Make legal
	of mapping symbols.
2015-07-07 16:40:13 -07:00
Han Shen 56b06706eb Patch for gold internal error while fixing erratum 843419.
The crash reason is that the insn to be moved to stub may be a
relocation spot, so instead of placing the origin insn (that is insn
before-relocation) to the stub, I have to place the relocated one.
Note the relocation involved is non-pc-relative, so it is safe to move
the relocated insn.

gold/ChangeLog:
2015-06-29  Han Shen  <shenhan@google.com>

    * AArch64.cc (Erratum_stub::Insn_utilities): New typedef.
    (Erratum_stub::update_erratum_insn): New method.
    (Stub_table::relocate_stubs): Modified to place relocated insn.
    (AArch64_relobj::fix_errata): Modified gold_assert.
2015-06-29 17:03:02 -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 5d7908e088 Fix gold build error at -O0.
In aarch64.cc, Erratum_stub::STUB_ADDR_ALIGN and Reloc_stub::STUB_ADDR_ALIGN
are declared as static const int, and initialized in the class body. These
values are referenced from outside the class body, and with no optimization,
the references go unresolved.

gold/
	* aarch64.cc (Erratum_stub::STUB_ADDR_ALIGN): Move initialization
	outside class body.
	(Reloc_stub::STUB_ADDR_ALIGN): Likewise.
2015-06-11 13:21:11 -07:00
Han Shen a48d0c12f8 Patch for erratum-843419 (2 of 2 - fix erratum occurrences).
Now fixing for 843419 is fully functional.

The first part of the erratum fix CL is here -
https://sourceware.org/ml/binutils/2015-04/msg00229.html

gold/ChangeLog
2015-06-10  Han Shen  <shenhan@google.com>

    * aarch64.cc(global enum): New constants representing stub types.
    (Stub_template): New POD struct.
    (Stub_template_repertoire): New class.
    (Stub_base): New class.
    (Erratum_stub): New class.
    (Reloc_stub): Refactored to be a subclass of Stub_base.
    (Reloc_stub::Stub_type): Removed.
    (Reloc_stub::offset): Moved to Stub_base.
    (Reloc_stub::set_offset): Moved to Stub_base.
    (Reloc_stub::destination_address): Moved to Stub_base.
    (Reloc_stub::set_destination_address): Moved to Stub_base.
    (Reloc_stub::reset_destination_address): Moved to Stub_base.
    (Reloc_stub::stub_type): Renamed and moved to Stub_base.
    (Reloc_stub::stub_size): Renamed and moved to Stub_base.
    (Reloc_stub::stub_insns): Renamed and moved to Stub_base.
    (Reloc_stub::write): Moved to Stub_base.
    (Reloc_stub::invalid_offset): Moved to Stub_base.
    (Reloc_stub::invalid_address): Moved to Stub_base.
    (Reloc_stub::stub_type_): Renamed and moved to Stub_base.
    (Reloc_stub::stub_insns_): Moved to Stub_base.
    (Reloc_stub::offset_): Moved to Stub_base.
    (Reloc_stub::destination_address_): Moved to Stub_base.
    (Stub_table::The_aarch64_relobj): New typedef.
    (Stub_table::The_erratum_stub): New typedef.
    (Stub_table::The_erratum_stub_less): New typedef.
    (Stub_table::The_erratum_stub_set): New typedef.
    (Stub_table::The_erratum_stub_set_iter): New typedef.
    (Stub_table::empty): Added emptiness testing for erratum stubs.
    (Stub_table::add_erratum_stub): New method to add an erratum stub.
    (Stub_table::find_erratum_stub): New method.
    (Stub_table::find_erratum_stubs_for_input_section): New method.
    (Stub_table::erratum_stub_address): New method.
    (Stub_table::update_date_size_changed_p): Modified to handle erratum stubs.
    (Stub_table::do_addralign): Modified to handle erratum stubs.
    (Stub_table::erratum_stubs_): New member.
    (Stub_table::erratum_stub_size_): New member.
    (Stub_table::relocate_stubs): Modified to handle erratum stubs.
    (Stub_table::do_write): Modified to handle erratum stubs.
    (AArch64_relobj::The_erratum_stub): New typedef.
    (AArch64_relobj::Erratum_stub_set_iter): New typedef.
    (AArch64_relobj::fix_errata): New method.
    (Target_aarch64::The_reloc_stub_type): Removed.
    (Target_aarch64::The_erratum_stub): New typede.
    (AArch64_relocate_functions::construct_b): New method.
2015-06-10 10:02:15 -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
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
Rafael Ávila de Espíndola 7fa5525f8e Fix the signature of a virtual method to match the one in the parent class. 2015-04-06 15:49:50 -04:00
Jing Yu 6b0ad2ebf6 Support AARCH64_TLSLD_ADD_DTPREL_* relocations.
Also Change _TLS_MODULE_BASE_. Always let it point to the start
of TLS segment.

2015-03-28  Jing Yu  <jingyu@google.com>

	* aarch64-reloc.def: New TLSLD_ADD_DTPREL_HI12,
	TLSLD_ADD_DTPREL_LO12_NC.
	* aarch64.cc (Target_aarch64::define_tls_base_symbol): Always
	let _TLS_MODULE_BASE_ point to the start of tls segment.
	(Target_aarch64::optimize_tls_reloc): Add cases for
	R_AARCH64_TLSLD_ADD_DTPREL_HI12 and
	R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC.
	(Target_aarch64::Scan::local): Likewise.
	(Target_aarch64::Scan::global): Likewise.
	(Target_aarch64::Relocate::relocate): Likewise.
	(Target_aarch64::Relocate::relocate_tls): Likewise. And remove
	subtracting tls segment size from symbol value for
	TLSLD_*_DTPREL relocations.
2015-03-30 14:11:48 -07:00
Jing Yu 1a920511af Add missing TLSLE relocations for gold aarch64 backend.
gold/ChangeLog:
	* aarch64-reloc.def (TLSLE_MOVW_TPREL_G2, TLSLE_MOVW_TPREL_G1,
	TLSLE_MOVW_TPREL_G1_NC, TLSLE_MOVW_TPREL_G0, TLSLE_MOVW_TPREL_G0_NC,):
	New relocation.
	* aarch64.cc (Target_aarch64::Scan::local): Add cases for new
	TLSLE_MOVW_* relocations.
	(Target_aarch64::Scan::global): Likewise.
	(Target_aarch64::Relocate::relocate): Likewise.
	(Target_aarch64::Relocate::relocate_tls): Add cases and handlings
	for new TLSLE_MOVW_* relocations.
2015-02-12 14:51:57 -08:00
Han Shen fa89cc82f5 This patch adds IFUNC support for arm gold backend.
This is a feature required in chromeos arm development work.

Tested:
1) Built passed all-gold on x86_64 machine
2) Tested with basic gold aarch64 ifunc unittests -
   a) global ifunc, statically/non-statically linked
   b) local ifunc, statically/non-statically linked
   c) global/local, other shared library routine mixed,
   statically/non-statically linked
   d) arm/thumb mode ifunc
   e) linking chrome browser passed
2015-01-29 10:15:42 -08:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
H.J. Lu add6016bac Cast current_group_size to unsigned long
* aarch64.cc (AArch64_relocate_functions::maybe_apply_stub):
	Cast current_group_size to unsigned long when reporting error.
2014-12-14 06:59:20 -08:00
Jing Yu 0bf32ea9e6 Give informative error message for stub-group-size
This patch gives current stub-group-size in error message when stub
is too far away.

	* aarch64.cc (Target_aarch64): Add new variable: stub_group_size_.
	(AArch64_relocate_functions::maybe_apply_stub): Add new parameter.
	Update error message.
	(Target_aarch64::do_relax): Use absolute value of option
	stub_group_size. Replace local variable with class member
	stub_group_size_.
2014-12-10 15:39:13 -08:00