Commit Graph

2238 Commits

Author SHA1 Message Date
Alan Modra
0af4fcc25d PR27625, powerpc64 gold __tls_get_addr calls
This patch supports linking powerpc64 glibc with gold, specifically
the __tls_get_addr call in elf/dl-sym.c.  That call lacks marker
relocations tying it to the arg setup instructions, but the arg setup
insns are also contructed lacking the usual relocations on a Global
Dynamic TLS code sequence.  So there is no chance that anything in
that sequence might be wrongly edited by the linker.

In fact, the aim of linking glibc could have been supported by simply
omitting the error whenever TLS optimisation is disabled, as it is
when linking a shared library.  The patch goes further than that,
disabling TLS GD and LD sequence optimisation on a per-object basis
for object files lacking marker relocs.

	PR gold/27625
	* powerpc.cc (Powerpc_relobj): Add no_tls_marker_, tls_marker_,
	and tls_opt_error_ variables and accessors.
	(Target_powerpc::Scan::local, global): Call set_tls_marker and
	set_no_tls_marker for GD and LD code sequence relocations.
	(Target_powerpc::Relocate::relocate): Downgrade the "lacks marker
	reloc" error to a warning when safe to do so, and omit the error
	entirely if not optimising TLS sequences.  Do not optimise GD and
	LD sequences for objects lacking marker relocs.
	(Target_powerpc::relocate_relocs): Heed no_tls_marker here too.
2021-03-30 13:38:41 +10:30
Cary Coutant
35891b4775 Use stdout when printing object file names for -t option.
gold/
	PR gold/27615
	* errors.cc (Errors::trace): New method.
	(gold_trace): New function.
	* errors.h (Errors::trace): New method.
	* gold.h (gold_trace): New function.
	* object.cc (Input_objects::add_object): Use gold_trace to print
	object file names.
2021-03-19 18:41:12 -07:00
Cary Coutant
b218a83935 Fix failing test for PR 23870.
gold/
	PR gold/pr23870
	* testsuite/aarch64_pr23870_bar.c: Return a magic value.
	* testsuite/aarch64_pr23870_foo.c: Check the magic value and return
	success or failure.
2021-03-19 17:58:32 -07:00
Holger Berger
07b1c3dbd9 Fix call to system fallocate to handle errno correctly.
2021-03-19  Holger Berger  <holger.berger@googlemail.com>

gold/
	PR gold/26541
	* output.cc (gold_fallocate): Use errno when calling system fallocate.
2021-03-19 16:18:53 -07:00
Cary Coutant
cc1849716f Fix typo in previous patch: should use struct mallinfo2.
PR gold/26585
	* main.cc (main): Fix typo in previous patch.
2021-03-19 15:29:49 -07:00
Cary Coutant
9331846e44 Regenerate config.in, missing from previous commit.
PR gold/26585
	* config.in: Regenerate from previous commit.
2021-03-19 15:23:49 -07:00
Duncan Simpson
4ee6049505 Fix gold to use mallinfo2 if available instead of deprecated mallinfo.
gold/
	PR gold/26585
	* configure.ac: Add check for mallinfo2.
	* configure: Regenerate.
	* main.cc (main): Use mallinfo2 if available.
2021-03-19 14:22:08 -07:00
Cary Coutant
5cde809b7b Add DWARF 5 support in gold.
elfcpp/
	PR gold/27246
	* dwarf.h (enum DW_LNCT): Add line number table content type codes.
	(enum DW_LINE_OPS): Reformat.
	(enum DW_LINE_EXTENDED_OPS): Reformat.
	(enum DW_CHILDREN): Reformat.
	(enum DW_RLE): Add range list entry types.
	(enum DW_SECT): Update values for DWARF 5.

gold/
	PR gold/27246
	* dwarf_reader.cc (Dwarf_abbrev_table::do_get_abbrev): Handle
	DW_FORM_implicit_const.
	(Dwarf_ranges_table::read_ranges_table): Add version parameter;
	Adjust all callers.  Look for .debug_rnglists section if DWARF 5.
	(Dwarf_ranges_table::read_range_list_v5): New method.
	(Dwarf_die::read_attributes): Handle new DWARF 5 DW_FORM codes.
	(Dwarf_die::skip_attributes): Likewise.
	(Dwarf_info_reader::do_parse): Support DWARF 5 unit header format.
	(Dwarf_info_reader::read_3bytes_from_pointer): New method.
	(Sized_dwarf_line_info::Sized_dwarf_line_info): Initialize
	str_buffer_, str_buffer_start, reloc_map_, line_number_map_.
	Look for .debug_line_str section.
	(Sized_dwarf_line_info::read_header_prolog): Support DWARF 5 prolog.
	(Sized_dwarf_line_info::read_header_tables): Rename to...
	(Sized_dwarf_line_info::read_header_tables_v2): ... this.
	(Sized_dwarf_line_info::read_header_tables_v5): New method.
	(Sized_dwarf_line_info::process_one_opcode): Insert missing "this->".
	Change advance_line to signed int64_t.
	(Sized_dwarf_line_info::read_lines): Add endptr parameter; adjust
	callers.  Insert missing "this->".
	(Sized_dwarf_line_info::read_line_mappings): Support DWARF 5.
	(Sized_dwarf_line_info::do_addr2line): Add debug code.
	* dwarf_reader.h (Dwarf_abbrev_table::Attribute): Add implicit_const
	field. Adjust constructor.
	(Dwarf_abbrev_table::add_sttribute): Add implicit_const parameter.
	(Dwarf_ranges_table::read_ranges_table): Add version parameter.
	(Dwarf_ranges_table::read_range_list_v5): New method.
	(Dwarf_die): Remove unused attr_off field.
	(Dwarf_info_reader::Dwarf_info_reader): Initialize unit_type_ field.
	(Dwarf_info_reader::is_type_unit): New method.
	(Dwarf_info_reader::read_3bytes_from_pointer): New method.
	(Dwarf_info_reader::read_range_list): Call read_range_list_v5 for
	DWARF 5 range lists.
	(Dwarf_info_reader::is_type_unit_): Remove.
	(Dwarf_info_reader::unit_type_): New field.
	(Sized_dwarf_line_info::~Sized_dwarf_line_info): Delete
	str_buffer_start_.
	(Sized_dwarf_line_info::read_header_tables): Rename to...
	(Sized_dwarf_line_info::read_header_tables_v2): ... this.
	(Sized_dwarf_line_info::read_header_tables_v5): New method.
	(Sized_dwarf_line_info::read_lines): Add endptr parameter.
	(Sized_dwarf_line_info::Dwarf_line_infoHeader): Add address_size field.
	(Sized_dwarf_line_info::str_buffer_): New field.
	(Sized_dwarf_line_info::str_buffer_end_): New field.
	(Sized_dwarf_line_info::str_buffer_start_): New field.
	(Sized_dwarf_line_info::end_of_header_length_): New field.
	(Sized_dwarf_line_info::end_of_unit_): New field.
2021-03-19 13:55:35 -07:00
H.J. Lu
0318cca493 gold: Skip address size and segment selector for DWARF5
The .debug_line secton in DWARF5 has a byte for address size and a byte
for segment selector after DWARF version.  Skip them for DWARF5.

	PR gold/27246
	* dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog):
	Skip address size and segment selector for DWARF5.
2021-01-28 04:21:31 -08:00
Alan Modra
a75a6a4164 [GOLD] powerpc assertion failure
A testcase with only ifuncs can result in no plt section (ifunc plt
entries might instead be in iplt), which means we can get to this code
without a static link.

	PR 27203
	* powerpc.cc (do_plt_fde_location): Remove doing_static_link
	assertion.
2021-01-19 13:27:13 +10:30
H.J. Lu
25294ff049 gold: Remove the circular IFUNC dependency in ifuncmain6pie
On Fedora 33 x86-64 with glibc 2.32-3, ifuncmain6pie failed with:

./ifuncmain6pie: IFUNC symbol 'foo' referenced in './ifuncmod6.so' is defined in the executable and creates an unsatisfiable circular dependency.
FAIL ifuncmain6pie (exit status: 127)

Remove non-JUMP_SLOT relocations against foo in ifuncmod6.so, which
trigger the circular IFUNC dependency.

	* testsuite/ifuncmain6pie.c: Remove non-JUMP_SLOT relocations
	against foo in ifuncmod6.so.
	* testsuite/ifuncmod6.c: Likewise.
2021-01-17 16:43:59 -08:00
Nick Clifton
5a10699ff3 Updated translations for some subdirectories 2021-01-14 12:55:25 +00:00
Nick Clifton
a8aa72b913 Updated translations for multiple subdirectories 2021-01-11 12:55:33 +00:00
Nick Clifton
055bc77a80 Add Changelog entries and NEWS entries for 2.36 branch 2021-01-09 10:40:28 +00:00
Alan Modra
e3b53295d5 PR27140, ppc32 segmentation fault in make_stub
This fixes a thinko in commit fa40fbe484.  st_other global entry bits
are relevant only for 64-bit ELFv2.  PowerPC gold leaves local sym
vector of st_other bits as NULL for 32-bit, hence the segfault.

	PR 27140
	* powerpc.cc (Target_powerpc::Branch_info::make_stub): Only access
	object->st_other() when 64-bit.
	(Stub_table::add_long_branch_entry): Ignore "other" when 32-bit.
2021-01-03 12:49:47 +10:30
Alan Modra
f9a6a8f09d PR27116, Spelling errors found by Debian style checker
PR 27116
bfd/
	* xcofflink.c: Correct spelling in comments.
binutils/
	* coffgrok.c (do_type): Correct spelling of auxiliary in errors.
	* doc/binutils.texi: Correct grammar.
	* readelf.c (process_version_sections): Correct spelling of auxiliary
	in warning.
	* testsuite/binutils-all/vax/objdump.exp: Comment grammar fix.
config/
	* override.m4: Correct comment grammar.
gas/
	* config/tc-i386.c: Correct comment spelling.
	* config/tc-riscv.c: Likewise.
	* config/tc-s390.c: Correct comment grammar.
	* doc/c-i386.texi: Correct spelling.
	* doc/c-s390.texi: Correct grammar.
gold/
	* tilegx.cc: Correct comment spelling.
gprof/
	* README: Correct grammar.
	* gprof.texi: Likewise.
include/
	* coff/internal.h: Correct comment spelling.
	* coff/sym.h: Likewise.
	* opcode/aarch64.h: Likewise.
ld/
	* configure.tgt: Correct comment grammar.
	* emultempl/m68hc1xelf.em: Likewise.
	* ld.texi: Correct grammar.
2021-01-01 14:36:35 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Alan Modra
c2795844e6 ChangeLog rotation 2021-01-01 10:31:02 +10:30
H.J. Lu
97aac4ec32 gold: Move sym declaration just before use
Move sym declaration just before use to avoid -Wmaybe-uninitialized
warning from GCC 11.

	PR gold/27097
	* incremental.cc (Sized_relobj_incr::do_add_symbols): Move sym
	declaration just before use.
	(Sized_incr_dynobj::do_add_symbols): Likewise.
	* plugin.cc (Sized_pluginobj::do_add_symbols): Likewise.
2020-12-19 13:37:04 -08:00
Cary Coutant
2b2d74f4a1 Cosmetic improvements for OSABI access.
Add accessor methods to elfcpp::Ehdr class for EI_OSABI and EI_ABIVERSION;
use those to simplify initialization of Osabi class and eliminate the need
to template the class.

elfcpp/
	* elfcpp.h (class Ehdr): Add get_ei_osabi and get_ei_abiversion methods.

gold/
	* dwp.cc (class Dwo_file): Use new Ehdr::get_ei_osabi and
	get_ei_abiversion methods.
	* incremental.cc (make_sized_incremental_binary): Likewise.
	* object.cc (Sized_relobj_file::Sized_relobj_file): Likewise.
	(make_elf_sized_object): Likewise.
	* object.h (class Osabi): Make the class untemplated.
2020-12-15 14:37:22 -08:00
H.J. Lu
8947abe6bf gold: Add missing ChangeLog entries for commit ff4bc37d7 2020-12-15 07:39:16 -08:00
Vivek Das Mohapatra
8a87b27911 Implement and document -z unique / -z nounique handling in gold
* layout.cc (Layout::finish_dynamic_section): Set DF_GNU_1_UNIQUE.
	* options.h (class General_options): Handle -z unique, -z nounique.
2020-12-15 18:45:24 +10:30
Cary Coutant
ff4bc37d77 Keep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD ELFOSABIs.
2020-12-14  H.J. Lu  <hjl.tools@gmail.com>
	    Cary Coutant  <ccoutant@gmail.com>

elfcpp/
	PR gold/27039
	* elfcpp.h (SHF): Add SHF_GNU_RETAIN.

gold/
    	PR gold/27039
	* layout.cc (Layout::layout): Strip SHF_GNU_RETAIN.
	* object.cc (Sized_relobj_file::Sized_relobj_file): Initialize osabi_.
	(Sized_relobj_file::do_layout): Keep SHF_GNU_RETAIN sections for
	GNU/FreBSD ELFOSABIs.
	* object.h (Osabi) New class.
	(Sized_relobj_file): Add osabi() and osabi_.
	* testsuite/Makefile.am (check_SCRIPTS): Add retain.sh.
	(check_DATA): Add retain_1.out retain_2.out.
	(MOSTLYCLEANFILES): Add retain_1 retain_2.
	(retain_1.out): New target.
	(retain_1): Likewise.
	(retain_1.o): Likewise.
	(retain_2.out): Likewise.
	(retain_2): Likewise.
	(retain_2.o): Likewise.
	* testsuite/Makefile.in: Regenerate.
	* testsuite/retain.sh: New file.
	* testsuite/retain_1.s: Likewise.
	* testsuite/retain_2.s: Likewise.
2020-12-14 15:49:27 -08:00
Cary Coutant
f22318ef0d Re-enable incremental tests that were failing with GCC 9+.
gold/
	PR gold/23539
	PR gold/24123
	* testsuite/Makefile.am (incremental_copy_test): Re-enable for GCC 9+.
	(incremental_comdat_test_1): Likewise.
	* testsuite/Makefile.in: Regenerate.
2020-12-13 16:50:52 -08:00
Cary Coutant
387a56a543 Fix incremental tests using gcc 9, which adds Gnu properties sections.
During an incremental link, we should simply ignore the Gnu properties
sections. We were not handling them properly -- failing to process the
properties from the base file. While that could be fixed, the property
sections are meant for deployed binaries, and incremental linking is
for development, so keeping the properties sections just adds to the
likelihood of forcing a full link sooner.

gold/
	PR gold/23539
	* object.cc (Sized_relobj_file::layout_gnu_property_section): Ignore
	Gnu properties during incremental links.
2020-12-13 15:28:36 -08:00
Cary Coutant
f12650bff1 Fix incremental linking with rodata merge sections.
When processing the incremental update, incoming .rodata merge sections
do not match the corresponding section in the base file, because the
SHF_MERGE flag had not been masked out of the latter.

gold/
	PR gold/24123
	* layout.cc (Layout::init_fixed_output_section): Mask out flags that
	should be ignored when matching sections.
2020-12-13 15:27:25 -08:00
Alan Modra
cd8d2039b0 [GOLD] gcc-11 stringop-overflow warning
I'm unsure why this is deserving of a warning.  Not writing the most
efficient code surely can't be a real problem, but that is what
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059#c1 seems to say.

plugin.cc:528:10: error: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  528 |   strncpy(tempdir, dir_template, len);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugin.cc:526:22: note: length computed here
  526 |   size_t len = strlen(dir_template) + 1;
      |                ~~~~~~^~~~~~~~~~~~~~

	* plugin.cc (Plugin_recorder::init): Replace strncpy with memcpy.
2020-12-07 22:36:22 +10:30
Alan Modra
c6162010ad [GOLD] PR26936 test
Fails if you configure with --disable-x86-used-note.  Fix that.

	* testsuite/Makefile.am (pr26936a.o): Pass -mx86-used-note=yes.
	(pr26936b.o, pr26936c.o, pr26936d.o): Likewise.
	* testsuite/Makefile.in: Regenerate.
2020-12-03 16:31:19 +10:30
H.J. Lu
4bccc875d2 gold: Add endbr64 to IBT TLSDESC PLT entry
Gold generates:

 c10:   ff 35 da 23 00 00       push   0x23da(%rip)        # 2ff0 <_GLOBAL_OFFSET_TABLE_+0x8>
 c16:   f2 ff 25 c3 23 00 00    bnd jmp *0x23c3(%rip)        # 2fe0 <_DYNAMIC+0x260>
 c1d:   0f 1f 00                nopl   (%rax)

for IBT TLSDESC PLT entry which misses endbr64.  Add endbr64 to generate:

 c10:   f3 0f 1e fa             endbr64
 c14:   ff 35 d6 23 00 00       push   0x23d6(%rip)        # 2ff0 <_GLOBAL_OFFSET_TABLE_+0x8>
 c1a:   ff 25 c0 23 00 00       jmp    *0x23c0(%rip)        # 2fe0 <_DYNAMIC+0x260>

	PR ld/26972
	* x86_64.cc (Output_data_plt_x86_64_ibt::tlsdesc_plt_entry): Add
	endbr64.
	(Output_data_plt_x86_64_ibt::do_fill_tlsdesc_entry): Adjusted.
2020-11-29 11:41:47 -08:00
H.J. Lu
568cbddc71 gold: Convert x86-64 GOTPCRELX only if addend == -4
Convert x86-64 GOTPCRELX relocations only if addend == -4.

	PR gold/26939
	* x86_64.cc (Target_x86_64<size>::Scan::local): Check
	get_r_addend() == -4 for GOTPCRELX conversion.
	(Target_x86_64<size>::Scan::global): Likewise.
	(Target_x86_64<size>::Relocate::relocate): Likewise.
	* testsuite/Makefile.am (check_DATA): Add
	x86_64_mov_to_lea15.stdout and x86_64_mov_to_lea16.stdout.
	(MOSTLYCLEANFILES): Add x86_64_mov_to_lea15 and
	x86_64_mov_to_lea16.
	(x86_64_mov_to_lea9.o): New target.
	(x86_64_mov_to_lea10.o): Likewise.
	(x86_64_mov_to_lea15): Likewise.
	(x86_64_mov_to_lea16): Likewise.
	(x86_64_mov_to_lea15.stdout): Likewise.
	(x86_64_mov_to_lea16.stdout): Likewise.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/x86_64_mov_to_lea.sh: Updated.
	* testsuite/x86_64_mov_to_lea5.s: New file.
2020-11-29 06:00:50 -08:00
H.J. Lu
8ca751ee63 gold: Get linkonce/comdate sections for debugging sections
When relocating debug sections, get the section index for the linkonce
section.  Since symbols referenced in debugging sections can be defined
a single comdat section with a different section name, also check the
single comdat section.

	PR gold/26937
	* object.cc (Sized_relobj_file::map_to_kept_section): Get the
	section index for linkonce section.  Also check the single
	comdat section.
	* testsuite/Makefile.am (check_SCRIPTS): Add pr26936.sh.
	(check_DATA): Add pr26936a.stdout and pr26936b.stdout.
	(MOSTLYCLEANFILES): Add pr26936a and pr26936b.
	(pr26936a.stdout): New target.
	(pr26936a): Likewise.
	(pr26936b.stdout): Likewise.
	(pr26936b): Likewise.
	(pr26936a.o): Likewise.
	(pr26936b.o): Likewise.
	(pr26936c.o): Likewise.
	(pr26936d.o): Likewise.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/pr26936.sh: New file.
	* testsuite/pr26936a.s: Likewise.
	* testsuite/pr26936b.s: Likewise.
	* testsuite/pr26936c.s: Likewise.
	* testsuite/pr26936d.s: Likewise.
2020-11-29 05:55:35 -08:00
Alan Modra
4e0e019fa8 [GOLD] powerpc incremental-dump assertion failure
incremental-dump wants to instantiate Target_powerpc without options
being set up.  This patch fixes
  internal error in options, at gold/parameters.h:92

	* powerpc.cc (Target_powerpc::no_tprel_opt_): Rename from tprel_opt_.
	Init to false.
	(Target_powerpc::tprel_opt): Test parameters->options().tls_optimize().
	(Target_powerpc::set_tprel_opt): Delete.
	(Target_powerpc::set_no_tprel_opt): New function.  Update all uses
	of set_tprel_opt.
2020-11-17 20:59:53 +10:30
Michael Hudson-Doyle
f1e05b1978 [GOLD] fix jump to long branch on powerpc
PR 26902
	* powerpc.cc (Relocate::relocate): Do not include local entry
	offset of target function when computing the address of a stub.
2020-11-17 20:59:53 +10:30
H.J. Lu
d4820dac5e gold: Avoid sharing Plugin_list::iterator
class Plugin_manager has

  // A pointer to the current plugin.  Used while loading plugins.
  Plugin_list::iterator current_;

The same iterator is shared by all threads. It is OK to use it to load
plugins since only one thread loads plugins.  Avoid sharing Plugin_list
iterator in all other cases.

	PR gold/26200
	* plugin.cc (Plugin_manager::claim_file): Don't share Plugin_list
	iterator.
	(Plugin_manager::all_symbols_read): Likewise.
	(Plugin_manager::cleanup): Likewise.
2020-11-08 04:10:15 -08:00
Alan Modra
b0d0d02bde PowerPC problem building gold with clang
* powerpc.cc (Target_powerpc::tocsave_loc): Return a pointer.
	(Target_powerpc::Relocate::relocate): Avoid -Wdangling-gsl error.
2020-11-04 00:48:51 +10:30
Nick Gasson
af61e84fd2 gold: ensure file_counts_lock is initialized before using
Since upgrading to binutils 2.35 I've been experiencing random memory
corruption related crashes with ld.gold --threads. It's caused by
multiple threads concurrently pushing elements onto the shared
std::vector in File_read::record_file_read(). This vector is supposed to
be protected by file_counts_lock, but that is initialized lazily and
might be NULL when File_read::open() is called, in which case
Hold_optional_lock silently skips locking it.

Fix by calling the initialize() method before attempting to acquire the
lock, the same as other places that use file_counts_lock.

	PR 26827
	* fileread.cc (File_read::open): Ensure file_counts_lock is
	initialized.
	* testsuite/Makefile.am (check_PROGRAMS): Add a test that passes
	-Wl,--threads.
	* testsuite/Makefile.in: Regenerate.
2020-11-03 10:34:51 +10:30
H.J. Lu
b8fd9b80ee gold: Support GNU_PROPERTY_X86_ISA_1_BASELINE marker
* testsuite/gnu_property_test.sh: Updated.
2020-10-30 06:51:24 -07:00
H.J. Lu
bec0b9f6f2 gold: Skip bootstrap-test/bootstrap-test-r for LTO build
Skip bootstrap-test and bootstrap-test-r for LTO build due to different
build IDs.

	* Makefile.am (bootstrap-test): Skip for LTO build.
	(bootstrap-test-r): Likewise.
2020-10-22 07:03:59 -07:00
H.J. Lu
6c0005b8f4 gold: Skip some incremental tests
Skip incremental_test_2, incremental_test_3, incremental_test_4,
incremental_test_5, incremental_copy_test, incremental_common_test_1
and incremental_comdat_test_1 when -fcf-protection is used to compile
gold since gold doesn't properly support -fcf-protection on Intel CET
enabled OS.

Also skip incremental_copy_test and incremental_comdat_test_1 for GCC 9
or later since they failed with GCC 9 or later.

	PR gold/23539
	* configure.ac: Check for GCC 9 or later and for -fcf-protection.
	* configure: Regenerated.
	* testsuite/Makefile.am (check_PROGRAMS): Skip incremental_test_2,
	incremental_test_3, incremental_test_4, incremental_test_5,
	incremental_copy_test, incremental_common_test_1 and
	incremental_comdat_test_1 for -fcf-protection.  Also Skip
	incremental_copy_test and incremental_comdat_test_1 for GCC 9 or
	later.
	* testsuite/Makefile.in: Regenerated.
2020-10-13 05:23:13 -07:00
H.J. Lu
29700bfff4 gold: Discard .note.gnu.property section
Discard .note.gnu.property section since it changes the expected section
order.

	PR gold/23503
	* testsuite/Makefile.am (justsyms_lib): Pass
	-T $(srcdir)/justsyms_lib.t to gold.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/justsyms_lib.t: New file.
	* testsuite/script_test_10.t: Discard .note.gnu.property section.
2020-10-13 05:22:08 -07:00
H.J. Lu
586e30940e gold: Update GNU_PROPERTY_X86_XXX macros
This patch updates GNU_PROPERTY_X86_XXX macros for gold:

1. GNU_PROPERTY_X86_UINT32_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_AND_LO      0xc0000002
 #define GNU_PROPERTY_X86_UINT32_AND_HI      0xc0007fff

2. GNU_PROPERTY_X86_UINT32_OR_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_LO    0xc0008000
 #define GNU_PROPERTY_X86_UINT32_OR_HI    0xc000ffff

3. GNU_PROPERTY_X86_UINT32_OR_AND_XXX: A 4-byte unsigned integer property.
A bit is set if it is set in any relocatable inputs and the property is
present in all relocatable inputs:

 #define GNU_PROPERTY_X86_UINT32_OR_AND_LO   0xc0010000
 #define GNU_PROPERTY_X86_UINT32_OR_AND_HI   0xc0017fff

4. GNU_PROPERTY_X86_FEATURE_2_NEEDED, GNU_PROPERTY_X86_FEATURE_2_USED
and GNU_PROPERTY_X86_FEATURE_2_XXX bits.

GNU_PROPERTY_X86_FEATURE_1_AND is unchanged.  GNU_PROPERTY_X86_ISA_1_USED
and GNU_PROPERTY_X86_ISA_1_NEEDED are updated to better support targeted
processors since GNU_PROPERTY_X86_ISA_1_?86 aren't isn't very useful.
A new set of GNU_PROPERTY_X86_ISA_1_XXX bits are defined.  The previous
GNU_PROPERTY_X86_ISA_1_XXX macros are deprecated and renamed to
GNU_PROPERTY_X86_COMPAT_ISA_1_XXX and GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX.

elfcpp/

	* elfcpp.h (GNU_PROPERTY_X86_ISA_1_USED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_ISA_1_USED): This.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED): This.
	(GNU_PROPERTY_X86_UINT32_AND_LO): New.
	(GNU_PROPERTY_X86_UINT32_AND_HI): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_LO): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_HI): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_AND_LO): Likewise.
	(GNU_PROPERTY_X86_UINT32_OR_AND_HI): Likewise.
	(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): New.
	(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): Likewise.
	(GNU_PROPERTY_X86_FEATURE_1_AND): Updated to
	(GNU_PROPERTY_X86_UINT32_AND_LO + 0).
	(GNU_PROPERTY_X86_ISA_1_NEEDED): New.  Defined to
	GNU_PROPERTY_X86_UINT32_OR_LO + 2.
	(GNU_PROPERTY_X86_FEATURE_2_NEEDED): New.  Defined to
	(GNU_PROPERTY_X86_UINT32_OR_LO + 1).
	(GNU_PROPERTY_X86_ISA_1_USED): New.  Defined to
	GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2.
	(GNU_PROPERTY_X86_FEATURE_2_USED): New.  Defined to
	(GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1).

gold/

	* x86_64.cc (Target_x86_64::Target_x86_64): Initialize
	feature_2_used_, feature_2_needed_ and object_feature_2_used_.
	(Target_x86_64::feature_2_used_): New data member.
	(Target_x86_64::feature_2_needed_): Likewise.
	(Target_x86_64::object_isa_1_used_): Likewise.
	(Target_x86_64::record_gnu_property): Support
	GNU_PROPERTY_X86_COMPAT_ISA_1_USED,
	GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED,
	GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED,
	GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED,
	GNU_PROPERTY_X86_FEATURE_2_USED and
	GNU_PROPERTY_X86_FEATURE_2_NEEDED.
	(Target_x86_64::merge_gnu_properties): Merge FEATURE_2_USED bits.
	Initialize object_feature_2_used_.
	(Target_x86_64::do_finalize_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_2_USED and
	GNU_PROPERTY_X86_FEATURE_2_NEEDED.
	* testsuite/gnu_property_a.S (GNU_PROPERTY_X86_ISA_1_USED): Set
	to 0xc0010002.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
	* testsuite/gnu_property_b.S (GNU_PROPERTY_X86_ISA_1_USED): Set
	to 0xc0010002.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
	* testsuite/gnu_property_c.S (GNU_PROPERTY_X86_ISA_1_USED): Set
	to 0xc0010002.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Set to 0xc0008002.
	* testsuite/gnu_property_test.sh: Updated.
2020-10-13 05:21:05 -07:00
H.J. Lu
6bf4a34047 gold: Properly align the NT_GNU_PROPERTY_TYPE_0 note
The NT_GNU_PROPERTY_TYPE_0 note should be aligned to 8 bytes for 64-bit
ELF as specified by gABI.  A note section can be only placed in a PT_NOTE
segment with the same alignment.

	PR gold/22914
	PR gold/23535
	* layout.cc (Layout::attach_allocated_section_to_segment): Place
	a note section in a PT_NOTE segment with the same alignment.  Set
	the alignment of the PT_NOTE segment from the alignment of the
	note section.
	(Layout::create_note): Align the NT_GNU_PROPERTY_TYPE_0 note to 8
	bytes for 64-bit ELF.
	(Layout::segment_precedes): Place segments with larger alignments
	first.
	* output.cc (Output_segment::Output_segment): Initialize align_.
	* output.h (Output_segment): Add align, set_align and align_.
	* testsuite/Makefile.am (gnu_property_test.stdout): Pass -lhSWn
	to $(TEST_READELF).
	(gnu_property_test): Pass --build-id to ld.
	* testsuite/Makefile.in: Regenerated.
	* testsuite/gnu_property_test.sh (check_alignment): New.
	Use check_alignment to check the NT_GNU_PROPERTY_TYPE_0 note
	alignment.  Verify that there are 2 PT_NOTE segments.
2020-10-13 05:18:24 -07:00
H.J. Lu
aac1d94f19 Gold: Enable safe ICF for shared object on x86-64
With

commit 4aebb6312e
Author: Rahul Chaudhry <rahulchaudhry@google.com>
Date:   Wed Feb 15 00:37:10 2017 -0800

    Improved support for --icf=safe when used with -pie.

we now check opcode with R_X86_64_PC32 relocation, which tell branches
from other instructions.  We can enable safe ICF for shared object on
x86-64.  Also, global symbols with non-default visibility should be
folded like local symbols.

	PR gold/21452
	* x86_64.cc (Scan::local_reloc_may_be_function_pointer): Remove
	check for shared library.
	(Scan::global_reloc_may_be_function_pointer): Remove check for
	shared library and symbol visibility.
	* testsuite/icf_safe_so_test.cc (bar_static): New function.
	(main): Take function address of bar_static and use it.
	* testsuite/icf_safe_so_test.sh (arch_specific_safe_fold): Also
	check fold on x86-64.  Check bar_static isn't folded.
2020-10-13 05:10:36 -07:00
H.J. Lu
1fb1d64f4a Gold: Skip zero-sized sections for ICF
Skip zero-sized sections since there is no need to do ICF on them.

	* icf.cc (Icf::find_identical_sections): Skip zero-sized sections.
2020-10-13 05:08:39 -07:00
Alan Modra
fa40fbe484 [GOLD] Power10 segv due to wild r2
Calling non-pcrel functions from pcrel code requires a stub to set up
r2.  Gold created the stub, but an "optimisation" made the stub jump
to the function local entry, ie. r2 was not initialised.

This patch fixes that long branch stub problem, and another that might
occur for plt call stubs to local functions.

bfd/
	* elf64-ppc.c (write_plt_relocs_for_local_syms): Don't do local
	entry offset optimisation.
gold/
	* powerpc.cc (Powerpc_relobj::do_relocate_sections): Don't do
	local entry offset optimisation for lplt_section.
	(Target_powerpc::Branch_info::make_stub): Don't add local
	entry offset to long branch dest passed to
	add_long_branch_entry.  Do pass st_other bits.
	(Stub_table::Branch_stub_ent): Add "other_" field.
	(Stub_table::add_long_branch_entry): Add "other" param, and
	save.
	(Stub_table::branch_stub_size): Adjust long branch offset.
	(Stub_table::do_write): Likewise.
	(Target_powerpc::Relocate::relocate): Likewise.
2020-10-09 23:24:17 +10:30
Alan Modra
4290b0ab2b [GOLD] internal error in relocate, at powerpc.cc:10473
GOT relocations can refer directly to a function in a fixed position
executable, unlike ADDR64 which needs a global entry stub, or branch
relocs, which need PLT stubs.

	* powerpc.cc (is_got_reloc): New function.
	(Target_powerpc::Relocate::relocate): Use it here, exclude GOT
	relocs when looking for stubs.
2020-10-09 23:23:27 +10:30
H.J. Lu
f511427204 gold: Update testsuite/split_[i386|x32|x86_64].sh
Update testsuite/split_i386.sh, testsuite/split_x32.sh and
testsuite/split_x86_64.sh for

commit f9ff65d4df
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Oct 8 10:27:43 2020 +1030

    [GOLD] Increase --split-stack-adjust-size

	* testsuite/split_i386.sh: Updated for --split-stack-adjust-size
	default change.
	* testsuite/split_x32.sh: Likewise.
	* testsuite/split_x86_64.sh: Likewise.
2020-10-08 05:01:22 -07:00
Alan Modra
f9ff65d4df [GOLD] Increase --split-stack-adjust-size
For functions with small (< 256 bytes) stack frames, the current x86
do_calls_non_split ignores --split-stack-adjust-size and, in
combination with __morestack_non_split, supplies a non-split-stack
function with at least 0x100000 (1M) available stack.  On powerpc64, a
default of 0x4000 is not large enough to reliably work with the golang
testsuite.  This increase the default size to the defacto x86 value.

	* options.h (split_stack_adjust_size): Default to 0x100000.
2020-10-08 11:28:05 +10:30
Alan Modra
63e5eea234 [GOLD] PPC64_OPT_LOCALENTRY is incompatible with tail calls
Gold version of commit 3cd7c7d7ef.

	* powerpc.cc (Target_powerpc): Rename power10_stubs_ to
	power10_relocs_.
	(Target_powerpc::set_power10_relocs): New accessor.
	(Target_powerpc::set_power10_stubs): Delete.
	(Target_powerpc::power10_stubs): Adjust.
	(Target_powerpc::has_localentry0): New accessor.
	(ld_0_11): New constant.
	(glink_eh_frame_fde_64v1, glink_eh_frame_fde_64v2): Adjust.
	(glink_eh_frame_fde_64v2_localentry0): New.
	(Output_data_glink::pltresolve_size): Update.
	(Output_data_glink::add_eh_frame): Use localentry0 version eh_frame.
	(Output_data_glink::do_write): Move r2 save to start of ELFv2 stub
	and only emit for has_localentry0.  Don't use r2 in the stub.
	(Target_powerpc::Scan::local, global): Adjust for
	set_power10_relocs renaming.
	(Target_powerpc::scan_relocs): Warn and reset plt_localentry0_.
2020-09-26 20:34:55 +09:30
Alan Modra
a993d270f8 [GOLD] PowerPC64 __tls_get_addr_opt stub
This stub doesn't have the r2 store at the beginning.

	* powerpc.cc (Target_powerpc::Relocate::relocate): Don't skip
	first insn of __tls_get_addr_opt stub.
2020-09-24 07:55:48 +09:30