Commit Graph

1746 Commits

Author SHA1 Message Date
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
Alan Modra a61d92b7bd [GOLD] testsuite/plugin_section_order.c fix
* testsuite/plugin_section_order.c (onload): Add missing break.
2017-04-27 11:54:29 +09:30
Vladimir Radosavljevic aab2c17756 Mips: Fix TLS LDM GOT entry.
gold/
	* mips.cc (Mips_got_entry::hash()): Shift addend to reduce
	possibility of collisions.
	(Mips_got_entry::equals): Fix case for GOT_TLS_LDM
	entries.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic 4d78db49e6 Mips: Omit empty objects for merging processor-specific data.
gold/
	* mips.cc (Mips_relobj::merge_processor_specific_data_): New data
	member.
	(Mips_relobj::merge_processor_specific_data): New method.
	(Mips_relobj::do_read_symbols): Set merge_processor_specific_data_
	to false, only if the input file is a binary or if object has no
	contents except the section name string table and an empty symbol
	table with the undefined symbol.
	(Target_mips::do_finalize_sections): Refactor.  Skip empty object files
	for merging processor-specific data.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic 152c92b261 Mips: Add support for resolving multiple consecutive relocations.
gold/
	* mips.cc (Target_mips::Relocate::calculated_value_): New data
	member.
	(Target_mips::Relocate::calculate_only_): Likewise.
	(Target_mips::Relocate::relocate): Handle multiple consecutive
	relocations with the same offset.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic 1e1247c89c Remove redundant checks for relocatable link (MIPS).
gold/
	* mips.cc (Target_mips::Relocate::relocate): Remove redundant
	checks for relocatable link.
	(Mips_relocate_functions::reljalr): Likewise.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic 1728969e93 Add support for .MIPS.options section.
gold/
        * mips.cc (class Mips_output_section_options): New class.
        (Target_mips::do_make_output_section): New method.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic c3847462f8 Improve relocation overflow errors on MIPS.
gold/
        * mips.cc (Mips_relocate_functions::rel26): Don't print relocation
        overflow error message.
        (Target_mips::relocate_special_relocatable): Improve relocation
        overflow error message.
        (Target_mips::Relocate::relocate): Likewise.
2017-03-15 16:51:35 -07:00
Vladimir Radosavljevic 453018bf44 Correct the definition of _gp and _GLOBAL_OFFSET_TABLE_ symbols for MIPS.
gold/
        * mips.cc (symbol_refs_local): Return false if a symbol
        is from a dynamic object.
        (Target_mips::got_section): Make _GLOBAL_OFFSET_TABLE_ STV_HIDDEN.
        (Target_mips::set_gp): Refactor.  Make _gp STT_NOTYPE and
        STB_LOCAL.
        (Target_mips::do_finalize_sections): Set _gp after all the checks
        for creating .got are done.
        (Target_mips::Scan::global): Remove unused code.
2017-03-15 16:51:35 -07:00
Alan Modra 6528b6eba8 PowerPC ld segfault on script discarding dynamic sections
bfd/
	* elf64-ppc.c (ppc64_elf_finish_dynamic_sections): Don't segfault
	on .got or .plt output section being discarded by script.
	* elf32-ppc.c (ppc_elf_finish_dynamic_sections): Likewise.  Move
	vxworks splt temp.
gold/
	* powerpc.cc (Target_powerpc::make_iplt_section): Check that
	output_section exists before attempting add_output_section_data.
	(Target_powerpc::make_brlt_section): Likewise.
2017-02-22 08:44:41 +10:30
Vladimir Radosavljevic f902956974 Don't give an internal error for unsupported relocations.
gold/
	* mips.cc (Target_mips::Scan::get_reference_flags): Remove
	gold_unreachable from default case.
2017-02-15 00:55:36 -08:00
Vladimir Radosavljevic e242ece1e8 Add support for R_MIPS_HIGHER/HIGHEST, R_MICROMIPS_HIGHER/HIGHEST relocations.
2017-02-15  Vladimir Radosavljevic  <Vladimir.Radosavljevic@imgtec.com>

        PR gold/21111
        * mips.cc (Mips_relocate_functions::relhigher): New method.
        (Mips_relocate_functions::relhighest): Likewise.
        (mips_get_size_for_reloc): Add support for relocs: R_MIPS_HIGHER and
        R_MIPS_HIGHEST.
        (Target_mips::Scan::local): Add support for relocs: R_MIPS_HIGHER,
        R_MIPS_HIGHEST, R_MICROMIPS_HIGHER and R_MICROMIPS_HIGHEST.
        (Target_mips::Scan::global): Likewise.
        (Target_mips::Scan::get_reference_flags): Likewise.
        (Target_mips::Relocate::relocate): Call static methods for resolving
        HIGHER and HIGHEST relocations.
2017-02-15 00:55:36 -08:00
Rahul Chaudhry 4aebb6312e Improved support for --icf=safe when used with -pie.
gold/
	* x86_64.cc (Target_x86_64::do_can_check_for_function_pointers):
	Return true even when building pie binaries.
	(Target_x86_64::possible_function_pointer_reloc): Check opcode
	for R_X86_64_PC32 relocations.
	(Target_x86_64::local_reloc_may_be_function_pointer): Pass
	extra arguments to local_reloc_may_be_function_pointer.
	(Target_x86_64::global_reloc_may_be_function_pointer): Likewise.
	* gc.h (gc_process_relocs): Add check for STT_FUNC.
	* testsuite/Makefile.am (icf_safe_pie_test): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/icf_safe_pie_test.sh: New shell script.
2017-02-15 00:37:10 -08:00
Alan Modra e666304ec6 [GOLD] PowerPC64 TOC indirect to TOC relative segfault
* powerpc.cc (Powerpc_relobj::make_toc_relative): Don't crash
	when no .toc section exists.
2017-02-03 20:06:53 +10:30
Cary Coutant ed35cc4a1c Don't allow mov-to-lea optimization for __ehdr_start.
gold/
	PR gold/21090
	* x86_64.cc (Target_x86_64::can_convert_mov_to_lea): Add check
	for predefined symbol.
	(Target_x86_64::Relocate::relocate): Fix formatting.
2017-01-31 16:33:58 -08:00
Rahul Chaudhry 741bcbe94d Add -e to test scripts where necessary.
gold/
        * testsuite/icf_safe_so_test.sh: Use "set -e".
        * testsuite/icf_safe_test.sh: Likewise.
        * testsuite/icf_test.sh: Likewise.
2017-01-23 17:34:42 -08:00
Vladimir Radosavljevic 04bc2a2854 Make the sh_info field of .rel.plt point to .plt (MIPS).
gold/
	* mips.cc (Mips_output_data_plt::rel_plt): Remove const from return
	type.
	(Target_mips::make_plt_entry): Make the sh_info field of .rel.plt
	point to .plt.
2017-01-23 17:18:00 -08:00
Vladimir Radosavljevic c1f59f8ff9 Fix MIPS GOT when global symbols are forced to local visibility.
gold/
	PR gold/21054
	* mips.cc (Mips_got_info::record_global_got_symbol): Don't add symbol
	to the dynamic symbol table if it is forced to local visibility.
	(Target_mips::do_finalize_sections): Don't add __RLD_MAP symbol to the
	dynamic symbol table if it is forced to local visibility.
2017-01-23 17:12:10 -08: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
H.J. Lu 857e829e3a Gold: Fix build with GCC 4.2
PR gold/21040
	* powerpc.cc (Powerpc_relobj<size, big_endian>::make_toc_relative):
	Cast 0x80008000 to uint64_t.
2017-01-13 07:47:52 -08:00
Cary Coutant aca5eec611 Fix incorrect byte counts.
gold/
	* object.cc (Sized_relobj_file): Fix byte counts for calls to memmem.
2017-01-12 11:51:40 -08:00
Cary Coutant 6624f3a142 Fix more compile errors with GCC 4.2.
gold/
	PR gold/21040
	* x86_64.cc (Output_data_plt_x86_64_bnd::do_fill_first_plt_entry):
	Remove unnecessary 'typename' keyword.
	(Output_data_plt_x86_64_bnd::do_fill_plt_entry): Likewise.
	(Output_data_plt_x86_64_bnd::fill_aplt_entry): Likewise.
	(Output_data_plt_x86_64_bnd::do_fill_tlsdesc_entry): Likewise.
	(Output_data_plt_x86_64_bnd::do_write): Likewise.
2017-01-11 13:42:24 -08:00
Cary Coutant 976e204b36 Fix compile errors with GCC 4.2.
gold/
	PR gold/21040
	* x86_64.cc (Output_data_plt_x86_64_bnd::do_fill_first_plt_entry):
	Remove unnecessary 'typename' keyword.
	(Output_data_plt_x86_64_bnd::do_fill_plt_entry): Likewise.
	(Output_data_plt_x86_64_bnd::do_fill_tlsdesc_entry): Likewise.
	(Output_data_plt_x86_64_bnd::fill_aplt_entry): Likewise.
	* testsuite/copy_test_relro_1.cc (p, b, c, q): Add separate extern
	declarations.
2017-01-11 11:47:27 -08:00
Cary Coutant 1fa5f68bf3 Fix test cases to work for i386.
gold/
	PR gold/21039
	* testsuite/script_test_13.sh: Adjust patterns to work for i386.
	* testsuite/script_test_15a.sh: Likewise.
	* testsuite/script_test_15b.sh: Likewise.
	* testsuite/script_test_15c.sh: Likewise.
2017-01-11 11:26:26 -08:00
Alan Modra 5edad15d7c [GOLD] PowerPC64 TOC indirect to TOC relative code editing
Doesn't yet trim off the unused TOC entries.

	* powerpc.cc (class Powerpc_copy_relocs): New.
	(Powerpc_copy_relocs::emit): New function.
	(Powerpc_relobj::relatoc_, toc_, no_toc_opt_): New variables.
	(Powerpc_relobj::toc_shndx, set_no_toc_opt, no_toc_opt): New inlines.
	(Powerpc_relobj::do_relocate_sections): New function.
	(Powerpc_relobj::make_toc_relative): Likewise.
	(Powerpc_relobj::do_find_special_sections): Stash away .rela.toc
	and .toc too.
	(ok_lo_toc_insn): Move earlier, and handle more insns.
	(Target_powerpc::Scan::local): If optimizing toc accesses, set
	no_toc_opt for entries we can't edit.  Check insn validity.
	Emit "toc optimization is not supported" warning, downgraded
	from error.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Edit TOC indirect code
	to TOC relative.  Don't emit "toc optimization is not supported"
	error here.
2017-01-11 07:41:53 +10:30
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 f7fd19e2b8 [GOLD] Fix tests for powerpc64
PowerPC64 defines .TOC. rather than _GLOBAL_OFFSET_TABLE_, and
what's more, doesn't define it at all unless referenced.  For ELFv1
ABI the symbol isn't normally referenced, so modify the test to accept
.TOC. as a variant of _GLOBAL_OFFSET_TABLE_ and 0 or 1 occurrences.

copy_test_relro as written doesn't need copy relocs on PowerPC64.
PowerPC64 is always PIC.  So, modify copy_test_relro to test that the
existing vars are in fact read-only directly by deliberately causing a
sigsegv, and add another couple of vars that do cause copy relocs even
when PIC.

	* testsuite/ver_test_8.sh: Accept .TOC. in lieu of
	_GLOBAL_OFFSET_TABLE_.  Allow zero count.
	* testsuite/copy_test_relro_1.cc (c, q): New vars.
	* testsuite/copy_test_relro.cc: Rewrite to test read-only
	status of variables directly.  Reference new vars in
	read-only data.
2017-01-10 11:50:07 +10: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 3254d32c4b [GOLD] Set sh_info of .rela.plt for powerpc
* powerpc.cc (Target_powerpc::make_plt_section): Point sh_info of
	".rela.plt" at ".plt".
2017-01-09 12:10:56 +10:30
Alan Modra 0e123f69da [GOLD] powerpc.cc tidies
Plus some paranoia in symval_for_branch.  We shouldn't get there with
dynamic symbols, but if we ever did the static_cast to Powerpc_relobj
would be wrong.

	* powerpc.cc: Use shorter equivalent elfcpp typedef for
	Reltype and reloc_size throughout.
	(Target_powerpc::symval_for_branch): Exclude dynamic symbols.
	(Target_powerpc::Scan::local): Use local var r_sym.
	(Target_powerpc::Scan::global: Likewise.
	(Target_powerpc::Relocate::relocate): Delete shadowing r_sym.
2017-01-07 22:04:51 +10:30
Alan Modra 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
Alan Modra 5c1ad6b5bb ChangeLog rotation 2017-01-02 13:55:05 +10:30
Andreas Schwab 913e12d44d Fix comment typo
* copy-relocs.h: Fix comment typo.
2016-12-28 18:31:07 +01:00
Cary Coutant 265d97f743 Add explicit instantiations for build_compressed_section_map().
gold/
	PR gold/20996
	* object.cc (build_compressed_section_map): Add explicit instantiations.
2016-12-28 08:29:57 -08:00
Cary Coutant 6142c999f2 Fix last ChangeLog entry.
* copy-relocs.cc (Copy_relocs::make_copy_reloc): Use .data.rel.ro for
	read-only data when linking with -z relro.
2016-12-28 08:29:56 -08:00
Cary Coutant b733bcb7f5 Place copy relocations in .dynbss when target is read-only.
gold/
	PR ld/20995
	* copy-relocs.cc (Copy_relocs::make_copy_reloc): Use .dynbss for
	read-only data when linking with -z relro.
	* copy-relocs.h (Copy_relocs::dynrelro_): New data member.
	* testsuite/Makefile.am (copy_test_relro): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/copy_test_relro.cc: New source file.
	* testsuite/copy_test_relro_1.cc: New source file.
2016-12-27 20:50:56 -08:00
Cary Coutant d81c735641 Bump gold version number to 1.14.
* NEWS: Add new features in 1.14.
	* version.cc (version_string): Bump to 1.14.
2016-12-23 08:00:13 -08:00
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 c4d5a76223 Fix placement of forced local symbols in the dynamic symbol table.
Gold was not placing forced-local symbols (e.g., hidden visibility)
at the front of the dynamic symbol table, or including them in the
count of local symbols recorded in the .dynsym section's sh_info field.

gold/
	* layout.cc (Layout::finalize): Track count of forced-local symbols
	in .dynsym.
	(Layout::create_symtab_sections): Add local_dynamic_count parameter;
	use that instead of sh_info value.
	(Layout::create_dynamic_symtab): Add pforced_local_dynamic_count
	parameter; pass it to Symtab::set_dynsym_indexes().  Include forced
	locals in sh_info value.  Pass index of first real global to
	Dynobj::create_gnu_hash_table() and Dynobj::create_elf_hash_table().
	* layout.h (Layout::create_symtab_sections): Add local_dynamic_count
	parameter.
	(Layout::create_dynamic_symtab): Add pforced_local_dynamic_count
	parameter.
	* symtab.cc (Symbol_table::set_dynsym_indexes): Add pforced_local_count
	parameter.  Process forced-local symbols first and return the count.
	(Symbol_table::finalize): Update comments.
	* symtab.h (Symbol_table::set_dynsym_indexes): Add pforced_local_count
	parameter.
	(Symbol_table::first_dynamic_global_index_): Update comment.
	(Symbol_table::dynamic_count_): Update comment.
	* testsuite/Makefile.am (ifuncmod1.sh): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ifuncmod1.sh: New shell script.
2016-12-22 16:00:06 -08:00
Cary Coutant 40d7d93ff4 Fix problem where version script causes predefined hidden symbol to be defined twice.
When creating a predefined hidden symbol like _GLOBAL_OFFSET_TABLE_, gold
was incorrectly letting a version script add a version to the symbol,
resulting in two copies of the symbol, both STB_LOCAL, but one of which
was grouped in the globals part of the symbol table.

gold/
	* symtab.cc (Symbol_table::define_special_symbol): Add is_forced_local
	parameter; if set, do not check version script.
	(Symbol_table::do_define_in_output_data): Pass is_forced_local for
	STB_LOCAL predefined symbols.
	(Symbol_table::do_define_in_output_segment): Likewise.
	(Symbol_table::do_define_in_output_segment): Likewise.
	(Symbol_table::do_define_as_constant): Likewise.
	* symtab.h (Symbol_table::define_special_symbol): Add is_forced_local
	parameter. Adjust all callers.
	* testsuite/Makefile.am (ver_test_8.sh): New test case.
	* testsuite/Makefile.in: Regenerate.
	* ver_test_8.sh: New test script.
2016-12-22 16:00:06 -08:00
Cary Coutant eb3908448b Make linker-created symbols relocatable where appropriate.
Linker-created symbols like __ehdr_start, __etext, __edata, and end
should be relocatable, not absolute.

gold/
	* output.cc (Output_segment::first_section): Return NULL if there are
	no sections in the segment.
	* output.h (Output_segment::first_section_load_address): Assert that
	first section is not NULL.
	* symtab.cc (Symbol_table::sized_write_globals): Attach linker-created
	segment-relative symbols to first section of the segment.
2016-12-21 16:21:23 -08:00
Alan Modra 4e25adb395 Remove high bit set characters
gas/
	* doc/c-lm32.texi: Fix chars with high bit set.
	* testsuite/gas/bfin/vector2.s: Likewise.
gold/
	* arm.cc: Fix comment chars with high bit set.
include/
	* coff/pe.h: Fix comment chars with high bit set.
	* opcode/xgate.h: Likewise.
ld/
	* testsuite/ld-scripts/sysroot-prefix.exp: Fix chars with high bit set.
2016-12-21 19:18:46 +10:30
Cary Coutant 78d9f182f5 Update testsuite Makefile with missing dependencies.
2016-12-20  Cary Coutant  <ccoutant@gmail.com>

gold/
	* testsuite/Makefile.am: Add missing dependencies on gcctestdir/ld
	or ../ld-new.
	* testsuite/Makefile.in: Regenerate.
2016-12-20 01:03:55 -08:00
Cary Coutant 092e01962d Fix read-beyond-end-of-buffer error in script parsing.
2016-12-19  Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/20949
	* script.cc (Lex::get_token): Don't look ahead past NUL characters.
2016-12-19 19:20:10 -08:00
Cary Coutant 412ffd830b Fix problem where linker does not place .note sections according to script.
gold/
	PR gold/14676
	PR gold/20983
	* layout.h (Layout::choose_output_section): Add match_input_spec
	parameter. Adjust all callers.
	* layout.cc (Layout::choose_output_section): Likewise.  Pass
	match_input_spec to Script_sections::output_section_name().
	(Layout::create_note): Pass true for match_input_spec.
	* script-sections.h (Script_sections::output_section_name): Add
	match_input_spec parameter.
	* script-sections.cc (Sections_element::output_section_name): Likewise.
	(Output_section_definition::output_section_name): Likewise.
	(Script_sections::output_section_name): Likewise.
2016-12-19 17:22:10 -08:00
Igor Kudrin ee7ef219cb Fix an internal error in the constructor of Target_arm.
gold/
	* arm.cc (Target_arm::Target_arm): Move initialization code ...
	(Target_arm::do_select_as_default_target): ... to here.
	* testsuite/Makefile.am (arm_target_lazy_init): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/arm_target_lazy_init.s: New source file.
	* testsuite/arm_target_lazy_init.t: New linker script.
2016-12-19 15:28:28 -08:00
Cary Coutant 89ede9f53b Fix forced allocation of common (-d) during -r links.
If the .bss section has other data in it besides common allocations,
gold was subtracting the wrong section start address from the symbol
value.

gold/
	PR gold/20976
	* symtab.cc (Symbol_table::sized_write_globals): Use address of
	output section, not input section.
	* testsuite/Makefile.am (pr20976): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/pr20976.c: New source file.
2016-12-19 10:37:34 -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
Cary Coutant 03fb64f837 Do not use linker script to place static relocation sections.
gold/
	PR gold/20522
	* layout.cc (Layout::choose_output_section): Add is_reloc parameter.
	Adjust all callers.  Do not use linker script for is_reloc sections.
	(Layout::layout_reloc): Pass is_reloc == true.
	* layout.h (Layout::choose_output_section): Add is_reloc parameter.
2016-12-13 13:01:26 -08:00
Cary Coutant bfbf34de2f When using linker scripts, place linker-generated sections by the output section name.
2016-12-12  Igor Kudrin  <ikudrin@accesssoftek.com>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/14676
	* script-sections.cc (Output_section_definition::output_section_name):
	For linker-generated sections, compare with output section name.
	* testsuite/Makefile.am (script_test_13): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/script_test_13.c: New source file.
	* testsuite/script_test_13.sh: New script.
	* testsuite/script_test_13.t: New linker script.
2016-12-12 18:52:44 -08:00
Cary Coutant d81222d386 Fix edge cases in orphan section placement.
There were still some cases I found where orphan section placement
was screwy -- where the script has no output section description for
either .data or .bss, a .bss orphan section ends up getting placed
before the .data section. In addition, if there is an output section
description for a data section not named .data (e.g., .rela.dyn),
the orphan .bss gets placed before it. This patch cleans that up,
by tracking the last allocated section even as we're adding orphans.

I've also improved segment layout in the absence of a PHDRS clause.
A zero-length NOBITS section will no longer force a new segment
when followed by a PROGBITS section.

2016-12-12  Cary Coutant  <ccoutant@gmail.com>

gold/
	* script-sections.cc (Orphan_section_placement::update_last_alloc):
	New method.
	(Orphan_section_placement::find_place): Place orphan .data section
	after either RODATA or TEXT.
	(Script_sections::place_orphan): Call update_last_alloc for allocated
	sections.
	(Script_sections::create_segments): Improve handling of BSS.
2016-12-12 17:52:53 -08:00
Alan Modra ea0ffd5be2 [GOLD] Allow for larger alignment in script_test_15
PowerPC64 aligns .got to a 256 byte boundary.  This tends to bump the
data segment file size.

	PR gold/16711
	* testsuite/script_test_15a.sh: Allows larger p_filesz.
	* testsuite/script_test_15b.sh: Likewise.
	* testsuite/script_test_15c.sh: Likewise.
2016-12-13 09:32:30 +10:30
Alan Modra d32a48b9f2 [GOLD] Adjust testcase for PowerPC64
Since the linker created .TOC. symbol is placed at roughly .got+32k,
.toc input sections must be placed in or after .got if .toc entries
are accessed using 16-bit signed offset relocs.  crt1.o contains such
a relocation.

	PR gold/20717
	* testsuite/pr20717.t: Add .got output section containing .toc.
2016-12-13 09:31:19 +10:30
Igor Kudrin cc90de4973 Fix earlier ChangeLog entry to give Igor credit, add testcases.
2016-12-01  Cary Coutant  <ccoutant@gmail.com>
	    Igor Kudrin  <ikudrin@accesssoftek.com>

	PR gold/20717
	* script-sections.cc (Script_sections): Set *keep to false when
	no match.

2016-12-11  Igor Kudrin  <ikudrin@accesssoftek.com>

	PR gold/20717
	* testsuite/Makefile.am (pr20717): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/pr20717.c: New test source file.
	* testsuite/pr20717.sh: New test script.
	* testsuite/pr20717.t: New test linker script.
2016-12-11 20:31:09 -08:00
Cary Coutant 5d9f66cb84 Fix problems with bss handling in linker scripts.
PR 16711 noted that gold allocates file space for BSS sections when using
a linker script. I've fixed that by rewriting set_section_addresses and
set_section_list_addresses to track the file offset separate from the
current virtual address, so that BSS sections do not move the file offset.
Now, if a series of BSS sections come at the end of a segment, we do not
allocate file space; but if a script forces them into the middle of a
segment, we will still allocate file space (matching Gnu ld behavior).
I've also added a warning when that happens.

That exposed another problem where orphan .bss sections were sometimes
placed in the middle of a segment. For example, if the script mentions
the .got section, but both .data and .bss are orphans, gold would put
both .data and .bss in front of .got. I've fixed that by ensuring that
orphan BSS sections are always placed after all other allocated sections.

It also exposed a problem where the SUBALIGN property is not handled
properly. The ld manual clearly states that it should override input section
alignment, whether greater or less than the given alignment, but gold would
only increase an input section's alignment. Gold would also place the output
section based on its original alignment before the SUBALIGN property took
effect, leading to a misaligned output section (where the input section
was properly aligned in memory, but was not aligned relative to the start
of the section), in violation of the ELF/gABI spec. I've fixed that by
making sure that the SUBALIGN property overrides the internal alignment of
the input sections as well as the external alignment of the output section.
This affected the behavior of script_test_2, which was written to expect
a misaligned section.

The net effect is, I think, improved compatibility with the BFD linker.
There are still cases where orphan placement differs, but the differences
should be rarer and less important. ALIGN and SUBALIGN behavior is closer,
but still not an exact match -- I still found cases where ld would create
a misaligned output section, and where gold will properly align it.

gold/
	PR gold/16711
	* output.cc (Output_section::set_final_data_size): Calculate data size
	based on relative offset rather than file offset.
	(Output_segment::set_section_addresses): Track file offset separately
	from address offset.
	(Output_segment::set_section_list_addresses): Add pfoff parameter.
	Track file offset separately.  Don't move file offset for BSS
	sections.
	* output.h (Output_segment::set_section_list_addresses): Add pfoff
	parameter.
	* script-sections.cc (Orphan_section_placement): Add PLACE_LAST_ALLOC.
	(Orphan_section_placement::Orphan_section_placement): Initialize it.
	(Orphan_section_placement::output_section_init): Track last allocated
	section.
	(Orphan_section_placement::find_place): Place BSS after last allocated
	section.
	(Output_section_element_input::set_section_addresses): Always override
	input section alignment when SUBALIGN is specified.
	(Output_section_definition::set_section_addresses): Override alignment
	of output section when SUBALIGN is specified.

	* testsuite/Makefile.am (script_test_15a, script_test_15b)
	(script_test_15c): New test cases.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/script_test_2.cc: Adjust expected layout.
	* testsuite/script_test_15.c: New source file.
	* testsuite/script_test_15a.sh: New shell script.
	* testsuite/script_test_15a.t: New linker script.
	* testsuite/script_test_15b.sh: New shell script.
	* testsuite/script_test_15b.t: New linker script.
	* testsuite/script_test_15c.sh: New shell script.
	* testsuite/script_test_15c.t: New linker script.
2016-12-11 17:31:25 -08:00
Cary Coutant e83563a9ed Regenerate Makefile.in to get rid of annoying diffs caused by non-deterministic automake.
* Makefile.in: Regenerate.
2016-12-11 16:40:11 -08:00
Alan Modra 980d0cdd2f [GOLD] Don't assert in powerpc stub_table
A branch in a non-exec section that needs a stub can lead to this
assertion.

	* powerpc.cc (Powerpc_relobj::stub_table): Return NULL rather
	then asserting.
2016-12-08 22:18:47 +10:30
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
Alan Modra dc60b26d98 [GOLD] PowerPC stub debug
Some more debug output, and a little hardening.

	* powerpc.cc (Stub_table_owner): Provide constructor.
	(Powerpc_relobj::set_stub_table): Resize fill with -1.
	(Target_powerpc::Branch_info::make_stub): Provide target debug
	output on returning false.
2016-12-07 14:11:57 +10:30
Cary Coutant 82d93790a8 Fix problem where absolute local symbols are omitted when output has many sections.
2016-12-05  Cary Coutant  <ccoutant@gmail.com>
            Tristan Gingold  <gingold@adacore.com>

gold/
	* object.cc (Sized_relobj_file::do_count_local_symbols): Check
	is_ordinary before using shndx.
	* testsuite/Makefile.am (file_in_many_sections_test.sh): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/file_in_many_sections.c: New source file.
	* testsuite/file_in_many_sections_test.sh: New script.
2016-12-05 10:41:09 -08:00
Cary Coutant 397b8d2a9f Fix problem where orphan section is treated as a KEEP section.
gold/
	PR gold/20717
	* script-sections.cc (Script_sections): Set *keep to false when
	no match.
2016-12-01 19:54:05 -08:00
Cary Coutant be2884c1ea Fix problem causing internal error when -z max-page-size is used.
If the default starting address is less than the new ABI page size,
we end up misaligning the file header, causing an internal error.

gold/
	PR gold/20834
	* target.h (Target::default_text_segment_address): Bump default
	start address up to ABI page size.
2016-12-01 19:00:30 -08:00
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 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 6223ef9497 Fix spelling in comments in .def files (gold)
* aarch64-reloc.def: Fix spelling in comments.
2016-11-27 15:09:18 +10:30
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
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
Ambrogino Modigliani 96fe45624e Fix spelling mistakes in comments in configure scripts
All changes are limited to comments, and no run-time behavior is
affected.

bfd/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * warning.m4: Fix spelling in comments.
        * configure.ac: Fix spelling in comments.
        * configure: Regenerate.

binutils/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.

gdb/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure.ac: Fix spelling in comments.
        * configure: Regenerate.

gas/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.

gold/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.

gprof/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.

ld/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.

opcodes/ChangeLog:
2016-11-22  Ambrogino Modigliani  <ambrogino.modigliani@gmail.com>

        * configure: Regenerate.
2016-11-22 15:43:03 +00:00
Cary Coutant c13b08dbbc Fix bug where -u option with empty archive results in internal error.
gold/
	PR gold/20693
	* gold.cc (queue_middle_tasks): Force valid target earlier.
2016-11-21 14:06:15 -08:00
Igor Kudrin b32e1756d9 Add --build-id=uuid support for MinGW32.
2016-11-21  Igor Kudrin  <ikudrin@accesssoftek.com>

gold/
	* layout.cc: Include windows.h and rpcdce.h (for MinGW32).
	(Layout::create_build_id): Generate uuid using UuidCreate().
2016-11-21 09:59:37 -08:00
Loïc Yhuel 7a34932bce Add missing '$' in configure.ac.
2016-11-04  Loïc Yhuel <loic.yhuel@softathome.com>

gold/
        * configure.ac: add missing '$'.
        * configure: Regenerate.
2016-11-07 08:00:21 -08:00
Gergely Nagy ac423761af Fix PR 17704.
This fix keeps the section with the highest alignment when folding sections with ICF.

	PR gold/17704
	* icf.cc (match_sections): Add new parameter section_addraligns.
	Check section alignment and keep the section with the strictest
	alignment.
	(find_identical_sections): New local variable section_addraligns.
	Store each section's alignment.
	* testsuite/pr17704a_test.s: New file.
	* testsuite/Makefile.am (pr17704a_test): New test.
	* testsuite/Makefile.in: Regenerate.
2016-10-21 11:10:46 -07:00
Alan Modra c25aa1e114 [GOLD] two more fall-through comments
* powerpc.cc (Target_powerpc::Relocate::relocate): Add fall
	through comment.
	* tilegx.cc (Target_tilegx::Relocate::relocate): Likewise.
2016-10-06 22:48:14 +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
Cary Coutant e3f07b5b75 Don't treat as separate symbols if unversioned symbol is undefined.
When we see an unversioned symbol reference in a shared library, followed
by a default definition of the symbol in another shared library, we were
treating them as separate symbols. That should only happen when both are
definitions.

gold/
	PR gold/20238
	* symtab.cc (Symbol_table::define_default_version): Check that
	unversioned symbol is defined.
2016-09-27 12:08:28 -07:00
Vlad Zakharov c5da193232 When building target binaries, ensure that the warning flags selected for the command line match the target compiler.
bfd	* warning.m4 (AC_EGREP_CPP_FOR_BUILD): Introduce macro
	to verify CC_FOR_BUILD compiler.
	(AM_BINUTILS_WARNINGS): Introduce ac_cpp_for_build variable
	and add CC_FOR_BUILD compiler checks.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

binutils	* Makefile.am: Replace AM_CLFAGS with AM_CFLAGS_FOR_BUILD
	when building with CC_FOR_BUILD compiler.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

gas	* Makefile.in: Regenerate.
	* configure: Likewise.
	* doc/Makefile.in: Likewise.

gold	* Makefile.in: Regenerate.
	* configure: Likewise.
	* testsuite/Makefile.in: Likewise.

gprof	* Makefile.in: Regenerate.
	* configure: Likewise.

ld	* Makefile.in: Regenerate.
	* configure: Likewise.

opcodes	* Makefile.in: Regenerate.
	* configure: Likewise.
2016-09-26 16:36:08 +01:00
Alan Modra 153679d55f [GOLD] regen testsuite/Makefile.in 2016-09-26 18:04:35 +09: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
Doug Kwan bc99685c73 Handle ARM-specific --target1-abs, --target1-rel and --target2 options 2016-09-02 15:51:59 -07:00
Alan Modra 8a37735f20 [GOLD] Further tidy to powerpc can_add_to_stub_group
This patch adds a little more debug output, and replaces two variables
with one, tracking current max group size by group_size_ rather than
by has14_.

	* powerpc.cc (class Stub_control): Delete stub14_group_size_
	and has14_.  Add group_size_.
	(Stub_control::can_add_to_stub_group): Adjust to suit.  Print
	debug info when switching to adding sections before stubs.
2016-08-31 19:22:43 +09:30
Alan Modra afe002dd66 [GOLD] Add debug output for powerpc section grouping
* debug.h (DEBUG_TARGET): New.
	(DEBUG_ALL): Add DEBUG_TARGET.
	(gold_debug): Delete FORMAT param.
	* powerpc.cc (Stub_control::can_add_to_stub_group): Print debug ourput.
2016-08-31 12:34:36 +09:30
Alan Modra 57f6d32dea [GOLD] correct grouping of stubs
This patch rewrites the rather obscure can_add_to_stub_group, fixing
a problem with the handling of sections containing conditional
external branches.  When a section group contains any such section,
the group size needs to be limited to a much smaller size than groups
with only non-conditional external branches.

	PR 20523
	* powerpc.cc (class Stub_control): Add has14_.  Comment owner_.
	(Stub_control::can_add_to_stub_group): Correct grouping of
	sections containing 14-bit external branches.  When returning
	false, set state_ to reflect the fact that we have one section
	for the next group.  Rewrite most of function for clarity.
	Add and expand comments.
	(Target_powerpc::do_relax): Print stub group size retry in hex.
2016-08-30 12:20:27 +09:30
Han Shen 6395d38b7f PR gold/20529 - relaxing loop never ends.
gold/ChangeLog

2016-08-26  Han Shen  <shenhan@google.com>

	* powerpc.cc (Stub_table::min_size_threshold_): New member to
	limit size.
	(Stub_table::set_min_size_threshold): New member function.
	(Stub_table::set_address_and_size): Add code to only allow size
	increase.
	(Target_powerpc::do_relax): Add code to record last size.
2016-08-28 14:17:31 -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
Cary Coutant a4aa1f5f01 Fix extraneous complaints about missing expected TLS relocation (i386).
Build the test objects with the in-tree assembler. Also fix some cascading
error messages caused by not resetting the skip_call_tls_get_addr_ flag
after printing the error.

gold/
	* i386.cc (Target_i386): Reset skip_call_tls_get_addr_ after printing
	error message.
	* testsuite/Makefile.am (pr20216a): Add missing dependencies.
	(pr20308a): Add -Bgcctestdir/ to compile rules.
	* testsuite/Makefile.in: Regenerate.
2016-08-17 10:53:31 -07:00
Roland McGrath 3785f51aa2 PR gold/20462: Fix bogus layout on ARM with linker script using PHDRS clause
gold/
	PR gold/20462
	* script-sections.cc (Script_sections::release_segments):
	Reset this->segments_created_.
2016-08-12 09:55:25 -07:00
Roland McGrath f300578f78 [gold] Implement HIDDEN syntax in linker scripts
gold/
	* yyscript.y (HIDDEN): New %token.
	(assignment): Handle HIDDEN(string = expr) syntax.
	* script.cc (script_keyword_parsecodes): Add HIDDEN.
2016-08-12 09:50:49 -07:00
Cary Coutant f571390111 Fix extraneous complaints about missing expected TLS relocation.
With some versions of gas, the call to tls_get_addr uses a GOTPCREL
relocation instead of a GOTPCRELX relocation. We should allow for that
when skip_call_tls_get_addr_ is true. We should also build the test
objects with the in-tree assembler.

This patch also fixes some cascading error messages caused by not
resetting the skip_call_tls_get_addr_ flag after printing the error.

gold/
	PR gold/20216
	* x86_64.cc (Target_x86_64::Relocate::relocate): Add check for
	R_X86_64_GOTPCREL. Reset skip_call_tls_get_addr_ after printing
	error message.
	* testsuite/Makefile.am (pr20216_gd.o): Add -Bgcctestdir/.
	(pr20216_ld.o): Likewise.
	* testsuite/Makefile.in: Regenerate.
2016-08-10 10:57:42 -07:00
James Clarke 2c00092dce Fix potential crashes when Target::make_symbol() returns NULL.
2016-08-10  James Clarke  <jrtc27@jrtc27.com>

gold/
	PR gold/20443
	* symtab.cc (Symbol_table::add_from_relobj): Handle NULL symbols,
	which will be present for STT_SPARC_REGISTER.
	(Symbol_table::add_from_pluginobj): Likewise.
	(Symbol_table::add_from_dynobj): Likewise.
	(Symbol_table::add_from_incrobj): Removed dead code.
2016-08-10 09:58:01 -07:00
James Clarke 007801eeb1 Fix improper handling of R_SPARC_GOTDATA_OP_LOX10 relocation.
The fall-through in Target_sparc::Relocate::relocate for
R_SPARC_GOTDATA_OP_LOX10 is currently R_SPARC_GOT13, but should
clearly be R_SPARC_GOT10. GCC has been seen to emit a sethi/xor
rather than a sethi/or sequence to load a 32-bit immediate, but
if R_SPARC_GOT13 is used then bits 10-12 get zeroed out as both
the sethi and xor immediates contain them.

gold/
	PR gold/20442
	* sparc.cc (Target_sparc::Relocate::relocate): R_SPARC_GOTDATA_OP_LOX10
	should fall back on R_SPARC_GOT10, not R_SPARC_GOT13.
2016-08-10 09:48:26 -07:00
James Clarke 55872e496e Add support for R_SPARC_32 relocation.
gold/
	PR gold/20441
	* sparc.cc (Target_sparc::Scan::check_non_pic): Allow R_SPARC_32 on
	sparc64.
2016-08-10 09:42:39 -07:00
Cary Coutant 6e25650792 Fix gold testsuite failure with GCC 6.
With GCC 6 when not using -static-libstdc++, the operator delete(void*)
function is defined in the shared C++ support library, rather than in
the main program. The test script is too aggressive in checking for
this symbol's presence among the exported symbols. This patch removes
the check for that symbol.

gold/
	PR gold/20310
	* testsuite/dynamic_list.sh: Remove check for _ZdlPv.
2016-06-29 23:24:35 -07:00
Cary Coutant 8db8e6948a Update "make clean" in gold/testsuite.
gold/
	* testsuite/Makefile.am (MOSTLYCLEANFILES): Add eh_test_2.
	* testsuite/Makefile.in: Regenerate.
2016-06-29 23:16:24 -07:00
Alan Modra 068e05badb [GOLD] Pass -Wl,-z to gcc, not plain -z
* testsuite/Makefile.am (memory_test, memory_test_2): Pass
	-Wl,-z to gcc, not plain -z.
	* testsuite/Makefile.in: Regenerate.
2016-06-30 12:40:36 +09:30
H.J. Lu b287eca391 gold: Support 386 TLS code sequences without PLT
There are extensions to 386 psABI:

https://groups.google.com/forum/#!topic/ia32-abi/awsRSvJOJfs

to call tls_get_addr via GOT:

call *___tls_get_addr@GOT(%reg)

where EBX register isn't required as GOT base.

Since direct call is 4-byte long and indirect call, is 5-byte long, the
extra one byte must be handled properly.

For general dynamic model, 7-byte lea instruction before call
instruction is replaced by 6-byte one to make room for indirect call.
For local dynamic model, we simply use 5-byte indirect call.

TLS linker optimization is updated to recognize new instruction
patterns.  For local dynamic model to local exec model transition,
we generate a 6-byte lea instruction as nop, instead of a 1-byte nop
plus a 4-byte lea instruction.

	PR gold/20308
	* i386.cc (Target_i386::Relocate::relocate): Allow
	R_386_GOT32X relocation against ___tls_get_addr.
	(Target_i386::Relocate::tls_gd_to_ie): Support indirect
	call to __tls_get_addr.
	(Target_i386::Relocate::tls_gd_to_le): Likewise.
	(Target_i386::Relocate::tls_ld_to_le): Likewise.
	* testsuite/Makefile.am (check_PROGRAMS): Add pr20308a_test,
	pr20308b_test, pr20308c_test, pr20308d_test, pr20308e_test.
	(pr20308a_test_SOURCES): New.
	(pr20308a_test_DEPENDENCIES): Likewise.
	(pr20308a_test_CFLAGS): Likewise.
	(pr20308a_test_LDFLAGS): Likewise.
	(pr20308a_test_LDADD): Likewise.
	(pr20308b_test_SOURCES): Likewise.
	(pr20308b_test_DEPENDENCIES): Likewise.
	(pr20308b_test_CFLAGS): Likewise.
	(pr20308b_test_LDFLAGS): Likewise.
	(pr20308b_test_LDADD): Likewise.
	(pr20308c_test_SOURCES): Likewise.
	(pr20308c_test_DEPENDENCIES): Likewise.
	(pr20308c_test_CFLAGS): Likewise.
	(pr20308c_test_LDFLAGS): Likewise.
	(pr20308c_test_LDADD): Likewise.
	(pr20308d_test_SOURCES): Likewise.
	(pr20308d_test_DEPENDENCIES): Likewise.
	(pr20308d_test_CFLAGS): Likewise.
	(pr20308d_test_LDFLAGS): Likewise.
	(pr20308d_test_LDADD): Likewise.
	(pr20308e_test_SOURCES): Likewise.
	(pr20308e_test_DEPENDENCIES): Likewise.
	(pr20308e_test_CFLAGS): Likewise.
	(pr20308e_test_LDFLAGS): Likewise.
	(pr20308e_test_LDADD): Likewise.
	(pr20308a.so): Likewise.
	(pr20308b.so): Likewise.
	(pr20308_gd.o): Likewise.
	(pr20308_ld.o): Likewise.
	(MOSTLYCLEANFILES): Add pr20308a.so pr20308b.so.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/pr20308_def.c: New file.
	* testsuite/pr20308_gd.S: Likewise.
	* testsuite/pr20308_ld.S: Likewise.
	* testsuite/pr20308_main.c: Likewise.
2016-06-29 08:38:58 -07:00
H.J. Lu ad961eab9a gold: Support x86-64 TLS code sequences without PLT
There are extensions to x86-64 psABI:

https://groups.google.com/forum/#!topic/x86-64-abi/de5_KnLHxtI

to call tls_get_addr via GOT:

call *__tls_get_addr@GOTPCREL(%rip)

Since direct call is 4-byte long and indirect call, is 5-byte long, the
extra one byte must be handled properly.

For general dynamic model, one 0x66 prefix before call instruction is
removed to make room for indirect call.  For local dynamic model, we
simply use 5-byte indirect call.

TLS linker optimization is updated to recognize new instruction
patterns.  For local dynamic model to local exec model transition, we
generate 4 0x66 prefixes, instead of 3, before mov instruction in 64-bit
and generate a 5-byte nop, instead of 4-byte, before mov instruction in
32-bit.

	PR gold/20216
	* configure.ac (DEFAULT_TARGET_X86_64_OR_X32): New
	AM_CONDITIONAL.
	* configure: Regenerated.
	* x86_64.cc (Target_x86_64<size>::Relocate::relocate): Allow
	R_X86_64_GOTPCRELX relocation against __tls_get_addr.
	(Target_x86_64<size>::Relocate::tls_gd_to_ie): Support indirect
	call to __tls_get_addr.
	(Target_x86_64<size>::Relocate::tls_gd_to_le): Likewise.
	(Target_x86_64<size>::Relocate::tls_ld_to_le): Likewise.
	* testsuite/Makefile.am (check_PROGRAMS): Add pr20216a_test,
	pr20216b_test, pr20216c_test, pr20216d_test, pr20216e_test.
	(pr20216a_test_SOURCES): New.
	(pr20216a_test_DEPENDENCIES): Likewise.
	(pr20216a_test_CFLAGS): Likewise.
	(pr20216a_test_LDFLAGS): Likewise.
	(pr20216a_test_LDADD): Likewise.
	(pr20216b_test_SOURCES): Likewise.
	(pr20216b_test_DEPENDENCIES): Likewise.
	(pr20216b_test_CFLAGS): Likewise.
	(pr20216b_test_LDFLAGS): Likewise.
	(pr20216b_test_LDADD): Likewise.
	(pr20216c_test_SOURCES): Likewise.
	(pr20216c_test_DEPENDENCIES): Likewise.
	(pr20216c_test_CFLAGS): Likewise.
	(pr20216c_test_LDFLAGS): Likewise.
	(pr20216c_test_LDADD): Likewise.
	(pr20216d_test_SOURCES): Likewise.
	(pr20216d_test_DEPENDENCIES): Likewise.
	(pr20216d_test_CFLAGS): Likewise.
	(pr20216d_test_LDFLAGS): Likewise.
	(pr20216d_test_LDADD): Likewise.
	(pr20216e_test_SOURCES): Likewise.
	(pr20216e_test_DEPENDENCIES): Likewise.
	(pr20216e_test_CFLAGS): Likewise.
	(pr20216e_test_LDFLAGS): Likewise.
	(pr20216e_test_LDADD): Likewise.
	(pr20216a.so): Likewise.
	(pr20216b.so): Likewise.
	(pr20216_gd.o): Likewise.
	(pr20216_ld.o): Likewise.
	(MOSTLYCLEANFILES): Add pr20216a.so pr20216b.so.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/pr20216_def.c: New file.
	* testsuite/pr20216_gd.S: Likewise.
	* testsuite/pr20216_ld.S: Likewise.
	* testsuite/pr20216_main.c: Likewise.
2016-06-29 08:37:42 -07:00
Alan Modra bebf013204 [GOLD] Modify script_test_12
Changes necessary to make this test pass on powerpc64.

	* script_test_12.t: Delete .plt, specify 64k page size.
	* script_test_12i.t: Likewise.
2016-06-29 08:37:00 +09:30
Alan Modra 1275dd7247 [GOLD] alignment test
PowerPC gcc aligns char arrays to a word which results in the test
failing since it expects a char alignment.  As the test already uses
gcc attributes to assign variables to sections, we may as well use an
attribute to align too.

	* testsuite/plugin_layout_with_alignment.c: Explicitly align all
	variables.
2016-06-29 08:37:00 +09:30
Alan Modra 38ac44ac99 [GOLD] Disable copy_test_protected on powerpc
A target like powerpc64 that is PIC by default doesn't need copy relocs.

	* testsuite/Makefile.am (copy_test_protected): Disable for powerpc.
	* testsuite/Makefile.in: Regenerate.
2016-06-29 08:36:53 +09:30
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
Sriraman Tallam 3a4f096e5f Convert indirect calls to direct when possible.
Please see patch discussion:
https://www.sourceware.org/ml/binutils/2016-05/msg00322.html

2016-06-28  Sriraman Tallam  <tmsriram@google.com>

	* x86_64.cc (Lazy_view): New class.
	(can_convert_mov_to_lea): Templatize function.  Make the function
	check for appropriate relocation types and use the view parameter
	to get section contents.
	(can_convert_callq_to_direct): New function.
	(Target_x86_64<size>::Scan::global): Refactor.
	(Target_x86_64<size>::Relocate::relocate): Refactor. Change any indirect
	call via GOT that can be converted.
	* testsuite/Makefile.am (x86_64_indirect_call_to_direct.sh): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/x86_64_indirect_call_to_direct1.s: New file.
	* testsuite/x86_64_indirect_jump_to_direct1.s: New file.
2016-06-28 15:42:33 -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
Igor Kudrin f224a3c590 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 13:56:05 -07:00
James Clarke 7160c10d65 Don't convert R_SPARC_32 to R_SPARC_RELATIVE if class is ELFCLASS64.
bfd	* elfxx-sparc.c (_bfd_sparc_elf_relocate_section): Don't convert
	R_SPARC_32 to R_SPARC_RELATIVE if class is ELFCLASS64.

gold	* sparc.cc (Target_sparc::Scan::local): Don't convert R_SPARC_32
	to R_SPARC_RELATIVE if class is ELFCLASS64.
	(Target_sparc::Scan::global): Likewise.

ld	* testsuite/ld-elf/symbolic-func.r: Allow non-zero offsets from
	.text.
2016-06-28 12:00:56 +01:00
Cary Coutant 3ca25b560a Fix bug with grouping sections.
The fix for PR 15370 did not correctly check all patterns in a group,
but instead threw all unassigned sections into the group. This patch
fixes that.

2016-06-23  Cary Coutant  <ccoutant@gmail.com>
	    Igor Kudrin  <ikudrin@accesssoftek.com>

gold/
	PR gold/15370
	* script-sections.cc
	(Output_section_element_input::set_section_addresses): Keep bin_count
	separate from input_pattern_count.
	* testsuite/script_test_12.t: Add another section .x4.
	* testsuite/script_test_12i.t: Likewise.
	* testsuite/script_test_12a.c: Likewise.
	* testsuite/script_test_12b.c: Likewise.
2016-06-23 09:45:25 -07:00
Igor Kudrin 2ec060b71c Fix compilation error in MSYS2 environment.
gold/
	* gold-threads.cc (impl_threads::Lock_impl_threads): Fix typos.
2016-06-23 08:50:18 -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
Cary Coutant f70be8a445 Update gold to version 1.12.
gold/
	* NEWS: Add new features in 1.12.
	* version.cc (version_string): Bump to 1.12.
2016-06-20 20:13:08 -07:00
H.J. Lu 8474a88fd2 gold/x86: Handle output without PLT
If there is no PLT in output, return 0 for first_plt_entry_offset and
plt_entry_size.

	PR gold/20245
	* i386.cc (Target_i386::first_plt_entry_offset): Return 0 if
	plt_ is NULL.
	(Target_i386::plt_entry_size): Likewise.
	(Target_x86_64<size>::first_plt_entry_offset): Likewise.
	(Target_x86_64<size>::plt_entry_size): Likewise.
2016-06-20 12:28:32 -07:00
Vladimir Radosavljevic a8ecc9fe61 Add support for MIPS .rld_map section.
Includes DT_MIPS_RLD_MAP and DT_MIPS_RLD_MAP_REL dynamic tags and
__RLD_MAP symbol.

2016-06-20  Vladimir Radosavljevic  <Vladimir.Radosavljevic@imgtec.com>

elfcpp/
        * elfcpp.h (DT_MIPS_RLD_MAP_REL): New enum constant.
gold/
        * mips.cc (Target_mips::Target_mips): Initialize rld_map_.
        (Target_mips::rld_map_): New data member.
        (Target_mips::do_finalize_sections): Add support for
        DT_MIPS_RLD_MAP and DT_MIPS_RLD_MAP_REL dynamic tags,
        .rld_map section, and __RLD_MAP symbol.
        (Target_mips::do_dynamic_tag_custom_value): Add support for
        DT_MIPS_RLD_MAP_REL dynamic tag.
        * output.cc (Output_data_dynamic::get_entry_offset): New method
        definition.
        * output.h (Output_data_dynamic::get_entry_offset): New method
        declaration.
2016-06-20 12:16:26 -07:00
Vladimir Radosavljevic beceef5043 Add unaligned check for R_MIPS_PC16.
gold/
        * mips.cc (Mips_relocate_functions::relpc16): Add unaligned check.
2016-06-20 12:06:56 -07:00
Vladimir Radosavljevic f5b117594f Add support for Mips32r6 and Mips64r6.
elfcpp/
	* mips.h (R_MIPS_PC21_S2, R_MIPS_PC26_S2, R_MIPS_PC18_S3,
	R_MIPS_PC19_S2, R_MIPS_PCHI16, R_MIPS_PCLO16): New enums for
	Mips32r6 and Mips64r6 relocations.
	(r6_isa): New function.
gold/
	* mips.cc (relocation_needs_la25_stub): Add support for relocs:
	R_MIPS_PC21_S2 and R_MIPS_PC26_S2.
	(hi16_reloc): Add support for R_MIPS_PCHI16 relocation.
	(is_matching_lo16_reloc): Likewise.
	(lo16_reloc): Add support for R_MIPS_PCLO16 relocation.
	(Mips_output_data_plt::plt_entry_r6): New static data member for
	R6 PLT entry.
	(Target_mips::is_output_r6): New method.
	(Target_mips::Mips_mach): Add new enum constants.
	(Mips_relocate_functions::Status): Likewise.
	(Mips_relocate_functions::pchi16_relocs): New static data member.
	(Mips_relocate_functions::relpc21): New method.
	(Mips_relocate_functions::relpc26): Likewise.
	(Mips_relocate_functions::relpc18): Likewise.
	(Mips_relocate_functions::relpc19): Likewise.
	(Mips_relocate_functions::relpchi16): Likewise.
	(Mips_relocate_functions::do_relpchi16): Likewise.
	(Mips_relocate_functions::relpclo16): Likewise.
	(Mips_output_data_plt::do_write): Add support for Mips r6 plt
	entry.
	(Target_mips::mips_32bit_flags): Add E_MIPS_ARCH_32R6 support.
	(Target_mips::elf_mips_mach): Add E_MIPS_ARCH_32R6 and
	E_MIPS_ARCH_64R6 support.
	(Target_mips::update_abiflags_isa): Likewise.
	(mips_get_size_for_reloc): Add support for relocs: R_MIPS_PCHI16,
	R_MIPS_PCLO16, R_MIPS_PC21_S2, R_MIPS_PC26_S2, R_MIPS_PC18_S3 and
	R_MIPS_PC19_S2.
	(Target_mips::Scan::local): Add support for relocs: R_MIPS_PCHI16
	and R_MIPS_PCLO16.
	(Target_mips::Scan::global): Add support for relocs:
	R_MIPS_PC21_S2 and R_MIPS_PC26_S2.
	(Target_mips::Relocate::relocate): Call functions for resolving
	Mips32r6 and Mips64r6 relocations, and print error message for
	STATUS_PCREL_UNALIGNED.
	(Target_mips::Scan::get_reference_flags): Add support for relocs:
	R_MIPS_PCHI16, R_MIPS_PCLO16, R_MIPS_PC21_S2, R_MIPS_PC26_S2,
	R_MIPS_PC18_S3 and R_MIPS_PC19_S2.
	(Target_mips::elf_mips_mach_name): Add E_MIPS_ARCH_32R6 and
	E_MIPS_ARCH_64R6 support.
2016-06-20 11:45:18 -07:00
H.J. Lu 3328c04b10 Add .got.plt to testsuite/script_test_2.t
The .got.plt section must be placed right after the .got section.
Otherwise, GOT offset will be wrong.

	PR gold/20246
	* testsuite/script_test_2.t: Add .got.plt after .got.
2016-06-13 11:15:12 -07:00
Vladimir Radosavljevic b52717c0e1 Add support for .MIPS.abiflags and .gnu.attributes sections.
elfcpp/
	* elfcpp.h (SHT_MIPS_ABIFLAGS): New enum constant.
	* mips.h (EF_MIPS_FP64, EF_MIPS_NAN2008): New enum constants for
	processor-specific flags.
	(E_MIPS_MACH_5900): New enum constant for machine variant.
	(AFL_REG_NONE, AFL_REG_32, AFL_REG_64, AFL_REG_128): New enum
	constants.
	(AFL_ASE_DSP, AFL_ASE_DSPR2, AFL_ASE_EVA, AFL_ASE_MCU,
	AFL_ASE_MDMX, AFL_ASE_MIPS3D, AFL_ASE_MT, AFL_ASE_SMARTMIPS,
	AFL_ASE_VIRT, AFL_ASE_MSA, AFL_ASE_MIPS16, AFL_ASE_MICROMIPS,
	AFL_ASE_XPA): Likewise.
	(AFL_EXT_XLR, AFL_EXT_OCTEON2, AFL_EXT_OCTEONP,
	AFL_EXT_LOONGSON_3A, AFL_EXT_OCTEON, AFL_EXT_5900, AFL_EXT_4650,
	AFL_EXT_4010, AFL_EXT_4100, AFL_EXT_3900, AFL_EXT_10000,
	AFL_EXT_SB1, AFL_EXT_4111, AFL_EXT_4120, AFL_EXT_5400,
	AFL_EXT_5500, AFL_EXT_LOONGSON_2E, AFL_EXT_LOONGSON_2F,
	AFL_EXT_OCTEON3): Likewise.
	(Tag_GNU_MIPS_ABI_FP, Tag_GNU_MIPS_ABI_MSA): Likewise.
	(Val_GNU_MIPS_ABI_FP_ANY, Val_GNU_MIPS_ABI_FP_DOUBLE,
	Val_GNU_MIPS_ABI_FP_SINGLE, Val_GNU_MIPS_ABI_FP_SOFT,
	Val_GNU_MIPS_ABI_FP_OLD_64,Val_GNU_MIPS_ABI_FP_XX,
	Val_GNU_MIPS_ABI_FP_64, Val_GNU_MIPS_ABI_FP_64A,
	Val_GNU_MIPS_ABI_FP_NAN2008, Val_GNU_MIPS_ABI_MSA_ANY,
	Val_GNU_MIPS_ABI_MSA_128): Likewise.
	(AFL_FLAGS1_ODDSPREG): New enum constant.
gold/
	* mips.cc (struct Mips_abiflags): New struct.
	(Mips_relobj::Mips_relobj): Initialize attributes_section_data_
	and abiflags_.
	(Mips_relobj::~Mips_relobj): Delete object pointed by
	attributes_section_data_.
	(Mips_relobj::abiflags): New method.
	(Mips_relobj::attributes_section_data): Likewise.
	(Mips_relobj::attributes_section_data_): New data member.
	(Mips_relobj::abiflags_): Likewise.
	(class Mips_output_section_abiflags): New class.
	(Target_mips::Target_mips): Initialize attributes_section_data_,
	abiflags_ and has_abiflags_section_.
	(Target_mips::do_should_include_section): Don't emit input
	.MIPS.abiflags sections to output .MIPS.abiflags.
	(Target_mips::Mips_mach): Add new enum constants.
	(Target_mips::mips_isa_ext_mach): New method.
	(Target_mips::mips_isa_ext): Likewise.
	(Target_mips::update_abiflags_isa): Likewise.
	(Target_mips::infer_abiflags): Likewise.
	(Target_mips::create_abiflags): Likewise.
	(Target_mips::fp_abi_string): Likewise.
	(Target_mips::select_fp_abi): Likewise.
	(Target_mips::merge_obj_attributes): Likewise.
	(Target_mips::merge_obj_abiflags): Likewise.
	(Target_mips::level_rev): Likewise.
	(Target_mips::merge_obj_e_flags): Rename from
	merge_processor_specific_flags. Remove dyn_obj argument,
	call update_abiflags_isa when needed, compare NaN encodings and
	compare FP64 state.
	(Target_mips::add_machine_extensions): Add two machine extensions
	and fix one.
	(Target_mips::attributes_section_data_): New data member.
	(Target_mips::abiflags_): Likewise.
	(Target_mips::has_abiflags_section_): Likewise.
	(Mips_relobj::do_read_symbols): Read .gnu.attributes and
	.MIPS.abiflags sections if they exists.
	(Target_mips::elf_mips_mach): Add E_MIPS_MACH_5900 and
	E_MIPS_MACH_OCTEON3 support.
	(Target_mips::do_adjust_elf_header): Setup EI_ABIVERSION flag.
	(Target_mips::do_finalize_sections): Merge .gnu.attributes and
	.MIPS.abiflags sections from input. Create these sections if
	needed.
	(Target_mips::elf_mips_mach_name): Add E_MIPS_MACH_5900 and
	E_MIPS_MACH_OCTEON3 support, and change strings for
	E_MIPS_MACH_LS2E, E_MIPS_MACH_LS2F and E_MIPS_MACH_LS3A just
	to match bfd.
2016-06-11 10:09:59 -07:00
Vladimir Radosavljevic 82e498727a Fix problems emitting MIPS .reginfo section.
gold/
	* mips.cc (Mips_relobj::Mips_relobj): Initialize
	has_reginfo_section_.
	(Mips_relobj::has_reginfo_section_): New data member.
	(Mips_relobj::has_reginfo_section): New method.
	(class Mips_output_section_reginfo): Change base class to
	Output_section_data, and set masks of the output .reginfo section
	in constructor.
	(Mips_output_section_reginfo::as_mips_output_section_reginfo):
	Remove.
	(Mips_output_section_reginfo::set_masks): Likewise.
	(Mips_output_section_reginfo::set_final_data_size): Likewise.
	(Mips_output_section_reginfo::do_print_to_mapfile): New method.
	(Target_mips::do_make_output_section): Remove.
	(Mips_relobj::do_read_symbols): Set has_reginfo_section_ to true
	if the object contains a .reginfo section.
	(Target_mips::do_finalize_sections): Create a .reginfo output
	section if needed.
2016-06-10 15:37:19 -07:00
Artemiy Volkov a080d84da0 Fix compilation error in mips.cc with some versions of GCC.
gold/
	* mips.cc (Mips_output_data_got::do_write): Add missing template
	args via typedef.
2016-06-09 11:39:57 -07:00
Marcin Kościelnicki 40d85a7f9c gold/s390: Fix compilation on gcc 4.4
gold/ChangeLog:

	PR/19960
	* s390.cc (Target_s390::ss_code_st_r14): Removed.
	(Target_s390::ss_code_l_r14): Removed.
	(Target_s390::ss_code_ear): Removed.
	(Target_s390::ss_code_c): Removed.
	(Target_s390::ss_match_st_r14): New function.
	(Target_s390::ss_match_l_r14): New function.
	(Target_s390::ss_match_mcount): Call ss_match_{l,st}_r14 instead
	of matching code directly.
	(Target_s390::ss_match_ear): New function.
	(Target_s390::ss_match_c): New function.
	(Target_s390::do_calls_non_split): Call ss_match_{ear,c} instead
	of matching code directly.
2016-05-30 19:06:45 +02:00
Cary Coutant 6eeb0170bb Don't allow COPY relocations for protected symbols.
gold/
	PR gold/19823
	* copy-relocs.cc (Copy_relocs::make_copy_reloc): Add object
	parameter; check for protected symbol.
	* copy-relocs.h (Copy_relocs::make_copy_reloc): Add object parameter.
	* mips.cc (Mips_copy_relocs): Adjust call to make_copy_reloc.
	* symtab.cc (Symbol::init_fields): Initialize is_protected_.
	(Symbol_table::add_from_dynobj): Mark protected symbols.
	* symtab.h (Symbol::is_protected): New method.
	(Symbol::set_is_protected): New method.
	(Symbol::is_protected_): New data member.

	* testsuite/Makefile.am (copy_test_protected): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/copy_test.cc (main): Add legal reference to protected
	symbol.
	* testsuite/copy_test_v1.cc (main): Likewise.
	* testsuite/copy_test_2.cc (ip): Add protected symbol.
	* testsuite/copy_test_protected.cc: New test source file.
	* testsuite/copy_test_protected.sh: New test script.
2016-05-19 15:05:03 -07:00
Vladimir Radosavljevic 15eb1bebe1 Fix non-deterministic behavior when generating MIPS GOT.
* mips.cc (Mips_got_entry::Mips_got_entry): Remove object argument
	for global got symbols, and set addend to 0.
	(Mips_got_entry::hash): Change hash algorithm.
	(Mips_got_entry::equals): Refactor.
	(Mips_got_entry::object): Return input object for local got symbols
	from union d.
	(Mips_got_entry::addend): Change return of the relocation addend.
	(Mips_got_entry::addend_): Move from union d.
	(Mips_got_entry::object_): Move into union d.
	(class Mips_symbol_hash): New class.
	(Mips_got_info::Global_got_entry_set): New type.
	(Mips_got_info::global_got_symbols): Change return type to
	Global_got_entry_set.
	(Mips_got_info::global_got_symbols_): Change type to
	Global_got_entry_set.
	(Mips_symbol::hash): New method.
	(Mips_output_data_la25_stub::symbols_): Change type to std::vector.
	(Mips_output_data_mips_stubs::Mips_stubs_entry_set): New type.
	(Mips_output_data_mips_stubs::symbols_): Change type to
	Mips_stubs_entry_set.
	(Mips_got_info::record_global_got_symbol): Don't pass object
	argument when creating global got symbol.
	(Mips_got_info::record_got_entry): Remove find before inserting
	got entries.
	(Mips_got_info::add_reloc_only_entries): Change type of iterator
	to Global_got_entry_set.
	(Mips_got_info::count_got_symbols): Likewise.
	(Mips_output_data_la25_stub::create_la25_stub): Use push_back
	for adding entries to symbols_.
	(Mips_output_data_la25_stub::do_write): Change type of iterator
	to std::vector.
	(Mips_output_data_mips_stubs::set_lazy_stub_offsets): Change type
	of iterator to Mips_stubs_entry_set.
	(Mips_output_data_mips_stubs::set_needs_dynsym_value): Likewise.
	(Mips_output_data_mips_stubs::do_write): Likewise.
2016-05-19 15:04:51 -07:00
Han Shen 5c28a50381 Fix for PR gold/19987. 2016-05-09 14:22:15 -07:00
Nick Clifton 786a118cdf Updated Chinese (simplified) translations for bfd, binutils and gold. 2016-04-28 14:09:49 +01:00
H.J. Lu 6fd8e7c249 Regenerate Makefile.in/aclocal.m4 automake 1.11.6
bfd/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

binutils/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gas/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* doc/Makefile.in: Likewise.

gold/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
	* testsuite/Makefile.in: Likewise.

gprof/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

ld/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.

opcodes/

	* Makefile.in: Regenerated with automake 1.11.6.
	* aclocal.m4: Likewise.
2016-04-15 16:20:55 -07:00
Cary Coutant b60ecbc6dd Don't override definition a shared object by one in a later shared object.
In PR 16979, a reference to malloc is being resolved to an unversioned
reference in libmalloc.so. When linked with --as-needed, however, the
dynamic table does not list libmalloc.so as a DT_NEEDED library.

If we have a reference to an unversioned symbol in a shared object,
and we later see a versioned definition in another shared object, we
were overriding the first definition with the second in the process of
defining the default version. As a result, we no longer think that the
first shared object was actually needed to resolve any symbols, and we
don't list it as a DT_NEEDED library.

This patch fixes the problem by treating the two definitions as separate
symbols, so the second definition does not override the first.

2016-03-30  Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/16979
	* symtab.cc (Symbol_table::define_default_version): Check for case
	where symbols are both in different shared objects.
2016-03-30 19:15:09 -07:00
Cary Coutant ed700649d0 Fix failure to diagnose GOTOFF relocation to undef symbol in shared lib (i386).
gold/
	PR gold/16111
	* i386.cc (Target_i386): Add check for fully-resolved symbol for
	R_386_GOTOFF.
2016-03-27 16:11:27 -07:00
Nick Clifton 9780e04507 Add -Wstack-usage to the gcc warning flags list, but only if using a sufficiently recent version of gcc.
bfd	* warning.m4 (GCC_WARN_CFLAGS): Only add -Wstack-usage if using a
	sufficiently recent version of GCC.
	* configure: Regenerate.

others	* configure: Regenerate.
2016-03-22 09:41:16 +00:00
Cary Coutant 648c5cbbf3 Fix problem where gold fails to issue an undefined symbol error during LTO.
During LTO, if (1) an IR file contains a COMDAT group that is kept,
(2) a later non-claimed file contains the same group, which we discard,
and (3) the plugin fails to provide a definition of the symbols in that
COMDAT group, gold silently resolves any references to those symbols
to 0.

This patch adds a check for a placeholder symbol when deciding
whether to issue an undefined symbol error. It also adds an extra
note after any undefined placeholder symbol error that explains
that a definition was expected from the plugin.

gold/
	PR gold/19842
	* errors.cc (Errors::undefined_symbol): Add info message when
	symbol should have been provided by a plugin.
	* target-reloc.h (issue_undefined_symbol_error): Check for
	placeholder symbols defined in discarded sections.
	* testsuite/Makefile.am (plugin_test_9b): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/plugin_test_9b_elf.cc: New test source file.
	* testsuite/plugin_test_9b_ir.cc: New test source file.
2016-03-21 21:42:15 -07:00
Cary Coutant 698400bfb9 Fix problem where gold cannot build .eh_frame_hdr from ld -r output.
When running ld -r on objects that have comdat groups, when gold
deduplicates a function in a comdat group, it removes the relocations
from the EH information that referred to the dropped copy of the function.
When running a final link using the result of the -r link, the missing
relocation cause it to fail to recognize the FDE for the dropped
function.

This patch improves gold's FDE scanning to take into account the
possibility that an FDE corresponds to a dropped function, and drops
that FDE as well.

Gnu ld, on the other hand, leaves the relocations in the ld -r output,
but makes them R_NONE with an r_sym field of 0. This was sufficient to
let both linkers recognize the FDE properly.

With this fix, if you do an ld -r with gold, then do the final link with
Gnu ld, the .eh_frame_hdr section will not be generated. To make it work
with Gnu ld, we would have to leave the R_NONE relocations in, but I
think it's better to drop the relocations entirely. I'd hope that if
you're doing a -r link with gold, you'll also do the final link with
gold.

gold/
	PR gold/19002
	* ehframe.cc (Eh_frame::read_fde): Check for dropped functions.
	* testsuite/Makefile.am (eh_test_2): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/eh_test_2.sh: New test script.
	* testsuite/eh_test_a.cc (bar): Make it comdat.
	* testsuite/eh_test_b.cc (bar): Add a duplicate copy.
2016-03-20 19:17:14 -07:00
Vladimir Radosavljevic 01b84e2553 Remove is_n64_ data member from Mips_relobj class.
elfcpp/
	* mips.h (abi_64): Remove.

gold/
	* mips.cc (Mips_relobj::is_n64_): Remove.
	(Target_mips::ei_class_): Likewise.
	(Mips_relobj::is_newabi): Call methods.
	(Mips_relobj::is_n64): Change checking for N64 ABI.
	(Target_mips::is_output_n64): Likewise.
	(Target_mips::merge_processor_specific_flags): Remove ei_class
	argument, and remove comparing ei_class.
	(Target_mips::do_adjust_elf_header): Remove setting EI_CLASS field
	of the ELF header.
	(Target_mips::do_finalize_sections): Don't pass ei_class argument
	to merge_processor_specific_flags.
	(Target_mips::elf_mips_abi_name): Remove ei_class argument, and
	change checking for N64 ABI.
2016-03-18 14:54:35 -07:00
Vladimir Radosavljevic 47a9f4fcab Add MIPS-64 support.
gold/
	* mips.cc (enum Special_relocation_symbol): New enum type.
	(is_readonly_section): New function.
	(eh_reloc): Likewise.
	(Mips_got_entry::is_section_symbol_): New member.
	(Mips_got_entry::is_section_symbol): New method.
	(Mips_got_info::record_local_got_symbol): Add is_section_symbol
	argument.
	(Mips_relobj::mips_elf_options_section_name): New method.
	(Mips_output_data_got::record_local_got_symbol): Add
	is_section_symbol argument, and pass it to
	Mips_got_info::record_local_got_symbol.
	(Mips_output_data_got::got_offset): Add addend argument, and pass
	it to Relobj::local_got_offset.
	(struct Mips_output_reloc_writer): New type.
	(class Mips_output_data_reloc): New class.
	(Mips_output_data_plt::Reloc_section): Change type to
	Mips_output_data_reloc.
	(Target_mips::Reloc_section): Likewise.
	(Mips_reloc_types::get_r_addend): Remove unsigned from return type.
	(Mips_classify_reloc::get_r_type2): New method.
	(Mips_classify_reloc::get_r_type3): Likewise.
	(Mips_classify_reloc::get_r_ssym): Likewise.
	(Target_mips::Reloca_section): Remove.
	(Relocate::should_apply_static_reloc): Rename from
	should_apply_r_mips_32_reloc.
	(Target_mips::copy_reloc): Replace Reltype parameter with r_type
	and r_offset.
	(Mips_relocate_functions::Valtype): New type.
	(Mips_relocate_functions::Valtype64): New type.
	(Mips_relocate_functions::check_overflow): New method.
	(Mips_relocate_functions::mips_reloc_unshuffle): Move to public
	interface.
	(Mips_relocate_functions::mips_reloc_shuffle): Likewise.
	(Mips_relocate_functions::rel16): Add support for resolving
	relocations for Mips64.
	(Mips_relocate_functions::rel32): Likewise.
	(Mips_relocate_functions::reljalr): Likewise.
	(Mips_relocate_functions::relpc32): Likewise.
	(Mips_relocate_functions::rel26): Likewise.
	(Mips_relocate_functions::relpc16): Likewise.
	(Mips_relocate_functions::relmicromips_pc7_s1): Likewise.
	(Mips_relocate_functions::relmicromips_pc10_s1): Likewise.
	(Mips_relocate_functions::relmicromips_pc16_s1): Likewise.
	(Mips_relocate_functions::do_relhi16): Likewise.
	(Mips_relocate_functions::do_relgot16_local): Likewise.
	(Mips_relocate_functions::rello16): Likewise.
	(Mips_relocate_functions::relgot): Likewise.
	(Mips_relocate_functions::relgotpage): Likewise.
	(Mips_relocate_functions::relgotofst): Likewise.
	(Mips_relocate_functions::relgot_hi16): Likewise.
	(Mips_relocate_functions::relgot_lo16): Likewise.
	(Mips_relocate_functions::relgprel): Likewise.
	(Mips_relocate_functions::relgprel32): Likewise.
	(Mips_relocate_functions::tlsrelhi16): Likewise.
	(Mips_relocate_functions::tlsrello16): Likewise.
	(Mips_relocate_functions::tlsrel32): Likewise.
	(Mips_relocate_functions::relsub): Likewise.
	(Mips_relocate_functions::releh): New method.
	(Mips_relocate_functions::rel64): Likewise.
	(Mips_got_info::record_local_got_symbol): Add is_section_symbol and
	pass it to Mips_got_entry.
	(Mips_got_info::add_local_entries): Pass addend argument
	to code functions, and for STT_SECTION symbols call
	add_symbolless_local_addend.
	(Mips_got_info::add_tls_entries): Pass addend argument to code
	functions.
	(Mips_relobj::do_read_symbols): Read gp value that was used to
	create object.
	(Mips_output_data_plt::plt_entry): Remove opcode from l[wd]
	instruction. Opcode for instruction will be selected later.
	(Target_mips::gc_process_relocs): Add case for SHT_RELA.
	(Target_mips::scan_relocatable_relocs): Likewise.
	(Target_mips::emit_relocs_scan): Likewise.
	(Target_mips::relocate_relocs): Likewise.
	(Target_mips::do_finalize_sections): Skip objects for merging
	processor specific flags in which all input sections will be
	discarded.
	(mips_get_size_for_reloc): Add case for R_MIPS_EH.
	(Target_mips::Scan::get_reference_flags): Likewise.
	(Target_mips::relocate_special_relocatable): Call rel26 method with
	calculate_only and calculated_value arguments.
	(Target_mips::Scan::local): Add case for R_MIPS_EH. Don't create a
	dynamic relocation against a readonly sections, and pass
	is_section_symbol to Mips_got_info::record_local_got_symbol.
	(Target_mips::Scan::global): Add case for R_MIPS_EH. Don't create a
	dynamic relocation against a readonly sections, and pass r_type
	and r_offset to Target_mips::copy_reloc.
	(Target_mips::Relocate::relocate): Add support for resolving
	relocations for Mips64.
	(Target_mips::mips_info): Add case for Mips64 default dynamic
	linker name.
	(Target_selector_mips): Correct emulation names.
2016-03-17 15:07:49 -07:00
Vladimir Radosavljevic 1a08ae216c Add missing Mips_output_data_la25_stub::do_print_to_mapfile.
gold/
	* mips.cc (class Mips_output_data_la25_stub): Add
	do_print_to_mapfile function.
2016-03-17 14:27:48 -07:00
Vladimir Radosavljevic c2fa9cedff Fix problem with --emit-relocs for Mips-32.
gold/
	* mips.cc (Mips_classify_reloc::put_r_info): Call 32bit version of
	elf_r_info.
2016-03-17 14:26:50 -07:00
H.J. Lu fd91f0024c Workaround a C++ bug in GCC 4.2 in gold test
G++ in GCC 4.2 silently ignores

---
__attribute__ ((section(".rodata.v1_a2")))
const short rodata_item1 = 101;
---

which leads to plugin_layout_with_alignment test failure with

Expected 12 sections, found 8 sections

since 4 .rodata sections are missing.  As a workaround, this patch
changes plugin_layout_with_alignment test from C++ to C.

	* testsuite/plugin_layout_with_alignment.cc: Renamed to ..
	* testsuite/plugin_layout_with_alignment.c: This.
	* testsuite/Makefile.am (plugin_layout_with_alignment.o): Updated.
	(plugin_layout_with_alignment): Likewise.
	* testsuite/Makefile.in: Regenerated.
2016-03-09 08:32:46 -08:00
Cary Coutant 7ff6eb49a2 Remove checks for constructors that might have been eliminated by GCC.
GCC 6 does not generate constructors for two of gold's test cases.
This patch simply removes the checks for them.

gold/
	PR 19751
	* testsuite/Makefile.am (retain_symbols_file_test): Remove check
	for constructor.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/dynamic_list.sh: Likewise.
	* testsuite/retain_symbols_file_test.sh: Likewise.
2016-03-08 20:36:31 -08:00
Cary Coutant 202736beb1 Add unused attribute where necessary to quiet GCC 6 warnings.
gold/
	PR 19751
	* arm.cc (Reloc_stub::Key::name): Add unused attribute.
	* dirsearch.cc (Dir_caches::~Dir_caches): Likewise.
2016-03-08 20:34:18 -08:00
Cary Coutant c32482d65c Refactor Output_data_reloc_base::do_write for MIPS-specific relocs.
This patch is a simple refactoring that will allow the MIPS backend to
replace the Output_data_reloc_base::do_write() method without copying
its entire implementation. I've moved the implementation of do_write()
into a function template, which can be instantiated with a custom
class to write the MIPS-specific relocation format. The custom class
for MIPS needs access to the symbol index and address from
Output_reloc, so I've included the part of Vlad's MIPS-64 patch that
makes those accessor methods public.

2016-03-08  Cary Coutant  <ccoutant@gmail.com>
            Vladimir Radosavljevic  <vladimir.radosavljevic@imgtec.com>

gold/
	* output.cc (Output_reloc_writer): New type.
	(Output_data_reloc_base::do_write): Move implementation to template
	in output.h and replace with invocation of template.
	* output.h (Output_file): Move to top of file.
	(Output_reloc::get_symbol_index): Move to public interface.
	(Output_reloc::get_address): Likewise.
	(Output_data_reloc_base::do_write_generic): New function template.
2016-03-08 15:06:59 -08:00
Cary Coutant 9b738e36e6 Fix datestamps on ChangeLog entries to read 2015 instead of 2016. 2016-03-04 14:19:12 -08:00
H.J. Lu 3f1f41f55f Add missing ChangeLog entries for commit 82838
Fix gold/testsuite/plugin_layout_with_alignment.sh permission.
2016-03-04 08:28:12 -08:00
Cary Coutant 8d04e81db4 Fix undefined symbol errors introduced with previous commit.
gold/
	PR gold/19019
	PR gold/19763
	* symtab.cc: Instantiate Sized_symbol::init_constant and
	Sized_symbol::init_undefined.
2016-03-04 08:13:35 -08:00
Cary Coutant dc1c8a16a3 Add support for STT_SPARC_REGISTER symbols.
gold/
	PR gold/19019
	* layout.h (Layout::add_target_specific_dynamic_tag): New function.
	* layout.cc (Layout::add_target_specific_dynamic_tag): New function.
	* mips.cc (Target_mips::make_symbol): Adjust function signature.
	* sparc.cc (Target_sparc::Target_sparc): Initialize register_syms_.
	(Target_sparc::do_is_defined_by_abi): Remove test for
	STT_SPARC_REGISTER.
	(Target_sparc::Register_symbol): New struct type.
	(Target_sparc::register_syms_): New data member.
	(Target_sparc<64, true>::sparc_info): Set has_make_symbol to true.
	(Target_sparc::make_symbol): New function.
	(Target_sparc::do_finalize_sections): Add register symbols and new
	dynamic table entries.
	* symtab.h (Sized_symbol::init_undefined): Add value parameter.
	(Symbol_table::add_target_global_symbol): New function.
	(Symbol_table::target_symbols_): New data member.
	* symtab.cc (Sized_symbol::init_undefined): Add value parameter.
	(Symbol_table::Symbol_table): Initialize target_symbols_.
	(Symbol_table::add_from_object): Pass additional parameters to
	Target::make_symbol.
	(Symbol_table::define_special_symbol): Likewise.
	(Symbol_table::add_undefined_symbol_from_command_line): Pass 0 for
	undefined symbol value.
	(Symbol_table::set_dynsym_indexes): Process target-specific symbols.
	(Symbol_table::sized_finalize): Likewise.
	(Symbol_table::sized_write_globals): Likewise.
	* target.h (Sized_target::make_symbol): Add name, st_type, object,
	st_shndx, and value parameters.
2016-03-03 18:19:53 -08:00
Rafael Ávila de Espíndola a06ed37d75 Don't handle every plugin symbol as defined.
Gold was fetching --start-lib/--end-lib members if that member defined
or used a currently undefined symbol.
2016-03-03 15:16:52 -05:00
Evgenii Stepanov 95ecdfbfcb get_symbols() plugin API tweak to support --start-lib/--end-lib.
Let the plugin know that a file is not being included in the link by
returning LDPS_NO_SYMS from get_symbols().

include/
	* plugin-api.h (enum ld_plugin_tag): Add LDPT_GET_SYMBOLS_V3.

gold/
	* plugin.h (Pluginobj::get_symbol_resolution_info): Add version
	parameter.
	* plugin.cc (get_symbols_v3): New function.
	(Plugin::load): Add LDPT_GET_SYMBOLS_V3.
	(Pluginobj::get_symbol_resolution_info): Return LDPS_NO_SYMS when using
	new version.
2016-03-03 11:42:13 -08:00
Cary Coutant fc5a9bd57c Discard FDEs for zero-length address ranges.
2016-02-26  Egor Kochetov  <egor.kochetov@intel.com>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/19735
	* ehframe.h (Cie::fde_encoding): New method.
	* ehframe.cc (Eh_frame::read_fde): Discard FDEs for zero-length
	address ranges.
2016-02-26 07:53:20 -08:00
H.J. Lu 1cd17042aa Pass -mrelax-relocations=yes to $(TEST_AS)
x86_64_mov_to_lea5.o and x86_64_mov_to_lea6.o must be assembled with
-mrelax-relocations=yes since when assembler is configured with
--disable-x86-relax-relocations, R_X86_64_GOTPCRELX relocation won't
be generated.  This linker optimization requires R_X86_64_GOTPCRELX
relocation.

This patch also removed the duplicated x86_64_overflow_pc32.o target.

	* testsuite/Makefile.am (x86_64_mov_to_lea5.o): Pass
	-mrelax-relocations=yes to $(TEST_AS).
	(x86_64_mov_to_lea6.o): Likewise.
	(x86_64_overflow_pc32.o): Remove duplicated target.
	* testsuite/Makefile.in: Regenerated.
2016-02-16 06:00:03 -08:00
Marcin Kościelnicki 2b63aca39c gold: Add s390 -fsplit-stack support.
gold/ChangeLog:

	* s390.cc (Target_s390::match_view_u): New helper method.
	(Target_s390::do_is_call_to_non_split): New method.
	(Target_s390::ss_code_st_r14): New const.
	(Target_s390::ss_code_l_r14): New const.
	(Target_s390::ss_code_bras_8): New const.
	(Target_s390::ss_code_l_basr): New const.
	(Target_s390::ss_code_a_basr): New const.
	(Target_s390::ss_code_ear): New const.
	(Target_s390::ss_code_c): New const.
	(Target_s390::ss_code_larl): New const.
	(Target_s390::ss_code_brasl): New const.
	(Target_s390::ss_code_jg): New const.
	(Target_s390::ss_code_jgl): New const.
	(Target_s390::ss_match_mcount): New helper method.
	(Target_s390::ss_match_l): New helper method.
	(Target_s390::ss_match_ahi): New helper method.
	(Target_s390::ss_match_alfi): New helper method.
	(Target_s390::ss_match_cr): New helper method.
	(Target_s390::do_calls_non_split): New method.
	* testsuite/Makefile.am: Added new tests.
	* testsuite/split_s390.sh: New test.
	* testsuite/split_s390_1_a1.s: New test.
	* testsuite/split_s390_1_a2.s: New test.
	* testsuite/split_s390_1_n1.s: New test.
	* testsuite/split_s390_1_n2.s: New test.
	* testsuite/split_s390_1_z1.s: New test.
	* testsuite/split_s390_1_z2.s: New test.
	* testsuite/split_s390_1_z3.s: New test.
	* testsuite/split_s390_1_z4.s: New test.
	* testsuite/split_s390_2_ns.s: New test.
	* testsuite/split_s390_2_s.s: New test.
	* testsuite/split_s390x_1_a1.s: New test.
	* testsuite/split_s390x_1_a2.s: New test.
	* testsuite/split_s390x_1_n1.s: New test.
	* testsuite/split_s390x_1_n2.s: New test.
	* testsuite/split_s390x_1_z1.s: New test.
	* testsuite/split_s390x_1_z2.s: New test.
	* testsuite/split_s390x_1_z3.s: New test.
	* testsuite/split_s390x_1_z4.s: New test.
	* testsuite/split_s390x_2_ns.s: New test.
	* testsuite/split_s390x_2_s.s: New test.
2016-02-15 11:59:25 +01: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
Cary Coutant 17ecd01611 Add additional information to relocation overflow errors.
gold/
	PR gold/18695
	* x86_64.cc (Target_x86_64::Relocate::relocate): Add additional
	information to relocation overflow errors.
2016-02-07 10:17:01 -08:00
Cary Coutant 7c8b700c92 Fix incorrect x32 overflow checking for refs to weak undef symbols.
On x32, a pc-relative reference to an undef weak symbol (value 0)
with a negative addend (typically -4) generates a spurious overflow
error because Symbol_value::value() returns a 32-bit negative number
as an unsigned number, which gets zero-extended before subtracting
the PC value. This patch fixes the problem by special-casing the
negative addend, and adding it to the value after widening it to
64 bits. Symbol_value::value() does not need the addend if it's
negative, since it is only important when processing section
symbols for merge sections, where a positive addend provides the
input section offset of the merged constant.

gold/
	* x86_64.cc (X86_64_relocate_functions::pcrela32_check): Fix x32
	overflow checking when symbol value + addend < 0.
2016-02-07 07:49:34 -08:00
Cary Coutant b7a4e9d8e6 Fix compile errors about shift counts too large.
In order to get around the optimizer and newer compiler warnings
about shift counts, the overflow checking code had resorted to
some messy shifting, and with the never-before-seen instantiations
of the template functions, we were still running afoul of the
compiler checks.

This patch replaces those messy shift sequences with a simple
class template that provides the min and max limits for any
bit size up to 64, with a specialization for 64 that prevents
the compiler from complaining.

gold/
	PR gold/19577
	* reloc.h (Limits): New class.
	(Bits::has_overflow32): Use min/max values from Limits.
	(Bits::has_unsigned_overflow32): Likewise.
	(Bits::has_signed_unsigned_overflow32): Likewise.
	(Bits::has_overflow): Likewise.
	(Bits::has_unsigned_overflow): Likewise.
	(Bits::has_signed_unsigned_overflow64): Likewise.
2016-02-06 18:19:13 -08:00
Cary Coutant 19ef3f4d2e Fix overflow checking for 32-bit pc-relative relocations on x32.
The problem here is that x32 is really using 64-bit addressing,
while pretending to be 32-bit. Even though the object file format
is 32-bit, we need to do the overflow checking with 64-bit
arithmetic (because that's what the hardware will be using).
This patch overrides the pcrela32_check functions in reloc.h
with target-specific versions that do 64-bit checking.

I've also updated the test case to use -Tdata instead of adding
a huge .space directive, to reduce the size of the .o files.

gold/
	PR gold/19567
	* reloc.h (Relocate_functions::Overflow_check): Add comments.
	* x86_64.cc (X86_64_relocate_functions): New class.
	(Target_x86_64::Relocate::relocate): Use the new class.
	* testsuite/Makefile.am (x86_64_overflow_pc32): Add -Tdata option.
	(x32_overflow_pc32): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/x32_overflow_pc32.sh: New script.
	* testsuite/x86_64_overflow_pc32.s: Remove .space directive.
2016-02-06 14:47:05 -08:00
Cary Coutant 72c55146bb Fix incorrect casts.
gold/
	PR gold/19577
	* reloc.h (Bits::has_unsigned_overflow32): Fix static_cast.
	(Bits::has_unsigned_overflow): Remove unnecessary static_cast.
2016-02-06 10:28:36 -08:00
Cary Coutant 3b8bcce879 Add PR number to ChangeLog entry. 2016-02-06 09:55:40 -08:00
Cary Coutant 2bf48941a7 Fix build failure in gold due to signed vs. unsigned comparisons.
* reloc.h (Bits::has_unsigned_overflow32): Fix unsigned/signed
	comparison.
	(Bits::has_unsigned_overflow): Likewise.
2016-02-06 09:53:58 -08:00
Marcin Kościelnicki bd8d853f77 gold: Add view and view_size parameters to is_call_to_non_split.
This is needed by s390 split-stack support, to distinguish call
and load-address relocations.

gold/ChangeLog:

	* i386.cc (Target_i386::is_call_to_non_split): Add view and view_size
	parameters.
	* reloc.cc (Sized_relobj_file::split_stack_adjust_reltype): Pass view
	and view_size to is_call_to_non_split.
	* target.cc (Target::is_call_to_non_split): Add view and view_size
	parameters.
	* target.h (class Target): Likewise.
2016-02-06 01:52:00 +01:00
Sriraman Tallam 84d543b7ed 2016-02-05 Sriraman Tallam <tmsriram@google.com>
* icf.cc (get_rel_addend): New function.
	(get_section_contents):  Move merge section addend computation to a
	new function.  Ignore negative values for SHT_REL and SHT_RELA addends.
	Fix bug to not read past the length of the section.

Fix bug related to addend computation for MERGE sections.
2016-02-05 15:07:45 -08:00
Cary Coutant c34c98ed62 Add some relocation overflow checks for x86_64.
2016-02-05  Cary Coutant  <ccoutant@gmail.com>
	    Andrew Senkevich  <andrew.senkevich@intel.com>

gold/
	PR gold/18695
	* x86_64.cc (Target_x86_64::Relocate::relocate): Add overflow
	checking for R_X86_64_32, R_X86_64_32S, R_X86_64_PC32, and
	R_X86_64_PLT32.
	* testsuite/Makefile.am (x86_64_overflow_pc32): New test.
	* testsuite/x86_64_overflow_pc32.sh: New test script.
	* testsuite/x86_64_overflow_pc32.s: New source file.
2016-02-05 09:19:47 -08:00
Cary Coutant 44803b5d87 Overhaul relocation framework to support overflow checking.
gold/
	PR gold/18695
	* reloc.h (Relocate_functions::Address): New typedef.
	(Relocate_functions::Addendtype): New typedef.
	(Relocate_functions::Overflow_check): New enum type.
	(Relocate_functions::Reloc_status): New enum type.
	(Relocate_functions::check_overflow): New function template.
	(Relocate_functions::rel): Add check parameter; check for overflow.
	(Relocate_functions::rel_unaligned): Likewise.
	(Relocate_functions::rela): Likewise.
	(Relocate_functions::pcrel): Likewise.
	(Relocate_functions::pcrel_unaligned): Likewise.
	(Relocate_functions::pcrela): Likewise.
	(Relocate_functions::rel8): Adjust parameter types.
	(Relocate_functions::rela8): Likewise.
	(Relocate_functions::pcrel8): Likewise.
	(Relocate_functions::pcrela8): Likewise.
	(Relocate_functions::rel16): Likewise.
	(Relocate_functions::rela168): Likewise.
	(Relocate_functions::pcrel16): Likewise.
	(Relocate_functions::pcrela16): Likewise.
	(Relocate_functions::rel32): Likewise.
	(Relocate_functions::rel32_unaligned): Likewise.
	(Relocate_functions::rela32): Likewise.
	(Relocate_functions::pcrel32): Likewise.
	(Relocate_functions::pcrel32_unaligned): Likewise.
	(Relocate_functions::pcrela32): Likewise.
	(Relocate_functions::rel8_check): New function.
	(Relocate_functions::rela8_check): New function.
	(Relocate_functions::pcrel8_check): New function.
	(Relocate_functions::pcrela8_check): New function.
	(Relocate_functions::rel16_check): New function.
	(Relocate_functions::rela168_check): New function.
	(Relocate_functions::pcrel16_check): New function.
	(Relocate_functions::pcrela16_check): New function.
	(Relocate_functions::rel32_check): New function.
	(Relocate_functions::rel32_unaligned_check): New function.
	(Relocate_functions::rela32_check): New function.
	(Relocate_functions::pcrel32_check): New function.
	(Relocate_functions::pcrel32_unaligned_check): New function.
	(Relocate_functions::pcrela32_check): New function.
	(Bits::has_unsigned_overflow32): New function.
	(Bits::has_unsigned_overflow): New function.
	* testsuite/Makefile.am (overflow_unittest): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/overflow_unittest.cc: New source file.
2016-02-05 08:28:04 -08:00
Alan Modra 4f038ee5d2 Fix "PowerPC64 ELFv2 entry code" for big-endian
bfd/
	* elf64-ppc.c (ppc64_elf_relocate_section): Adjust last patch
	for big-endian.
gold/
	* powerpc.cc (relocate): Adjust last patch for big-endian.
2016-02-04 00:31:14 +10:30
Alan Modra 85fabe715c PowerPC64 ELFv2 entry code
This tightens the condition under which ld optimizes PIC entry code
to non-PIC.

bfd/
	* elf64-ppc.c (ppc64_elf_relocate_section): Further restrict
	ELFv2 entry optimization.
gold/
	* powerpc.cc (relocate): Further restrict ELFv2 entry optimization.
2016-02-02 23:59:03 +10:30
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
H.J. Lu 41549dfbcc Fix compile error with use of 'typename' outside of template
* i386.cc (Target_i386::Classify_reloc::get_r_addend): Remove
	'typename'.
2016-01-12 12:21:53 -08:00
Cary Coutant 8a8880cb67 Fix breakage for SHT_REL targets where get_r_addend() gives internal error.
gold/
	* arm.cc (Target_arm::Classify_reloc::get_r_addend): New method.
	* i386.cc (Target_i386::Classify_reloc::get_r_addend): New method.
	* mips.cc (Target_arm::Mips_classify_reloc::get_r_addend): (Both
	specializations) New method.
2016-01-12 11:39:50 -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 3499769a6a New 2016 binutils ChangeLog files
Note that this does not create bfd/doc/ChangeLog, */testsuite/ChangeLog
and include/*/ChangeLog files.
2016-01-01 22:59:42 +10:30
Alan Modra 4120fa118f binutils ChangeLog rotation 2016-01-01 22:59:17 +10:30
Alan Modra 331e61312e Fix assorted ChangeLog errors 2015-12-30 11:44:35 +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
Roland McGrath 95c29a83eb PR gold/17473: Fix gold build with system C++ headers that use <ctype.h>.
gold/
	PR gold/17473
	* binary.cc: Move #include "safe-ctype.h" to be last #include.
2015-12-16 16:35:27 -08:00
Cary Coutant 39040bb911 Remove const from return type of get_output_view.
gold/
	* object.h (Object::get_output_view): remove const from return type.
	(Object::do_get_output_view): Likewise.
	(Sized_relobj_file::do_get_output_view): Likewise.
	* reloc.cc (Sized_relobj_file::do_get_output_view): Likewise.
2015-12-13 14:04:24 -08:00
Cary Coutant 6e0813d359 Pass relocations to Target::do_calls_non_split.
gold/
	* target.h (Target::calls_non_split): Add prelocs, reloc_count
	parameters.
	(Target::do_calls_non_split): Likewise.
	* target.cc (Target::do_calls_non_split): Likewise.
	* reloc.cc (Sized_relobj_file::split_stack_adjust_reltype): Adjust
	call to Target::calls_non_split.

	* i386.cc (Target_i386::do_calls_non_split): Add prelocs, reloc_count
	parameters.
	* powerpc.cc (Target_powerpc::do_calls_non_split): Likewise.
	* x86_64.cc (Target_x86_64::do_calls_non_split): Likewise.
2015-12-11 14:23:59 -08:00
Cary Coutant 6b2353a53a Make output views accessible to Target during do_relocate().
gold/
	* object.cc (Sized_relobj_file::Sized_relobj_file): Initialize
	output_views_.
	* object.h (Object::get_output_view): New function.
	(Object::do_get_output_view): New function.
	(Sized_relobj_file::do_get_output_view): New function.
	(Sized_relobj_file::output_views_): New data member.
	* reloc.cc: (Sized_relobj_file::do_relocate): Store pointer to
	output views in class object.
	(Sized_relobj_file::do_get_output_view): New function.
2015-12-11 14:23:58 -08:00
H.J. Lu bebf4942b0 ld -r doesn't need plugin for slim lto object
Plugin isn't required on slim lto object for relocatable link.

	PR ld/19317
	* symtab.cc (Symbol_table::add_from_relobj): Don't complain
	plugin needed to handle slim lto object for relocatable link.
2015-12-10 11:29:03 -08:00
Alan Modra dcfc7dd477 [GOLD] PowerPC style fix
* powerpc.cc (Target_powerpc::Relocate::relocate): New constant
	d_offset.  Use throughout.
	(Target_powerpc::relocate_relocs): Likewise.
2015-12-09 10:36:44 +10:30
Alan Modra e3a7574e2e [GOLD] Edit PowerPC64 ELFv2 function entry code
In an fixed position executable, the entry code does not need to be
PIC and can thus lose a dependency on r12.

	* powerpc.cc (Target_powerpc::Relocate::relocate): Edit ELFv2
	entry code.
	(Target_powerpc::relocate_relocs): Edit relocs to suit.
2015-12-09 10:36:43 +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
Alan Modra 549dba7104 [GOLD] R_PPC64_ENTRY support
elfcpp/
	* powerpc.h (R_PPC64_ENTRY): Define.
gold/
	* powerpc.cc (add_2_2_12, ld_2_12, lis_2): Define.
	(Target_powerpc::Scan::local, global): Handle R_PPC64_ENTRY.
	(Target_powerpc::Relocate::relocate): Edit code at R_PPC64_ENTRY.
2015-12-07 13:17:00 +10:30
Vladimir Radosavljevic 7ef8ae7c5f Take addend into account when making GOT entries for local symbols.
gold/
	* object.cc (Sized_relobj::do_for_all_local_got_entries): Use
	Local_got_entry_key for searching in local_got_offsets_.
	* object.h (class Local_got_entry_key): New class.
	(Relobj::local_has_got_offset): New overloaded method.
	(Relobj::local_got_offset): Likewise.
	(Relobj::set_local_got_offset): Likewise.
	(Relobj::do_local_has_got_offset): Add addend argument.
	(Relobj::do_local_got_offset): Likewise.
	(Relobj::do_set_local_got_offset): Likewise.
	(Sized_relobj::do_local_has_got_offset): Add addend argument, and use
	Local_got_entry_key for searching through local_got_offsets_.
	(Sized_relobj::do_local_got_offset): Likewise.
	(Sized_relobj::do_set_local_got_offset): Likewise.
	(Sized_relobj::Local_got_offsets): Change type of the key from
	unsigned int to Local_got_entry_key, and add hash and equal_to.
	* output.cc (Got_entry::write): Take addend into account for
	calculating value of the local symbol for GOT.
	(Output_data_got::add_local): New definition of overloaded method.
	(Output_data_got::add_local_with_rel): Likewise.
	(Output_data_got::add_local_pair_with_rel): Likewise.
	* output.h (Output_data_got::add_local): New declaration of overloaded
	method.
2015-12-03 15:29:17 -08:00
Cary Coutant 74b03b9133 Adjust local symbol value in relocatable link to be relative to section.
gold/
	PR gold/19291
	* object.cc (Sized_relobj_file::write_local_symbols): If relocatable,
	subtract section address from symbol value.
2015-11-25 08:50:41 -08:00
Alan Modra 751e4d66b4 [GOLD] Align PowerPC64 GOT
As done in a27e685f for bfd ld.

	* powerpc.cc (Output_data_got_powerpc::Output_data_got_powerpc): Align
	to 256 byte boundary.
2015-11-25 15:06:12 +10:30
Alan Modra 32d849b35d [GOLD] PowerPC TOC16 and GOT16 relocs are relative
* powerpc.cc (Target_powerpc::Scan::get_reference_flags): Correct
	GOT16 and TOC16 relocs to RELATIVE_REF.
2015-11-19 17:01:04 +10:30
Cary Coutant db1ff0288b Fix problem where bss symbols for copy relocations are marked local.
gold/
	PR gold/19244
	PR gold/18548
	* symtab.cc (Symbol_table::do_define_in_output_data): Check for forced
	local symbols only for predefined symbols.
2015-11-14 11:04:01 -08:00
Peter Bergner a680de9a98 Add assembler, disassembler and linker support for power9.
include/opcode/
	* ppc.h (PPC_OPCODE_POWER9): New define.
	(PPC_OPCODE_VSX3): Likewise.

opcodes/
	* ppc-dis.c (ppc_opts): Add "power9" and "pwr9" entries.
	Add PPC_OPCODE_VSX3 to the vsx entry.
	(powerpc_init_dialect): Set default dialect to power9.
        * ppc-opc.c (insert_dcmxs, extract_dcmxs, insert_dxd, extract_dxd,
        insert_dxdn, extract_dxdn, insert_l0, extract_l0, insert_l1,
        extract_l1 insert_xtq6, extract_xtq6): New static functions.
        (insert_esync): Test for illegal L operand value.
	(DCMX, DCMXS, DXD, NDXD, L0, L1, RC, FC, UIM6, X_R, RIC, PRS, XSQ6,
	XTQ6, LRAND, IMM8, DQX, DQX_MASK, DX, DX_MASK, VXVAPS_MASK, VXVA,XVA,
	XX2VA, XVARC, XBF_MASK, XX2UIM4_MASK, XX2BFD_MASK, XX2DCMXS_MASK,
	XVA_MASK, XRLA_MASK, XBFRARB_MASK, XLRAND_MASK, POWER9, PPCVEC3,
	PPCVSX3): New defines.
	(powerpc_opcodes) <ps_cmpu0, ps_cmpo0, ps_cmpu1, ps_cmpo1, fcmpu,
	fcmpo, ftdiv, ftsqrt>: Use XBF_MASK.
	<mcrxr>: Use XBFRARB_MASK.
	<addpcis, bcdcfn., bcdcfsq., bcdcfz., bcdcpsgn., bcdctn., bcdctsq.,
	bcdctz., bcds., bcdsetsgn., bcdsr., bcdtrunc., bcdus., bcdutrunc.,
	cmpeqb, cmprb, cnttzd, cnttzd., cnttzw, cnttzw., copy, copy_first,
	cp_abort, darn, dtstsfi, dtstsfiq, extswsli, extswsli., ldat, ldmx,
	lwat, lxsd, lxsibzx, lxsihzx, lxssp, lxv, lxvb16x, lxvh8x, lxvl, lxvll,
	lxvwsx, lxvx, maddhd, maddhdu, maddld, mcrxrx, mfvsrld, modsd, modsw,
	modud, moduw, msgsync, mtvsrdd, mtvsrws, paste, paste., paste_last,
	rmieg, setb, slbieg, slbsync, stdat, stop, stwat, stxsd, stxsibx,
	stxsihx, stxssp, stxv, stxvb16x, stxvh8x, stxvl, stxvll, stxvx,
	subpcis, urfid, vbpermd, vclzlsbb, vcmpneb, vcmpneb., vcmpneh,
	vcmpneh., vcmpnew, vcmpnew., vcmpnezb, vcmpnezb., vcmpnezh, vcmpnezh.,
	vcmpnezw, vcmpnezw., vctzb, vctzd, vctzh, vctzlsbb, vctzw, vextractd,
	vextractub, vextractuh, vextractuw, vextsb2d, vextsb2w, vextsh2d,
	vextsh2w, vextsw2d, vextublx, vextubrx, vextuhlx, vextuhrx, vextuwlx,
	vextuwrx, vinsertb, vinsertd, vinserth, vinsertw, vmul10cuq,
	vmul10ecuq, vmul10euq, vmul10uq, vnegd, vnegw, vpermr, vprtybd,
	vprtybq, vprtybw, vrldmi, vrldnm, vrlwmi, vrlwnm, vslv, vsrv, wait,
	xsabsqp, xsaddqp, xsaddqpo, xscmpeqdp, xscmpexpdp, xscmpexpqp,
	xscmpgedp, xscmpgtdp, xscmpnedp, xscmpoqp, xscmpuqp, xscpsgnqp,
	xscvdphp, xscvdpqp, xscvhpdp, xscvqpdp, xscvqpdpo, xscvqpsdz,
	xscvqpswz, xscvqpudz, xscvqpuwz, xscvsdqp, xscvudqp, xsdivqp,
	xsdivqpo, xsiexpdp, xsiexpqp, xsmaddqp, xsmaddqpo, xsmaxcdp,
	xsmaxjdp, xsmincdp, xsminjdp, xsmsubqp, xsmsubqpo, xsmulqp, xsmulqpo,
	xsnabsqp, xsnegqp, xsnmaddqp, xsnmaddqpo, xsnmsubqp, xsnmsubqpo,
	xsrqpi, xsrqpix, xsrqpxp, xssqrtqp, xssqrtqpo, xssubqp, xssubqpo,
	xststdcdp, xststdcqp, xststdcsp, xsxexpdp, xsxexpqp, xsxsigdp,
	xsxsigqp, xvcmpnedp, xvcmpnedp., xvcmpnesp, xvcmpnesp., xvcvhpsp,
	xvcvsphp, xviexpdp, xviexpsp, xvtstdcdp, xvtstdcsp, xvxexpdp,
	xvxexpsp, xvxsigdp, xvxsigsp, xxbrd, xxbrh, xxbrq, xxbrw, xxextractuw,
	xxinsertw, xxperm, xxpermr, xxspltib>: New instructions.
	<doze, nap, sleep, rvwinkle, waitasec, lxvx, stxvx>: Disable on POWER9.
	<tlbiel, tlbie, sync, slbmfev, slbmfee>: Add additional operands.

include/elf/
	* ppc.h (R_PPC_REL16DX_HA): New reloction.
	* ppc64.h (R_PPC64_REL16DX_HA): Likewise.

bfd/
	* elf32-ppc.c (ppc_elf_howto_raw): Add R_PPC_REL16DX_HA.
	(ppc_elf_reloc_type_lookup): Handle R_PPC_REL16DX_HA.
	(ppc_elf_addr16_ha_reloc): Likewise.
	(ppc_elf_check_relocs): Likewise.
	(ppc_elf_relocate_section): Likewise.
	(is_insn_dq_form): Handle lxv and stxv instructions.
	* elf64-ppc.c (ppc64_elf_howto_raw): Add R_PPC64_REL16DX_HA.
	(ppc64_elf_reloc_type_lookup): Handle R_PPC64_REL16DX_HA.
	(ppc64_elf_ha_reloc): Likewise.
	(ppc64_elf_check_relocs): Likewise.
	(ppc64_elf_relocate_section): Likewise.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Likewise.
	* reloc.c (BFD_RELOC_PPC_REL16DX_HA): New.

elfcpp/
	* powerpc.h (R_POWERPC_REL16DX_HA): Define.

gas/
	* doc/as.texinfo (Target PowerPC): Document -mpower9 and -mpwr9.
	* doc/c-ppc.texi (PowerPC-Opts):  Likewise.
	* config/tc-ppc.c (md_show_usage): Likewise.
	(md_assemble): Handle BFD_RELOC_PPC_REL16DX_HA.
	(md_apply_fix): Likewise.
	(ppc_handle_align): Handle power9's group ending nop.

gas/testsuite/
	* gas/ppc/altivec3.s: New test.
	* gas/ppc/altivec3.d: Likewise.
	* gas/ppc/vsx3.s: Likewise.
	* gas/ppc/vsx3.d: Likewise.
	* gas/ppc/power9.s: Likewise.
	* gas/ppc/power9.d: Likewise.
	* gas/ppc/ppc.exp: Run them.
	* gas/ppc/power8.s <lxvx, lxvd2x, stxvx, stxvd2x>: Add new tests.
	* gas/ppc/power8.d: Likewise.
	* gas/ppc/vsx.s: <lxvx, stxvx>: Rename invalid mnemonics ...
	<lxvd2x, stxvd2x>: ...to this.
	* gas/ppc/vsx.d: Likewise.

gold/
	* gold/powerpc.cc (Powerpc_relocate_functions::addr16_dq): New function.
	(Powerpc_relocate_functions::addr16dx_ha): Likewise.
	(Target_powerpc::Scan::local): Handle R_POWERPC_REL16DX_HA.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.

ld/testsuite/
	* ld-powerpc/addpcis.d: New test.
	* ld-powerpc/addpcis.s: New test.
	* ld-powerpc/powerpc.exp: Run it.
2015-11-11 19:52:52 -06:00
Vladimir Radosavljevic cc203475bd Recognize .pdr debug sections.
gold/
	* layout.h (Layout::is_debug_info_section): Recognize .pdr debug
	sections.
2015-11-09 10:46:43 -08:00
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 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
Alan Modra c1e7d6a827 [GOLD] Regenerate POTFILES.in to add s390.cc
* po/POTFILES.in: Regenerate.
2015-11-03 22:51:30 +10:30
Nick Clifton 26f187cd16 Updated (simplified) Chinese translations for ld, bfd, binutils and gold.
* po/zh_CN.po: Updated (simplified) Chinese translation.
2015-10-30 12:50:27 +00:00
H.J. Lu 41e83f2b16 Make GOT entry size target-dependent
The GOT entry size is target-dependent.  This patch adds a got_entry_size
function to Sized_target class so that a target can provide a value
different from default.

	PR gold/19184
	* incremental.cc (Got_plt_view_info): Add got_entry_size.
	(Local_got_offset_visitor::visit): Replace got_entry_size_
	with info_.got_entry_size.
	(Local_got_offset_visitor::got_entry_size_): Removed.
	(Global_got_offset_visitor::visit): Replace got_entry_size_
	with info_.got_entry_size.
	(Global_got_offset_visitor::got_entry_size_): Removed.
	(Output_section_incremental_inputs::write_got_plt): Initialize
	view_info.got_entry_size.
	* target.h (Sized_target::got_entry_size): New virtual function.
	* x86_64.cc (Target_x86_64::got_entry_size): New function.
2015-10-29 09:26:41 -07:00
Marcin Kościelnicki 238830c697 Add __attribute__((__aligned__(1))) to unaligned symbols from scripts (for s390).
gold/
	* testsuite/binary_test.cc: Add __attribute__((aligned(1))).
	* testsuite/script_test_12a.c: Likewise.
	* testsuite/script_test_1a.cc: Likewise.
	* testsuite/script_test_2.cc: Likewise.
2015-10-28 16:49:13 -07:00
Marcin Kościelnicki bd890911da Make debug_msg.sh more open-minded about line numbers (needed for s390).
gold/
	* testsuite/debug_msg.sh: Accept more fuzz in line numbers.
2015-10-28 16:48:46 -07:00
Marcin Kościelnicki a817ff49c3 Fix empty string alignment in .rodata.str*
gold/
	PR gold/18959
	* stringpool.cc (Stringpool_template::new_key_offset): Align all
	strings, even zero-length.
	(Stringpool_template::set_string_offsets):
2015-10-28 16:48:16 -07:00
Marcin Kościelnicki e79a4bad70 Add s390 backend.
elfcpp/
	* s390.h: New file.

gold/
	* s390.cc: New file.
	* Makefile.am (TARGETSOURCES): Add s390.cc.
	(ALL_TARGETOBJS): Add s390.o.
	* Makefile.in: Regenerate.
	* configure.ac: Add s390 support.
	* configure: Regenerate.
	* configure.tgt: Add s390-*-* and s390x-*-*.
	* testsuite/icf_safe_test.sh (arch_specific_safe_fold): Add s390
	support.
2015-10-28 16:47:27 -07:00
Marcin Kościelnicki 6f97897dbe Add 64-bit archive support.
gold/
	* archive.cc (Archive::sym64name): New const.
	(Archive::setup): Add support for SYM64 armap.
	(Archive::read_armap): Likewise.
	(Archive::interpret_header): Likewise.
	(Archive::const_iterator::read_next_header): Likewise.
	* archive.h (Archive::sym64name): New const.
	(Archive::read_armap): Add mapsize template parameter.
2015-10-28 16:46:07 -07: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
H.J. Lu 3043c1aba1 Check R_386_GOT32/R_386_GOT32X without base register
The R_386_GOT32 and R_386_GOT32X relocations may be used without base
register:

	movl	bar@GOT, %eax

Its calculation is G + A, instead of G + A - GOT, and it can only used
to generate non-PIC executable.  Include the .got.plt section address
for R_386_GOT32 and R_386_GOT32X relocations without base register.
Don't allow R_386_GOT32 and R_386_GOT32X relocations without base
register when making a PIC output.

	PR gold/19177
	* i386.cc (Target_i386::Relocate::relocate): Check R_386_GOT32
	and R_386_GOT32X relocations without base register.
2015-10-28 09:15:40 -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
H.J. Lu 2891b49104 Gold: Don't fail on R_X86_64_[REX_]GOTPCRELX relocations
This patch updates gold to treat the R_X86_64_GOTPCRELX and
R_X86_64_REX_GOTPCRELX relocations proposed in

https://groups.google.com/forum/#!topic/x86-64-abi/n9AWHogmVY0

the same as R_X86_64_GOTPCREL.  FIXME: Gold should perform the
transformations as suggested.

elfcpp/

	* x86_64.h (R_X86_64_GOTPCRELX): New.
	(R_X86_64_REX_GOTPCRELX): Likewise.

gold/

	* x86_64.cc (Target_x86_64<size>::Scan::get_reference_flags):
	Treat R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX the same
	as R_X86_64_GOTPCREL.
	(Target_x86_64<size>::Scan::local): Likewise.
	(Target_x86_64<size>::Scan::possible_function_pointer_reloc):
	Likewise.
	(Target_x86_64<size>::Scan::global): Likewise.
	(Target_x86_64<size>::Relocate::relocate): Likewise.
	(Target_x86_64<size>::Relocatable_size_for_reloc::get_size_for_reloc):
	Likewise.
2015-10-22 04:56:57 -07:00
H.J. Lu 493d4b48de Gold: Don't fail on R_386_GOT32X relocation
This patch updates gold to treat the R_386_GOT32X relocation proposed in

https://groups.google.com/forum/#!topic/ia32-abi/GbJJskkid4I

the same as R_386_GOT32.  FIXME: Gold should perform the transformations
as suggested.

elfcpp/

	* i386.h (R_386_GOT32X): New.

gold/

	* i386.cc (Target_i386::Scan::get_reference_flags(): Treat
	R_386_GOT32X the same as R_386_GOT32.
	(Target_i386::Scan::local): Likewise.
	(Target_i386::Scan::possible_function_pointer_reloc): Likewise.
	(Target_i386::Scan::global): Likewise.
	(Target_i386::Relocate::relocate): Likewise.
	(Target_i386::Relocatable_size_for_reloc::get_size_for_reloc):
	Likewise.
2015-10-22 04:56:49 -07:00
H.J. Lu 0fd153457c Feed right input object to x86_64_mov_to_lea1[12]
x86_64_mov_to_lea1.o is a 64-bit x86-64 object and x86_64_mov_to_lea2.o
is a 32-bit x86-64 object.  x86_64_mov_to_lea11 should use
x86_64_mov_to_lea2.o and x86_64_mov_to_lea12 should use
x86_64_mov_to_lea1.o.

	* testsuite/Makefile.am (x86_64_mov_to_lea11): Replace
	x86_64_mov_to_lea1.o with x86_64_mov_to_lea2.o.
	(x86_64_mov_to_lea12): Replace x86_64_mov_to_lea2.o with
	x86_64_mov_to_lea1.o.
	* testsuite/Makefile.in: Regenerated.
2015-10-20 10:46:47 -07: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
H.J. Lu 01f573ad8a Add EM_IAMCU support to gold
elfcpp/

	PR gold/19118
	* elfcpp.h (EM): Add EM_IAMCU.

gold/

	PR gold/19118
	* i386.cc (Target_iamcu): New class.
	(Target_selector_iamcu): Likewise.
	(Target_iamcu::iamcu_info): New variable.
	(target_selector_iamcu): Likewise.
2015-10-13 09:02: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
Cary Coutant 9eacb935ac Fix bug when applying R_SPARC_GOTDATA_OP* relocations to local symbols.
When applying a GOTDATA_OP* relocation to a local symbol, the addend
is being applied after getting the value of the symbol. When the
relocation refers to a merge section, however, the addend must be
provided when computing the symbol value, since the contents of
the section may have been rearranged.

gold/
	PR gold/18855
	* sparc.cc (Sparc_relocate_functions::gdop_hix22): Remove addend
	parameter.
	(Sparc_relocate_functions::gdop_lox10): Likewise.
	(Target_sparc::Relocate::relocate): Use addend when computing
	symbol value for R_SPARC_GOTDATA_OP*.
2015-10-06 14:44:10 -07:00
Cary Coutant 3d4fde6974 Fix internal error caused by IFUNC patch.
The previous commit to fix PR gold/18886 converted STT_IFUNC
to STT_FUNC when resolving to a symbol defined in a shared library.
This leads to an internal error if the shared library symbol is
seen first, as we do not convert the symbol at all.

We need to override the STT_IFUNC in add_from_dynobj() instead of
in override_base().

gold/
	PR gold/18930
	PR gold/18886
	* resolve.cc (Symbol::override_base): Don't convert IFUNC symbols here.
	* symtab.cc (Symbol_table::add_from_dynobj): Convert them here instead.
2015-09-07 09:44:11 -07:00
H.J. Lu 358de98820 Turn IFUNC symbols from shared libraries into normal FUNC symbols
Turn IFUNC symbols from shared libraries into normal FUNC symbols when
we are resolving symbol references, instead of when we are writing out
the symbol table.

	PR gold/18886
	* resolve.cc (Symbol::override_base): Turn IFUNC symbols from
	shared libraries into normal FUNC symbols.
	* symtab.cc (Symbol_table::sized_write_symbol): Assert IFUNC
	symbols aren't from shared libraries.
2015-09-02 04:17:43 -07:00
Alan Modra d49044c753 [GOLD] ppc64 out-of-line register save/restore functions
Gold version of a4b6fadd.  Don't emit long branch or plt branch stubs
to save/restore functions.  Copy them instead.

	PR 18878
	* powerpc.cc (Target_powerpc): Add savres_section_ and accessor.
	(Target_powerpc::Branch_info::make_stub): Determine whether long
	branch stub is for save/restore function.
	(Branch_stub_ent): Add save_res_, and extra parm to constructor.
	(Stub_table): Add need_save_res_.
	(Stub_table:clear_stubs): Clear need_save_res_.
	(Stub_table:set_address_and_size): Add save/restore section size.
	(Stub_table::add_long_branch_entry): Add save_res param.  Set
	need_save_res_, but don't add space for save/restore stubs.
	(Stub_table::find_long_branch_entry): Return offset to local copy
	of save/restore func.
	(Stub_table::do_write): Don't output save/restore stubs.  Instead
	copy the save/restore functions.
	(Output_data_save_res:contents): New accessor.
	(Target_powerpc::define_save_restore_funcs): Set savres_section_.
2015-09-02 16:07:02 +09:30
Cary Coutant 7c61d651fd Fix problem where script specified both address and region for a section.
If a script specifies both address and region for an output section
declaration, gold ignores the region specification. This can lead to
bogus "moves backward" errors. This patch fixes gold so that if a
section specifies both address and region, it will place the section
at the specified address in the region, and update the location counter
within the region.

gold/
	PR gold/18847
	* script-sections.cc (Memory_region::set_address): New method.
	(Script_sections::find_memory_region): Add explicit_only parameter.
	(Output_section_definition::set_section_addresses): Handle case where
	script specifies both address and vma region.
	* script-sections.h (Script_sections::find_memory_region): Add
	explicit_only parameter.
2015-08-26 00:03:04 -07:00
Cary Coutant 4bfacfd359 Fix --no-as-needed when shared library is listed twice on the command line.
When a shared library is listed twice on the command line, the linker
ignores the second mention. If the first mention is in the scope of
an --as-needed option, and the second one is under the scope of a
--no-as-needed option, the --no-as-needed should take effect, but
doesn't.  This patch keeps track of the objects we've already seen,
and updates the --as-needed flag so that if a shared object is ever
seen with --no-as-needed, it will be marked as such.

gold/
	PR gold/18859
	* object.cc (Input_objects::add_object): Store objects in a map,
	indexed by soname; update as-needed flag when necessary.
	* object.h (Object::clear_as_needed): New method.
	(Input_objects::so_names_): Change from set to map.
2015-08-25 18:39:20 -07:00
Cary Coutant 1757d35c8a Fix internal error in gold when script uses section address in assignment.
When processing assignment expressions in a linker script, gold processes
absolute assignments early, but when one of those assignments involves the
address of a section that has not yet been finalized, we get an internal
error in address. This patch fixes the problem by gracefully returning
from expression evaluation even if the address is not yet valid, and
deferring the assignment in such a case.

gold/
	PR gold/14746
	* expression.cc (Expression::Expression_eval_info): Add
	is_valid_pointer field.
	(Expression::eval_maybe_dot): Add is_valid_pointer parameter.
	Adjust all callers.
	(Addr_expression::value_from_output_section): Check whether address
	is valid.
	* script.cc (Symbol_assignment::set_if_absolute): Defer assignment
	if evaluation failed due to address that is not yet valid.
	* script.h: (Expression::eval_maybe_dot): Add is_valid_pointer
	parameter.
2015-08-25 18:11:19 -07:00
Cary Coutant 3ac0a36c29 Fix regression introduced by fix for PR 18703.
When a user object overrides a versioned definition in a shared object,
it's possible to trigger an internal error because the versioned
definition we saw didn't override the unversioned definition. This
was introduced by the fix for PR 18703. This patch fixes the problem
by reordering the tests so that we do not check ret->is_default()
until we're confident that the symbol is in fact versioned.

gold/
	PR gold/18866
	PR gold/18703
	* symtab.cc (Symbol_table): Reorder conditions to avoid internal error.
2015-08-25 17:53:53 -07:00
Alan Modra 9215b98bb2 gold --emit-relocs
A symbol value in an ELF final linked binary is absolute, in contrast
to a relocatable object file where the value is section relative.  For
--emit-relocs it is therefore incorrect to use the value of a section
symbol as the addend when adjusting relocs against input section
symbols to output section symbols.

	PR gold/18846
	* target-reloc.h (relocate_relocs <RELOC_ADJUST_FOR_SECTION_RELA>):
	Subtract os->address() from addend.
	* powerpc.cc (relocate_relocs): Likewise.
2015-08-20 12:02:45 +09:30
Simon Dardis 40fc1451c6 [MIPS] Map 'move' to 'or'.
The MIPS assembly idiom 'move' now maps to the 'or' machine instruction. This
change affects microMIPS, MIPS32, MIPS64.

2015-08-12  Simon Dardis  <simon.dardis@imgtec.com>

opcodes/

	* micromips-opc.c (micromips_opcodes): Re-order table so that move
	based on 'or' is first.
	* mips-opc.c (mips_builtin_opcodes): Ditto.

bfd/

	* elfxx-mips.c (STUB_MOVE): Change to use 'or' only.
	(mips_o32_exec_plt0_entry, mips_n32_exec_plt0_entry,
	mips_n64_exec_plt0_entry, micromips_insn32_o32_exec_plt0_entry):
	Update to use 'or' instead of 'addu/daddu'.
	(_bfd_mips_elf_finish_dynamic_symbol): Update usage of STUB_MOVE.
	(move_insns_32): Reorder table.

gas/

	* config/tc-mips.c (move_register): Change to use 'or' only.
	(s_cpload, s_cpsetup, s_cprestore, s_cpreturn): Update to
	use or for move.

gas/testsuite/

	* gas/mips/elf-rel23.d: Update test.
	* gas/mips/elf-rel23.d: Ditto.
	* gas/mips/elf-rel23a.d: Ditto.
	* gas/mips/elf-rel23b.d: Ditto.
	* gas/mips/elf_e_flags1.d: Ditto.
	* gas/mips/elf_e_flags2.d: Ditto.
	* gas/mips/elf_e_flags3.d: Ditto.
	* gas/mips/elf_e_flags4.d: Ditto.
	* gas/mips/loc-swap-dis.d: Ditto.
	* gas/mips/micromips-insn32.d: Ditto.
	* gas/mips/micromips-noinsn32.d: Ditto.
	* gas/mips/micromips-trap.d: Ditto.
	* gas/mips/micromips.d: Ditto.
	* gas/mips/mips-abi32-pic.d: Ditto.
	* gas/mips/mips-abi32.d: Ditto.
	* gas/mips/mips-gp32-fp32-pic.d: Ditto.
	* gas/mips/mips-gp32-fp32.d: Ditto.
	* gas/mips/mips-gp32-fp64-pic.d: Ditto.
	* gas/mips/mips-gp32-fp64.d: Ditto.
	* gas/mips/mips-gp64-fp32-pic.d: Ditto.
	* gas/mips/mips-gp64-fp32.d: Ditto.
	* gas/mips/mips-gp64-fp64-pic.d: Ditto.
	* gas/mips/mips-gp64-fp64.d: Ditto.
	* gas/mips/mipsr6@loc-swap-dis.d: Ditto.
	* gas/mips/tls-o32.d: Ditto.
	* gas/mips/uld2-eb.d: Ditto.
	* gas/mips/uld2-el.d: Ditto.
	* gas/mips/ulw2-eb-ilocks.d: Ditto.
	* gas/mips/ulw2-eb.d: Ditto.
	* gas/mips/ulw2-el-ilocks.d: Ditto.
	* gas/mips/ulw2-el.d: Ditto.
	* gas/mips/move.d: New test.
	* gas/mips/move.s: Ditto.
	* gas/mips/micromips32-move.d: Ditto.
	* gas/mips/micromips32-move.s: Ditto.
	* gas/mips/mips.exp: Run the new tests.

gold/

	* mips.cc (plt0_entry_o32, plt0_entry_n32, plt0_entry_n64,
	lazy_stub_normal_1, lazy_stub_normal_1_n64,
	lazy_stub_normal_2, lazy_stub_normal_2_n64, lazy_stub_big,
	lazy_stub_big_n64, lazy_stub_micromips32_normal_1_n64,
	lazy_stub_micromips32_normal_2_n64, lazy_stub_micromips32_big,
	lazy_stub_micromips32_big_n64): Update to use 'or' for move instead
	of 'addu/daddu'.

ld/testsuite/

	* ld-mips-elf/compressed-plt-1-n32-mips16.od: Update test.
	* ld-mips-elf/compressed-plt-1-n32-umips.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-mips16-got.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-mips16-only.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-mips16-word.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-mips16.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-se.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-umips-got.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-umips-word.od: Ditto.
	* ld-mips-elf/compressed-plt-1-o32-umips.od: Ditto.
	* ld-mips-elf/jalx-2.dd: Ditto.
	* ld-mips-elf/mips16-pic-3.dd: Ditto.
	* ld-mips-elf/pic-and-nonpic-3a.dd: Ditto.
	* ld-mips-elf/pic-and-nonpic-3b.dd: Ditto.
	* ld-mips-elf/pic-and-nonpic-5b.dd: Ditto.
	* ld-mips-elf/pic-and-nonpic-6-n32.dd: Ditto.
	* ld-mips-elf/pic-and-nonpic-6-o32.dd: Ditto.
	* ld-mips-elf/stub-dynsym-1-10000.d: Ditto.
	* ld-mips-elf/stub-dynsym-1-2fe80.d: Ditto.
	* ld-mips-elf/stub-dynsym-1-7fff.d: Ditto.
	* ld-mips-elf/stub-dynsym-1-8000.d: Ditto.
	* ld-mips-elf/stub-dynsym-1-fff0.d: Ditto.
	* ld-mips-elf/tlsbin-o32.d: Ditto.
	* ld-mips-elf/tlsdyn-o32-1.d: Ditto.
	* ld-mips-elf/tlsdyn-o32-2.d: Ditto.
	* ld-mips-elf/tlsdyn-o32-3.d: Ditto.
	* ld-mips-elf/tlsdyn-o32.d: Ditto.
	* ld-mips-elf/tlslib-o32.d: Ditto.
2015-08-12 17:10:22 +01:00
H.J. Lu 37a42ee9ad Regenerate configure files
bfd/

	* configure: Regenerated.

binutils/

	* configure: Regenerated.

gas/

	* configure: Regenerated.

gold/

	* configure: Regenerated.

gprof/

	* configure: Regenerated.

ld/

	* configure: Regenerated.

opcodes/

	* configure: Regenerated.
2015-07-27 07:56:32 -07:00
Doug Kwan ab3b14b04b Make arm_unaligned_reloc test less sensitive to disassembler output format. 2015-07-26 00:54:26 -07:00
H.J. Lu 72f4393d8c Remove leading/trailing white spaces in ChangeLog 2015-07-24 04:16:47 -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 5b2af7dd40 Don't compare symbol addresses directly
GCC 5 will fold symbol address comparison, assuming each symbol has a
different address, which leads to abort.  We should use separate
functions to compare symbol address.

	PR gold/18663
	* testsuite/Makefile.am (script_test_1_SOURCES): Set to
	script_test_1a.cc script_test_1b.cc.
	(script_test_11_r.o): Replace script_test_11.o with
	script_test_11a.o script_test_11b.o.
	(script_test_11.o): Removed.
	(script_test_11a.o): New.
	(script_test_11b.o): Likewise.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/script_test_1.h: New file.
	* testsuite/script_test_1b.cc: Likewise.
	* testsuite/script_test_11.h: Likewise.
	* testsuite/script_test_11b.c: Likewise.
	* testsuite/script_test_1.cc: Renamed to ...
	* testsuite/script_test_1a.cc: This.
	Include "script_test_1.h".
	(main): Call check_int and check_ptr.
	* testsuite/script_test_11.c: Renamed to ...
	* testsuite/script_test_11a.c: This.
	Include "script_test_11.h".
	(main): Call ptr_equal.
2015-07-22 03:38:00 -07:00
H.J. Lu cd78ea777c Mark global with hidden attribute
GCC 5 will generate a relocation for protected symbol:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

when compiling for a shared library.  It is undefined to access protected
symbol in IFUNC selector function inside a shared library.

	PR gold/18628
	* testsuite/ifuncdep2.c (global): Change protected to hidden.
	* testsuite/ifuncmod1.c (global): Likewise.
	* testsuite/ifuncmod5.c (global): Likewise.
2015-07-22 03:37:50 -07: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
Cary Coutant 5417c94d1a Fix problem where __start_ and __stop_ section symbols do not honor version script.
When creating the special __start_ and __stop_ section symbols, gold
does not check the version script to see if they should be local
instead of global.

2015-07-21  Cary Coutant  <ccoutant@gmail.com>

gold/
	PR gold/18548
	* symtab.cc (Symbol_table::do_define_in_output_data): Check for
	forced local symbol even when oldsym != NULL.
	(Symbol_table::do_define_in_output_segment): Likewise.
	(Symbol_table::do_define_as_constant): Likewise.
2015-07-21 16:10:05 -07:00
Cary Coutant b8c6c5ef99 Fix typo in PR number.
Fix internal error when linking an archive library with no preceding objects.

    gold/
	PR gold/18698
	* archive.cc (Library_base::should_include_member): Don't use entry
	point for relocatable links, or if target is not yet valid.
	* parameters.cc (Parameters::entry): Check target_valid().
2015-07-21 12:50:45 -07:00
Cary Coutant cb5cf5e26e Fix internal error when linking an archive library with no preceding objects.
gold/
	PR gold/18696
	* archive.cc (Library_base::should_include_member): Don't use entry
	point for relocatable links, or if target is not yet valid.
	* parameters.cc (Parameters::entry): Check target_valid().
2015-07-21 12:42:07 -07:00
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 2bca03770d Properly set arm-specific elf flags wrt hardfp.
gold/ChangeLog:
	* arm.cc (Target_arm::do_adjust_elf_header): Set flags into view.
2015-07-20 11:50:10 -07:00
H.J. Lu f54f5e31ce Clear SHF_COMPRESSED flag bit from input to output
For relocatable link, we should clear the SHF_COMPRESSED flag bit from
input group section.

	PR gold/18689
	* layout.cc (Layout::layout): Clear the SHF_COMPRESSED flag bit
	from input group section for relocatable link.
	* testsuite/Makefile.am (check_SCRIPTS): Add pr18689.sh.
	(check_DATA): Add pr18689.stdout.
	(MOSTLYCLEANFILES): Add pr18689a.o pr18689b.o.
	(pr18689.stdout): New rule.
	(pr18689a.o): Likewise.
	(pr18689b.o): Likewise.
	(pr18689.o): Likewise.
	* testsuite/pr18689.c: New file.
	* testsuite/pr18689.sh: Likewise.
	* testsuite/Makefile.in: Regenerated.
2015-07-20 10:14:35 -07:00
Yiran Wang c20ceeb226 Remove warning about references from shared objects to hidden symbols.
gold/
	PR gold/15574
	* resolve.cc (Symbol_table): Remove warning about references
	from shared objects to hidden symbols.
	* testsuite/Makefile.am (hidden_test): Add hidden_test.syms.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/hidden_test.sh: Check dynamic symbol table; update
	expected error messages.
2015-07-20 09:19:02 -07:00
H.J. Lu 19a7fe52ae Make default compression gABI compliant
All programs in binutils+gdb git repo now support gABI compression
with the SHF_COMPRESSED bit.  This patch makes the zlib-gabi option
as compression default for gas, gold, ld and objcopy, instead of the
zlib-gnu option whose outputs are incompatible with gABI.

binutils/

	* objcopy.c (copy_file): Set BFD_COMPRESS_GABI if not
	zlib-gnu.
	* doc/binutils.texi: Change --compress-debug-sections and
	--compress-debug-sections=zlib to zlib-gabi.

binutils/testsuite/

	* binutils-all/compress.exp: Update.

gas/

	* as.c (parse_args): Make --compress-debug-sections and
	--compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* doc/as.texinfo: Change --compress-debug-sections and
	--compress-debug-sections=zlib to zlib-gabi.

gold/

	* compressed_output.cc (Output_compressed_section::set_final_data_size):
	Make --compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* testsuite/Makefile.am (flagstest_compress_debug_sections.check):
	Expect ".debug_.*" with the SHF_COMPRESSED bit, instead of
	".zdebug_".
	* testsuite/Makefile.in: Regenerated.

ld/

	* emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Make
	--compress-debug-sections=zlib the same as
	--compress-debug-sections=zlib-gabi.
	* ld.texinfo: Change --compress-debug-sections=zlib to zlib-gabi.

ld/testsuite/

	* ld-elf/zlibbegin.rS: Updated to .debug_.* with the
	SHF_COMPRESSED bit.
	* ld-elf/zlibnormal.rS: Likewise.
2015-07-14 10:26:23 -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
H.J. Lu 480586639d Add SHF_COMPRESSED section decompression to gold
This patch adds SHF_COMPRESSED section decompression to gold.

	PR gold/18321
	* compressed_output.h (decompress_input_section): Add arguments
	for ELF class, big endian and sh_flags.
	* compressed_output.cc (decompress_input_section): Likewise.
	Support the SHF_COMPRESSED section.
	* dynobj.h (Dynobj): Add elfsize and is_big_endian member
	functions.
	* plugin.h (Pluginobj): Likewise.
	* layout.cc (Layout::get_output_section_flags): Also clear the
	SHF_COMPRESSED bit.
	* object.h (Compressed_section_info): Add flag to store sh_flags.
	(Object): Add pure virtual elfsize and is_big_endian member
	functions.
	* object.cc (need_decompressed_section): Don't skip the ".zdebug"
	prefix here.
	(build_compressed_section_map): Check SHF_COMPRESSED for
	uncompressed size.  Store sh_flags in Compressed_section_info.
	Pass size, big_endian and sh_flags to decompress_input_section.
	Skip the ".debug"/".zdebug" prefix when passing section name to
	need_decompressed_section.
	(Sized_relobj_file<size, big_endian>::do_find_special_section):
	Don't check ".zdebug_*" sections.
	(Object::decompressed_section_contents): Pass ELF class, big
	endian and sh_flags to decompress_input_section.
	* reloc.cc (Sized_relobj_file<size, big_endian>::write_sections):
	Likewise.
	* testsuite/Makefile.am (check_DATA): Add
	debug_msg_cdebug_gabi.err and gdb_index_test_2_gabi.stdout.
	(MOSTLYCLEANFILES): Add debug_msg_cdebug_gabi.err and
	gdb_index_test_2_gabi.stdout.
	(debug_msg_cdebug_gabi.o): New.
	(odr_violation1_cdebug_gabi.o): Likewise.
	(odr_violation2_cdebug_gabi.o): Likewise.
	(debug_msg_cdebug_gabi.err): Likewise.
	(check_SCRIPTS): Add gdb_index_test_2_gabi.sh.
	(gdb_index_test_cdebug_gabi.o): Likewise.
	(gdb_index_test_2_gabi): Likewise.
	(gdb_index_test_2_gabi.stdout): Likewise.
	* testsuite/gdb_index_test_2_gabi.sh: New file.
	* testsuite/Makefile.in: Regenerated.
2015-07-12 10:50:40 -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
Doug Kwan 15162befa3 Align text section ends so that stub tables appears at expected addresses. 2015-07-06 15:02:40 -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
Cary Coutant dd68f8fa8e Fix bug where SECTIONS clause does not handle compressed debug sections.
When laying out .debug_* sections, we translate the names of compressed
debug sections that start with ".zdebug", but when processing input
section specs in a linker script, we do not handle the translation there.
This results in an internal error as reported in PR 17731.

gold/
	PR gold/17731
	* layout.cc (corresponding_uncompressed_section_name): New function.
	(Layout::choose_output_section): Call it.
	* layout.h (corresponding_uncompressed_section_name): New function.
	* script-sections.cc (Input_section_info::set_section_name): Check
	for compressed debug section (.zdebug style).
2015-06-11 13:21:10 -07:00
Jing Yu a3a0c39166 Fix broken gold/testsuite/script_test_12 in some setup.
This patch adds -O0 to gold script_test_12 test, hoping that compiler
won't change the order of globel variables that the test assumes.

Changelog:
	testsuite/Makefile.am: Add -O0 to compile script_test_12 test.
	testsuite/Makefile.in: Regenerate.
2015-06-11 12:52:07 -07:00
Davide Italiano 970cdef261 [GOLD] Fix handling of __start/__stop symbols
If the section contains 'Q' in the name, is_cident() returns false,
__start and __stop symbols for the section are not generated..

	* gold.h (is_cident): Correct typo.
2015-06-11 14:36:05 +09:30
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
Nick Clifton 1e1b2efc46 Update French Translations for LD and GOLD.
ld	* po/fr.po: Updated French Translation.
gold	* po/fr.po: New French Translation.
2015-06-08 15:04:17 +01:00
Cary Coutant b8cf50755b Fix incorrect handling of STT_COMMON symbols in shared libraries.
The gABI allows STT_COMMON symbols to appear in executables and shared
objects, so that the dynamic loader can resolve commons across modules.
When reading a shared object, however, an STT_COMMON symbol should be
treated as a regular definition at link time.

In a relocatable object, the gABI requires that any STT_COMMON symbols
must also be defined in the special SHN_COMMON section (which we extend
to include target-specific small and large common sections). Thus,
there is no need for gold to treat STT_COMMON symbols as common unless
the st_shndx field is also set to a common section.

gold/
	PR gold/18288
	* resolve.cc (symbol_to_bits): Remove type parameter; adjust all
	callers. Don't use STT_COMMON to check for common symbols.
	(Symbol_table::resolve): Warn if relocatable object has STT_COMMON
	symbol that's not in a common section.
	* symtab.h (Symbol::is_common): Don't use STT_COMMON to check for
	common symbols.
2015-06-07 14:03:52 -07:00
Cary Coutant bdd2d2b7e6 Add diststuff target to Makefile.
gold/
	PR gold/18200
	* Makefile.am (diststuff): Add target.
	* Makefile.in: Regenerate.
2015-06-04 22:58:39 -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
Cary Coutant 8086551f52 Fix SIZEOF_HEADERS in gold.
Gold undercounts the number of program headers it's going to add when
initially evaluating the SIZEOF_HEADERS expression. As a result, scripts
that use it end up skipping a page unnecessarily when the starting address
is too low. The undercounting is because it doesn't count the PT_INTERP
segment.

Then, when finalizing symbols, gold overcounts the program headers: all
segments have already been created, but we still count the headers we
expected to add from the script.

This patch fixes both problems.

gold/
	* script-sections.cc (Script_sections::Script_sections): Initialize
	segments_created_.
	(Script_sections::create_note_and_tls_segments): Set flag when
	segments are created.
	(Script_sections::expected_segment_count): Count PT_INTERP.
	(Script_sections::attach_sections_using_phdrs_clause): Set flag when
	segments are created.
	* script-sections.h (Script_sections::segments_created_): New data
	member.
2015-06-03 20:30:11 -07:00