Commit Graph

469 Commits

Author SHA1 Message Date
Igor Kudrin cefdd1cd64 Fix bad offset calculation for R_AARCH64_TLSDESC_* relocs.
If a custom linker script with an unexpected relative layout of .got
and .got.plt sections was used, gold might produce a wrong offset
when applying R_AARCH64_TLSDESC_* relocations.
This patch fixes the issue by calculating "got_tlsdesc_offset"
in a more direct way.

gold/
	* aarch64.cc (Target_aarch64::Relocate::relocate_tls):
	Make got_tlsdesc_offset signed and fix its calculation.
	* testsuite/Makefile.am (aarch64_tlsdesc): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/aarch64_tlsdesc.s: New test source file.
	* testsuite/aarch64_tlsdesc.sh: New test script.
	* testsuite/aarch64_tlsdesc.t: New test linker script.
2017-08-28 08:03:00 -07:00
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
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
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
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 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 2571583aed Update year range in copyright notice of all files. 2017-01-02 14:08:56 +10:30
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 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 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
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 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
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
Alan Modra efe4db3f06 Fix gold/testsuite/file_in_many_sections_test.sh file mode
chmod a+x
2016-12-06 07:56:12 +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
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
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
Doug Kwan bc99685c73 Handle ARM-specific --target1-abs, --target1-rel and --target2 options 2016-09-02 15:51:59 -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
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
Alan Modra 23fcf59aeb Fix aarch64_relocs.sh file mode 2016-07-27 16:26:42 +09:30
Han Shen 8769bc4bab [Gold, aarch64] Implement some AArch64 relocs.
This CL implemented the following relocs for AArch64 target.
  - R_AARCH64_MOVW_UABS_G*
  - R_AARCH64_MOVW_SABS_G* relocations

gold/ChangeLog

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

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

gold/
	* aarch64-reloc.def (NONE): New relocation.
	* aarch64.cc (Target_aarch64::Scan::local): Handle R_AARCH64_NONE.
	(Target_aarch64::Scan::global): Likewise.
	* testsuite/Makefile.am (aarch64_reloc_none): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/aarch64_reloc_none.s: New test source file.
	* testsuite/aarch64_reloc_none.sh: New test script.
2016-06-28 15:50:29 -07:00
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 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
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
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
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
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 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
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