Commit Graph

327 Commits

Author SHA1 Message Date
H.J. Lu
8c16443418 gold: Compile common tests with -fcommon
Since GCC 10 defaults to -fno-common, add -fcommon to common tests to
force common behavior.

	PR gold/25904
	* testsuite/Makefile.am (COMMON_TEST_C_CFLAGS): New.
	(common_test_1.o): New rule.
	(common_test_2.o): Likewise.
	(common_test_3.o): Likewise.
	(plugin_common_test_1.o): Likewise.
	(plugin_common_test_2.o): Likewise.
	(common_test_1_v1.o): Likewise.
	(common_test_1_v2.o): Likewise.
	(common_test_2_pic.o): Compile with $(COMMON_TEST_C_CFLAGS).
	(common_test_3_pic.o): Likewise.
	* testsuite/Makefile.in: Regenerated.
2020-05-02 06:48:26 -07:00
H.J. Lu
ccf20d460f gold: x86-64: Fix TLSDESC relaxation for x32
X32 TLSDESC sequences can be:

40 8d 05 00 00 00 00	rex lea	foo@TLSDESC(%rip), %reg
...
67 ff 10		call	*foo@TLSCALL(%eax)

or the same sequence as LP64:

48 8d 05 00 00 00 00	lea	foo@TLSDESC(%rip), %reg
...
ff 10			call	*foo@TLSCALL(%rax)

We need to support both sequences for x32.  For both GDesc -> IE/LE
transitions,

67 ff 10		call	*foo@TLSCALL(%eax)

should relaxed to

0f 1f 00		nopl	(%rax)

For GDesc -> LE transition,

40 8d 05 00 00 00 00	rex lea	foo@TLSDESC(%rip), %reg

should relaxed to

40 c7 c0 fc ff ff ff	rex movl $foo@tpoff, %reg

For GDesc -> IE transition,

40 8d 05 00 00 00 00	rex lea	foo@TLSDESC(%rip), %reg

should relaxed to

40 8b 05 00 00 00 00	rex movl foo@gottpoff(%rip), %eax

	PR gold/25426
	* x86_64.cc (Target_x86_64<size>::Relocate::tls_desc_gd_to_ie):
	For x32, relax "rex leal foo@tlsdesc(%rip), %reg" to
	"rex movl foo@gottpoff(%rip), %eax" and relax ""call *(%eax)"
	to "nopl (%rax)".
	(Target_x86_64<size>::Relocate::tls_desc_gd_to_le): For x32,
	relax "rex leal foo@tlsdesc(%rip), %reg" to
	"rex movl foo@tpoff, %eax" and relax "call *foo@tlscall(%eax)"
	to "nopl (%rax)".
	* testsuite/Makefile.am (tls_test_gnu2.o): Depend on
	gcctestdir/as.
	(tls_test_file2_gnu2.o): Likewise.
	(tls_test_c_gnu2.o): Likewise.
	* testsuite/Makefile.in: Regenerated.
2020-05-01 10:11:23 -07:00
H.J. Lu
6d520e36de gold: x86-64: Fix TLSDESC -> LE relaxation
X86-64 TLSDESC sequences can be:

4c 8d 0d 00 00 00 00	leaq	foo@TLSDESC(%rip), %r9
4c 89 c8		movq	%r9, %rax
ff 10			call	*foo@TLSCALL(%rax)

TLSDESC -> LE relaxation can turn them into:

49 c7 c1 fc ff ff ff 	mov    $0xfffffffffffffffc,%r9
4c 89 c8             	mov    %r9,%rax
66 90                	xchg   %ax,%ax

We need to check and update the REX byte in this case.

	PR gold/25473
	* x86_64.cc (Target_x86_64<size>::Relocate::tls_desc_gd_to_ie):
	Properly check r8 - r15 in "lea foo@TLSDESC(%rip), %reg".
	(Target_x86_64<size>::Relocate::tls_desc_gd_to_le): Properly
	relax r8 - r15 in "lea foo@TLSDESC(%rip), %reg".
	* testsuite/Makefile.am (check_SCRIPTS): Add x86_64_gd_to_le.sh.
	(check_DATA): Add x86_64_gd_to_le.stdout.
	(MOSTLYCLEANFILES): Add x86_64_gd_to_le.
	(x86_64_gd_to_le.o): New target.
	(x86_64_gd_to_le): Likewise.
	(x86_64_gd_to_le.stdout): Likewise.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/x86_64_gd_to_le.s: New file.
	* testsuite/x86_64_gd_to_le.sh: Likewise.
2020-05-01 10:08:48 -07:00
Joshua Oreman
e173ea00c2 Fix problem with ICF where diffs in EH frame info is ignored.
PR gold/21066
	* gc.h (gc_process_relocs): Track relocations in .eh_frame sections
	when ICF is enabled, even though the .eh_frame sections themselves
	are not foldable.
	* icf.cc (get_section_contents): Change arguments to permit operation
	on just part of a section. Include extra identity regions in the
	referring section's contents recursively.
	(match_sections): Lock object here instead of in get_section_contents
	so that get_section_contents can operate recursively.
	(Icf::add_ehframe_links): New method.
	(Icf::find_identical_sections): Pass .eh_frame sections to
	add_ehframe_links(). Increase default iteration count from 2 to 3
	because handling exception info typically requires one extra iteration.
	* icf.h (Icf::extra_identity_list_): New data member with accessor.
	(is_section_foldable_candidate): Include .gcc_except_table sections.
	* options.h: Update documentation for new default ICF iteration count.
	* testsuite/Makefile.am (icf_test_pr21066): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/icf_test_pr21066.cc: New source file.
	* testsuite/icf_test_pr21066.sh: New test script.
2019-05-11 07:27:10 +08:00
Egeyar Bagcioglu
7ae39e2d40 Check whether symbols with MOVW_.ABS relocations require PLT entries (aarch64).
2019-02-19  Egeyar Bagcioglu  <egeyar.bagcioglu@oracle.com>

gold/
     PR gold/23870
     * aarch64.cc (Target_aarch64::Scan::global): Check if a symbol with
     R_AARCH64_MOVW_.ABS_* relocations requires a PLT entry.
     * testsuite/Makefile.am: Add aarch64_pr23870 test case.
     * testsuite/Makefile.in: Regenerate.
     * testsuite/aarch64_pr23870_bar.c: New file.
     * testsuite/aarch64_pr23870_foo.c: New file.
     * testsuite/aarch64_pr23870_main.S: New file.
2019-02-19 16:13:24 -08:00
Alan Modra
a529dcc854 [GOLD] Tweak keep_text_section_prefix test for PowerPC64 ELFv1
This test checks code layout by function symbol ordering, but that
doesn't work on powerpc64 ELFv1 where the function symbol is on a
descriptor.  A simple work-around is to have nm emit synthetic symbols
marking the code entry point of functions.  Since the text segment is
laid out before the data segment, the synthetic symbols will have
lower addresses than function descriptor symbols and be seen first in
nm -n output.

On other targets, nm --synthetic typically emits symbols on plt
entries.  Since the testcase doesn't call any of the functions of
interest there shouldn't be plt entries for those functions, so there
should be no potentially confusing extra symbols.

	* testsuite/Makefile.am (keep_text_section_prefix_nm.stdout):
	Pass --synthetic to nm.
	* testsuite/Makefile.in: Regenerate.
2018-12-18 11:57:45 +10:30
Alan Modra
9b4e3a5e23 [GOLD] justsyms_exec test fail on powerpc64
This test fails on powerpc64le due to the justsyms_lib being built
with exported_data at 0x2010000, apparently due to the powerpc target
code generating an empty relro .branch_lt section.  Since the test
relies on the library having exported_data at 0x2000000, avoid the
problem by linking with -z norelro.  Also, the test doesn't need to
avoid checking the function symbol on powerpc elfv2.

	* testsuite/Makefile.am (justsyms_lib): Link with -z norelro.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/justsyms_exec.c (main): Do check exported_func
	on PowerPC64 ELFv2.
2018-11-26 22:07:46 +10:30
Alan Modra
5acaada745 Make gold testsuite work with CC and CXX specifying -B
The patch allows the gold testsuite to pass when using something like
the following configure line, which works for the rest of the binutils
testsuite.  At least, it does if you don't configure your gcc with any
of the options that force a particular path to as or ld.

gccdir="/home/alan/build/gcc/prev-"
gccsrc="/home/alan/src/gcc.git"
gcctarg="x86_64-linux"
CC="${gccdir}gcc/xgcc -B${gccdir}gcc/" \
CXX="${gccdir}gcc/xg++ -B${gccdir}gcc/ -I${gccdir}$gcctarg/libstdc++-v3/include -I${gccdir}$gcctarg/libstdc++-v3/include/$gcctarg -I${gccsrc}/libstdc++-v3/libsupc++ -L${gccdir}$gcctarg/libstdc++-v3/src/.libs/" \
~/src/binutils-gdb/configure ...

gold's -Bgcctestdir/ option must come before the -B supplied by $CC
or $CXX, in order to pick up the linker we want to test.  Also when
using a not-yet-installed gcc, it is necessary to provide a collect-ld
in gcctestdir/ as otherwise a collect-ld script in -B${gccdir}gcc/
will be used and the wrong linker tested.

Besides this, the patch fixes some bugs: The $COMPILE -D_FORTIFY_SOURCE
edit was wrong (but worked for usual values), and the $CXXLINK_S edit
unnecessarily but harmlessly used extra backslash quoting.  See
posix shell documentation regarding quoting, or
www.gnu.org/software/bash/manual/bashref.html#Command-Substitution

Also, -Bgcctestdir/ in one place makes it less likely a new test will
be added that accidentally lacks the option.

	* Makefile.am (gcctestdir1/ld): Use $@ and absolute paths.
	(gcctestdir1/collect-ld): New.
	(ld1_DEPENDENCIES): Add gcctestdir1/collect-ld.
	(ld1_LDFLAGS): Remove -Bgcctestdir1/.
	(editcc1, ld1_LINK): Define.
	(gcctestdir2/ld, gcctestdir2/collect-ld, ld2_DEPENDENCIES),
	(ld2_LDFLAGS, editcc2, ld2_LINK),
	(ld1_r_DEPENDENCIES, ld1_r_LDFLAGS, ld1_r_LINK),
	(gcctestdir2-r/ld, gcctestdir2-r/collect-ld, ld2_r_DEPENDENCIES),
	(ld2_r_LDFLAGS, editcc2r, ld2_r_LINK),
	(gcctestdir3/ld, gcctestdir3/collect-ld, ld3_DEPENDENCIES),
	(ld3_LDFLAGS, editcc3, ld3_LINK),
	(gcctestdir4/ld, gcctestdir4/collect-ld, ld4_DEPENDENCIES),
	(ld4_LDFLAGS, editcc4, ld4_LINK): Similarly.
	* Makefile.in: Regenerate.
	* testsuite/Makefile.am (editcc): Define sed command to put
	our -B option first.  Remove other occurrences of -Bgcctestdir/
	throughout file.
	(editcc1): Define for -D_FORTIFY_SOURCE stripping.
	(editcc2): Define for -static-libgcc/libstdc++ stripping.
	(LINK1, CXXLINK1): Don't use CCLD or CXXLD.
	(CCLD, CXXLD, COMPILE, LINK, CXXCOMPILE, CXXLINK, CXXLINK_S): Define
	using editcc macros.
	(gcctestdir/collect-ld): New rule, add as a dependency of..
	(gcctestdir/ld): ..this.  Use $@ and abs_top_buildir.
	(gcctestdir/as): Use $@.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/incremental_test.sh (actual): Match collect-ld too.
2018-11-08 11:20:34 +10:30
Alan Modra
396ce99883 [GOLD] make clean
Cleans a few more test files.

	* Makefile.am (MOSTLYCLEANFILES): Define.
	* Makefile.in: Regnerate.
	* testsuite/Makefile.am (MOSTLYCLEANFILES): Add ver_test_14 and
	gnu_property_test.
	* testsuite/Makefile.in: Regnerate.
2018-11-02 14:00:15 +10:30
Cary Coutant
1074bc6d41 Fix internal error when using --emit-relocs with plugins.
When an .eh_frame section has deferred layout because of plugins, gold
was neglecting to mark the section as deferred. When we later processed
the corresponding relocation section, we were then ignoring it, causing
the internal error later on in the link.

gold/
	PR gold/23397
	* object.cc (Sized_relobj_file::do_layout): Mark section as deferred.
	* testsuite/Makefile.am (plugin_test_1): Add --emit-relocs option to
	existing test case.
	* testsuite/Makefile.in: Regenerate.
2018-07-14 12:44:48 -07:00
Cary Coutant
1b115e8e0e Fix problem causing duplicated linker-generated symbols with versions.
When generating _end, _edata, etc. symbols, and a version script provides
a version name, and we are linking against another shared library that
provides those symbols with a different version, gold ends up trying to
resolve the other shared library's symbols to the new definitions, resulting
in two copies of each symbol, one as default, and one as non-default.
This patch tests for that condition, and ignores the symbols provided
by the other shared library.

gold/
	PR gold/23409
	* symtab.cc (Symbol_table::define_special_symbol): Add check for
	version name on existing symbol.
	* testsuite/Makefile.am (ver_test_pr23409): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ver_test_pr23409.sh: New test script.
	* testsuite/ver_test_pr23409_1.script: New version script.
	* testsuite/ver_test_pr23409_2.script: New version script.
2018-07-14 12:29:50 -07:00
Cary Coutant
a2575bec24 Update support for .note.gnu.property sections.
The original patch did not give the target enough hooks to discover that
an input object file does not have a particular property. For the
GNU_PROPERTY_X86_FEATURE_1_AND property, for example, where a missing
property should be assumed to be all zeroes, and ANDed with other
object modules, this is essential. We now store the target-specific
properties locally in the Target structure as native uint32_t fields,
then AND the per-object feature bits with the program's feature bits
when we're finished processing each input object file. The target-specific
properties are then added back to the output note section during
finalization.

gold/
	PR gold/22914
	* layout.cc (read_sized_value): Fix spelling of section name.
	(Layout::layout_gnu_property): Call Sized_target::record_gnu_property
	for target-specific properties;
	don't store them with target-independent properties yet.
	(Layout::merge_gnu_properties): New method.
	(Layout::add_gnu_property): New method.
	(Layout::create_gnu_properties_note): Call target to finalize
	target-specific properties. Fix spelling of output section name.
	* layout.h (Layout::merge_gnu_properties): New method.
	(Layout::add_gnu_property): New method.
	* object.cc (Sized_relobj_file::do_layout): Call
	Layout::merge_gnu_properties.
	* target.h (Target::merge_gnu_property): Remove.
	(Target::finalize_gnu_properties): New method.
	(Target::do_merge_gnu_property): Move to Sized_target and rename.
	(Target::do_finalize_gnu_properties): New virtual method.
	(Sized_target::record_gnu_property): Moved and renamed from
	Target::do_merge_gnu_property.
	(Sized_target::merge_gnu_properties): New virtual method.
	* x86_64.cc (Target_x86_64::isa_1_used_, isa_1_needed_)
	(feature_1_, object_feature_1_, seen_first_object_): New data members.
	(Target_x86_64::do_merge_gnu_property): Rename to ...
	(Target_x86_64::record_gnu_property): ... this.  Save target-specific
	properties in Target class object.
	(Target_x86_64::merge_gnu_properties): New method.
	(add_property): New static inline function.
	(Target_x86_64::do_finalize_gnu_properties): New method.
	* testsuite/Makefile.am (gnu_property_test): Remove C source file;
	link directly without compiler driver.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/gnu_property_a.S: Add _start.
2018-06-22 23:36:50 -07:00
Cary Coutant
6c04fd9b2f Add support for .note.gnu.property sections.
elfcpp/
	PR gold/22914
	* elfcpp.h (NT_GNU_PROPERTY_TYPE_0): New note type.
	(GNU_PROPERTY_*): New Gnu property types.
	* x86_64.h (GNU_PROPERTY_X86_FEATURE_1_IBT)
	(GNU_PROPERTY_X86_FEATURE_1_SHSTK): New x86 feature bits.

gold/
	PR gold/22914
	* layout.cc (Layout::Layout): Initialize gnu_properties_.
	(read_sized_value, write_sized_value): New functions.
	(Layout::layout_gnu_property): New method.
	(Layout::create_notes): Call create_gnu_properties_note.
	(Layout::create_gnu_properties_note): New method.
	* layout.h (Layout::layout_gnu_property): New method.
	(Layout::create_gnu_properties_note): New method.
	(Layout::Gnu_property, Layout::Gnu_properties): New types.
	(Layout::gnu_properties_): New data member.
	* object.cc (Sized_relobj_file::layout_gnu_property_section): New
	method.
	(Sized_relobj_file::do_layout): Handle .note.gnu.property sections.
	* object.h (Sized_relobj_file::layout_gnu_property_section): New
	method.
	* target.h (Target::merge_gnu_property): New method.
	(Target::do_merge_gnu_property): New virtual method.
	* x86_64.cc (Target_x86_64::do_merge_gnu_property): New method.
	* testsuite/Makefile.am (gnu_property_test): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/gnu_property_a.S: New source file.
	* testsuite/gnu_property_b.S: New source file.
	* testsuite/gnu_property_c.S: New source file.
	* testsuite/gnu_property_main.c: New source file.
	* testsuite/gnu_property_test.sh: New test script.
2018-06-22 09:52:00 -07:00
Cary Coutant
cea6ffbd06 Fix treatment of symbol versions with unused as-needed libraries.
When we have a weak reference to a symbol defined in an
as-needed library, and that library ends up not-needed, gold
simply clears the version information in the symbol table, even
if the symbol could have been resolved by a needed library later
in the link order. This results in a loss of version information,
which can cause the program to bind to the wrong version at run
time.

This patch lets a dynamic definition override an earlier one if
the earlier one is from a not-needed library, so that we can
retain the version information from the binding to the needed
library. In order to do that, the tracking of needed/not-needed
had to be moved up to symbol resolution time, instead of during
Symbol_table::set_dynsym_indexes().

In cases where we still end up discarding version information,
I've added a warning.

For the original problem report and discussion, see:

https://stackoverflow.com/questions/50751421/undefined-behavior-in-shared-lib-using-libpthread-but-not-having-it-in-elf-as-d

gold/
	* resolve.cc (Symbol_table::resolve): Rename tobinding to
	orig_tobinding.  Call set_is_needed() for objects that resolve
	non-weak references.
	(Symbol_table::should_override): Allow a dynamic definition to
	override an earlier one in a not-needed library.
	* symtab.cc (Symbol_table::set_dynsym_indexes): Remove separate
	processing for as-needed symbols.  Add warning when discarding
	version informatin.
	* testsuite/Makefile.am (weak_as_needed): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/weak_as_needed.sh: New test script.
	* testsuite/weak_as_needed_a.c: New source file.
	* testsuite/weak_as_needed_b.c: New source file.
	* testsuite/weak_as_needed_b.script: New version script.
	* testsuite/weak_as_needed_c.c: New source file.
	* testsuite/weak_as_needed_c.script: New version script.
2018-06-21 13:54:16 -07:00
Cary Coutant
ebb1332297 Fix problem where gold does not create base version for executables.
gold/
	PR gold/23268
	* dynobj.cc (Versions::Versions): Change init for needs_base_version_.
	(Versions::record_version): Add verdefs for both shared objects and
	executables.
	(Versions::add_def): Likewise for base version.
	(Versions::add_need): Don't add base version for executables.
	(Versions::version_index): Look up version for both shared objects and
	executables.
	* testsuite/Makefile.am (ver_test_14): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ver_test_14.script: New version script.
	* testsuite/ver_test_14.sh: New test script.
2018-06-20 01:25:04 -07:00
Cary Coutant
c8dc28bcc0 Replace thread config with automatic config using ax_pthread.m4.
The autotools library macro (AX_PTHREAD) is now used to detect if
pthreads is present and multi-threaded linking in gold is automatically
enabled if it is found. This enables multi-threaded gold on platforms
where pthreads is enabled via other methods than just -lpthread
(e.g., MinGW).

2018-06-19  Joshua Watt  <jpewhacker@gmail.com>
	    Cary Coutant  <ccoutant@gmail.com>

gold/
	* configure.ac: Replace manual thread configuration with AX_PTHREAD.
	Add --enable-threads=auto.
	* Makefile.am (THREADFLAGS, THREADLIBS): New defines.
	(AM_CFLAGS, AM_CXXFLAGS): Add $(THREADFLAGS.
	(THREADSLIB): Remove; change all references to THREADLIBS.
	* Makefile.in: Regenerate.
	* aclocal.m4: Regenerate.
	* config.in: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.am (THREADSLIB): Replace with...
	(THREADFLAGS, THREADLIBS): ... these.
	(LDADD): Remove; add as individual defines for...
	(object_unittest, binary_unittest, leb128_unittest)
	(overflow_unittest): ... these tests.
	(tls_test, tls_pic_test, tls_pie_test, tls_pie_pic_test)
	(tls_shared_test, tls_shared_ie_test, tls_shared_gd_to_ie_test)
	(tls_shared_gnu2_gd_to_ie_test, tls_shared_gnu2_test_LDFLAGS)
	(tls_shared_nonpic_test_LDFLAGS): Add $(THREADFLAGS) and ($THREADLIBS).
	* testsuite/Makefile.in: Regenerate.
2018-06-19 18:57:28 -07:00
Cary Coutant
27ab04240b Remove *.stderr when "make clean".
gold/
	* testsuite/Makefile.am (MOSTLYCLEANFILES): Add *.stderr.
	* testsuite/Makefile.in: Regenerate.
2018-06-19 17:02:26 -07:00
Cary Coutant
890d155592 Fix internal error caused by conflicting default version definitions.
gold/
	PR gold/16504
	* dynobj.cc (Versions::symbol_section_contents): Don't set
	VERSYM_HIDDEN flag for undefined symbols.
	* symtab.cc (Symbol_table::add_from_object): Don't override default
	version definition with a different default version.
	* symtab.h (Symbol::from_dyn): New method.
	* testsuite/plugin_test.c (struct sym_info): Add ver field.
	(claim_file_hook): Pass symbol version to plugin API.
	(parse_readelf_line): Parse symbol version.
	* testsuite/Makefile.am (ver_test_pr16504): New test case.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/ver_test_pr16504.sh: New test script.
	* testsuite/ver_test_pr16504_a.c: New source file.
	* testsuite/ver_test_pr16504_a.script: New version script.
	* testsuite/ver_test_pr16504_b.c: New source file.
	* testsuite/ver_test_pr16504_b.script: New version script.
2018-04-24 13:51:24 -07:00
Cary Coutant
bce5a025d2 Fix problem where mixed section types can cause internal error during a -r link.
During a -r (or --emit-relocs) link, if two sections had the same name but
different section types, gold would put relocations for both sections into
the same relocation section even though the data sections remained separate.

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

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

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

	* testsuite/Makefile.am (pr23016_1, pr23016_2): New test cases.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/testfile.cc: Add unwind_section_type.
	* testsuite/pr23016_1.sh: New test script.
	* testsuite/pr23016_1a.s: New source file.
	* testsuite/pr23016_1b.s: New source file.
	* testsuite/pr23016_2.sh: New test script.
	* testsuite/pr23016_2a.s: New source file.
	* testsuite/pr23016_2b.s: New source file.
2018-04-02 19:07:04 -07:00
Cary Coutant
0b7a4aa6ba Fix case where IR file provides symbol visibility but replacement file does not.
In PR 22868, two IR files provide conflicting visibility for a symbol.
When a def with PROTECTED visibility is seen after a def with DEFAULT
visibility, gold does not override the visibility. Later, if the
replacement object define the symbol with DEFAULT visibility, the symbol
remains DEFAULT. This was caused by a recent change to allow multiply-defined
absolute symbols, combined with the fact that the plugin framework was using
SHN_ABS as the section index for placeholder symbols. The solution is to
use a real (but arbitrary) section index.

gold/
	PR gold/22868
	* plugin.cc (Sized_pluginobj::do_add_symbols): Use a real section
	index instead of SHN_ABS for defined symbols.
	* testsuite/Makefile.am (plugin_pr22868): New test case.
	* testsuite/Makefile.in: Regenerate
	* testsuite/plugin_pr22868.sh: New test script.
	* testsuite/plugin_pr22868_a.c: New source file.
	* testsuite/plugin_pr22868_b.c: New source file.
2018-03-26 10:54:45 -07:00
Sriraman Tallam
779bdadbea New option -z,keep-text-section prefix.
This option does not merge certain text sections with prefixes
.text.hot, .text.unlikely, .text.startup and .text.exit.

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

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

	* expression.cc (Symbol_expression::set_expr_sym_in_real_elf):
	New method.
	(Unary_expression::set_expr_sym_in_real_elf): New method.
	(Binary_expression::set_expr_sym_in_real_elf): New method.
	(Trinary_expression::set_expr_sym_in_real_elf): New method.
	* plugin.cc (get_symbol_resolution_info): Fix symbol resolution if
	defined or used in defsyms.
	* plugin.h (Plugin_manager::is_defsym_def): New method.
	(Plugin_manager::Plugin_manager): Initialize defsym_defines_set_.
	(Plugin_manager::defsym_defines_set_): New member.
	(Plugin_manager::Defsym_defines_set): New typedef.
	* script.cc (Script_options::set_defsym_uses_in_real_elf): New method.
	(Script_options::find_defsym_defs): New method.
	* script.h (Expression::set_expr_sym_in_real_elf): New method.
	(Symbol_assignment::is_defsym): New method.
	(Symbol_assignment::value): New method.
	(Script_options::find_defsym_defs): New method.
	(Script_options::set_defsym_uses_in_real_elf): New method.
	* testsuite/Makefile.am (plugin_test_defsym): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/plugin_test.c: Check for new symbol resolution.
	* testsuite/plugin_test_defsym.sh: New script.
	* testsuite/plugin_test_defsym.c: New test source.
2018-02-15 17:35:16 -08:00
Stephen Crane
c4e648430f Add plugin API for processing plugin-added input files
Gold plugins may wish to further process an input file added by a plugin. For
example, the plugin may need to assign a unique segment for sections in a
plugin-generated input file. This patch adds a plugin callback that the linker
will call when reading symbols from a new input file added after the
all_symbols_read event (i.e. an input file added by a plugin).

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

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

	* plugin.cc (Plugin::load): Include hooks for register_new_input
	in transfer vector.
	(Plugin::new_input): New function.
	(register_new_input): New function.
	(Plugin_manager::claim_file): Call Plugin::new_input if in
	replacement phase.
	* plugin.h (Plugin::set_new_input_handler): New function.
	* testsuite/plugin_new_section_layout.c: New plugin to test
	new_input plugin API.
	* testsuite/plugin_final_layout.sh: Add new input test.
	* testsuite/Makefile.am (plugin_layout_new_file): New test case.
	* testsuite/Makefile.in: Regenerate.
2017-12-11 14:58:38 -08:00
Cary Coutant
158600eb98 Disallow --incremental with -pie and force -no-pie for incremental tests.
This is a partial fix for the gold testsuite failures documented in
PR 21090. The use of -fpie triggers some mov-to-lea optimizations that
are not compatible with incremental linking, so those optimizations need
to be disabled. We also diagnose the attempt to use -pie with incremental
linking, and force -no-pie for the incremental tests in case the build has
been configured to have GCC pass -pie all the time.

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

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

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

gold/
	PR gold/22406
	* gold.cc (queue_initial_tasks) Check for number of real input files.
	* options.cc (Command_line::process) Check for unterminated --start-lib
	options.
	* testsuite/Makefile.am: Add new test script.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/check_empty_command_lines.sh: New test script.
2017-12-01 12:59:36 -08:00
James Clarke
333d0055f6 Fix problems with -r.
The fix committed for PR gold/19291 ended up breaking other cases. The
commit added adjustment code to write_local_symbols, but in many cases
compute_final_local_value_internal had already subtracted the output
section's address. To fix this, all other adjustments are now removed, so
only the one in write_local_symbols is left.

gold/
	PR gold/22266
	* object.cc (Sized_relobj_file::compute_final_local_value_internal):
	Drop relocatable parameter and stop adjusting output value based on
	it.
	(Sized_relobj_file::compute_final_local_value): Stop passing
	relocatable to compute_final_local_value_internal.
	(Sized_relobj_file::do_finalize_local_symbols): Ditto.
	* object.h (Sized_relobj_file::compute_final_local_value_internal):
	Drop relocatable parameter.
2017-11-08 15:13:53 -08:00
Sriraman Tallam
3b4190ccb3 New gold linker option -z,text-unlikely-segment.
2017-10-04  Sriraman Tallam  <tmsriram@google.com>

	* options.h (-z,text_unlikely_segment): New option.
	* layout.cc (Layout::layout): Create new output section
	for .text.unlikely sections with the new option.
	(Layout::segment_precedes): Check for the new option
	when segment flags match.
	* testsuite/text_unlikely_segment.cc: New test source.
	* testsuite/text_unlikely_segment.sh: New test script.
	* testsuite/Makefile.am (text_unlikely_segment): New test.
	* testsuite/Makefile.in: Regenerate.
2017-10-20 11:00:28 -07:00
Umesh Kalappa
36862fc052 Implement BE8 support for ARM.
gold/
	* arm.cc (Stub::do_fixed_endian_write):Far call stubs support for arm
	in the be8 mode.
	* testsuite/Makefile.am: New test cases.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/arm_farcall_arm_arm_be8.sh: New script for arm to arm far
	call stubs.
	* testsuite/arm_farcall_thumb_thumb_be8.sh: New script for thumb to
	thumb far call stubs.
2017-10-19 20:53:14 -07:00
Teresa Johnson
ca464aac1b Check for export dynamic symbol options when doing symbol resolution in plugins.
2017-09-20  Teresa Johnson  <tejohnson@google.com>
	* plugin.cc (is_visible_from_outside): Check for export dynamic symbol
        option and list.
	* testsuite/Makefile.am (plugin_test_12): New test.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/export_dynamic_plugin.cc: New test source.
	* testsuite/plugin_test_12.sh: New test script.
2017-09-20 15:45:04 -07:00
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
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
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
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
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
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
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