Commit Graph

4791 Commits

Author SHA1 Message Date
Alan Modra
5160d0f323 PR26979, Visibility of undefined foo@v1 should constrain foo@@v1
Also, undefined foo should constrain the visibility of foo@@v1 just as
it does for a later plain foo definition.

bfd/
	PR 26979
	* elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype.
	* elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace
	isym parameter with st_other.  Adjust code.
	* elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise.
	* elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elflink.c (elf_merge_st_other): Likewise.
	(_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit.
	(_bfd_elf_copy_link_hash_symbol_type): Likewise.
	(_bfd_elf_add_default_symbol): Merge st_other from undecorated
	symbol and @VER symbol to @@VER symbol.
ld/
	* testsuite/ld-elf/pr26979a.s,
	* testsuite/ld-elf/pr26979b.s,
	* testsuite/ld-elf/pr26979c.s,
	* testsuite/ld-elf/pr26979.ver,
	* testsuite/ld-elf/pr26979a.d,
	* testsuite/ld-elf/pr26979b.d: New tests.
2020-12-01 11:26:35 +10:30
H.J. Lu
15eb8c2d92 ld: Xfail PR ld/26936 test if not supported
Linkonce sections and comdat groups can be mixed only if comdat groups
have only a single member with matching symbol table entries.  Xfail
ld/26936 test:

1. If comdat groups always have more than one member.
2. If symbol table entries in linkonce and comdat group don't match.
3. If the assembly source file is renamed.

	PR ld/26936
	* testsuite/ld-elf/pr26936.d: Xfail targets which don't support
	mixing linkonce and comdat sections.
2020-11-30 05:21:51 -08:00
Alan Modra
8d748d1dc5 PR26907, segment contains empty SHT_NOBITS section
Section ordering is important for _bfd_elf_map_sections_to_segments
and assign_file_positions_for_load_sections, which are only prepared
to handle sections in increasing LMA order.  When zero size sections
are involved it is possible to have multiple sections at the same LMA.
In that case the zero size sections must sort before any non-zero size
sections regardless of their types.

bfd/
	PR 26907
	* elf.c (elf_sort_sections): Don't sort zero size !load sections
	after load sections.
ld/
	* testsuite/ld-elf/pr26907.ld,
	* testsuite/ld-elf/pr26907.s,
	* testsuite/ld-elf/pr26907.d: New test.
2020-11-28 18:31:32 +10:30
Jozef Lawrynowicz
2c6f3e56cb ELF: Support .noinit and .persistent sections
The ".persistent" section is for data that should be initialized during
load, but not during application reset.

The ".noinit" section is for data that should not be initialized during
load or application reset.

Targets utilizing the elf.sc linker script template can define
HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent
output sections in the generated linker script.

Targets with existing support for .noinit did not handle unique
.noinit.* and .gnu.linkonce.n.* sections the .noinit output section,
this patch also fixes that.

bfd/ChangeLog:

	* elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p.
	(special_sections_n): Add .noinit.
	(special_sections_p): Add .persistent.

binutils/ChangeLog:

	* testsuite/lib/binutils-common.exp (supports_noinit_section): New.
	(supports_persistent_section): New.

gas/ChangeLog:

	* testsuite/gas/elf/elf.exp: Run new tests.
	* testsuite/gas/elf/section25.d: New test.
	* testsuite/gas/elf/section25.s: New test.
	* testsuite/gas/elf/section26.d: New test.
	* testsuite/gas/elf/section26.s: New test.

ld/ChangeLog:

	* emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section
	definition.
	Define HAVE_{NOINIT,PERSISTENT}=yes.
	* scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*
	input section wildcard patterns.
	* scripttempl/elf.sc: Define .noinit and .persistent sections when
	HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes".
	* scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	(.persistent): Add .persistent.* and
	.gnu.linkonce.p.*. input section wildcard patterns.
	* scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	* scripttempl/pru.sc: Likewise.
	* testsuite/ld-elf/noinit-sections-1.d: New test.
	* testsuite/ld-elf/noinit-sections-2.d: New test.
	* testsuite/ld-elf/noinit-sections-2.l: New test.
	* testsuite/ld-elf/noinit-sections.s: New test.
	* testsuite/ld-elf/persistent-sections-1.d: New test.
	* testsuite/ld-elf/persistent-sections-2.d: New test.
	* testsuite/ld-elf/persistent-sections-2.l: New test.
	* testsuite/ld-elf/persistent-sections.s: New test.
2020-11-27 10:45:35 +00:00
Alan Modra
9ed0136bff PR26936 testsuite fixes
Many targets fail this test due to -z noseparate-code not being
supported, or _start not being the proper entry symbol, or "as -g"
something other than "generate debug".

	PR 26936
	* testsuite/ld-elf/pr26936.d: Pass --gen-debug to gas rather than -g.
	Only run when -shared -z options are supported.
	* testsuite/ld-elf/pr26936b.s: Define more entry symbols.
2020-11-26 18:40:10 +10:30
H.J. Lu
58349d00f4 elf: Get the real kept section
When mixing linkonce and comdat sections, we need to keep searching to
get the real kept section.

bfd/

	PR ld/26936
	* elflink.c (_bfd_elf_check_kept_section): Get the real kept
	section.

ld/

	PR ld/26936
	* testsuite/ld-elf/pr26936.d: New file.
	* testsuite/ld-elf/pr26936a.s: Likewise.
	* testsuite/ld-elf/pr26936b.s: Likewise.
	* testsuite/ld-elf/pr26936c.s: Likewise.
2020-11-25 16:14:29 -08:00
Alan Modra
21401fc7bf Duplicate output sections in scripts
Previously, ld merged duplicate output sections if such existed in
scripts, except for those with a constraint of SPECIAL.  This makes
scripts with duplicate output section statements create duplicate
output sections in the linker output file.

	* ldlang.c (lang_output_section_statement_lookup): Change "create"
	parameter to a tristate, if 2 then always create a new output
	section statement.  Update all callers, with
	lang_enter_output_section_statement using "2".
	(map_input_to_output_sections): Don't ignore SPECIAL constraint
	here.
	* ldlang.h (lang_output_section_statement_type): Update prototype.
	(lang_output_section_find): Update.
2020-11-25 19:13:51 +10:30
H.J. Lu
d0089f12f6 ld/x86-64: Add PR gold/26939 tests
GOTPCRELX relocations can be transformed only when addend == -4.  Add
tests for GOTPCRELX relocations with addend != -4.

	PR gold/26939
	* testsuite/ld-x86-64/pr26939-x32.d: New file.
	* testsuite/ld-x86-64/pr26939.d: Likewise.
	* testsuite/ld-x86-64/pr26939.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR gold/26939 tests.
2020-11-24 11:32:26 -08:00
H.J. Lu
cbf097d7b0 s390x: Set .got sh_entsize only if .got size > 0
bfd/

	PR ld/26918
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Set .got
	sh_entsize only if .got size > 0.

ld:

	PR ld/26918
	* testsuite/ld-s390/pr26918-1.d: New file.
	* testsuite/ld-s390/pr26918-1.s: Likewise.
	* testsuite/ld-s390/s390.exp: Run all *.d tests.
2020-11-23 05:13:55 -08:00
Shahab Vahedi
e1b9725dfa ld: Make ARC's tls_ie-01 test more flexible
This is to address the regressions addressed by Nic [1].

The regular expression pattern for the tls_ie-01 test was
too strict and raising false alarms.  The new pattern only
looks for matches that should be there AND ignores the boiler
plates from the object dump.

[1] New failures for ARC targets in linker testsuite
https://sourceware.org/pipermail/binutils/2020-November/114177.html

ld/

	* testsuite/ld-arc/tls_ie-01.d: Use a more general pattern.
2020-11-23 12:25:44 +02:00
Nelson Chu
abd20cb637 RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.
I get the feedback recently that enable linker relaxations may fail to
build some program.  Consider the following case,

	.text
foo:
	addi	a0, a0, %pcrel_lo(.L2)
	call	foo
.L1:	auipc	a1, %pcrel_hi(data_g)
	addi	a1, a1, %pcrel_lo(.L1)
	lui	a2, %hi(data_g)
	addi	a2, a2, %lo(data_g)
	lui	a3, %tprel_hi(data_t)
	add	a3, a3, tp, %tprel_add(data_t)
	addi	a3, a3, %tprel_lo(data_t)
.L2:	auipc	a0, %pcrel_hi(data_g)

	.data
	.word 0x0
	.global data_g
data_g:	.word 0x1

	.section .tbss
data_t:	.word 0x0

The current ld reports `dangerous relocation error` when doing the
pcgp relaxation,
test.o: in function `foo':
(.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi

The .L2 auipc should not be removed since it is behind the corresponding
addi, so we record the information in the pcgp_relocs table to avoid
removing the auipc later.  But current ld still remove it since we do not
update the pcgp_relocs table while doing other relaxations.  I have two
solutions to fix the problem,

1. Update the pcgp_relocs table once we actually delete the code.
2. Add new relax pass to do the pcgp relaxations

At first I tried to do the first solution, and we need to update at
least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off
and hi_addr (symbol value) of riscv_pcgp_hi_reloc.  Update the hi_sec_off
is simple, but it is more complicate to update the symbol value, since we
almost have to do parts the same works of _bfd_riscv_relax_call again in
the riscv_relax_delete_bytes to get the correct symbol value.

Compared with the first solution, the second one is more intuitive and
simple.  We add a new relax pass to do the pcgp relaxations later, so
we will get all the information correctly in the _bfd_riscv_relax_call,
including the symbol value, without changing so much code.  I do not see
any penalty by adding a new relax pass for now, so it should be fine
to delay the pcgp relaxations.

Besides, I have pass all riscv-gnu-toolchain regressions for this patch.

	bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_section):  Add a new relax pass
	to do the pcgp relaxation later, after the lui and call relaxations,
	but before the delete and alignment relaxations.

	ld/
	* emultempl/riscvelf.em (riscv_elf_before_allocation): Change
	link_info.relax_pass from 3 to 4.
	* testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
	* testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-11-21 09:41:58 +08:00
Nick Alcock
0e28ade476 libctf, ld: properly deduplicate function types
Some type kinds in CTF (functions, arrays, pointers, slices, and
cvr-quals) are intrinsically nameless: the ctt_name field in the CTF
is always zero, and the libctf API provides no way to set a name.
But the compiler can and does sometimes set names for some of these
kinds: in particular, the name it sets on CTF_K_FUNCTION types is the
means it uses to force the name of the function into the string table
so that it can point at it from the function info section.

So null out the name at hashing time so that the deduplicator can
correctly detect that e.g. function types identical but for name should
be considered truly identical, since they will not have a name when the
deduplicator re-emits them into the output.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/data-func-conflicted.d: Shrink the expected
	size of the type section now that function types are being
	deduplicated properly.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dedup.c (ctf_dedup_rhash_type): Null out the names of nameless
	type kinds, just in case the input has named them.
2020-11-20 13:34:10 +00:00
Nick Alcock
0ad70c536a ld, ctf: new and adjusted CTF tests due to func info / object data sections
The flags word is nonzero now (so all the tests have been adjusted to
not depend on its content): some of them have data objects and functions
in the data object and function info sections now, rather than in the
variable section or recorded nowhere.  There is a new test for
parent/child relationships and index section emission.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for nonzero flags word and
	public symbols in the data section rather than variables: use
	sysv hash style to keep test results the same on non-GNU targets.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise, but in the function section.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d:  Adjust for nonzero
	flags word.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
	* testsuite/ld-ctf/cycle-1.d: Likewise.
	* testsuite/ld-ctf/cycle-2.A.d: Likewise.
	* testsuite/ld-ctf/cycle-2.B.d: Likewise.
	* testsuite/ld-ctf/cycle-2.C.d: Likewise.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d:  Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d:  Likewise.
	* testsuite/ld-ctf/data-func-1.c: New test.
	* testsuite/ld-ctf/data-func-2.c: Likewise.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
2020-11-20 13:34:10 +00:00
Nick Alcock
3d16b64e28 bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym
This is embarrassing.

The whole point of CTF is that it remains intact even after a binary is
stripped, providing a compact mapping from symbols to types for
everything in the externally-visible interface of an ELF object: it has
connections to the symbol table for that purpose, and to the string
table to avoid duplicating symbol names.  So it's a shame that the hooks
I implemented last year served to hook it up to the .symtab and .strtab,
which obviously disappear on strip, leaving any accompanying the CTF
dict containing references to strings (and, soon, symbols) which don't
exist any more because their containing strtab has been vaporized.  The
original Solaris design used .dynsym and .dynstr (well, actually,
.ldynsym, which has more symbols) which do not disappear. So should we.

Thankfully the work we did before serves as guide rails, and adjusting
things to use the .dynstr and .dynsym was fast and easy.  The only
annoyance is that the dynsym is assembled inside elflink.c in a fairly
piecemeal fashion, so that the easiest way to get the symbols out was to
hook in before every call to swap_symbol_out (we also leave in a hook in
front of symbol additions to the .symtab because it seems plausible that
we might want to hook them in future too: for now that hook is unused).
We adjust things so that rather than being offered a whole hash table of
symbols at once, libctf is now given symbols one at a time, with st_name
indexes already resolved and pointing at their final .dynstr offsets:
it's now up to libctf to resolve these to names as needed using the
strtab info we pass it separately.

Some bits might be contentious.  The ctf_new_dynstr callback takes an
elf_internal_sym, and this remains an elf_internal_sym right down
through the generic emulation layers into ldelfgen.  This is no worse
than the elf_sym_strtab we used to pass down, but in the future when we
gain non-ELF CTF symtab support we might want to lower the
elf_internal_sym to some other representation (perhaps a
ctf_link_symbol) in bfd or in ldlang_ctf_new_dynsym.  We rename the
'apply_strsym' hooks to 'acquire_strings' instead, becuse they no longer
have anything to do with symbols.

There are some API changes to pieces of API which are technically public
but actually totally unused by anything and/or unused by anything but ld
so they can change freely: the ctf_link_symbol gains new fields to allow
symbol names to be given as strtab offsets as well as strings, and a
symidx so that the symbol index can be passed in.  ctf_link_shuffle_syms
loses its callback parameter: the idea now is that linkers call the new
ctf_link_add_linker_symbol for every symbol in .dynsym, feed in all the
strtab entries with ctf_link_add_strtab, and then a call to
ctf_link_shuffle_syms will apply both and arrange to use them to reorder
the CTF symtab at CTF serialization time (which is coming in the next
commit).

Inside libctf we have a new preamble flag CTF_F_DYNSTR which is always
set in v3-format CTF dicts from this commit forwards: CTF dicts without
this flag are associated with .strtab like they used to be, so that old
dicts' external strings don't turn to garbage when loaded by new libctf.
Dicts with this flag are associated with .dynstr and .dynsym instead.
(The flag is not the next in sequence because this commit was written
quite late: the missing flags will be filled in by the next commit.)

Tests forthcoming in a later commit in this series.

bfd/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* elflink.c (elf_finalize_dynstr): Call examine_strtab after
	dynstr finalization.
	(elf_link_swap_symbols_out): Don't call it here.  Call
	ctf_new_symbol before swap_symbol_out.
	(elf_link_output_extsym): Call ctf_new_dynsym before
	swap_symbol_out.
	(bfd_elf_final_link): Likewise.
	* elf.c (swap_out_syms): Pass in bfd_link_info.  Call
	ctf_new_symbol before swap_symbol_out.
	(_bfd_elf_compute_section_file_positions): Adjust.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* readelf.c (dump_section_as_ctf): Use .dynsym and .dynstr, not
	.symtab and .strtab.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* bfdlink.h (struct elf_sym_strtab): Replace with...
	(struct elf_internal_sym): ... this.
	(struct bfd_link_callbacks) <examine_strtab>: Take only a
	symstrtab argument.
	<ctf_new_symbol>: New.
	<ctf_new_dynsym>: Likewise.
	* ctf-api.h (struct ctf_link_sym) <st_symidx>: New.
	<st_nameidx>: Likewise.
	<st_nameidx_set>: Likewise.
	(ctf_link_iter_symbol_f): Removed.
	(ctf_link_shuffle_syms): Remove most parameters, just takes a
	ctf_dict_t now.
	(ctf_link_add_linker_symbol): New, split from
	ctf_link_shuffle_syms.
	* ctf.h (CTF_F_DYNSTR): New.
	(CTF_F_MAX): Adjust.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ldelfgen.c (struct ctf_strsym_iter_cb_arg): Rename to...
	(struct ctf_strtab_iter_cb_arg): ... this, changing fields:
	<syms>: Remove.
	<symcount>: Remove.
	<symstrtab>: Rename to...
	<strtab>: ... this.
	(ldelf_ctf_strtab_iter_cb): Adjust.
	(ldelf_ctf_symbols_iter_cb): Remove.
	(ldelf_new_dynsym_for_ctf): New, tell libctf about a single
	symbol.
	(ldelf_examine_strtab_for_ctf): Rename to...
	(ldelf_acquire_strings_for_ctf): ... this, only doing the strtab
	portion and not symbols.
	* ldelfgen.h: Adjust declarations accordingly.
	* ldemul.c (ldemul_examine_strtab_for_ctf): Rename to...
	(ldemul_acquire_strings_for_ctf): ... this.
	(ldemul_new_dynsym_for_ctf): New.
	* ldemul.h: Adjust declarations accordingly.
	* ldlang.c (ldlang_ctf_apply_strsym): Rename to...
	(ldlang_ctf_acquire_strings): ... this.
	(ldlang_ctf_new_dynsym): New.
	(lang_write_ctf): Call ldemul_new_dynsym_for_ctf with NULL to do
	the actual symbol shuffle.
	* ldlang.h (struct elf_strtab_hash): Adjust accordingly.
	* ldmain.c (bfd_link_callbacks): Wire up new/renamed callbacks.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-link.c (ctf_link_shuffle_syms): Adjust.
	(ctf_link_add_linker_symbol): New, unimplemented stub.
	* libctf.ver: Add it.
	* ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized
	dicts.
	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the
	symtab/strtab if not present, dynsym/dynstr otherwise.
	* ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from
	some arbitrary member of a CTF archive.
	* ctf-impl.h (ctf_arc_bufpreamble): Declare it.
2020-11-20 13:34:07 +00:00
Nick Alcock
139633c307 libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t
The naming of the ctf_file_t type in libctf is a historical curiosity.
Back in the Solaris days, CTF dictionaries were originally generated as
a separate file and then (sometimes) merged into objects: hence the
datatype was named ctf_file_t, and known as a "CTF file".  Nowadays, raw
CTF is essentially never written to a file on its own, and the datatype
changed name to a "CTF dictionary" years ago.  So the term "CTF file"
refers to something that is never a file!  This is at best confusing.

The type has also historically been known as a 'CTF container", which is
even more confusing now that we have CTF archives which are *also* a
sort of container (they contain CTF dictionaries), but which are never
referred to as containers in the source code.

So fix this by completing the renaming, renaming ctf_file_t to
ctf_dict_t throughout, and renaming those few functions that refer to
CTF files by name (keeping compatibility aliases) to refer to dicts
instead.  Old users who still refer to ctf_file_t will see (harmless)
pointer-compatibility warnings at compile time, but the ABI is unchanged
(since C doesn't mangle names, and ctf_file_t was always an opaque type)
and things will still compile fine as long as -Werror is not specified.
All references to CTF containers and CTF files in the source code are
fixed to refer to CTF dicts instead.

Further (smaller) renamings of annoyingly-named functions to come, as
part of the process of souping up queries across whole archives at once
(needed for the function info and data object sections).

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
	(dump_ctf_archive_member): Likewise.
	(dump_ctf): Likewise. Use ctf_dict_close, not ctf_file_close.
	* readelf.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
	(dump_ctf_archive_member): Likewise.
	(dump_section_as_ctf): Likewise.  Use ctf_dict_close, not
	ctf_file_close.

gdb/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctfread.c: Change uses of ctf_file_t to ctf_dict_t.
	(ctf_fp_info::~ctf_fp_info): Call ctf_dict_close, not ctf_file_close.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_file_t): Rename to...
	(ctf_dict_t): ... this.  Keep ctf_file_t around for compatibility.
	(struct ctf_file): Likewise rename to...
	(struct ctf_dict): ... this.
	(ctf_file_close): Rename to...
	(ctf_dict_close): ... this, keeping compatibility function.
	(ctf_parent_file): Rename to...
	(ctf_parent_dict): ... this, keeping compatibility function.
	All callers adjusted.
	* ctf.h: Rename references to ctf_file_t to ctf_dict_t.
	(struct ctf_archive) <ctfa_nfiles>: Rename to...
	<ctfa_ndicts>: ... this.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ldlang.c (ctf_output): This is a ctf_dict_t now.
	(lang_ctf_errs_warnings): Rename ctf_file_t to ctf_dict_t.
	(ldlang_open_ctf): Adjust comment.
	(lang_merge_ctf): Use ctf_dict_close, not ctf_file_close.
	* ldelfgen.h (ldelf_examine_strtab_for_ctf): Rename ctf_file_t to
	ctf_dict_t.  Change opaque declaration accordingly.
	* ldelfgen.c (ldelf_examine_strtab_for_ctf): Adjust.
	* ldemul.h (examine_strtab_for_ctf): Likewise.
	(ldemul_examine_strtab_for_ctf): Likewise.
	* ldeuml.c (ldemul_examine_strtab_for_ctf): Likewise.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h: Rename ctf_file_t to ctf_dict_t: all declarations
	adjusted.
	(ctf_fileops): Rename to...
	(ctf_dictops): ... this.
	(ctf_dedup_t) <cd_id_to_file_t>: Rename to...
	<cd_id_to_dict_t>: ... this.
	(ctf_file_t): Fix outdated comment.
	<ctf_fileops>: Rename to...
	<ctf_dictops>: ... this.
	(struct ctf_archive_internal) <ctfi_file>: Rename to...
	<ctfi_dict>: ... this.
	* ctf-archive.c: Rename ctf_file_t to ctf_dict_t.
	Rename ctf_archive.ctfa_nfiles to ctfa_ndicts.
	Rename ctf_file_close to ctf_dict_close.  All users adjusted.
	* ctf-create.c: Likewise.  Refer to CTF dicts, not CTF containers.
	(ctf_bundle_t) <ctb_file>: Rename to...
	<ctb_dict): ... this.
	* ctf-decl.c: Rename ctf_file_t to ctf_dict_t.
	* ctf-dedup.c: Likewise.  Rename ctf_file_close to
	ctf_dict_close. Refer to CTF dicts, not CTF containers.
	* ctf-dump.c: Likewise.
	* ctf-error.c: Likewise.
	* ctf-hash.c: Likewise.
	* ctf-inlines.h: Likewise.
	* ctf-labels.c: Likewise.
	* ctf-link.c: Likewise.
	* ctf-lookup.c: Likewise.
	* ctf-open-bfd.c: Likewise.
	* ctf-string.c: Likewise.
	* ctf-subr.c: Likewise.
	* ctf-types.c: Likewise.
	* ctf-util.c: Likewise.
	* ctf-open.c: Likewise.
	(ctf_file_close): Rename to...
	(ctf_dict_close): ...this.
	(ctf_file_close): New trivial wrapper around ctf_dict_close, for
	compatibility.
	(ctf_parent_file): Rename to...
	(ctf_parent_dict): ... this.
	(ctf_parent_file): New trivial wrapper around ctf_parent_dict, for
	compatibility.
	* libctf.ver: Add ctf_dict_close and ctf_parent_dict.
2020-11-20 13:34:04 +00:00
Jozef Lawrynowicz
cc6fd584ed Fix SHF_GNU_RETAIN testsuite fallout
binutils/ChangeLog:

	* testsuite/binutils-all/readelf-maskos-1a.d: Fix test for unrecognized
	bit set in SHF_MASKOS range.
	* testsuite/binutils-all/readelf-maskos-1b.d: Likewise.
	* testsuite/binutils-all/readelf-maskos-unknown.s: New test.

ld/ChangeLog:

	* testsuite/ld-elf/retain3.s: Move symbolic reference into writeable
	.data section from read-only .text section.
	* testsuite/ld-elf/retain5.d: Don't pass --print-gc-sections for test
	that doesn't require it.
	* testsuite/ld-elf/retain6a.d: Adjust test.
	* testsuite/ld-elf/retain6main.s: Move symbolic reference into writeable
	.data section from read-only .text section.
2020-11-20 10:33:28 +00:00
Alan Modra
e4d9e5422f PowerPC paranioa testing of symbol merging involving comdat groups
Ensures we don't mistreat st_other localentry bits.

	* testsuite/ld-powerpc/group1.d,
	* testsuite/ld-powerpc/group1.s,
	* testsuite/ld-powerpc/group1.sym,
	* testsuite/ld-powerpc/group2.d,
	* testsuite/ld-powerpc/group2.s,
	* testsuite/ld-powerpc/group2.sym,
	* testsuite/ld-powerpc/group3.s,
	* testsuite/ld-powerpc/group3.sym: New test files.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2020-11-18 23:49:31 +10:30
Jozef Lawrynowicz
99fabbc973 Support SHF_GNU_RETAIN ELF section flag
The SHF_GNU_RETAIN section flag is an extension to the GNU ELF OSABI.
It is defined as follows:

=========================================================
Section Attribute Flags
+-------------------------------------+
| Name           | Value              |
+-------------------------------------+
| SHF_GNU_RETAIN | 0x200000 (1 << 21) |
+-------------------------------------+

SHF_GNU_RETAIN
  The link editor should not garbage collect the section.
=========================================================

The .section directive accepts the "R" flag, which indicates
SHF_GNU_RETAIN should be applied to the section.

There is not a direct mapping of SHF_GNU_RETAIN to the BFD
section flag SEC_KEEP. Keeping these flags distinct allows
SHF_GNU_RETAIN sections to be explicitly removed by placing them in
/DISCARD/.

bfd/ChangeLog:

	* elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_retain.
	(struct elf_obj_tdata): Increase has_gnu_osabi to 4 bits.
	* elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_retain
	for SHF_GNU_RETAIN.
	(_bfd_elf_final_write_processing): Report if SHF_GNU_RETAIN is
	not supported by the OSABI.
	Adjust error messages.
	* elflink.c (elf_link_input_bfd): Copy enabled has_gnu_osabi bits from
	input BFD to output BFD.
	(bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set.

binutils/ChangeLog:

	* NEWS: Announce SHF_GNU_RETAIN support.
	* readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN.
	Recognize SHF_GNU_RETAIN and SHF_GNU_MBIND only for supported OSABIs.
	* testsuite/binutils-all/readelf.exp: Run new tests.
	Don't run run_dump_test when there isn't an assembler available.
	* testsuite/lib/binutils-common.exp (supports_gnu_osabi): Adjust
	comment.
	* testsuite/binutils-all/readelf-maskos-1a.d: New test.
	* testsuite/binutils-all/readelf-maskos-1b.d: New test.
	* testsuite/binutils-all/readelf-maskos.s: New test.
	* testsuite/binutils-all/retain1.s: New test.
	* testsuite/binutils-all/retain1a.d: New test.
	* testsuite/binutils-all/retain1b.d: New test.

gas/ChangeLog:

	* NEWS: Announce SHF_GNU_RETAIN support.
	* config/obj-elf.c (obj_elf_change_section): Merge SHF_GNU_RETAIN bit
	between section declarations.
	(obj_elf_parse_section_letters): Handle 'R' flag.
	Handle numeric flag values within the SHF_MASKOS range.
	(obj_elf_section): Validate SHF_GNU_RETAIN usage.
	* doc/as.texi: Document 'R' flag to .section directive.
	* testsuite/gas/elf/elf.exp: Run new tests.
	* testsuite/gas/elf/section10.d: Unset SHF_GNU_RETAIN bit.
	* testsuite/gas/elf/section10.s: Likewise.
	* testsuite/gas/elf/section22.d: New test.
	* testsuite/gas/elf/section22.s: New test.
	* testsuite/gas/elf/section23.s: New test.
	* testsuite/gas/elf/section23a.d: New test.
	* testsuite/gas/elf/section23b.d: New test.
	* testsuite/gas/elf/section23b.err: New test.
	* testsuite/gas/elf/section24.l: New test.
	* testsuite/gas/elf/section24.s: New test.
	* testsuite/gas/elf/section24a.d: New test.
	* testsuite/gas/elf/section24b.d: New test.

include/ChangeLog:

	* elf/common.h (SHF_GNU_RETAIN): Define.

ld/ChangeLog:

	* NEWS: Announce support for SHF_GNU_RETAIN.
	* ld.texi (garbage collection): Document SHF_GNU_RETAIN.
	(Output Section Discarding): Likewise.
	* testsuite/ld-elf/elf.exp: Run new tests.
	* testsuite/ld-elf/retain1.s: New test.
	* testsuite/ld-elf/retain1a.d: New test.
	* testsuite/ld-elf/retain1b.d: New test.
	* testsuite/ld-elf/retain2.d: New test.
	* testsuite/ld-elf/retain2.ld: New test.
	* testsuite/ld-elf/retain2.map: New test.
	* testsuite/ld-elf/retain3.d: New test.
	* testsuite/ld-elf/retain3.s: New test.
	* testsuite/ld-elf/retain4.d: New test.
	* testsuite/ld-elf/retain4.s: New test.
	* testsuite/ld-elf/retain5.d: New test.
	* testsuite/ld-elf/retain5.map: New test.
	* testsuite/ld-elf/retain5lib.s: New test.
	* testsuite/ld-elf/retain5main.s: New test.
	* testsuite/ld-elf/retain6a.d: New test.
	* testsuite/ld-elf/retain6b.d: New test.
	* testsuite/ld-elf/retain6lib.s: New test.
	* testsuite/ld-elf/retain6main.s: New test.
2020-11-18 11:51:13 +00:00
Alan Modra
7cc340055d PR26882, --enable-textrel-check=warning test failures on powerpc
PR 26882
	* testsuite/ld-powerpc/dotsym3.d: Add "-z notext" to ld options.
	* testsuite/ld-powerpc/dotsym4.d: Likewise.
	* testsuite/ld-powerpc/ppc476-shared.d: Likewise.
	* testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
	* testsuite/ld-powerpc/powerpc.exp: Likewise for various tests.
	* testsuite/ld-undefined/weak-fundef.s: Add BLPLT variant.
	* testsuite/ld-undefined/weak-undef.exp: Define BLPLT for ppc32.
2020-11-17 20:59:53 +10:30
Nick Clifton
10c9f4e584 Update the Spanish translation for the ld/ subdirectory.
* po/es.po: Updated Spanish translation.
2020-11-16 12:32:06 +00:00
Shahab Vahedi
315d05eb3f ld: Fix the tls_ie-01 test for arc
The purpose of the test is to look for entries of "foo" and
"bar" in the ".got".  The old "objdump -s ..." has been replaced
with "objdump -D ..." to inspect the final executable.  A sample
output looks like:

------------------------8<------------------------

$ arc-elf32-objdump -D -j .got tls_ie-01

tls_ie-01:     file format elf32-littlearc

Disassembly of section .got:

00002110 <_GLOBAL_OFFSET_TABLE_>:
        ...
    211c:       08 00 00 00        .word   0x00000008
    2120:       0c 00 00 00        .word   0x0000000c

------------------------>8------------------------

ld/
	* testsuite/ld-arc/tls_ie-01.d: Update the dump command.
2020-11-16 13:48:49 +02:00
Borislav Petkov
0fa0fc8539 x86: Ignore CS/DS/ES/SS segment-override prefixes in 64-bit mode
"In 64-bit mode, the CS, DS, ES, and SS segment-override prefixes have
no effect. These four prefixes are not treated as segment-override
prefixes for the purposes of multiple-prefix rules. Instead, they are
treated as null prefixes." (AMD APM v2).

However, objdump disassembles instructions containing those ignored
prefixes by still generating that segment override:

  66 66 2e 0f 1f 84 00 	data16 nopw %cs:0x0(%rax,%rax,1)
  00 00 00 00

Print those segment override prefixes as excessive ones:

  66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
  00 00 00 00

which is what they actually are - they have no effect and the decoding
hardware ignores them.

gas/

2020-11-14  Borislav Petkov  <bp@suse.de>

	* testsuite/gas/i386/x86-64-segovr.d: Adjust regexes.
	* testsuite/gas/i386/x86-64-nops.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-1.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-1-g64.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-1-core2.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-1-k8.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-2.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-3.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-4.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-4-core2.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-4-k8.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-5.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-5-k8.d: Likewise.
	* testsuite/gas/i386/x86-64-nops-7.d: Likewise.
	* testsuite/gas/i386/x86-64-nop-1.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-1a.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-1b.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-1c.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-1d.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-1g.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-2c.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-6.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-7.d: Likewise.
	* testsuite/gas/i386/x86-64-align-branch-8.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-1-core2.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-1-k8.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-1.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-2.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-3.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-4-core2.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-4-k8.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-4.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-5-k8.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops-5.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-nops.d:: Likewise.

ld/

2020-11-14  Borislav Petkov  <bp@suse.de>

	* testsuite/ld-x86-64/pe-x86-64-4.od: Adjust regexes.
	* testsuite/ld-x86-64/tlsld3.dd: Likewise.
	* testsuite/ld-x86-64/tlsld4.dd: Likewise.

opcodes/

2020-11-14  Borislav Petkov  <bp@suse.de>

	* i386-dis.c (ckprefix): Do not assign active_seg_prefix in
	64-bit addressing mode.
	(NOTRACK_Fixup): Test prefixes for PREFIX_DS, instead of
	active_seg_prefix.
2020-11-14 06:20:33 -08:00
H.J. Lu
cbd5b99cce elf: Set rel_from_abs to 1 for __ehdr_start
bfdlink.h has

  /* Symbol will be converted from absolute to section-relative.  Set for
     symbols defined by a script from "dot" (also SEGMENT_START or ORIGIN)
     outside of an output section statement.  */
  unsigned int rel_from_abs : 1;

linker.c has

.{* Return TRUE if the symbol described by a linker hash entry H
.   is going to be absolute.  Linker-script defined symbols can be
.   converted from absolute to section-relative ones late in the
.   link.  Use this macro to correctly determine whether the symbol
.   will actually end up absolute in output.  *}
.#define bfd_is_abs_symbol(H) \
.  (((H)->type == bfd_link_hash_defined \
.    || (H)->type == bfd_link_hash_defweak) \
.   && bfd_is_abs_section ((H)->u.def.section) \
.   && !(H)->rel_from_abs)
.

Set rel_from_abs to 1 for __ehdr_start which will be converted from
absolute to section-relative in assign_file_positions_for_load_sections.

	PR ld/26869
	* ldelf.c (ldelf_before_allocation): Set rel_from_abs to 1 for
	__ehdr_start.
	* testsuite/ld-i386/i386.exp: Run pr26869.
	* testsuite/ld-i386/pr26869.d: New file.
	* testsuite/ld-i386/pr26869.s: Likewise.
2020-11-13 15:44:47 -08:00
Andreas Schwab
a76bf0e55d Fix regexp for development.exp
binutils/:
	* Makefile.am (development.exp): Fix regexp.
	* Makefile.in: Regenerate.
gas/:
	* Makefile.am (development.exp): Fix regexp.
	* Makefile.in: Regenerate.
ld/:
	* Makefile.am (development.exp): Fix regexp.
	* Makefile.in: Regenerate.
2020-11-09 12:05:39 +01:00
Nick Clifton
2c72361c81 Extend ld's -Map=<dir> functionality by allowing '%' to be replaced with the output file path.
* lexsup.c (parse_args): Add more checks of the mapfile.  If it is
	a directory use the basename of the output file as the file
	component.  If the % character is present, replace it with the
	full output filepath.
	* testsuite/ld-scripts/map-address.exp: Add test of %
	functionality.
	* ld.texi: Document the new behaviour.
2020-11-06 14:36:45 +00:00
Nick Clifton
fa63ba779d Updated Serbian translation for the ld subdirectory 2020-11-06 12:41:29 +00:00
Nick Clifton
70237b84c5 Fix compile time warning 2020-11-03 08:56:27 +00:00
Alan Modra
b1a92c635c PR26806, Suspected linker bug with LTO
This patch reverts most of git commit 1e3b96fd6c, so IR symbols are
again not marked def_regular or ref_regular.  That should be enough to
stop IR symbols from becoming dynamic.  To mark as-needed shared
libraries referenced by IR symbols, use the referencing BFD rather
than the ref flags.

bfd/
	PR 15146
	PR 26314
	PR 26530
	PR 26806
	* elflink.c (elf_link_add_object_symbols): Don't set def/ref flags
	for plugin syms.  Do allow plugin syms to mark as-needed libs.
ld/
	PR 26806
	* testsuite/ld-plugin/lto-19.h,
	* testsuite/ld-plugin/lto-19a.c,
	* testsuite/ld-plugin/lto-19b.c,
	* testsuite/ld-plugin/lto-19c.c: New test.
	* testsuite/ld-plugin/pr26806.c,
	* testsuite/ld-plugin/pr26806.d: New test.
	* testsuite/ld-plugin/lto.exp: Run them.
2020-11-02 09:39:53 +10:30
H.J. Lu
b0ab069373 x86: Support GNU_PROPERTY_X86_ISA_1_BASELINE marker
GCC 11 supports -march=x86-64-v[234] to enable x86 micro-architecture ISA
levels:

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

X86 ISA markers are updated:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13

GNU_PROPERTY_X86_ISA_1_BASELINE is added and GNU_PROPERTY_X86_ISA_1_V[234]
are updated:

 #define GNU_PROPERTY_X86_ISA_1_BASELINE (1U << 0)
 #define GNU_PROPERTY_X86_ISA_1_V2       (1U << 1)
 #define GNU_PROPERTY_X86_ISA_1_V3       (1U << 2)
 #define GNU_PROPERTY_X86_ISA_1_V4       (1U << 3)

Add -z x86-64-baseline linker command line option to mark x86-64-baseline
ISA level as needed.

bfd/

	PR gas/26703
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Generate
	GNU_PROPERTY_X86_ISA_1_BASELINE for -z x86-64-baseline.

binutils/

	PR gas/26703
	* readelf.c (decode_x86_isa): Handle
	* GNU_PROPERTY_X86_ISA_1_BASELINE.
	* testsuite/binutils-all/i386/empty.d: Updated.
	* testsuite/binutils-all/i386/ibt.d: Likewise.
	* testsuite/binutils-all/i386/pr21231a.d: Likewise.
	* testsuite/binutils-all/i386/pr21231b.d: Likewise.
	* testsuite/binutils-all/i386/shstk.d: Likewise.
	* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.d: Likewise.
	* testsuite/binutils-all/x86-64/pr21231a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.d: Likewise.

gas/

	PR gas/26703
	* config/tc-i386.c (output_insn): Update for
	GNU_PROPERTY_X86_ISA_1_BASELINE.
	* testsuite/gas/i386/property-1.d: Updated.
	* testsuite/gas/i386/property-2.d: Likewise.
	* testsuite/gas/i386/property-3.d: Likewise.
	* testsuite/gas/i386/property-4.d: Likewise.
	* testsuite/gas/i386/property-5.d: Likewise.
	* testsuite/gas/i386/property-6.d: Likewise.
	* testsuite/gas/i386/property-11.d: Likewise.
	* testsuite/gas/i386/property-12.d: Likewise.
	* testsuite/gas/i386/x86-64-property-1.d: Likewise.
	* testsuite/gas/i386/x86-64-property-2.d: Likewise.
	* testsuite/gas/i386/x86-64-property-3.d: Likewise.
	* testsuite/gas/i386/x86-64-property-4.d: Likewise.
	* testsuite/gas/i386/x86-64-property-5.d: Likewise.
	* testsuite/gas/i386/x86-64-property-6.d: Likewise.
	* testsuite/gas/i386/x86-64-property-11.d: Likewise.
	* testsuite/gas/i386/x86-64-property-12.d: Likewise.

include/

	PR gas/26703
	* elf/common.h (GNU_PROPERTY_X86_ISA_1_BASELINE): New.
	(GNU_PROPERTY_X86_ISA_1_V2): Uppdated.
	(GNU_PROPERTY_X86_ISA_1_V3): Likewise.
	(GNU_PROPERTY_X86_ISA_1_V4): Likewise.

ld/

	PR gas/26703
	* NEWS: Mention -z x86-64-baseline.
	* ld.texi: Document -z x86-64-baseline.
	* emulparams/x86-64-level.sh: Handle -z x86-64-baseline.
	* testsuite/ld-elf/x86-feature-1a.rd: Update.
	* testsuite/ld-elf/x86-feature-1b.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1c.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1d.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1e.rd: Likewise.
	* testsuite/ld-i386/pr23372c.d: Likewise.
	* testsuite/ld-i386/pr23486c.d: Likewise.
	* testsuite/ld-i386/pr23486d.d: Likewise.
	* testsuite/ld-i386/pr24322a.d: Likewise.
	* testsuite/ld-i386/pr24322b.d: Likewise.
	* testsuite/ld-i386/property-1a.r: Likewise.
	* testsuite/ld-i386/property-2a.r: Likewise.
	* testsuite/ld-i386/property-3.r: Likewise.
	* testsuite/ld-i386/property-3a.r: Likewise.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-4a.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-5a.r: Likewise.
	* testsuite/ld-i386/property-7a.r: Likewise.
	* testsuite/ld-i386/property-x86-3.d: Likewise.
	* testsuite/ld-i386/property-x86-4a.d: Likewise.
	* testsuite/ld-i386/property-x86-5.d: Likewise.
	* testsuite/ld-i386/property-x86-cet1.d: Likewise.
	* testsuite/ld-i386/property-x86-cet2a.d: Likewise.
	* testsuite/ld-i386/property-x86-cet5a.d: Likewise.
	* testsuite/ld-i386/property-x86-cet5b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt2.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt4.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt5.d: Likewise.
	* testsuite/ld-i386/property-x86-isa1.d: Likewise.
	* testsuite/ld-i386/property-x86-isa2.d: Likewise.
	* testsuite/ld-i386/property-x86-isa3.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk2.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk4.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk5.d: Likewise.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23486c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486c.d: Likewise.
	* testsuite/ld-x86-64/pr23486d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486d.d: Likewise.
	* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322a.d: Likewise.
	* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322b.d: Likewise.
	* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458a.d: Likewise.
	* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458b.d: Likewise.
	* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458c.d: Likewise.
	* testsuite/ld-x86-64/property-1a.r: Likewise.
	* testsuite/ld-x86-64/property-2a.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-3a.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-4a.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-5a.r: Likewise.
	* testsuite/ld-x86-64/property-7a.r: Likewise.
	* testsuite/ld-x86-64/property-x86-3-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet1-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet1.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet2a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet2a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa3-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa3.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run property-x86-isa4.
	* testsuite/ld-i386/property-x86-isa4.d: New file.
	* testsuite/ld-x86-64/property-x86-isa4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa4.d: Likewise.
	* ld/testsuite/ld-x86-64/x86-64.exp: Run property-x86-isa4
	and property-x86-isa4-x32.
2020-10-30 06:50:10 -07:00
H.J. Lu
e7f8dd4a14 ld: Pass -fno-lto in ld-elfweak/elfweak.exp
* testsuite/ld-elfweak/elfweak.exp: Pass $NOLTO_CFLAGS to CC.
2020-10-26 16:45:35 -07:00
Nick Clifton
93cf38c095 Invoke the linker's error handling script with the keyword "undefined-symbol" when using it to help with undefined symbol errors.
PR 26626
	* ldmain.c (undefined_symbol): Use the keyword undefined-symbol
	when invoking the error handling script for undefined symbols.
	* ld.texi: Update documentation.
2020-10-26 12:39:50 +00:00
Cooper Qu
1b03c32c3b CSKY: Change default linker script for elf toolchain.
ld/
	* emulparams/cskyelf.sh (TEXT_START_ADDR): Change to 0x60000000.
	(DATA_ADDR) : Define.
	(OTHER_SYMBOLS) : Define.
	(OTHER_BSS_SYMBOLS) : Set symbol __sbss__.
	(OTHER_BSS_END_SYMBOLS) : Set symbol __ebss__.
	* ld/emulparams/cskyelf_linux.sh : Don't include cskyelf.sh.
	* testsuite/ld-csky/data.d : Fix '/s*' to match spaces.
	* testsuite/ld-csky/hilo16.d : Likewise.

Change-Id: Ia29b32eab4157ae5be0fc0b6125fb5b7d9dac939
2020-10-26 17:13:21 +08:00
H.J. Lu
72d813f35e ld: Set plug_opt only if compiler is available
* testsuite/config/default.exp (plug_opt): Set only if compiler
	is available.
2020-10-23 11:25:15 -07:00
H.J. Lu
6faad766e7 ld: Skip bootstrap tests for -fprofile-generate=
Make plug_opt available to all linker tests.  Skip bootstrap tests when
linker is compiled with -fprofile-generate=.

	* testsuite/ld-plugin/lto.exp (plug_opt): Moved to ...
	* testsuite/config/default.exp (plug_opt): Here.  New.
	* testsuite/ld-bootstrap/bootstrap.exp: Skip when linker is
	compiled with -fprofile-generate=.
2020-10-22 07:03:59 -07:00
H.J. Lu
c6d47bff77 ld: Pass -fno-lto to non LTO tests
* testsuite/config/default.exp (NOLTO_CFLAGS): New.
	* ld/testsuite/ld-elfcomm/elfcomm.exp: Add $NOLTO_CFLAGS to CC.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-gc/gc.exp: Likewise.
	* testsuite/ld-plugin/plugin.exp: Likewise.
	* testsuite/ld-scripts/crossref.exp: Likewise.
	* testsuite/ld-selective/selective.exp: Likewise.
	* testsuite/ld-undefined/undefined.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Add $NOLTO_CFLAGS to CC.  Override
	CXXFLAGS.
	* testsuite/lib/ld-lib.exp (run_ld_link_tests): Prepend -fno-lto
	to cflags.
2020-10-22 06:04:36 -07:00
Alan Modra
740341b9be Provide dummy libraries for alpha-vms
alpha-dec-vms always loads a number of libraries, -limagelib,
-lstarlet, and -lsys$public_vectors.  When running the ld testsuite
without a full cross-build environment, those libraries are missing
and cause fails.  This patch provides dummies, and tidies default.exp
a little.

	* testsuite/config/default.exp: Provide dummy libraries for
	alpha-dec-vms.
	(compiler_supports): New proc.  Use it for compiler tests.
	* testsuite/lib/ld-lib.exp (default_ld_assemble): Don't die if
	subdir not set.
	(run_ld_link_tests): Pass LDFLAGS to ld.
	* testsuite/ld-checks/checks.exp (section_check): Likewise.
	* testsuite/ld-scripts/assert.exp: Likewise.
	* testsuite/ld-scripts/extern.exp: Likewise.
	* testsuite/ld-scripts/log2.exp: Likewise.
	* testsuite/ld-scripts/map-address.exp: Likewise.
	* testsuite/ld-scripts/script.exp: Likewise.
	* testsuite/ld-scripts/sizeof.exp: Likewise.
2020-10-19 16:28:43 +10:30
Andrew Burgess
874ef0386f ld: Allow symbols from PROVIDE to be use in MEMORY regions
I wanted to write a linker script like this:

  PROVIDE(mem_origin = 0x1000);
  PROVIDE(mem_length = 0x1000);

  MEMORY
  {
    REGION : ORIGIN = mem_origin, LENGTH = mem_length
  }

  ....

Then when I link using this script I can optionally supply:

  --defsym=mem_origin=..... --defsym=mem_length=....

to override the defaults.

And though passing `--defsym' does work, if I remove the use of
`--defsym' and just rely on the defaults I get an error:

  ld-new: invalid origin for memory region REGION

Interestingly, if I make the above error non-fatal and dump a linker
map file I see that (a) REGION has origin 0x0, and length 0xffff...,
and (b) the symbol from the PROVIDE is provided.

An examination of ldlang.c:lang_process shows us what the issue is,
the origin and length of all memory regions are set as a result of a
single call to lang_do_memory_regions, this call is done after calling
open_input_bfds.

During the open_input_bfds call provide statements can be converted to
provided statements if we know that the assigned symbol is needed, but
for symbols that are only used in the memory regions we are unaware
that we need these symbols.

What I propose in this patch is to make two calls to
lang_do_memory_regions, in the first call we process the expressions
for the origin and length fields of each region, however, errors,
especially undefined symbols, will be ignored.  The origin and length
values are not updated.  However, by evaluating the expressions any
symbols we need will be added to the symbol table.

Now when we call open_input_bfds, when we process the provide
statements, we will see that the assigned symbol is needed add its new
value to the symbol table.

Finally we reach the original call to lang_do_memory_regions, in
this (now second) call we again process the expressions, and this time
update the origin and length values.  Any errors encountered now are
reported to the user.

ld/ChangeLog:

	* ldlang.c (lang_process): Add extra call to
	lang_do_memory_regions, and pass parameter.
	(lang_do_memory_regions): Add parameter, only define origin and
	length when requested.  Reindent.
	* testsuite/ld-scripts/provide-10.d: New file.
	* testsuite/ld-scripts/provide-10.map: New file.
	* testsuite/ld-scripts/provide-11.d: New file.
	* testsuite/ld-scripts/provide-11.map: New file.
	* testsuite/ld-scripts/provide-12.d: New file.
	* testsuite/ld-scripts/provide-12.map: New file.
	* testsuite/ld-scripts/provide-9.d: New file.
	* testsuite/ld-scripts/provide-9.map: New file.
	* testsuite/ld-scripts/provide-9.t: New file.
2020-10-16 13:43:49 +01:00
Andrew Burgess
54874444da ld: More documentation for --defsym
The ordering of command line options --defsym and -T is important,
however, the description of --defsym in the manual doesn't mention
this.

This commit adds more text to the description of --defsym to try and
explain this ordering requirement.

ld/ChangeLog:

	* ld.texi (Options): Extend the description of --defsym.
2020-10-16 13:43:48 +01:00
Nick Clifton
23ae20f5e3 Add a new option to the linker: --error-handling-script=<NAME>. Run the script <NAME> if an undefined symbol or unfound library error is encountered.
PR 26626
	* ldmain.c (undefined_symbol): If an error handlign script is
	available, call it.
	* ldfile.c  (error_handling_script): Declare.
	(ldfile_open_file): If a library cannot be found and an error
	handling script is available, call it.
	* ldmain.h  (error_handling_script): Prototype.
	* ldlex.h (OPTION_ERROR_HANDLING_SCRIPT): Define.
	* lexsup.c (ld_options): Add --error-handling-script.
	(parse_args): Add support for --errror-handling-script.
	* ld.texi: Document the new feature.
	* configure.ac: Add --error-handling-script option to disable
	support for the new feature.
	* NEWS: Mention the new feature.
	* config.in: Regenerate.
	* configure: Regenerate.
2020-10-16 11:37:26 +01:00
Nelson Chu
51a8a7c2e3 RISC-V: Fix that IRELATIVE relocs may be inserted to the wrong place.
For the ifunc symbol, which is referenced by GOT rather than PLT relocs,
we should add the dynamic reloc (usually IRELATIVE) into the .rel.iplt
when generating the static executable.  But if we use riscv_elf_append_rela
to add the dynamic relocs into .rela.iplt, this may cause the overwrite
problem.

The reason is that we don't handle the `reloc_index` of .rela.iplt, but
the riscv_elf_append_rela adds the relocs to the place that are calculated
from the reloc_index (in seqential).  Therefore, we may overwrite the
dynamic relocs when the `reloc_index` of .rela.iplt isn't handled correctly.

One solution is that we can add these dynamic relocs (GOT ifunc) from
the last of .rela.iplt section.  But I'm not sure if it is the best way.

	bfd/
	* elfnn-riscv.c (riscv_elf_link_hash_table): Add last_iplt_index.
	(riscv_elf_size_dynamic_sections): Initialize the last_iplt_index.
	(riscv_elf_relocate_section): Use riscv_elf_append_rela.
	(riscv_elf_finish_dynamic_symbol): If the use_elf_append_rela is
	false, then we should add the dynamic relocs from the last of
	the .rela.iplt, and don't use the riscv_elf_append_rela to add.

	ld/
	* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite.s: New testcase.
	* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-got-overwrite-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-10-16 10:11:23 +08:00
Nelson Chu
02dd9d2568 RISC-V: Support GNU indirect functions.
Generally, glibc dynamic linker should have two ways to deal with ifunc
- one is to handle the IRELATIVE relocations for the non-preemtive ifunc
symbols, the other is to handle the R_RISCV_32/64 and R_RISCV_JUMP_SLOT
relocations with the STT_IFUNC preemtive symbols.  No matter which method
is used, both of them should get the resolved ifunc symbols at runtime.
Therefore, linker needs to generate the correct dynamic relocations for
ifunc to make sure the the dynamic linker works well.  For now, there are
thirteen relocations are supported for ifunc in GNU ld,

* R_RISCV_CALL and R_RISCV_CALL_PLT:
The RISC-V compiler won't generate R_RISCV_JAL directly to jump to an
ifunc.  Besides, we disable the relaxations for the relocation referenced
to ifunc, so just handling the R_RISCV_CALL and R_RISCV_CALL_PLT should be
enough.  Linker should generate a .plt entry and a .got.plt entry for it,
and also needs to insert a dynamic IRELATIVE in the .got.plt enrty, or
insert a R_RISCV_JUMP_SLOT when generating shared library.

* R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO12_I/S:
LA/LLA pattern with local fPIC ifunc symbol, or any non-PIC ifunc symbol.
The PC-relative relocation.  The current linker will deal with them in
the same way as R_RISCV_CALL_PLT.

* R_RISCV_GOT_HI20 and R_RISCV_PCREL_LO12_I/S:
LA pattern with global PIC ifunc symbol.  Linker should insert a dynamic
IRELATIVE in the .got entry, or insert a R_RISCV_32/64 when generating
shared library.

* R_RISCV_32 and R_RISCV_64:
Store the ifunc symbol into the data section.  Linker should insert a
dynamic IRELATIVE in the data section, or insert a R_RISCV_32/64 when
generating shared library.

* R_RISCV_HI20 and R_RISCV_LO12_I/S:
The LUI + ADDI/LW/SW patterns.  The absolute access relocation.  The
medlow model without the -fPIC compiler option should generate them.
The ld ifunc testsuites "Build pr23169a" and "Build pr23169d" need the
relocations, they are in the ld/testsuite/ld-ifunc/, and need compiler
support.

However, we also made some optimizations with reference to x86,

* If GOT and PLT relocations refer to the same ifunc symbol when generating
pie, then they can actually share a .got entry without creating two entries
to store the same value and relocation.

* If GOT, PLT and DATA relocations refer to the same ifunc symbol when
generating position dependency executable, then linker will fill the address
of .plt entry into the corresponding .got entry and data section, without
insert any dynamic relocations for the GOT and DATA relocations.

For the ifunc testcases, there are three types of them,

1. ifunc-reloc-*: Only check the single type of relocation refers to
ifunc symbol.
* ifunc-reloc-call: R_RISCV_CALL and R_RISCV_CALL_PLT.
* ifunc-reloc-data: R_RISCV_32 and R_RISCV_64.
* ifunc-reloc-got: R_RISCV_GOT_HI20 and R_RISCV_PCREL_LO_I/S.
* ifunc-reloc-pcrel: R_RISCV_PCREL_HI20 and R_RISCV_PCREL_LO_I/S.

2. ifunc-[nonplt|plt]-*: If we don't have PLT relocs, then don't need to
create the PLT and it's .plt entries.
* ifunc-nonplt: Combine R_RISCV_GOT_HI20 and R_RISCV_32/64.
* ifunc-plt: Combine all ifunc relocations.

3. ifunc-seperate-*: If we link the ifunc caller and resolver into the
same module (link the objects), then the results are the same as the
ifunc-reloc-* and ifunc-[noplt|plt]-* testcases.  Consider the cases that
the ifunc callers and resolver are in the different modules, that is, we
compile the ifunc resolver to the shared library first, and then link it
with the ifunc callers.  The output of ifunc callers should be the same as
the normal STT_FUNC cases, and the shared ifunc resolver should define the
symbols as STT_IFUNC.

The R_RISCV_PCREL_HI20 reloc is special.  It should be linked and resolved
locally, so if the ifunc resolver is defined in other modules (other shared
libraries), then the R_RISCV_PCREL_HI20 is unresolvable, and linker should
issue an unresolvable reloc error.

	bfd/
	* elfnn-riscv.c: Include "objalloc.h" since we need objalloc_alloc.
	(riscv_elf_link_hash_table): Add loc_hash_table and loc_hash_memory
	for local STT_GNU_IFUNC symbols.
	(riscv_elf_got_plt_val): Removed.
	(riscv_elf_local_htab_hash, riscv_elf_local_htab_eq): New functions.
	Use to compare local hash entries.
	(riscv_elf_get_local_sym_hash): New function.  Find a hash entry for
	local symbol, and create a new one if needed.
	(riscv_elf_link_hash_table_free): New function.  Destroy an riscv
	elf linker hash table.
	(riscv_elf_link_hash_table_create): Create hash table for local ifunc.
	(riscv_elf_check_relocs): Create a fake global symbol to track the
	local ifunc symbol.  Add support to check and handle the relocations
	reference to ifunc symbols.
	(allocate_dynrelocs): Let allocate_ifunc_dynrelocs and
	allocate_local_ifunc_dynrelocs to handle the ifunc symbols if they
	are defined and referenced in a non-shared object.
	(allocate_ifunc_dynrelocs): New function.  Allocate space in .plt,
	.got and associated reloc sections for ifunc dynamic relocs.
	(allocate_local_ifunc_dynrelocs): Likewise, but for local ifunc
	dynamic relocs.
	(riscv_elf_relocate_section): Add support to handle the relocation
	referenced to ifunc symbols.
	(riscv_elf_size_dynamic_sections): Updated.
	(riscv_elf_adjust_dynamic_symbol): Updated.
	(riscv_elf_finish_dynamic_symbol): Finish up the ifunc handling,
	including fill the PLT and GOT entries for ifunc symbols.
	(riscv_elf_finish_local_dynamic_symbol): New function.  Called by
	riscv_elf_finish_dynamic_symbol to handle the local ifunc symbols.
	(_bfd_riscv_relax_section): Don't do the relaxation for ifunc.
	* elfxx-riscv.c: Add R_RISCV_IRELATIVE.
	* configure.ac: Link elf-ifunc.lo to use the generic ifunc support.
	* configure: Regenerated.

	include/
	* elf/riscv.h: Add R_RISCV_IRELATIVE to 58.

	ld/
	* emulparams/elf32lriscv-defs.sh: Add IREL_IN_PLT.
	* testsuite/ld-ifunc/ifunc.exp: Enable ifunc tests for RISC-V.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp (run_dump_test_ifunc):
	New dump test for ifunc.  There are two arguments, 'target` and
	`output`.  The `target` is rv32 or rv64, and the `output` is used
	to choose which output you want to test (exe, pie or .so).
	* testsuite/ld-riscv-elf/ifunc-reloc-call-01.s: New testcase.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-01.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-01-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-01-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-01-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-02.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-02.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-02-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-02-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-call-02-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-data.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-data.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-data-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-data-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-data-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-got.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-got.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-got-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-got-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-got-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-pcrel.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-pcrel.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-reloc-pcrel-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-nonplt.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-nonplt.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-nonplt-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-nonplt-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-nonplt-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-01.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-01.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-01-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-01-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-01-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-02.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-02.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-02-exe.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-02-pic.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-plt-02-pie.rd: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-resolver.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-caller.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-exe.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-pic.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-pie.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-caller-pcrel.s: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-pcrel-pic.d: Likewise.
	* testsuite/ld-riscv-elf/ifunc-seperate-pcrel-pie.d: Likewise.
2020-10-16 10:11:18 +08:00
H.J. Lu
32930e4edb x86: Support GNU_PROPERTY_X86_ISA_1_V[234] marker
GCC 11 supports -march=x86-64-v[234] to enable x86 micro-architecture ISA
levels:

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

Update GNU_PROPERTY_X86_ISA_1_XXX macros:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/13

in x86 ELF binaries to indicate that micro-architecture ISA levels
required to execute the binary:

 #define GNU_PROPERTY_X86_ISA_1_NEEDED (GNU_PROPERTY_X86_UINT32_OR_LO + 2)
 #define GNU_PROPERTY_X86_ISA_1_USED (GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2)
 #define GNU_PROPERTY_X86_ISA_1_V2 (1U << 0)
 #define GNU_PROPERTY_X86_ISA_1_V3 (1U << 1)
 #define GNU_PROPERTY_X86_ISA_1_V4 (1U << 2)

The previous GNU_PROPERTY_X86_ISA_1_XXX  macros are deprecated and renamed
to GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX.

In addition to EM_X86_64, GNU_PROPERTY_X86_ISA_1_V[234] marker can be used
by ld.so to detect the x86-64-v4 shared library placed in an x86-64-v2
directory by mistake on an x86-64-v2 machine to avoid crashes on x86-64-v4
instructions.

Add -z x86-64-v[234] linker command line option to mark x86-64-v[234]
ISA level as needed.

Also add

 #define GNU_PROPERTY_X86_FEATURE_2_MASK (1U << 11)

for mask registers.

bfd/

	PR gas/26703
	* elf-linker-x86.h (elf_linker_x86_params): Add isa_level.
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Merge
	GNU_PROPERTY_X86_ISA_1_V[234].
	(_bfd_x86_elf_link_setup_gnu_properties): Generate
	GNU_PROPERTY_X86_ISA_1_V[234] for -z x86-64-v[234].

binutils/

	PR gas/26703
	* readelf.c (decode_x86_compat_2_isa): New function.
	(decode_x86_isa): Updated for new X86_ISA_1_XXX bits.
	(decode_x86_feature_1): Handle GNU_PROPERTY_X86_FEATURE_2_MASK.
	(print_gnu_property_note): Handle X86_COMPAT_2_ISA_1_USED,
	and X86_COMPAT_2_ISA_1_NEEDED.
	* testsuite/binutils-all/i386/pr21231b.s: Updated to the current
	GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
	values.
	* testsuite/binutils-all/x86-64/pr21231b.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494b.s: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.s: Likewise.
	* testsuite/binutils-all/i386/empty.d: Updated.
	* testsuite/binutils-all/i386/ibt.d: Likewise.
	* testsuite/binutils-all/i386/pr21231a.d: Likewise.
	* testsuite/binutils-all/i386/pr21231b.d: Likewise.
	* testsuite/binutils-all/i386/shstk.d: Likewise.
	* testsuite/binutils-all/x86-64/empty-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/empty.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/ibt.d: Likewise.
	* testsuite/binutils-all/x86-64/pr21231a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr21231b.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494a.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494c.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494d.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/pr23494e.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk-x32.d: Likewise.
	* testsuite/binutils-all/x86-64/shstk.d: Likewise.

gas/

	PR gas/26703
	* config/tc-i386.c (xstate): Add xstate_mask.
	(md_assemble): Check i.types[j], instead of i.tm.operand_types[j],
	for xstate.  Set xstate_mask, instead of xstate_zmm, for RegMask.
	(output_insn): Update for GNU_PROPERTY_X86_ISA_1_V[234].  Update
	xstate for mask register and VSIB.
	* testsuite/gas/i386/i386.exp: Run more GNU_PROPERTY tests.
	* testsuite/gas/i386/property-1.s: Updated to the current
	GNU_PROPERTY_X86_ISA_1_USED value.
	* testsuite/gas/i386/property-2.s: Only keep cmove.
	* testsuite/gas/i386/property-3.s: Changed to addsubpd.
	* testsuite/gas/i386/property-1.d: Updated.
	* testsuite/gas/i386/property-2.d: Likewise.
	* testsuite/gas/i386/property-3.d: Likewise.
	* testsuite/gas/i386/property-4.d: Likewise.
	* testsuite/gas/i386/property-5.d: Likewise.
	* testsuite/gas/i386/property-6.d: Likewise.
	* testsuite/gas/i386/x86-64-property-1.d: Likewise.
	* testsuite/gas/i386/x86-64-property-2.d: Likewise.
	* testsuite/gas/i386/x86-64-property-3.d: Likewise.
	* testsuite/gas/i386/x86-64-property-4.d: Likewise.
	* testsuite/gas/i386/x86-64-property-5.d: Likewise.
	* testsuite/gas/i386/x86-64-property-6.d: Likewise.
	* testsuite/gas/i386/x86-64-property-7.d: Likewise.
	* testsuite/gas/i386/x86-64-property-8.d: Likewise.
	* testsuite/gas/i386/x86-64-property-9.d: Likewise.
	* testsuite/gas/i386/property-11.d: New file.
	* testsuite/gas/i386/property-11.s: Likewise.
	* testsuite/gas/i386/property-12.d: Likewise.
	* testsuite/gas/i386/property-12.s: Likewise.
	* testsuite/gas/i386/property-13.d: Likewise.
	* testsuite/gas/i386/property-13.s: Likewise.
	* testsuite/gas/i386/x86-64-property-11.d: Likewise.
	* testsuite/gas/i386/x86-64-property-12.d: Likewise.
	* testsuite/gas/i386/x86-64-property-13.d: Likewise.
	* testsuite/gas/i386/x86-64-property-14.d: Likewise.
	* testsuite/gas/i386/x86-64-property-14.s: Likewise.

include/

	PR gas/26703
	* elf/common.h (GNU_PROPERTY_X86_ISA_1_USED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED): This.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED): This.
	(GNU_PROPERTY_X86_ISA_1_XXX): Renamed to ...
	(GNU_PROPERTY_X86_COMPAT_2_ISA_1_XXX): This.
	(GNU_PROPERTY_X86_ISA_1_NEEDED): New.
	(GNU_PROPERTY_X86_ISA_1_USED): Likewise.
	(GNU_PROPERTY_X86_ISA_1_V2): Likewise.
	(GNU_PROPERTY_X86_ISA_1_V3): Likewise.
	(GNU_PROPERTY_X86_ISA_1_V4): Likewise.
	(GNU_PROPERTY_X86_FEATURE_2_MASK): Likewise.

ld/

	PR gas/26703
	* NEWS: Mention -z x86-64-v[234].
	* ld.texi: Document -z x86-64-v[234].
	* emulparams/elf32_x86_64.sh: Use x86-64-level.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/x86-64-level.sh: New file.
	* testsuite/ld-elf/x86-feature-1a.rd: Update.
	* testsuite/ld-elf/x86-feature-1b.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1c.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1d.rd: Likewise.
	* testsuite/ld-elf/x86-feature-1e.rd: Likewise.
	* testsuite/ld-i386/pr23372c.d: Likewise.
	* testsuite/ld-i386/pr23486c.d: Likewise.
	* testsuite/ld-i386/pr23486d.d: Likewise.
	* testsuite/ld-i386/pr24322a.d: Likewise.
	* testsuite/ld-i386/pr24322b.d: Likewise.
	* testsuite/ld-i386/property-1a.r: Likewise.
	* testsuite/ld-i386/property-2a.r: Likewise.
	* testsuite/ld-i386/property-3.r: Likewise.
	* testsuite/ld-i386/property-3a.r: Likewise.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-4a.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-i386/property-5a.r: Likewise.
	* testsuite/ld-i386/property-7a.r: Likewise.
	* testsuite/ld-i386/property-x86-3.d: Likewise.
	* testsuite/ld-i386/property-x86-4a.d: Likewise.
	* testsuite/ld-i386/property-x86-5.d: Likewise.
	* testsuite/ld-i386/property-x86-cet1.d: Likewise.
	* testsuite/ld-i386/property-x86-cet2a.d: Likewise.
	* testsuite/ld-i386/property-x86-cet5a.d: Likewise.
	* testsuite/ld-i386/property-x86-cet5b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt2.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt4.d: Likewise.
	* testsuite/ld-i386/property-x86-ibt5.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk2.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk4.d: Likewise.
	* testsuite/ld-i386/property-x86-shstk5.d: Likewise.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23486c.d: Likewise.
	* testsuite/ld-x86-64/pr23486d-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23486d.d: Likewise.
	* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322a.d: Likewise.
	* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24322b.d: Likewise.
	* testsuite/ld-x86-64/pr24458a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458a.d: Likewise.
	* testsuite/ld-x86-64/pr24458b-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458b.d: Likewise.
	* testsuite/ld-x86-64/pr24458c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr24458c.d: Likewise.
	* testsuite/ld-x86-64/property-1a.r: Likewise.
	* testsuite/ld-x86-64/property-2a.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-3a.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-4a.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-5a.r: Likewise.
	* testsuite/ld-x86-64/property-7a.r: Likewise.
	* testsuite/ld-x86-64/property-x86-3-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-3.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-4a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet1-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet1.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet2a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet2a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-cet5b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-ibt5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-shstk5.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run property-x86-6,
	property-x86-isa1, property-x86-isa2 and property-x86-isa3.
	* testsuite/ld-i386/property-x86-1.S: Updated to the current
	GNU_PROPERTY_X86_ISA_1_USED and GNU_PROPERTY_X86_ISA_1_NEEDED
	values.
	* testsuite/ld-i386/property-x86-2.S: Likewise.
	* testsuite/ld-i386/property-x86-3.s: Likewise.
	* testsuite/ld-x86-64/pr23372d.s: Likewise.
	* testsuite/ld-x86-64/pr23372e.s: Likewise.
	* testsuite/ld-x86-64/pr23372f.s: Likewise.
	* testsuite/ld-x86-64/pr23486c.s: Likewise.
	* testsuite/ld-x86-64/pr23486d.s: Likewise.
	* testsuite/ld-x86-64/property-x86-1.S: Likewise.
	* testsuite/ld-x86-64/property-x86-2.S: Likewise.
	* testsuite/ld-x86-64/property-x86-3.s: Likewise.
	* testsuite/ld-x86-64/property-x86-5a.s: Likewise.
	* testsuite/ld-x86-64/property-x86-5b.s: Likewise.
	* testsuite/ld-i386/property-x86-6.d: New file.
	* testsuite/ld-i386/property-x86-isa1.d: Likewise.
	* testsuite/ld-i386/property-x86-isa2.d: Likewise.
	* testsuite/ld-i386/property-x86-isa3.d: Likewise.
	* testsuite/ld-x86-64/property-x86-6-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-6.d: Likewise.
	* testsuite/ld-x86-64/property-x86-6.s: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa1.s: Likewise.
	* testsuite/ld-x86-64/property-x86-isa2-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa3-x32.d: Likewise.
	* testsuite/ld-x86-64/property-x86-isa3.d: Likewise.
	* testsuite/ld-x86-64/simple.s: Likewise.
	* ld/testsuite/ld-x86-64/x86-64.exp: Run property-x86-6,
	property-x86-6-x32, property-x86-isa1, property-x86-isa1-x32,
	property-x86-isa2, property-x86-isa2-x32, property-x86-isa3-x32
	and property-x86-isa3.
2020-10-09 05:13:26 -07:00
H.J. Lu
3d08aa66b3 x86: Update GNU property tests
Update property tests for glibc compiled by Fedora binary annotation
plugin for GCC, which may insert additonal GNU properties:

	x86 ISA needed: SSE, SSE2

	* testsuite/ld-i386/property-3.r: Updated for Fedora binary
	annotation plugin for GCC.
	* testsuite/ld-i386/property-4.r: Likewise.
	* testsuite/ld-i386/property-5.r: Likewise.
	* testsuite/ld-x86-64/property-3.r: Likewise.
	* testsuite/ld-x86-64/property-4.r: Likewise.
	* testsuite/ld-x86-64/property-5.r: Likewise.
2020-10-07 15:54:18 -07:00
H.J. Lu
574df58f52 x86: Properly merge -z ibt and -z shstk
Merge -z ibt and -z shstk only with GNU_PROPERTY_X86_FEATURE_1_AND, not
any GNU_PROPERTY_X86_UINT32_AND_XXX properties.

bfd/

	PR ld/26711
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Merge -z ibt
	and -z shstk only with GNU_PROPERTY_X86_FEATURE_1_AND.

ld/

	PR ld/26711
	* testsuite/ld-i386/i386.exp: Run ld/26711 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr26711-1.d: Likewise.
	* testsuite/ld-i386/pr26711-2.d: Likewise.
	* testsuite/ld-i386/pr26711-3.d: Likewise.
	* testsuite/ld-x86-64/pr26711-1-x32.d: Likewise.
	* testsuite/ld-x86-64/pr26711-1.d: Likewise.
	* testsuite/ld-x86-64/pr26711-2-x32.d: Likewise.
	* testsuite/ld-x86-64/pr26711-2.d: Likewise.
	* testsuite/ld-x86-64/pr26711-3-x32.d: Likewise.
	* testsuite/ld-x86-64/pr26711-3.d: Likewise.
	* testsuite/ld-x86-64/pr26711.s: Likewise.
2020-10-06 15:38:34 -07:00
Brandon Bergren
6afcdeb358 PR26667, Add powerpc64le-*-freebsd* support
PR 26667
bfd/
	* config.bfd: Add powerpc64le-*-freebsd*.
	* configure.ac: Add powerpc_elf64_fbsd_le_vec.
	* elf64-ppc.c (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME): Define for
	freebsd.
	* targets.c (powerpc_elf64_fbsd_le_vec): Declare.
	(_bfd_target_vector): Add it.
	* configure: Regenerate.
ld/
	* Makefile.am (ALL_64_EMULATION_SOURCES): Add eelf64lppc_fbsd.c.
	Include $(DEPDIR)/eelf64lppc_fbsd.Pc.
	* configure.tgt: Add powerpc64le-*-freebsd*.
	* emulparams/elf64lppc_fbsd.sh: New file.
	* Makefile.in: Regenerate.
	* po/BLD-POTFILES.in: Regenerate.
2020-10-06 17:09:27 +10:30
T.K. Chia
6d96a5946d i386: Allow non-absolute segment values for lcall/ljmp
Allow an unresolved or non-absolute symbol as the segment operand of an
immediate far jump (`ljmp SEG, OFF') or far call (`lcall SEG, OFF').

gas/

2020-10-05  T.K. Chia  <u1049321969@caramail.com>

	PR gas/26694
	* NEWS: Updated for i386 lcall and ljmp change.
	* config/tc-i386.c (output_interseg_jump): Allow non-absolute
	segment operand for immediate lcall and ljmp.
	* testsuite/gas/i386/jump.d,
	* testsuite/gas/i386/jump.s,
	* testsuite/gas/i386/jump16.d,
	* testsuite/gas/i386/jump16.e,
	* testsuite/gas/i386/jump16.s: Add tests for non-absolute
	segment operand for immediate ljmp.

ld/

2020-10-05  T.K. Chia  <u1049321969@caramail.com>

	PR gas/26694
	* testsuite/ld-i386/ljmp.s,
	* testsuite/ld-i386/ljmp1.d,
	* testsuite/ld-i386/ljmp1.s,
	* testsuite/ld-i386/ljmp2.d,
	* testsuite/ld-i386/ljmp2.s,
	* testsuite/ld-x86-64/ljmp1.d,
	* testsuite/ld-x86-64/ljmp2.d: New testcases.
	* testsuite/ld-i386/i386.exp,
	* testsuite/ld-x86-64/x86-64.exp: Run them.
2020-10-05 05:58:33 -07:00
Nick Clifton
983d925db6 Update the BFD linker so that it deprecates grouped short options.
* lexsup.c (parse_args): Generate an error or warning message when
	multiple short options are used together.
2020-10-05 13:53:59 +01:00
H.J. Lu
7026832e52 Allow note sections to be discarded when they are linked to another discarded secction.
PR 26681
bfd	* elflink.c (bfd_elf_gc_sections): Do not arbitrarily keep note
	sections which are linked to another section.

ld	* testsuite/ld-elf/pr26681.s: New test.
	* testsuite/ld-elf/pr26681.d: New test driver.
	* testsuite/ld-elf/pr26681.l: New test output.
2020-10-02 11:08:19 +01:00
H.J. Lu
04e433a857 ld: Override the IR definition for non-ELF targets
For non-ELF targets, override the IR definition before all LTO symbols
have been read.

	PR ld/26675
	* plugin.c (plugin_notice): Override the IR definition before
	all LTO symbols have been read for non-ELF targets.
2020-09-30 05:23:35 -07:00
Jeremy Drake
51dee44b37 After preventing creating an import library for an exe when there are no exports, to avoid a crash, it turned out that some projects expected to be able to create an import library for a dll with no exports, so more closely match the condition to the condition around initializing the dll name.
PR 26588
	* emultempl/pe.em (_finish): Generate an import library for DLLs,
	even if they have no exports.
	* emultempl/pep.em (_finish): Likewise.
2020-09-30 10:50:46 +01:00
Alan Modra
f243e458cd PR26656 testcases
* testsuite/ld-powerpc/tlsget.d,
	* testsuite/ld-powerpc/tlsget.s,
	* testsuite/ld-powerpc/tlsget.wf,
	* testsuite/ld-powerpc/tlsget2.d.
	* testsuite/ld-powerpc/tlsget2.wf: New testcases.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2020-09-28 19:36:35 +09:30
Alan Modra
3cd7c7d7ef PPC64_OPT_LOCALENTRY is incompatible with tail calls
The save of r2 in __glink_PLTresolve is the culprit.  Remove it,
unless we know we need it for --plt-localentry.  --plt-localentry
should not be used with power10 pc-relative code that makes tail
calls.

The patch also removes use of r2 as a scratch reg in the ELFv2
__glink_PLTresolve.  Using r2 isn't a problem, this is just reducing
the number of scratch regs.

bfd/
	* elf64-ppc.c (GLINK_PLTRESOLVE_SIZE): Depend on has_plt_localentry0.
	(LD_R0_0R11, ADD_R11_R0_R11): Define.
	(ppc64_elf_tls_setup): Disable params->plt_localentry0 when power10
	code detected.
	(ppc64_elf_size_stubs): Update __glink_PLTresolve eh_frame.
	(ppc64_elf_build_stubs): Move r2 save to start of __glink_PLTresolve,
	and only emit for has_plt_localentry0.  Don't use r2 in the stub.
ld/
	* testsuite/ld-powerpc/elfv2so.d,
	* testsuite/ld-powerpc/notoc2.d,
	* testsuite/ld-powerpc/tlsdesc.wf,
	* testsuite/ld-powerpc/tlsdesc2.d,
	* testsuite/ld-powerpc/tlsdesc2.wf,
	* testsuite/ld-powerpc/tlsopt5.d,
	* testsuite/ld-powerpc/tlsopt5.wf,
	* testsuite/ld-powerpc/tlsopt6.d,
	* testsuite/ld-powerpc/tlsopt6.wf: Update __glink_PLTresolve.
2020-09-26 19:03:02 +09:30
Alan Modra
c94053440e PR26655, Power10 libstdc++.so R_PPC64_NONE dynamic relocs
Some of the powerpc64 code editing functions are better run after
dynamic symbols have stabilised in order to make proper decisions
based on SYMBOL_REFERENCES_LOCAL.  The dynamic symbols are processed
early in bfd_elf_size_dynamic_sections, before the backend
always_size_sections function is called.

One function, ppc64_elf_tls_setup must run before
bfd_elf_size_dynamic_sections because it changes dynamic symbols.
ppc64_elf_edit_opd and ppc64_elf_inline_plt can run early or late, I
think.  ppc64_elf_tls_optimize and ppc64_elf_edit_toc are better run
later.

So this patch arranges to call some edit functions later via
always_size_sections.

	PR 26655
bfd/
	* elf64-ppc.c (ppc64_elf_func_desc_adjust): Rename to..
	(ppc64_elf_edit): Call params->edit.
	(ppc64_elf_tls_setup): Don't call _bfd_elf_tls_setup.  Return a
	bfd_boolean.
	* elf64-ppc.h (struct ppc64_elf_params): Add "edit".
	(ppc64_elf_tls_setup): Update declaration.
ld/
	* emultempl/ppc64elf.em (params): Add ppc_edit.
	(ppc_before_allocation): Split off some edit functions to..
	(ppc_edit): ..this, new function.
2020-09-24 07:52:53 +09:30
Frediano Ziglio
307f2595dd Linker: If the type is pie the results should be an executable which entry point should be an executable entry point, not a DLL one.
* emultempl/pe.em (set_entry_point): Only use the DLL entry point
	for DLLs.
	* emultempl/pep.em (set_entry_point): Likewise.
2020-09-22 12:48:04 +01:00
Mikael Pettersson
be7628ca50 Add -Av9 to AFLAGS_PIC and AFLAGS_PIE in the ld test suite on SPARC.
* testsuite/ld-elf/shared.exp: Add -Av9 to AFLAGS_PIE on sparc.
	* testsuite/ld-elf/tls.exp: Add -Av9 to AFLAGS_PIC on sparc.
2020-09-16 16:20:51 +01:00
H.J. Lu
36068e2fa5 elf/x86-64: Adjust relocation for PE/x86-64 inputs
PE linker calls _bfd_relocate_contents to resolve relocation, instead of
bfd_perform_relocation.  But ELF linker calls bfd_perform_relocation, not
_bfd_relocate_contents.  When linking PE/x86-64 inputs to generate ELF
output, we need to adjust PE/x86-64 relocations in bfd_perform_relocation.

Enable PE/x86-64 in bfd together with PEI/x86-64.  Update run_ld_link_tests
to handle bzip2 binary inputs.

bfd/

	PR ld/26583
	* config.bfd (targ64_selvecs, targ_selvecs): Add x86_64_pe_vec
	to x86_64_pei_vec.
	* reloc.c: Include "coff/internal.h".
	(bfd_perform_relocation): Adjust relocation for PE/x86-64 inputs.

ld/

	PR ld/26583
	* testsuite/ld-x86-64/pe-x86-64-1.od: New file.
	* testsuite/ld-x86-64/pe-x86-64-1a.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-1b.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-1c.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2a.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2b.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-2c.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3a.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3b.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3c.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-3d.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4.od: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4a.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4b.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4c.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64-4d.obj.bz2: Likewise.
	* testsuite/ld-x86-64/pe-x86-64.exp: Likewise.
	* testsuite/lib/ld-lib.exp (run_ld_link_tests): Handle bz2 binary
	inputs.
2020-09-16 07:11:31 -07:00
Alan Modra
c1229f84a4 Tidy elf_symbol_from
bfd/
	* elf-bfd.h (elf_symbol_from): Remove unused ABFD parameter.
	* elf.c (ignore_section_sym, _bfd_elf_copy_private_symbol_data),
	(swap_out_syms): Adjust elf_symbol_from invocation.
binutils/
	* nm.c (print_symbol): Adjust elf_symbol_from invocation.
	* objcopy.c (is_hidden_symbol): Likewise.
gas/
	* config/obj-elf.c (obj_elf_visibility, elf_frob_symbol): Adjust
	elf_symbol_from invocation.
	* config/tc-aarch64.c (s_variant_pcs): Likewise.
	* config/tc-m68hc11.c (s_m68hc11_mark_symbol): Likewise.
	* config/tc-ppc.c (ppc_elf_localentry, ppc_force_relocation),
	(ppc_fix_adjustable): Likewise.
	* config/tc-xgate.c (xgate_frob_symbol): Likewise.
ld/
	* plugin.c (asymbol_from_plugin_symbol): Adjust elf_symbol_from
	invocation.
opcodes/
	* ppc-dis.c (ppc_symbol_is_valid): Adjust elf_symbol_from invocation.
2020-09-16 16:41:33 +09:30
H.J. Lu
0403e9ccae elf: Check bfd_target_elf_flavour on input first
Check bfd_target_elf_flavour on input first in ldelf_after_open before
checking elf_tdata.

	* ldelf.c (ldelf_after_open): Check bfd_target_elf_flavour first.
2020-09-15 13:07:38 -07:00
Hans-Peter Nilsson
4a8f181d19 CRIS: fix PR ld/26589, a missing NULL check in fix for PR ld/22269
Not sure why there wasn't a NULL check in the ld/22269 patch
(e01c16a8) at the time, as there was one for the corresponding patch
to elf32-m68k.c (5056ba1d).

Incidentally, I had missed that in 2017, as a prerequisite for the
ld/22269 series, the check_relocs function finally were made "safe"!
(I.e. the number of references and symbol types are final, garbage
collection done, so port-specific accounting can be made sanely.)

Committed.

bfd:
	PR ld/26589
	* elf32-cris.c (cris_elf_check_relocs): Add missing NULL check
	on argument before calling UNDEFWEAK_NO_DYNAMIC_RELOC.

ld:
	PR ld/26589
	* testsuite/ld-elf/pr26589.d, testsuite/ld-elf/locref3.s: New test.
2020-09-15 02:57:39 +02:00
Alan Modra
1f656a652e Re: elf: Add -z unique-symbol
PR 26391
	* testsuite/ld-elf/pr26391.nd: Adjust to match powerpc64 function
	descriptors.
2020-09-13 18:42:12 +09:30
H.J. Lu
496afd1705 elf: Add -z unique-symbol to avoid duplicated local symbol names
The symbol string table in the .symtab section is optional and cosmetic.
The contents of the .symtab section have no impact on run-time execution.
The symbol names in the symbol string table help distinguish addresses at
different locations.  Add a linker option, -z unique-symbol, to avoid
duplicated local symbol names in the symbol string table.

This feature was well received by the livepatch maintainers.  It not only
solves the duplicated local symbol name problem, but also would allow
livepatch to more precisely locate duplicate symbols in general for
patching.

bfd/

	PR ld/26391
	* elflink.c (elf_final_link_info): Add local_hash_table.
	(local_hash_entry): New.
	(local_hash_newfunc): Likewise.
	(elf_link_output_symstrtab): Append ".COUNT" to duplicated local
	symbols.
	(bfd_elf_final_link): Initialize and free local_hash_table for
	"-z unique-symbol".

include/

	PR ld/26391
	* bfdlink.h (bfd_link_info): Add unique_symbol.

ld/

	PR ld/26391
	* NEWS: Mention "-z unique-symbol".
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Handle
	"-z unique-symbol" and "-z nounique-symbol".
	* ld.texi: Document "-z unique-symbol" and "-z nounique-symbol".
	* lexsup.c (elf_static_list_options): Add "-z unique-symbol" and
	"-z nounique-symbol".
	* testsuite/ld-elf/elf.exp: Add PR ld/26391 tests.
	* testsuite/ld-elf/pr26391.nd: New file.
	* testsuite/ld-elf/pr26391.out: Likewise.
	* testsuite/ld-elf/pr26391a.c: Likewise.
	* testsuite/ld-elf/pr26391b.c: Likewise.
	* testsuite/ld-elf/pr26391c.c: Likewise.
	* testsuite/ld-elf/pr26391d.c: Likewise.
2020-09-12 05:37:43 -07:00
Jeremy Drake
9cdc5bacdd Fix a segfault when creating an import library with 0 exports.
PR 26588
	* emultempl/pe.em (_finish): Only generate a import library if not
	exporting relocs.
	* emultempl/pep.em: Likewise.
2020-09-11 17:51:16 +01:00
Siddhesh Poyarekar
c7cd291722 aarch64: Return an error on conditional branch to an undefined symbol
The fix in 7e05773767 introduced a PLT
for conditional jumps when the target symbol is undefined.  This is
incorrect because conditional branch relocations are not allowed to
clobber IP0/IP1 and hence, should not result in a dynamic relocation.

Revert that change and in its place, issue an error when the target
symbol is undefined.

bfd/

	2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Revert
	changes in 7e05773767.  Set
	error for undefined symbol in BFD_RELOC_AARCH64_BRANCH19 and
	BFD_RELOC_AARCH64_TSTBR14 relocations.

ld/

	2020-09-10  Siddhesh Poyarekar  <siddesh.poyarekar@arm.com>

	* testsuite/ld-aarch64/emit-relocs-560.d: Expect error instead
	of valid output.
2020-09-10 21:42:37 +05:30
H.J. Lu
93d49941ed ld: Add more tests for --as-needed
Prior to

commit 1e3b96fd6c
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Sep 4 13:54:21 2020 +0930

    Allow plugin syms to mark as-needed shared libs needed

when removing unused IR symbol references, ld didn't add unnecessary
DT_NEEDED libraries which may lead to undefined symbol reference in a
--as-needed library when the symbol is defined in a prior --as-needed
library and there is no reference in relocatable inputs.  This behavior
is desirable since it ensures that both lazy and non-lazy bindings work
the same way.  The problem is with --as-needed libraries, which happens
with and without LTO.  Now, the linker may add many unnecessary DT_NEEDED
libraries for IR inputs.

	PR ld/26590
	* testsuite/ld-elf/pr26590.err: New file.
	* testsuite/ld-elf/pr26590a.c: Likewise.
	* testsuite/ld-elf/pr26590b.c: Likewise.
	* testsuite/ld-elf/pr26590c.c: Likewise.
	* testsuite/ld-elf/pr26590d.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run ld/26590 tests.
2020-09-10 07:52:20 -07:00
Alan Modra
36efe0aea5 Re: PR26580, Size and alignment of commons vs as-needed shared lib
Some MIPS targets, for reasons I didn't analyse, use the larger common
symbol in a shared lib rather than a smaller common in an executable.
That doesn't seem unreasonable, so allow that to pass for pr26580-2.

bfin-elf complains about not supporting copy relocs, but it's quite
silly to want a copy reloc for common symbols, so leave the fail
there.  mn10300-elf and score-elf both fail the test with "PHDR
segment not covered by LOAD segment".  Other tests fail similarly so
one more doesn't hurt.  The failure is a consequence of supporting
dynamic objects but setting EMBEDDED in ld scripts.

	PR 26580
	* testsuite/ld-elf/pr26580-2.sd: Accept undefined symbol.
2020-09-10 18:58:51 +09:30
Alan Modra
36dcb3a97d Re: lto-18 test
Extend the test a little to archives, not that we expect this to
fail.  Nor has the lto-18 test ever failed without -flto.

	* testsuite/ld-plugin/lto-18b.c (select): Remove.
	* testsuite/ld-plugin/lto-18c.c (select): Remove.
	* testsuite/ld-plugin/lto.exp: Build archives for lto-18 too,
	and run static versions of the test.
2020-09-10 18:58:51 +09:30
Alan Modra
fb7331ae2b lto-18 test
Demonstrates a reason to use IR symbols when deciding an --as-needed
library should be loaded.

	* testsuite/ld-plugin/lto-18a.c,
	* testsuite/ld-plugin/lto-18b.c,
	* testsuite/ld-plugin/lto-18c.c,
	* testsuite/ld-plugin/lto-18d.c,
	* testsuite/ld-plugin/lto-18.out: New test.
	* testsuite/ld-plugin/lto.exp: Run it.
2020-09-09 12:36:59 +09:30
Jozef Lawrynowicz
7d81bc937c MSP430: Support relocations for subtract expressions in .uleb128 directives
Link-time relaxations of branches are common for MSP430, given that GCC
can generate pessimal branch instructions, and the
-mcode-region=either/-mdata-region=either options to shuffle sections
can further change the type of branch instruction required.

These relaxations can result in invalid code when .uleb128
directives, used in the .gcc_except_table section, are used to calculate
the distance between two labels. A value for the .uleb128 directive is
calculated at assembly-time, and can't be updated at link-time, even if
relaxation causes the distance between the labels to change.

This patch adds relocations for subtract expressions in .uleb128
directives, to allow the linker to re-calculate the value of these
expressions after relaxation has been performed.

bfd/ChangeLog:
	* bfd-in2.h (bfd_reloc_code_real): Add
	BFD_RELOC_MSP430_{SET,SUB}_ULEB128.
	* elf32-msp430.c (msp430_elf_ignore_reloc): New.
	(elf_msp430_howto_table): Add R_MSP430{,X}_GNU_{SET,SUB}_ULEB128.
	(msp430_reloc_map): Add R_MSP430_GNU_{SET,SUB}_ULEB128.
	(msp430x_reloc_map): Add R_MSP430X_GNU_{SET,SUB}_ULEB128.
	(write_uleb128): New.
	(msp430_final_link_relocate): Handle R_MSP430{,X}_GNU_{SET,SUB}_ULEB128.
	* libbfd.c (_bfd_write_unsigned_leb128): New.
	* libbfd.h (_bfd_write_unsigned_leb128): New prototype.
	Add BFD_RELOC_MSP430_{SET,SUB}_ULEB128.
	* reloc.c: Document BFD_RELOC_MSP430_{SET,SUB}_ULEB128.

binutils/ChangeLog:
	* readelf.c (target_specific_reloc_handling): Handle
	R_MSP430{,X}_GNU_{SET,SUB}_ULEB128.

gas/ChangeLog:
	* config/tc-msp430.c (msp430_insert_uleb128_fixes): New.
	(msp430_md_end): Call msp430_insert_uleb128_fixes.

include/ChangeLog:
	* elf/msp430.h (elf_msp430_reloc_type): Add
	R_MSP430_GNU_{SET,SUB}_ULEB128.
	(elf_msp430x_reloc_type): Add R_MSP430X_GNU_{SET,SUB}_ULEB128.

ld/ChangeLog:
	* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
	* testsuite/ld-msp430-elf/uleb128.s: New test.
	* testsuite/ld-msp430-elf/uleb128_430.d: New test.
	* testsuite/ld-msp430-elf/uleb128_430x.d: New test.
2020-09-08 16:18:38 +01:00
Alan Modra
7ba115508a PR26580, Size and alignment of commons vs as-needed shared lib
Two pieces to this puzzle:
1) Revert HJ's fix for PR13250 so that size and alignment isn't
   sticky, instead attack the real underlying problem that
   _bfd_generic_link_add_one_symbol does the wrong thing in making a
   common section in a shared library bfd.
2) Save and restore common u.c.p fields, which hold the section and
   alignment.

A better fix for (2) would be to throw away all of that horrible code
saving and restoring the hash table when loading as-needed library
symbols, and instead do a scan over as-needed library symbols before
adding anything.

bfd/
	PR 13250
	PR 26580
	* elflink.c (_bfd_elf_merge_symbol): Make "override" a bfd**.
	Return oldbfd in override when old common should override new
	common.
	(_bfd_elf_add_default_symbol): Adjust to suit.
	(elf_link_add_object_symbols): Likewise.  Pass "override" to
	_bfd_generic_link_add_one_symbol.  Save and restore common u.c.p
	field for --as-needed shared libraries.  Revert pr13250 changes.
ld/
	* testsuite/ld-elf/pr26580-a.s,
	* testsuite/ld-elf/pr26580-b.s,
	* testsuite/ld-elf/pr26580-1.sd,
	* testsuite/ld-elf/pr26580-2.sd: New tests
	* testsuite/ld-elf/comm-data.exp: Run new tests.
	* testsuite/ld-elf/pr26580-a.c,
	* testsuite/ld-elf/pr26580-b.c,
	* testsuite/ld-elf/pr26580-3.out,
	* testsuite/ld-elf/pr26580-4.out: New tests.
	* testsuite/ld-elf/shared.exp: Run new tests.
2020-09-08 22:30:38 +09:30
Alan Modra
1e3b96fd6c Allow plugin syms to mark as-needed shared libs needed
We must tell LTO about symbols in all shared libraries loaded.  That
means we can't load extra shared libraries after LTO recompilation, at
least, not those that affect the set of symbols that LTO cares about,
the IR symbols.

This change will likely result in complaints about --as-needed
libraries being loaded unnecessarily, but being correct is more
important than being optimal.  One of the PR15146 tests regresses, and
while that could be hidden by disabling the missing dso message by
making it conditional on h->root.non_ir_ref_regular, that would just
be sweeping a problem under the rug.

bfd/
	PR 15146
	PR 26314
	PR 26530
	* elflink.c (elf_link_add_object_symbols): Do set def_regular
	and ref_regular for IR symbols.  Don't clear dynsym, allowing
	IR symbols to load --as-needed shared libraries, but prevent
	IR symbols from becoming dynamic.
ld/
	* testsuite/ld-plugin/lto.exp: Don't run pr15146 tests.
	* testsuite/ld-plugin/pr15146.d: Delete.
	* testsuite/ld-plugin/pr15146a.c: Delete.
	* testsuite/ld-plugin/pr15146b.c: Delete.
	* testsuite/ld-plugin/pr15146c.c: Delete.
	* testsuite/ld-plugin/pr15146d.c: Delete.
2020-09-04 14:06:44 +09:30
H.J. Lu
e062fcc8c2 ld: Change NOSANTIZE_CFLAGS to NOSANITIZE_CFLAGS
* testsuite/config/default.exp: Change NOSANTIZE_CFLAGS to
	NOSANITIZE_CFLAGS.
	* testsuite/ld-elf/dwarf.exp: Likewise.
	* testsuite/ld-elf/indirect.exp: Likewise.
	* testsuite/ld-elf/linux-x86.exp: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elf/tls.exp: Likewise.
	* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-gc/gc.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-plugin/plugin.exp: Likewise.
	* testsuite/ld-scripts/crossref.exp: Likewise.
	* testsuite/ld-selective/selective.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2020-09-03 17:17:19 -07:00
Nelson Chu
9184ef8a92 RISC-V: Minor cleanup and typos when merging elf attributes.
bfd/
	* elfnn-riscv.c (riscv_i_or_e_p): Minor cleanup for warnings/errors.
	(riscv_merge_std_ext): Likewise.
	(riscv_merge_arch_attr_info): Likewise.
	(riscv_merge_attributes): Likewise and fix comment typos.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Remove
	the useless `warnings` keywords.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
2020-09-03 11:12:02 +08:00
Nelson Chu
32f0ce4db9 RISC-V: Report warnings rather than errors for the mis-matched ISA versions.
Same as the privileged spec attributes check - different ISA versions
should be compatible, unless there are some known conflicts.  Therefore,
we should allow to link objects with different ISA versions, and update
the output ISA versions once the corresponding input ones are newer.
But it's better to also warn people that the conflicts may happen when
the ISA versions are mis-matched.

	bfd/
	* elfnn-riscv.c (riscv_version_mismatch): Change the return type
	from void to bfd_boolean.  Report warnings rather than errors
	when the ISA versions are mis-matched.  Afterwards, remember to
	update the output ISA versions to the newest ones.
	(riscv_merge_std_ext): Allow to link objects with different
	standard ISA versions.  Try to add output ISA versions to
	merged_subsets first.
	(riscv_merge_multi_letter_ext): Likewise.  But for standard additional
	ISA and non-standard ISA versions.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Update the
	message from error to warning.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: New testcases.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-09-03 11:11:51 +08:00
Kito Cheng
72bd6912ea RISC-V: Improve the error message for the mis-matched ISA versions.
Consider the updated attr-merge-arch-failed-01.d testcase.  Extension
A's version are mis-matched between attr-merge-arch-failed-01a.s and
attr-merge-arch-failed-01b.s.  But the old binutils reports that the
mis-matched extension is M rather than A.  This commit is used to fix
the wrong mis-matched error message.

Besides, when parsing the arch string in the riscv_parse_subset, it
shouldn't be NULL or empty.  However, it might be empty when we failed
to merge the arch string in the riscv_merge_attributes.  Since we should
already issue the correct error message in another side, and the message
- ISA string must begin with rv32 or rv64 - is meaninglesss when the arch
string is empty, so do not issue it.

	bfd/
	* elfnn-riscv.c (riscv_merge_std_ext): Fix to report the correct
	error message when the versions of extension are mis-matched.
	* elfxx-riscv.c (riscv_parse_subset): Don't issue the error when
	the string is empty.

	ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Updated.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s: Likewise.
2020-09-03 11:11:38 +08:00
Alan Modra
d48b742bc1 heap use after free in xcoff_archive_info_eq
Using an input file objalloc memory for anything that isn't created
when opening the bfd is not a good idea.  The problem is that this
memory can disappear if bfd_free_cached_info is called or when bfd
closes files in order to keep the number of open files reasonable.

bfd/
	* xcofflink.c (xcoff_get_archive_info): Allocate xcoff_archive_info
	on the output bfd objalloc memory.
ld/
	* testsuite/ld-scripts/sysroot-prefix.exp (single_sysroot_prefix_test):
	Log $scriptname.
2020-09-03 11:04:46 +09:30
H.J. Lu
42afa120eb ld: Add $NOSANTIZE_CFLAGS to more linker tests
* testsuite/ld-elf/dwarf.exp: Append $NOSANTIZE_CFLAGS to CFLAGS.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
	* testsuite/ld-size/size.exp: Likewise.
2020-08-30 07:28:17 -07:00
Jozef Lawrynowicz
64b63c2993 MSP430: Fix alignment of __*_array_start symbols in default linker script
__{preinit,init,fini}_array_start symbols must be word aligned in
linker scripts. If the section preceding the __*_array_start symbol
has an odd size, then a NULL byte will be present between the start
symbol and the .*_array section itself, when the section gets
automatically word-aligned.

This results in a branch to an invalid address when the CRT startup
code tries to run through the functions listed in the array sections.

Some MSP430 linker scripts do not align the __*_array start symbols, so
this added warning will catch that problem and help the user avoid
the potential incorrect execution of the program.

ld/ChangeLog:

	* emultempl/msp430.em (input_section_exists): New.
	(check_array_section_alignment): New.
	(gld${EMULATION_NAME}_finish): New.
	* scripttempl/elf32msp430.sc: Add ALIGN directives before the
	definition of __*_array_start symbols.
	* testsuite/ld-msp430-elf/finiarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/finiarray-warn.r: New test.
	* testsuite/ld-msp430-elf/initarray-nowarn.ld: New test.
	* testsuite/ld-msp430-elf/initarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/initarray-warn.r: New test.
	* testsuite/ld-msp430-elf/initarray.s: New test.
	* testsuite/ld-msp430-elf/msp430-elf.exp: Run new tests.
	* testsuite/ld-msp430-elf/preinitarray-warn.ld: New test.
	* testsuite/ld-msp430-elf/preinitarray-warn.r: New test.
2020-08-28 14:01:10 +01:00
Jozef Lawrynowicz
87870682f3 LD: Add new %pU vfinfo format for printing linker script name
The %pT vfinfo format prints the linker script name with a line number,
however sometimes it may be necessary to print the linker script name
without any associated line number.

ld/ChangeLog:

	* ldmisc.c (vfinfo): Support new "%pU" format specifier.
2020-08-28 14:00:54 +01:00
Cooper Qu
0861f561eb CSKY: Support attribute section.
bfd
        * elf32-csky.c (csky_archs): Fix arch names.
        (csky_find_arch_with_name): New.
        (elf32_csky_merge_attributes): New.
        (csky_elf_merge_private_bfd_data): Add process of merge
        attribute section.
        (elf32_csky_obj_attrs_arg_type): New.
        (elf32_csky_obj_attrs_handle_unknown): New.
        (elf_backend_obj_attrs_vendor): Define.
        (elf_backend_obj_attrs_section): Define.
        (elf_backend_obj_attrs_arg_type): Define.
        (elf_backend_obj_attrs_section_type): Define.

binutils/
        * readelf.c (get_csky_section_type_name): New.
        (get_section_type_name): Add handler for CSKY.
        (display_csky_attribute): New.
        (process_arch_specific): Add handler for CSKY.
        * testsuite/binutils-all/strip-3.d: Remove .csky.attributes
        section.

elfcpp/
        * elfcpp.h (enum SHT): New enum SHT_CSKY_ATTRIBUTES.

gas/
        * gas/config/tc-csky.c (md_begin): Set attributes.
        (isa_flag): Change type to unsigned 64 bits.
        (struct csky_cpu_info): Likewise.
        (struct csky_macro_info): Likewise.
        (set_csky_attribute): New.
        * testsuite/gas/csky/802j.d: Ignore .csky.attributes section.
        * testsuite/gas/csky/all.d: Likewise.
        * testsuite/gas/csky/bsr1.d: Likewise.
        * testsuite/gas/csky/csky_vdsp.d: Likewise.
        * testsuite/gas/csky/cskyv2_all.d: Likewise.
        * testsuite/gas/csky/cskyv2_ck803r2.d: Likewise.
        * testsuite/gas/csky/cskyv2_ck860.d: Likewise.
        * testsuite/gas/csky/cskyv2_dsp.d: Likewise.
        * testsuite/gas/csky/cskyv2_elrw.d: Likewise.
        * testsuite/gas/csky/cskyv2_float.d: Likewise.
        * testsuite/gas/csky/enhance_dsp.d: Likewise.
        * testsuite/gas/csky/java.d: Likewise.
        * testsuite/gas/csky/v1_float.d: Likewise.
        * testsuite/gas/csky/v2_float_part1.d: Likewise.
        * testsuite/gas/csky/v2_float_part2.d: Likewise.
        * testsuite/gas/csky/v2_tls_gd.d: Likewise.
        * testsuite/gas/csky/v2_tls_ie.d: Likewise.
        * testsuite/gas/csky/v2_tls_ld.d: Likewise.
        * testsuite/gas/csky/v2_tls_le.d: Likewise.
        * testsuite/gas/elf/elf.exp: Add handler for CSKY.
        * testsuite/gas/elf/section2.e-csky: New.

include/
        * elf/csky.h (SHT_CSKY_ATTRIBUTES): Define.
        (Tag_CSKY_ARCH_NAME): New enum constant.
        (Tag_CSKY_CPU_NAME): Likewise.
        (Tag_CSKY_ISA_FLAGS): Likewise.
        (Tag_CSKY_DSP_VERSION): Likewise.
        (Tag_CSKY_VDSP_VERSION): Likewise.
        (Tag_CSKY_FPU_VERSION): Likewise.
        (Tag_CSKY_FPU_ABI): Likewise.
        (Tag_CSKY_FPU_ROUNDING): Likewise.
        (Tag_CSKY_FPU_DENORMAL): Likewise.
        (Tag_CSKY_FPU_Exception): Likewise.
        (Tag_CSKY_FPU_NUMBER_MODULE): Likewise.
        (Tag_CSKY_FPU_HARDFP): Likewise.
        (Tag_CSKY_MAX): Likewise.
        (VAL_CSKY_DSP_VERSION_EXTENSION): Likewise.
        (VAL_CSKY_DSP_VERSION_2): Likewise.
        (VAL_CSKY_VDSP_VERSION_1): Likewise.
        (VAL_CSKY_VDSP_VERSION_2): Likewise.
        (VAL_CSKY_FPU_ABI_SOFT): Likewise.
        (VAL_CSKY_FPU_ABI_SOFTFP): Likewise.
        (VAL_CSKY_FPU_ABI_HARD): Likewise.
        (VAL_CSKY_FPU_HARDFP_HALF): Likewise.
        (VAL_CSKY_FPU_HARDFP_SINGLE): Likewise.
        (VAL_CSKY_FPU_HARDFP_DOUBLE): Likewise.
        * opcode/csky.h (CSKY_ISA_VDSP_V2): Define.
        CSKYV1_ISA_E1: Change to long constant type.
        CSKYV2_ISA_E1: Likewise.
        CSKYV2_ISA_1E2: Likewise.
        CSKYV2_ISA_2E3: Likewise.
        CSKYV2_ISA_3E7: Likewise.
        CSKYV2_ISA_7E10: Likewise.
        CSKYV2_ISA_3E3R1: Likewise.
        CSKYV2_ISA_3E3R2: Likewise.
        CSKYV2_ISA_10E60: Likewise.
        CSKY_ISA_TRUST: Likewise.
        CSKY_ISA_CACHE: Likewise.
        CSKY_ISA_NVIC: Likewise.
        CSKY_ISA_CP: Likewise.
        CSKY_ISA_MP: Likewise.
        CSKY_ISA_MP_1E2: Likewise.
        CSKY_ISA_JAVA: Likewise.
        CSKY_ISA_MAC: Likewise.
        CSKY_ISA_MAC_DSP: Likewise.
        CSKY_ISA_DSP: Likewise.
        CSKY_ISA_DSP_1E2: Likewise.
        CSKY_ISA_DSP_ENHANCE: Likewise.
        CSKY_ISA_FLOAT_E1: Likewise.
        CSKY_ISA_FLOAT_1E2: Likewise.
        CSKY_ISA_FLOAT_1E3: Likewise.
        CSKY_ISA_FLOAT_3E4: Likewise.
        CSKY_ISA_VDSP: Likewise.

ld/
        * emulparams/cskyelf.sh: Support attribute section.
        * testsuite/ld-csky/tls-le-v1.d: Match .csky.attributes section.
        * ld/testsuite/ld-csky/tls-le.d: Likewise.
        * testsuite/ld-elf/non-contiguous.ld: Ignore .csky.attributes
        section.

opcodes/
        * csky-dis.c (CSKY_DEFAULT_ISA): Define.
        (csky_dis_info): Add member isa.
        (csky_find_inst_info): Skip instructions that do not belong to
        current CPU.
        (csky_get_disassembler): Get infomation from attribute section.
        (print_insn_csky): Set defualt ISA flag.
        * csky.h (CSKY_ISA_VDSP_2): Rename from CSKY_ISA_VDSP_V2.
        * csky-opc.h (struct csky_opcode): Change isa_flag16 and
        isa_flag32'type to unsigned 64 bits.
2020-08-28 17:23:24 +08:00
Nick Clifton
6194b866b7 Fixes for testsuite failures introduced by the changes made for PR 19011.
PR19011
bfd	* cofflink.c (_bfd_coff_generic_relocate_section): Provide a value
	for undefined symbols which will not generate extra warning
	messages about truncated relocs.

ld	* testsuite/lib/ld-lib.exp (ld_link_defsyms): For PE based targets
	define the __main and ___main symbols in terms of the main symbol.
2020-08-28 09:43:13 +01:00
Alan Modra
16f9c644c7 mingw plugin test regressions due to commit 514b4e191d
Fixes new failures due to image base change.

	PR 19011
	* testsuite/ld-plugin/plugin.exp: Use modified CFLAGS throughout
	file.  Add --image-base for pecoff.
2020-08-28 13:12:20 +09:30
Nelson Chu
3b1450b38c RISC-V: Treat R_RISCV_CALL and R_RISCV_CALL_PLT as the same in check_relocs.
In fact, we can treate these two relocation as the same one in the
riscv_elf_check_relocs.  I have heard that RISC-V lld had made this
improvement, and so had GNU AARCH64, they only need R_AARCH64_CALL26
for calls rather than two seperate relocations.

Beside, the following PLT issue for RISC-V 32-bit glibc seems to be
fixed by applying at least this patch.

<https://sourceware.org/pipermail/libc-alpha/2020-August/117214.html>

I have ran the toolchain regression, and everything seems fine for now.

	bfd/
	* elfnn-riscv.c (riscv_elf_check_relocs): Treat R_RISCV_CALL
	and R_RISCV_CALL_PLT as the same in the riscv_elf_check_relocs.
	(riscv_elf_relocate_section): Remove the R_RISCV_CALL for the
	unresolved reloc checks.

	ld/
	testsuite/ld-riscv-elf/lib-nopic-01a.s: Use R_RISCV_JAL rather
	than R_RISCV_CALL.
	testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
	testsuite/ld-riscv-elf/lib-nopic-01b.s: Likewise.
2020-08-28 09:37:35 +08:00
Jozef Lawrynowicz
82b946165d ld/emultempl/msp430.em: Remove unused variable
ld/ChangeLog:

	* emultempl/msp430.em: Remove unused variable "buf".
2020-08-27 20:10:52 +01:00
Nick Clifton
ec10b3bb91 Remove commit 9fb2400ce6 2020-08-27 13:52:45 +01:00
Nick Clifton
9fb2400ce6 Fix linker testcase for alpha-linux affected by fix for PR 26416
PR 26416
	* testsuite/ld-alpha/tlsbinr.rd: Update expected output.
	* testsuite/ld-alpha/tlsbinr.dd: Likewise.
	* testsuite/ld-alpha/tlsbinr.sd: Likewise.
2020-08-27 13:47:02 +01:00
Nick Alcock
5e9b84f7a2 binutils, ld: dequote libctf error messages
These are not identifiers and should not be quoted.  (Also, quoting them
just looks odd.)

Adjust diagnostics tests accordingly.

binutils/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (dump_ctf_errs): Unquote CTF error messages.
	* readelf.c (dump_ctf_errs): Likewise.

ld/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* ldlang.c (dump_ctf_errs): Unquote CTF error messages.
	(ldlang_open_ctf): Likewise.
	(lang_merge_ctf): Likewise.
	(lang_write_ctf): Likewise.
	* testsuite/ld-ctf/diag-ctf-version-f.d: Adjust.
	* testsuite/ld-ctf/diag-cttname-invalid.d: Adjust.
	* testsuite/ld-ctf/diag-decompression-failure.d: Adjust.
	* testsuite/ld-ctf/diag-parname.d: Adjust.
	* testsuite/ld-ctf/diag-unsupported-flag.d: Adjust.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d: Adjust.
	* testsuite/ld-ctf/diag-wrong-magic-number.d: Adjust.
2020-08-27 13:16:39 +01:00
Nick Alcock
926c9e7665 libctf, binutils, include, ld: gettextize and improve error handling
This commit follows on from the earlier commit "libctf, ld, binutils:
add textual error/warning reporting for libctf" and converts every error
in libctf that was reported using ctf_dprintf to use ctf_err_warn
instead, gettextizing them in the process, using N_() where necessary to
avoid doing gettext calls unless an error message is actually generated,
and rephrasing some error messages for ease of translation.

This requires a slight change in the ctf_errwarning_next API: this API
is public but has not been in a release yet, so can still change freely.
The problem is that many errors are emitted at open time (whether
opening of a CTF dict, or opening of a CTF archive): the former of these
throws away its incompletely-initialized ctf_file_t rather than return
it, and the latter has no ctf_file_t at all. So errors and warnings
emitted at open time cannot be stored in the ctf_file_t, and have to go
elsewhere.

We put them in a static local in ctf-subr.c (which is not very
thread-safe: a later commit will improve things here): ctf_err_warn with
a NULL fp adds to this list, and the public interface
ctf_errwarning_next with a NULL fp retrieves from it.

We need a slight exception from the usual iterator rules in this case:
with a NULL fp, there is nowhere to store the ECTF_NEXT_END "error"
which signifies the end of iteration, so we add a new err parameter to
ctf_errwarning_next which is used to report such iteration-related
errors.  (If an fp is provided -- i.e., if not reporting open errors --
this is optional, but even if it's optional it's still an API change.
This is actually useful from a usability POV as well, since
ctf_errwarning_next is usually called when there's been an error, so
overwriting the error code with ECTF_NEXT_END is not very helpful!
So, unusually, ctf_errwarning_next now uses the passed fp for its
error code *only* if no errp pointer is passed in, and leaves it
untouched otherwise.)

ld, objdump and readelf are adapted to call ctf_errwarning_next with a
NULL fp to report open errors where appropriate.

The ctf_err_warn API also has to change, gaining a new error-number
parameter which is used to add the error message corresponding to that
error number into the debug stream when LIBCTF_DEBUG is enabled:
changing this API is easy at this point since we are already touching
all existing calls to gettextize them.  We need this because the debug
stream should contain the errno's message, but the error reported in the
error/warning stream should *not*, because the caller will probably
report it themselves at failure time regardless, and reporting it in
every error message that leads up to it leads to a ridiculous chattering
on failure, which is likely to end up as ridiculous chattering on stderr
(trimmed a bit):

CTF error: `ld/testsuite/ld-ctf/A.c (0): lookup failure for type 3: flags 1: The parent CTF dictionary is unavailable'
CTF error: `ld/testsuite/ld-ctf/A.c (0): struct/union member type hashing error during type hashing for type 80000001, kind 6: The parent CTF dictionary is unavailable'
CTF error: `deduplicating link variable emission failed for ld/testsuite/ld-ctf/A.c: The parent CTF dictionary is unavailable'
ld/.libs/lt-ld-new: warning: CTF linking failed; output will have no CTF section: `The parent CTF dictionary is unavailable'

We only need to be told that the parent CTF dictionary is unavailable
*once*, not over and over again!

errmsgs are still emitted on warning generation, because warnings do not
usually lead to a failure propagated up to the caller and reported
there.

Debug-stream messages are not translated.  If translation is turned on,
there will be a mixture of English and translated messages in the debug
stream, but rather that than burden the translators with debug-only
output.

binutils/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (dump_ctf_archive_member): Move error-
	reporting...
	(dump_ctf_errs): ... into this separate function.
	(dump_ctf): Call it on open errors.
	* readelf.c (dump_ctf_archive_member): Move error-
	reporting...
	(dump_ctf_errs): ... into this separate function.  Support
	calls with NULL fp. Adjust for new err parameter to
	ctf_errwarning_next.
	(dump_section_as_ctf): Call it on open errors.

include/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_errwarning_next): New err parameter.

ld/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* ldlang.c (lang_ctf_errs_warnings): Support calls with NULL fp.
	Adjust for new err parameter to ctf_errwarning_next.  Only
	check for assertion failures when fp is non-NULL.
	(ldlang_open_ctf): Call it on open errors.
	* testsuite/ld-ctf/ctf.exp: Always use the C locale to avoid
	breaking the diags tests.

libctf/ChangeLog
2020-08-27  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-subr.c (open_errors): New list.
	(ctf_err_warn): Calls with NULL fp append to open_errors.  Add err
	parameter, and use it to decorate the debug stream with errmsgs.
	(ctf_err_warn_to_open): Splice errors from a CTF dict into the
	open_errors.
	(ctf_errwarning_next): Calls with NULL fp report from open_errors.
	New err param to report iteration errors (including end-of-iteration)
	when fp is NULL.
	(ctf_assert_fail_internal): Adjust ctf_err_warn call for new err
	parameter: gettextize.
	* ctf-impl.h (ctfo_get_vbytes): Add ctf_file_t parameter.
	(LCTF_VBYTES): Adjust.
	(ctf_err_warn_to_open): New.
	(ctf_err_warn): Adjust.
	(ctf_bundle): Used in only one place: move...
	* ctf-create.c: ... here.
	(enumcmp): Use ctf_err_warn, not ctf_dprintf, passing the err number
	down as needed.  Don't emit the errmsg.  Gettextize.
	(membcmp): Likewise.
	(ctf_add_type_internal): Likewise.
	(ctf_write_mem): Likewise.
	(ctf_compress_write): Likewise.  Report errors writing the header or
	body.
	(ctf_write): Likewise.
	* ctf-archive.c (ctf_arc_write_fd): Use ctf_err_warn, not
	ctf_dprintf, and gettextize, as above.
	(ctf_arc_write): Likewise.
	(ctf_arc_bufopen): Likewise.
	(ctf_arc_open_internal): Likewise.
	* ctf-labels.c (ctf_label_iter): Likewise.
	* ctf-open-bfd.c (ctf_bfdclose): Likewise.
	(ctf_bfdopen): Likewise.
	(ctf_bfdopen_ctfsect): Likewise.
	(ctf_fdopen): Likewise.
	* ctf-string.c (ctf_str_write_strtab): Likewise.
	* ctf-types.c (ctf_type_resolve): Likewise.
	* ctf-open.c (get_vbytes_common): Likewise. Pass down the ctf dict.
	(get_vbytes_v1): Pass down the ctf dict.
	(get_vbytes_v2): Likewise.
	(flip_ctf): Likewise.
	(flip_types): Likewise. Use ctf_err_warn, not ctf_dprintf, and
	gettextize, as above.
	(upgrade_types_v1): Adjust calls.
	(init_types): Use ctf_err_warn, not ctf_dprintf, as above.
	(ctf_bufopen_internal): Likewise. Adjust calls. Transplant errors
	emitted into individual dicts into the open errors if this turns
	out to be a failed open in the end.
	* ctf-dump.c (ctf_dump_format_type): Adjust ctf_err_warn for new err
	argument.  Gettextize.  Don't emit the errmsg.
	(ctf_dump_funcs): Likewise.  Collapse err label into its only case.
	(ctf_dump_type): Likewise.
	* ctf-link.c (ctf_create_per_cu): Adjust ctf_err_warn for new err
	argument.  Gettextize.  Don't emit the errmsg.
	(ctf_link_one_type): Likewise.
	(ctf_link_lazy_open): Likewise.
	(ctf_link_one_input_archive): Likewise.
	(ctf_link_deduplicating_count_inputs): Likewise.
	(ctf_link_deduplicating_open_inputs): Likewise.
	(ctf_link_deduplicating_close_inputs): Likewise.
	(ctf_link_deduplicating): Likewise.
	(ctf_link): Likewise.
	(ctf_link_deduplicating_per_cu): Likewise. Add some missed
	ctf_set_errnos to obscure error cases.
	* ctf-dedup.c (ctf_dedup_rhash_type): Adjust ctf_err_warn for new
	err argument.  Gettextize.  Don't emit the errmsg.
	(ctf_dedup_populate_mappings): Likewise.
	(ctf_dedup_detect_name_ambiguity): Likewise.
	(ctf_dedup_init): Likewise.
	(ctf_dedup_multiple_input_dicts): Likewise.
	(ctf_dedup_conflictify_unshared): Likewise.
	(ctf_dedup): Likewise.
	(ctf_dedup_rwalk_one_output_mapping): Likewise.
	(ctf_dedup_id_to_target): Likewise.
	(ctf_dedup_emit_type): Likewise.
	(ctf_dedup_emit_struct_members): Likewise.
	(ctf_dedup_populate_type_mapping): Likewise.
	(ctf_dedup_populate_type_mappings): Likewise.
	(ctf_dedup_emit): Likewise.
	(ctf_dedup_hash_type): Likewise. Fix a bit of messed-up error
	status setting.
	(ctf_dedup_rwalk_one_output_mapping): Likewise. Don't hide
	unknown-type-kind messages (which signify file corruption).
2020-08-27 13:15:43 +01:00
Jeremy Drake
514b4e191d Change the default characteristics of DLLs built by the linker to more secure settings.
PR 19011
	* emultempl/pe.em (DEFAULT_DLL_CHARACTERISTICS): Define.
	(pe_dll_characteristics): Initialise to DEFAULT_DLL_CHARACTERISTICS.
	(add_options): Add options to disable DLL characteristics.
	(list_options): List the new options.
	(handle_options): Handle the new options.
	* emultempl/pep.em: Similar changes to above.
	(NT_EXE_IMAGE_BASE): Default to an address above 4G.
	(NT_DLL_IMAGE_BASE, NT_DLL_AUTO_IMAGE_BASE,
	(NT_DLL_AUTO_IMAGE_MASK): Likewise.
	* ld.texi: Document the new options.
	* pe-dll.c (pe_dll_enable_reloc_section): Change to default to
	true.
	(generate_reloc): Do nothing if there is no reloc section.
	(pe_exe_fill_sections): Only assign the reloc section contents if
	the section exists.
	* testsuite/ld-pe/pe.exp: Add the --disable-reloc-section flag to
	the .secrel32 tests.
	* testsuite/ld-scripts/provide-8.d: Expect for fail on PE targets.
	* NEWS: Mention the change in DLL generation.
2020-08-27 12:58:27 +01:00
H.J. Lu
05fd99cc80 ld: Add $NOSANTIZE_CFLAGS to more linker tests
-fsanitize= can be used to build binutils with

$ CC="gcc -fsanitize=address,undefined" CXX="g++ -fsanitize=address,undefined" .../configure --disable-werror

Since not all linker tests are compatible with -fsanitize=, pass
$NOSANTIZE_CFLAGS to disable -fsanitize= for such tests.

	* testsuite/ld-elf/indirect.exp: Append $NOSANTIZE_CFLAGS to CC.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-elfcomm/elfcomm.exp: Likewise.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-plugin/plugin.exp: Likewise.
	* testsuite/ld-scripts/crossref.exp: Likewise.
2020-08-26 11:57:35 -07:00
Alan Modra
32168ca6c3 PR26499 UBSAN: eelf32_spu.c:537 member access null pointer
Another &p->field.

	PR 26499
	* emultempl/spuelf.em (spu_elf_relink): Check for NULL tmp_file_list.
2020-08-26 23:23:45 +09:30
Alan Modra
aaf9875ef9 PR26431 UBSAN: pe-dll.c:568 null pointer bsearch
PR 26431
	* pe-dll.c (auto_export): Don't call bsearch with zero count.
2020-08-26 23:23:44 +09:30
Alan Modra
8d30354667 tic54x ld testsuite
* testsuite/ld-libs/libs.exp: Don't run on sh-pe, tic30 or tic54x.
	* testsuite/ld-scripts/data.d: xfail tic4x and tic54x.
	* testsuite/ld-scripts/empty-address-2a.d: xfail tic54x.
	* testsuite/ld-scripts/empty-address-2b.d: Likewise.
	* testsuite/ld-scripts/include-1.d: xfail tic4x and tic54x.
	* testsuite/ld-scripts/provide-1.d: xfail tic54x.
	* testsuite/ld-scripts/provide-2.d: Likewise.
	* testsuite/ld-scripts/provide-4.d: Likewise.
2020-08-25 19:31:57 +09:30
Alan Modra
f1a9fbd995 sparc testsuite fallout 2020-08-24 21:48:16 +09:30
Alan Modra
252dcdf432 PowerPC TPREL_HA/LO optimisation
ppc64 ld optimises sequences like the following
	addis 3,13,wot@tprel@ha
	lwz 3,wot@tprel@l(3)
to
	nop
	lwz 3,wot@tprel(13)
when "wot" is located near enough to the thread pointer.
However, the ABI doesn't require that R_PPC64_TPREL16_HA always be on
an addis rt,13,imm instruction, and while ld checked for that on the
high-part instruction it didn't disable the optimisation on the
low-part instruction.  This patch fixes that problem, disabling the
tprel optimisation globally if high-part instructions don't pass
sanity checks.  The optimisation is also enabled for ppc32, where
before ld.bfd had the code in the wrong place and ld.gold had it in a
block only enabled for ppc64.

bfd/
	* elf32-ppc.c (ppc_elf_check_relocs): Set has_tls_reloc for
	high part tprel16 relocs.
	(ppc_elf_tls_optimize): Sanity check high part tprel16 relocs.
	Clear do_tls_opt on odd instructions.
	(ppc_elf_relocate_section): Move TPREL16_HA/LO optimisation later.
	Don't sanity check them here.
	* elf64-ppc.c (ppc64_elf_check_relocs): Set has_tls_reloc for
	high part tprel16 relocs.
	(ppc64_elf_tls_optimize): Sanity check high part tprel16 relocs.
	Clear do_tls_opt on odd instructions.
	(ppc64_elf_relocate_section): Don't sanity check TPREL16_HA.
ld/
	* testsuite/ld-powerpc/tls32.d: Update for TPREL_HA/LO optimisation.
	* testsuite/ld-powerpc/tlsexe32.d: Likewise.
	* testsuite/ld-powerpc/tlsldopt32.d: Likewise.
	* testsuite/ld-powerpc/tlsmark32.d: Likewise.
	* testsuite/ld-powerpc/tlsopt4_32.d: Likewise.
	* testsuite/ld-powerpc/tprel.s,
	* testsuite/ld-powerpc/tprel.d,
	* testsuite/ld-powerpc/tprel32.d: New tests.
	* testsuite/ld-powerpc/tprelbad.s,
	* testsuite/ld-powerpc/tprelbad.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
gold/
	* powerpc.cc (Target_powerpc): Add tprel_opt_ and accessors.
	(Target_powerpc::Scan::local): Sanity check tprel high relocs.
	(Target_powerpc::Scan::global): Likewise.
	(Target_powerpc::Relocate::relocate): Control tprel optimisation
	with tprel_opt_ and enable for 32-bit.
2020-08-24 21:15:06 +09:30
H.J. Lu
3f2e969923 elf: Keep only one '@' for undefined versioned symbols
The symbol string table in the .symtab section is optional and cosmetic.
Keep only one '@' for undefined versioned symbols, which are defined in
shared objects, in the symbol string table.  Update "nm -D" to display
only one '@' for undefined versioned symbols.

bfd/

	PR ld/26382
	* elflink.c (elf_link_output_symstrtab): Keep only one '@' for
	versioned symbols, which are defined in shared objects, in
	symbol string table.

binutils/

	PR ld/26382
	* nm.c (print_symname): Display only one '@' for undefined
	versioned symbols.
	* doc/binutils.texi: Update nm version information.

ld/

	PR ld/26382
	* testsuite/ld-elf/pr26302.nd: Updated.
	* testsuite/ld-elf/pr26302.rd: New file.
	* testsuite/ld-elf/shared.exp: Add a test for readelf -sW.
2020-08-22 08:32:02 -07:00
Nick Clifton
01147b2082 Ensure that compressed sections that have an ELF compression header structure at the start are correctly aligned.
PR 26428
bfd	* bfd.c (bfd_update_compression_header): Also set the sh_addralign
	field in the ELF header of the compressed sections.

ld	* testsuite/ld-elf/zlibbegin.rS: Update expected output.
	* testsuite/ld-elf/zlibnormal.rS: Likewise.
2020-08-20 15:03:21 +01:00
Alan Modra
0dbd452ad2 PowerPC64 inline PLT call tests
* testsuite/ld-powerpc/inline.s,
	* testsuite/ld-powerpc/inline-1.d,
	* testsuite/ld-powerpc/inline-2.d,
	* testsuite/ld-powerpc/inline-3.d,
	* testsuite/ld-powerpc/inline-4.d,
	* testsuite/ld-powerpc/inlinepcrel.s,
	* testsuite/ld-powerpc/inlinepcrel-1.d,
	* testsuite/ld-powerpc/inlinepcrel-2.d,
	* testsuite/ld-powerpc/inlinepcrel-3.d: New tests.
	* testsuite/ld-powerpc/powerpc.exp: Run them.
2020-08-16 23:00:34 +09:30
H.J. Lu
246b9ea198 ld: Add a PR binutils/26389 test
PR binutils/26389
	* testsuite/ld-plugin/lto.exp: Run PR binutils/26389 test.
	* testsuite/ld-plugin/pr26389.c: New file.
	* testsuite/ld-plugin/pr26389.d: Likewise.
2020-08-16 05:45:02 -07:00
Tamar Christina
95c210664d AArch64: Relax thumb-plt testcases regexpr.
The regexpr in these two files are a bit strict in that they don't account for
the slight changes in tags in certain arm targets which cause our address
offsets to change.   This changes the tests to allow slight movement in
locations while still strictly checking the rest.

ld/ChangeLog:

2020-08-03  Tamar Christina  <tamar.christina@arm.com>

	* testsuite/ld-arm/thumb-plt-got.d: Relax regexpr.
	* testsuite/ld-arm/thumb-plt.d: Likewise.
2020-08-14 07:52:00 +01:00
Alan Modra
6738c8a7c9 PowerPC64 --no-pcrel-optimize
This new option effectively ignores R_PPC64_PCREL_OPT, disabling the
optimization of instructions marked by that relocation.  The patch
also disables GOT indirect to GOT/TOC pointer relative code editing
when --no-toc-optimize.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add no_pcrel_opt.
	* elf64-ppc.c (ppc64_elf_relocate_section): Disable GOT reloc
	optimizations when --no-toc-optimize.  Disable R_PPC64_PCREL_OPT
	optimization when --no-pcrel-optimize.
ld/
	* emultempl/ppc64elf.em (params): Init new field.
	(enum ppc64_opt): Add OPTION_NO_PCREL_OPT.
	(PARSE_AND_LIST_LONGOPTS, PARSE_AND_LIST_OPTIONS),
	(PARSE_AND_LIST_ARGS_CASES): Support --no-pcrel-optimize.
2020-08-13 08:10:18 +09:30
Nick Clifton
ccd9fae5d5 Improve the documentation of the linker's --relax option.
PR ld/21351
	* ld.texi: Clarify the behaviour of the --relax and --no-relax
	options on systems that do not support them.
2020-08-10 16:35:57 +01:00
H.J. Lu
9b0ac51b22 nm: Remove --with-symbol-versions
Since

commit 7e6e972f74
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Mar 24 04:23:11 2020 -0700

    bfd: Display symbol version for nm -D

always displays symbol version for nm, remove --with-symbol-versions and
silently accept it for backward compatibility.

binutils/

	PR binutils/26302
	* nm.c (with_symbol_versions): Removed.
	(long_option_values): Add OPTION_WITH_SYMBOL_VERSIONS.
	(long_options): Update --with-symbol-versions entry.
	(print_symbol): Remove the with_symbol_versions check.
	(main): Add OPTION_WITH_SYMBOL_VERSIONS for backward
	compatibility.
	* doc/binutils.texi: Remove --with-symbol-versions.

ld/

	PR binutils/26302
	* testsuite/ld-elf/pr26302.nd: New file.
	* testsuite/ld-elf/pr26302.ver: Likewise.
	* testsuite/ld-elf/pr26302a.c: Likewise.
	* testsuite/ld-elf/pr26302b.c: Likewise.
	* testsuite/ld-elf/shared.exp: Run binutils/26302 tests.
2020-08-10 05:17:41 -07:00
David Faust
d844f10ac2 bpf: fix false overflow in eBPF ELF backend linker
When performing DISP{16,32} relocations, the eBPF ELF backend linker
needs to convert the relocation from an address into a signed number
of 64-bit words (minus one) to jump.

Because of this unsigned-to-signed conversion, special care needs to
be taken when dividing to ensure the sign bits remain correct.
Otherwise, a false relocation overflow error can be triggered.

bfd/ChangeLog

2020-08-07  David Faust  <david.faust@oracle.com>

	* elf64-bpf.c (bpf_elf_relocate_section): Ensure signed division for
	DISP16 and DISP32 relocations.

ld/ChangeLog

2020-08-07  David Faust  <david.faust@oracle.com>

	* testsuite/ld-bpf/call-3.s: New file.
	* testsuite/ld-bpf/call-3.d: Likewise.
2020-08-07 20:36:47 +02:00
David Faust
3ee9565c95 bpf: relocation fixes for eBPF ELF backend
The eBPF ELF backend was not properly recording relocation addends
during installation, nor reading and applying them when performing
the final relocation. This lead to various issues with incorrect
relocations.

These issues are fixed with a new howto special function to install
the relocations, and updates to bpf_elf_relocate_section to read and
use the addends as recorded in the input_bfd.

bfd/ChangeLog

2020-08-05  David Faust  <david.faust@oracle.com>

	* elf64-bpf.c (bpf_elf_generic_reloc): New function.
	(bpf_elf_howto_table): Use it here.
	(bpf_elf_relocate_section): Use addends recorded in input_bfd for
	instruction and data relocations.

ld/ChangeLog

2020-08-05  David Faust  <david.faust@oracle.com>

	* testsuite/ld-bpf/call-2.s: New file.
	* testsuite/ld-bpf/call-2.d: Likewise.
	* testsuite/ld-bpf/reloc-data-be.d: Likewise.
	* testsuite/ld-bpf/reloc-data-le.d: Likewise.
	* testsuite/ld-bpf/reloc-data.s: Likewise.
	* testsuite/ld-bpf/reloc-insn-external-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn-external-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn-external.s: Likewise.
	* testsuite/ld-bpf/reloc-insn32-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn32-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn32.s: Likewise.
	* testsuite/ld-bpf/reloc-insn64-be.d: Likewise.
	* testsuite/ld-bpf/reloc-insn64-le.d: Likewise.
	* testsuite/ld-bpf/reloc-insn64.s: Likewise.
2020-08-06 15:14:54 +02:00
Jozef Lawrynowicz
1a9f72a7a8 MSP430: ld: Update output section tail when shuffling ".either" sections
The MSP430 linker shuffles input sections with names beginning with
".either" between the upper and lower memory regions, to try to avoid
one region overflowing when there is space in the other region.

However, when an ".either" input section attached to the tail of an
output section was moved to a different output section in the other
region, that tail wasn't being updated to the new section at the end
of the original output section.

This caused a bug where a shuffled section could end up in the
middle of another section in the output executable, resulting in
corrupted code or data.

When changing the output section of an input section attached to the
tail of its output section, that tail is now updated to point to
the new input section at the end of the section list.

ld/ChangeLog:

2020-08-06  Jozef Lawrynowicz  <jozef.l@mittosystems.com>

	* emultempl/msp430.em (change_output_section): Update the tail
	of the output section statement list when moving the original
	tail to a different output section.
	(eval_upper_either_sections): Don't move sections from the upper
	region to the lower region unless the upper region is
	overflowing.
2020-08-06 11:19:36 +01:00
Alan Modra
ee44c2ac7b Use xmalloc rather than malloc
As far as I can tell, the following comment is false nowadays.
/* Calls to m-alloc get turned by sed into xm-alloc.  */

Remove it, and call xmalloc.

	* ldlex.l (yy_create_string_buffer): Use xmalloc rather than malloc.
	* lexsup.c (parse_args): Likewise.
2020-08-03 10:59:38 +09:30
Alan Modra
bfd133d0d8 PR26328, Compilation warning when building ld v2.35 with MinGW
PR 26328
	* configure.ac: AC_CHECK_DECLS asprintf.
	* configure: Regenerate.
	* config.in: Regenerate.
2020-08-03 10:58:39 +09:30
Alan Modra
39d744bdcc Tidy objdump_symstuff and objdump_dynsymstuff
* testsuite/ld-elfvers/vers.exp (objdump_symstuff): Remove unused
	variable.  Init list_a and list_b to empty.
	(objdump_dynsymstuff): Likewise, and remove undefined list_a
	handling.
	* testsuite/ld-elfweak/elfweak.exp (objdump_symstuff): Similarly.
	(objdump_dynsymstuff): Similarly.
2020-08-03 10:57:09 +09:30
H.J. Lu
e6a6c7676a ld: Add -fno-lto to linker tests
LTO can be used to build binutils with

$ CC="gcc -flto -ffat-lto-objects -Wl,--as-needed" CXX="g++ -flto -ffat-lto-objects -Wl,--as-needed" .../configure

But not all linker tests are compatible with LTO.  Pass -fno-lto to CC
to disable LTO on linker tests by default.  -flto is passed explicitly
to CC in linker LTO tests.

	* testsuite/ld-elf/indirect.exp: Append -fno-lto to CC.
	* testsuite/ld-elfvers/vers.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-ifunc/ifunc.exp: Likewise.
	* testsuite/ld-plugin/lto.exp (no_lto): New.
	Add $no_lto to build pr15146c.so.
	* testsuite/lib/ld-lib.exp (at_least_gcc_version): Filter out
	-Wl,xxx options.
	(check_gcc_plugin_enabled): Likewise.
	(run_ld_link_exec_tests): Prepend -fno-lto to $cflags.
	(run_cc_link_tests): Likewise.
2020-07-31 07:57:04 -07:00
Shahab Vahedi
223d5266de ARC: Fix ld/pr24511 test
With this patch, ld/pr24511 test passes for ARC.

At first glance, the test was failing because the order of
"__init_array_start" and "__fini_array_start" weak symbols were
reversed:

$ nm -n dump.out

      expected output          |          real output
00002104 D __init_array_start  |  00002104 D __fini_array_start
0000210c D __fini_array_start  |  00002104 D __init_array_start

The order of the symbols are different as a side effect of both
symbols being mapped to the _same_ address (0x2104).  Looking
further into the mapping logs [1] revealed that the linker
script must consider all instances of ".init_array" (in other
words ".init_array.*") inside its relevant section. Same logic
holds for ".fini_array".

Therefore, adding "KEEP (*(SORT(.init_array.*)))" to the linker
script, along with the one for ".finit_array.*", resolved the
problem.  While at it, I took the liberty of refactoring the
script a little bit and made those pieces of script macros.

[1] Linker's mapping for the relevant part of the test
---------------------------------------------------------------
.init_array     0x2104        0x0
                0x2104        PROVIDE (__init_array_start = .)
 *(.init_array)
                [!provide]    PROVIDE (__init_array_end = .)

.fini_array     0x2104        0x0
                0x2104        PROVIDE (__fini_array_start = .)
 *(.fini_array)
                [!provide]    PROVIDE (__fini_array_end = .)

.data           0x2104        0x0
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x2104        0x0 pr24511.o

.init_array.01000
                0x2104        0x8
 .init_array.01000
                0x2104        0x8 pr24511.o

.fini_array.01000
                0x210c        0x8
 .fini_array.01000
                0x210c        0x8 pr24511.o
---------------------------------------------------------------

ld:
	* scripttempl/elfarc.sc (.init_array): Keep ".init_array.*".
	  (.fini_array): Keep ".fini_array.*".

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2020-07-31 12:15:17 +03:00
Rainer Orth
c8693053f8 Unify Solaris procfs and largefile handling
GDB currently doesn't build on 32-bit Solaris:

* On Solaris 11.4/x86:

In file included from /usr/include/sys/procfs.h:26,
                 from /vol/src/gnu/gdb/hg/master/dist/gdb/i386-sol2-nat.c:24:
/usr/include/sys/old_procfs.h:31:2: error: #error "Cannot use procfs in the large file compilation environment"
 #error "Cannot use procfs in the large file compilation environment"
  ^~~~~

* On Solaris 11.3/x86 there are several more instances of this.

The interaction between procfs and large-file support historically has
been a royal mess on Solaris:

* There are two versions of the procfs interface:

** The old ioctl-based /proc, deprecated and not used any longer in
   either gdb or binutils.

** The `new' (introduced in Solaris 2.6, 1997) structured /proc.

* There are two headers one can possibly include:

** <procfs.h> which only provides the structured /proc, definining
   _STRUCTURED_PROC=1 and then including ...

** <sys/procfs.h> which defaults to _STRUCTURED_PROC=0, the ioctl-based
   /proc, but provides structured /proc if _STRUCTURED_PROC == 1.

* procfs and the large-file environment didn't go well together:

** Until Solaris 11.3, <sys/procfs.h> would always #error in 32-bit
   compilations when the large-file environment was active
   (_FILE_OFFSET_BITS == 64).

** In both Solaris 11.4 and Illumos, this restriction was lifted for
   structured /proc.

So one has to be careful always to define _STRUCTURED_PROC=1 when
testing for or using <sys/procfs.h> on Solaris.  As the errors above
show, this isn't always the case in binutils-gdb right now.

Also one may need to disable large-file support for 32-bit compilations
on Solaris.  config/largefile.m4 meant to do this by wrapping the
AC_SYS_LARGEFILE autoconf macro with appropriate checks, yielding
ACX_LARGEFILE.  Unfortunately the macro doesn't always succeed because
it neglects the _STRUCTURED_PROC part.

To make things even worse, since GCC 9 g++ predefines
_FILE_OFFSET_BITS=64 on Solaris.  So even if largefile.m4 deciced not to
enable large-file support, this has no effect, breaking the gdb build.

This patch addresses all this as follows:

* All tests for the <sys/procfs.h> header are made with
  _STRUCTURED_PROC=1, the definition going into the various config.h
  files instead of having to make them (and sometimes failing) in the
  affected sources.

* To cope with the g++ predefine of _FILE_OFFSET_BITS=64,
  -U_FILE_OFFSET_BITS is added to various *_CPPFLAGS variables.  It had
  been far easier to have just

  #undef _FILE_OFFSET_BITS

  in config.h, but unfortunately such a construct in config.in is
  commented by config.status irrespective of indentation and whitespace
  if large-file support is disabled.  I found no way around this and
  putting the #undef in several global headers for bfd, binutils, ld,
  and gdb seemed way more invasive.

* Last, the applicability check in largefile.m4 was modified only to
  disable largefile support if really needed.  To do so, it checks if
  <sys/procfs.h> compiles with _FILE_OFFSET_BITS=64 defined.  If it
  doesn't, the disabling only happens if gdb exists in-tree and isn't
  disabled, otherwise (building binutils from a tarball), there's no
  conflict.

  What initially confused me was the check for $plugins here, which
  originally caused the disabling not to take place.  Since AC_PLUGINGS
  does enable plugin support if <dlfcn.h> exists (which it does on
  Solaris), the disabling never happened.

  I could find no explanation why the linker plugin needs large-file
  support but thought it would be enough if gld and GCC's lto-plugin
  agreed on the _FILE_OFFSET_BITS value.  Unfortunately, that's not
  enough: lto-plugin uses the simple-object interface from libiberty,
  which includes off_t arguments.  So to fully disable large-file
  support would mean also disabling it in libiberty and its users: gcc
  and libstdc++-v3.  This seems highly undesirable, so I decided to
  disable the linker plugin instead if large-file support won't work.

The patch allows binutils+gdb to build on i386-pc-solaris2.11 (both
Solaris 11.3 and 11.4, using GCC 9.3.0 which is the worst case due to
predefined _FILE_OFFSET_BITS=64).  Also regtested on
amd64-pc-solaris2.11 (again on Solaris 11.3 and 11.4),
x86_64-pc-linux-gnu and i686-pc-linux-gnu.

	config:
	* largefile.m4 (ACX_LARGEFILE) <sparc-*-solaris*|i?86-*-solaris*>:
	Check for <sys/procfs.h> incompatilibity with large-file support
	on Solaris.
	Only disable large-file support and perhaps plugins if needed.
	Set, substitute LARGEFILE_CPPFLAGS if so.

	bfd:
	* bfd.m4 (BFD_SYS_PROCFS_H): New macro.
	(BFD_HAVE_SYS_PROCFS_TYPE): Require BFD_SYS_PROCFS_H.
	Don't define _STRUCTURED_PROC.
	(BFD_HAVE_SYS_PROCFS_TYPE_MEMBER): Likewise.
	* elf.c [HAVE_SYS_PROCFS_H] (_STRUCTURED_PROC): Don't define.
	* configure.ac: Use BFD_SYS_PROCFS_H to check for <sys/procfs.h>.
	* configure, config.in: Regenerate.
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.

	binutils:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.
	* configure: Regenerate.

	gas:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in, doc/Makefile.in: Regenerate.
	* configure: Regenerate.

	gdb:
	* proc-api.c (_STRUCTURED_PROC): Don't define.
	* proc-events.c: Likewise.
	* proc-flags.c: Likewise.
	* proc-why.c: Likewise.
	* procfs.c: Likewise.

	* Makefile.in (INTERNAL_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* configure, config.in: Regenerate.

	gdbserver:
	* configure, config.in: Regenerate.

	gdbsupport:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* common.m4 (GDB_AC_COMMON): Use BFD_SYS_PROCFS_H to check for
	<sys/procfs.h>.
	* Makefile.in: Regenerate.
	* configure, config.in: Regenerate.

	gnulib:
	* configure.ac: Run ACX_LARGEFILE before gl_EARLY.
	* configure: Regenerate.

	gprof:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in: Regenerate.
	* configure: Regenerate.

	ld:
	* Makefile.am (AM_CPPFLAGS): Add LARGEFILE_CPPFLAGS.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
2020-07-30 15:41:50 +02:00
Maciej W. Rozycki
c77cb2a09c MIPS: Make the IRIX naming of local section symbols consistent
Make the MIPS/IRIX naming of local section symbols consistent between
files produced by generic ELF code and ELF linker code, complementing
commit 174fd7f955 ("New bfd elf hook: force naming of local section
symbols"), <https://sourceware.org/ml/binutils/2004-02/msg00072.html>.

Local section symbols have no names in the standard ELF gABI, however
the lack of a name causes problems with IRIX's MIPSpro linker.  To work
around the issue we give them names, however we do that in generic ELF
code only, based on what the `elf_backend_name_local_section_symbols'
hook returns if present.  That makes objects created by GAS or `objdump'
work correctly, however not ones created by `ld -r'.  That would not
normally cause issues with IRIX systems using GAS and `objdump' only
with the MIPSpro linker, however if GNU LD was used for whatever reason
in producing objects later fed to IRIX's MIPSpro linker, then things
would break.

Modify ELF linker code accordingly then, using the same hook.  Adjust
the `ld-elf/64ksec-r' test accordingly so that it also accepts a section
symbol with a name.

Also modify the hook itself so that only actual ET_REL objects have
names assigned to local section symbols.  Other kinds of ELF files are
not ever supposed to be relocated with the MIPSpro linker, so we can
afford producing more standard output.

Add suitable GAS, LD and `objcopy' test cases to the relevant testsuites
to keep these tools consistently verified.  This change also fixes:

FAIL: objcopy executable (pr25662)

across MIPS targets using the IRIX compatibility mode.

	bfd/
	* elflink.c (bfd_elf_final_link): Give local symbols a name if
	so requested.
	* elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): Only
	return TRUE if making ET_REL output.

	binutils/
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n64.d:
	New test.
	* testsuite/binutils-all/mips/mips.exp: Run the new tests.

	gas/
	* testsuite/gas/mips/global-local-symtab-sort-o32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-o32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64t.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-elf/sec64k.exp: Also accept a section symbol with
	a name.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n64.d: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2020-07-29 20:56:41 +01:00
Maciej W. Rozycki
3f1b17bbf0 MIPS/LD: Set symtab's `sh_info' correctly for IRIX emulations
Correct ELF linker code so as to set the `sh_info' value of the static
symbol table section according to the section symbols vs other symbols
split where required by the selection of the IRIX compatibility mode for
MIPS target.  Add a `elf_backend_elfsym_local_is_section' hook for that
purpose, returning TRUE if it is only STB_LOCAL/STT_SECTION symbols that
are to be considered local for the purpose of this split rather than all
STB_LOCAL symbols.

We do it already in generic ELF code, and have done it since 1993, with
the `elf_backend_sym_is_global' hook, affecting GAS and `objcopy', so
these tools produce correct ELF output in the IRIX compatibility mode,
however if such output is fed as input to `ld -r', then the linker's
output is no longer valid for that mode.  The relevant changes to
generic ELF code are:

commit 062189c6ea
Author: Ian Lance Taylor <ian@airs.com>
Date:   Thu Nov 18 17:12:47 1993 +0000

and:

commit 6e07e54f1b
Author: Ian Lance Taylor <ian@airs.com>
Date:   Thu Jan 6 20:01:42 1994 +0000

(split across two GIT commits likely due to repository conversion
peculiarities).

The `elf_backend_sym_is_global' hook however operates on BFD rather than
ELF symbols, making it unsuitable for the ELF linker as the linker does
not convert any symbol tables processed into the BFD format.  Converting
the hook to operate on ELF symbols would in principle be possible, but
it would still require a considerable rewrite of `bfd_elf_final_link' to
adapt to the interface.

Therefore, especially given that no new use for the IRIX compatibility
mode is expected, minimize changes made to the ELF linker code and just
add an entirely new hook, and wire it in the o32 and n32 MIPS backends
accordingly; the n64 backend never uses the IRIX compatibility mode.

Since we have no coverage here at all add suitable GAS, LD and `objcopy'
test cases to the relevant testsuites to keep these tools consistently
verified.

	bfd/
	* elf-bfd.h (elf_backend_data): Add
	`elf_backend_elfsym_local_is_section' member.
	* elfxx-target.h (elf_backend_elfsym_local_is_section): New
	macro.
	(elfNN_bed): Add `elf_backend_elfsym_local_is_section' member.
	* elflink.c (bfd_elf_final_link): Use it to determine whether
	set the `.symtab' section's `sh_info' value to the index of the
	first non-local or non-section symbol.
	* elf32-mips.c (mips_elf32_elfsym_local_is_section): New
	function.
	(elf_backend_elfsym_local_is_section): New macro.
	* elfn32-mips.c (mips_elf_n32_elfsym_local_is_section): New
	function.
	(elf_backend_elfsym_local_is_section): New macro.

	binutils/
	* testsuite/binutils-all/mips/global-local-symtab-o32.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-o32t.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n32.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n32t.d: New
	test.
	* testsuite/binutils-all/mips/global-local-symtab-n64.d: New
	test.
	* testsuite/binutils-all/mips/mips.exp: Run the new tests.

	gas/
	* testsuite/gas/mips/global-local-symtab-o32.d: New test.
	* testsuite/gas/mips/global-local-symtab-o32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-n32.d: New test.
	* testsuite/gas/mips/global-local-symtab-n32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-n64.d: New test.
	* testsuite/gas/mips/global-local-symtab.s: New test source.
	* testsuite/gas/mips/mips.exp: Run the new tests.

	ld/
	* testsuite/ld-mips-elf/global-local-symtab-o32.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-o32t.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n32.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n32t.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab-n64.d: New test.
	* testsuite/ld-mips-elf/global-local-symtab.ld: New test linker
	script.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2020-07-29 20:56:41 +01:00
Alan Modra
5987401fcb Don't assert at ldwrite.c:212
When excluding SHF_LINK_ORDER sections that happen to have SEC_KEEP
set, we need to set SEC_EXCLUDE here to avoid a problem later.

	* ldelf.c (ldelf_before_place_orphans): Set SEC_EXCLUDE for
	discarded sections.
2020-07-29 17:38:01 +09:30
Alan Modra
f437dadd89 More just-syms changes
* ldlang.c (lang_check): Don't complain about relocs or merge
	attributes from --just-symbols input.
	* testsuite/ld-misc/just-symbols.exp: Just dump .data section.
	Don't run test on a number of targets.
2020-07-28 13:09:20 +09:30
Alan Modra
c38166b376 Re: Allow new just-symbols test to run on XCOFF and PE
This ensures we don't match random data *before* the line we want to
see, ie. that --just-symbols has excluded section contents from
just-symbols-0.o.  Oops, missed the ChangeLog entry before too.

	* testsuite/ld-misc/just-symbols-1.dd: Revert last change.
2020-07-28 13:09:20 +09:30
Alan Modra
32377a8037 Allow new just-symbols test to run on XCOFF and PE
* testsuite/ld-misc/just-symbols.exp: Run for x86_64 PE too.
	Set LDFLAGS for PE and XCOFF.
	* testsuite/ld-misc/just-symbols.ld: Accept XCOFF mapped .data.
2020-07-27 22:31:37 +09:30
Alan Modra
344e66534e ctf test ERROR: $target-cc does not exist
* testsuite/lib/ld-lib.exp (check_ctf_available): Check first that
	target compiler is available.
2020-07-27 22:31:37 +09:30
Maciej W. Rozycki
97c79e2174 PR ld/26288: Allow the use of `--just-symbols' with ET_EXEC input
Fix a regression from commit a87e1817a4 ("Have the linker fail if any
attempt to link in an executable is made.") and do not reject ET_EXEC
input supplied with the `--just-symbols' option.  Such use is legitimate
as the file requested is not actually linked and only the symbols are
extracted. Furthermore it is often the most useful application, as
already observed in our documentation for the option, where it allows
"to refer symbolically to absolute locations of memory defined in other
programs."

Provide a set of tests for the use of ET_EXEC with `--just-symbols'.
These are excluded however for SH/PE targets because they complain if a
section's VMA is 0:

ld: zero vma section reloc detected: `.text' #0 f=32795
ld: zero vma section reloc detected: `.data' #1 f=291

and for x86_64/PE targets because they seem to hardwire the VMA:

 100000000 12000000 01000000 00000000 00000000  ................

	ld/
	PR ld/26288
	* ldelf.c (ldelf_after_open): Do not reject ET_EXEC input
	supplied with `--just-symbols'.
	* testsuite/ld-misc/just-symbols.exp: New test script.
	* testsuite/ld-misc/just-symbols-1.dd: New test dump.
	* testsuite/ld-misc/just-symbols.ld: New test linker script.
	* testsuite/ld-misc/just-symbols-0.s: New test source.
	* testsuite/ld-misc/just-symbols-1.s: New test source.
2020-07-23 20:11:29 +01:00
Maciej W. Rozycki
b5dd7120f6 PR ld/26288: Revert obsolete part of PR ld/26047 fix
Revert commit a3fc941881 ("Stop the linker from accepting executable
ELF files as inputs to other links."), which has been made obsolete by
commit a87e1817a4 ("Have the linker fail if any attempt to link in an
executable is made.").  An earlier check triggers added with the latter
commit making the piece of code removed dead.

	ld/
	PR ld/26288

	Revert:
	PR 26047
	* ldelf.c (ldelf_after_open): Fail if attempting to link one
	executable into another.
2020-07-23 20:11:29 +01:00
Nick Alcock
62cdd7b18f ld, testsuite: do not run CTF tests at all on non-ELF for now
Right now, the linker is not emitting CTF sections on (at least some)
non-ELF platforms, because work similar to that done for ELF needs to be
done to each platform in turn to emit linker-generated sections whose
contents are programmatically derived.  (Or something better needs to be
done.)

So, for now, the CTF tests will fail on non-ELF for lack of a .ctf
section in the output: so skip the CTF tests there temporarily.
(This is not the same as the permanent skip of the diags tests, which is
done because the input for those is assembler that depends on the ELF
syntax of pseudos like .section: this is only a temporary skip, until
the linker grows support for CTF on more targets.)

ld/
	* testsuite/ld-ctf/ctf.exp: Skip on non-ELF for now.
2020-07-22 18:05:32 +01:00
Nick Alcock
fa03171fb4 ld: do not produce one empty output .ctf section for every input .ctf
The trick we use to prevent ld doing as it does for almost all other
sections and copying the input CTF section into the output has recently
broken, causing output to be produced with a valid CTF section followed
by massive numbers of CTF sections, one per .ctf in the input (minus
one, for the one that was filled out by ctf_link).  Their size is being
forcibly set to zero, but they're still present, wasting space and
looking ridiculous.

This is not right:

ld/ld-new  :
section                     size      addr
.interp                       28   4194984
[...]
.bss                       21840   6788544
.comment                      92         0
.ctf                       87242         0
.ctf                           0         0
.ctf                           0         0
[snip 131 more empty sections]
.gnu.build.attributes       7704   6818576
.debug_aranges              6592         0
.debug_info              4488859         0
.debug_abbrev             150099         0
.debug_line               796759         0
.debug_str                237926         0
.debug_loc               2247302         0
.debug_ranges             237920         0
Total                   10865285

The fix is to exclude these unwanted input sections from being present
in the output.  We tried this before and it broke things, because if you
exclude all the .ctf sections there isn't going to be one in the output
so there is nowhere to put the deduplicated CTF. The solution to that is
really simple: set SEC_EXCLUDE on *all but one* CTF section.  We don't
care which one (they're all the same once their size has been zeroed),
so just pick the first we see.

ld/
	* ldlang.c (ldlang_open_ctf): Set SEC_EXCLUDE on all but the
	first input .ctf section.
2020-07-22 18:05:32 +01:00
Nick Alcock
7cdfc3462f ld, testsuite: only run CTF tests when ld and GCC support CTF
The CTF testsuite runs GCC to generate CTF that it knows matches the
input .c files before doing a run_dump_test over it.  So we need a GCC
capable of doing that, and we need to always avoid running those tests
if libctf was disabled because the linker will never be capable of it.

ld/
	* configure.ac (enable_libctf): Substitute it.
	* Makefile.am (enablings.exp): New.
	(EXTRA_DEJAGNU_SITE_CONFIG): Add it.
	(DISTCLEANFILES): Likewise.
	* Makefile.in: Regenerate.
	* configure: Likewise.
	* testsuite/lib/ld-lib.exp (compile_one_cc): New.
	(check_ctf_available): Likewise.
	(skip_ctf_tests): Likewise.
	* testsuite/ld-ctf/ctf.exp: Call skip_ctf_tests.
2020-07-22 18:05:32 +01:00
Egeyar Bagcioglu
b1b33524ad ld: new CTF testsuite
Uses the new cc option to run_dump_test to compile most tests from C
code, ensuring that the types in the C code accurately describe what the
.d file is testing.

(Some tests, mostly those testing malformed CTF, run directly from .s,
or include both .s and .c.)

ld/
	* testsuite/ld-ctf/ctf.exp: New file.
	* testsuite/ld-ctf/A-2.c: New file.
	* testsuite/ld-ctf/A.c: New file.
	* testsuite/ld-ctf/B-2.c: New file.
	* testsuite/ld-ctf/B.c: New file.
	* testsuite/ld-ctf/C-2.c: New file.
	* testsuite/ld-ctf/C.c: New file.
	* testsuite/ld-ctf/array-char.c: New file.
	* testsuite/ld-ctf/array-int.c: New file.
	* testsuite/ld-ctf/array.d: New file.
	* testsuite/ld-ctf/child-float.c: New file.
	* testsuite/ld-ctf/child-int.c: New file.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: New file.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: New file.
	* testsuite/ld-ctf/conflicting-enums.d: New file.
	* testsuite/ld-ctf/conflicting-typedefs.d: New file.
	* testsuite/ld-ctf/cross-tu-1.c: New file.
	* testsuite/ld-ctf/cross-tu-2.c: New file.
	* testsuite/ld-ctf/cross-tu-conflicting-2.c: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-1.c: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-2.c: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-3.c: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-4.c: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: New file.
	* testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d: New file.
	* testsuite/ld-ctf/cross-tu-into-cycle.d: New file.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: New file.
	* testsuite/ld-ctf/cycle-1.c: New file.
	* testsuite/ld-ctf/cycle-1.d: New file.
	* testsuite/ld-ctf/cycle-2.A.d: New file.
	* testsuite/ld-ctf/cycle-2.B.d: New file.
	* testsuite/ld-ctf/cycle-2.C.d: New file.
	* testsuite/ld-ctf/diag-ctf-version-0.d: New file.
	* testsuite/ld-ctf/diag-ctf-version-0.s: New file.
	* testsuite/ld-ctf/diag-ctf-version-2-unsupported-feature.d: New file.
	* testsuite/ld-ctf/diag-ctf-version-2-unsupported-feature.s: New file.
	* testsuite/ld-ctf/diag-ctf-version-f.d: New file.
	* testsuite/ld-ctf/diag-ctf-version-f.s: New file.
	* testsuite/ld-ctf/diag-cttname-invalid.d: New file.
	* testsuite/ld-ctf/diag-cttname-invalid.s: New file.
	* testsuite/ld-ctf/diag-cttname-null.d: New file.
	* testsuite/ld-ctf/diag-cttname-null.s: New file.
	* testsuite/ld-ctf/diag-cuname.d: New file.
	* testsuite/ld-ctf/diag-cuname.s: New file.
	* testsuite/ld-ctf/diag-decompression-failure.d: New file.
	* testsuite/ld-ctf/diag-decompression-failure.s: New file.
	* testsuite/ld-ctf/diag-parlabel.d: New file.
	* testsuite/ld-ctf/diag-parlabel.s: New file.
	* testsuite/ld-ctf/diag-parname.d: New file.
	* testsuite/ld-ctf/diag-parname.s: New file.
	* testsuite/ld-ctf/diag-unsupported-flag.d: New file.
	* testsuite/ld-ctf/diag-unsupported-flag.s: New file.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d: New file.
	* testsuite/ld-ctf/diag-wrong-magic-number.d: New file.
	* testsuite/ld-ctf/diag-wrong-magic-number.s: New file.
	* testsuite/ld-ctf/enum-2.c: New file.
	* testsuite/ld-ctf/enum.c: New file.
	* testsuite/ld-ctf/function.c: New file.
	* testsuite/ld-ctf/function.d: New file.
	* testsuite/ld-ctf/slice.c: New file.
	* testsuite/ld-ctf/slice.d: New file.
	* testsuite/ld-ctf/super-sub-cycles.c: New file.
	* testsuite/ld-ctf/super-sub-cycles.d: New file.
	* testsuite/ld-ctf/typedef-int.c: New file.
	* testsuite/ld-ctf/typedef-long.c: New file.
	* testsuite/ld-ctf/union-1.c: New file.
2020-07-22 18:05:19 +01:00
Nick Alcock
5dba6f05b7 ld: new options --ctf-variables and --ctf-share-types
libctf recently changed to make it possible to not emit the CTF
variables section.  Make this the default for ld: the variables section
is a simple name -> type mapping, and the names can be quite voluminous.
Nothing in the variables section appears in the symbol table, by
definition, so GDB cannot make use of them: special-purpose projects
that implement their own analogues of symbol table lookup can do so, but
they'll need to tell the linker to emit the variables section after all.

The new --ctf-variables option does this.

The --ctf-share-types option (valid values "share-duplicated" and
"share-unconflicted") allow the caller to specify the CTF link mode.
Most users will want share-duplicated, since it allows for more
convenient debugging: but very large projects composed of many decoupled
components may want to use share-unconflicted mode, which places types
that appear in only one TU into per-TU dicts.  (They may also want to
relink the CTF using the ctf_link API and cu-mapping, to make their
"components" larger than a single TU.  Right now the linker does not
expose the CU-mapping machinery.  Perhaps it should in future to make
this use case easier.)

For now, giving the linker the ability to emit share-duplicated CTF lets
us add testcases for that mode to the testsuite.

ld/
	* ldlex.h (option_values) <OPTION_CTF_VARIABLES,
	OPTION_NO_CTF_VARIABLES, OPTION_CTF_SHARE_TYPES>: New.
	* ld.h (ld_config_type) <ctf_variables, ctf_share_duplicated>:
	New fields.
	* ldlang.c (lang_merge_ctf): Use them.
	* lexsup.c (ld_options): Add ctf-variables, no-ctf-variables,
	ctf-share-types.
	(parse_args) <OPTION_CTF_VARIABLES, OPTION_NO_CTF_VARIABLES,
	OPTION_CTF_SHARE_TYPES>: New cases.
	* ld.texi: Document new options.
	* NEWS: Likewise.
2020-07-22 18:03:57 +01:00
Egeyar Bagcioglu
f320bba50f ld: Reformat CTF errors into warnings.
ld/
	* ldlang.c (lang_merge_ctf): Turn errors into warnings.
	Fix a comment typo.
	(lang_write_ctf): Turn an error into a warning.
	(ldlang_open_ctf): Reformat warnings. Fix printing file names.

Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
2020-07-22 18:03:39 +01:00
Nick Alcock
8b37e7b63e libctf, ld, binutils: add textual error/warning reporting for libctf
This commit adds a long-missing piece of infrastructure to libctf: the
ability to report errors and warnings using all the power of printf,
rather than being restricted to one errno value.  Internally, libctf
calls ctf_err_warn() to add errors and warnings to a list: a new
iterator ctf_errwarning_next() then consumes this list one by one and
hands it to the caller, which can free it.  New errors and warnings are
added until the list is consumed by the caller or the ctf_file_t is
closed, so you can dump them at intervals.  The caller can of course
choose to print only those warnings it wants.  (I am not sure whether we
want objdump, readelf or ld to print warnings or not: right now I'm
printing them, but maybe we only want to print errors?  This entirely
depends on whether warnings are voluminous things describing e.g. the
inability to emit single types because of name clashes or something.
There are no users of this infrastructure yet, so it's hard to say.)

There is no internationalization here yet, but this at least adds a
place where internationalization can be added, to one of
ctf_errwarning_next or ctf_err_warn.

We also provide a new ctf_assert() function which uses this
infrastructure to provide non-fatal assertion failures while emitting an
assert-like string to the caller: to save space and avoid needlessly
duplicating unchanging strings, the assertion test is inlined but the
print-things-out failure case is not.  All assertions in libctf will be
converted to use this machinery in future commits and propagate
assertion-failure errors up, so that the linker in particular cannot be
killed by libctf assertion failures when it could perfectly well just
print warnings and drop the CTF section.

include/
	* ctf-api.h (ECTF_INTERNAL): Adjust error text.
	(ctf_errwarning_next): New.
libctf/
	* ctf-impl.h (ctf_assert): New.
	(ctf_err_warning_t): Likewise.
	(ctf_file_t) <ctf_errs_warnings>: Likewise.
	(ctf_err_warn): New prototype.
	(ctf_assert_fail_internal): Likewise.
	* ctf-inlines.h (ctf_assert_internal): Likewise.
	* ctf-open.c (ctf_file_close): Free ctf_errs_warnings.
	* ctf-create.c (ctf_serialize): Copy it on serialization.
	* ctf-subr.c (ctf_err_warn): New, add an error/warning.
	(ctf_errwarning_next): New iterator, free and pass back
	errors/warnings in succession.
	* libctf.ver (ctf_errwarning_next): Add.
ld/
	* ldlang.c (lang_ctf_errs_warnings): New, print CTF errors
	and warnings.  Assert when libctf asserts.
	(lang_merge_ctf): Call it.
	(land_write_ctf): Likewise.
binutils/
	* objdump.c (ctf_archive_member): Print CTF errors and warnings.
	* readelf.c (dump_ctf_archive_member): Likewise.
2020-07-22 18:02:17 +01:00
H.J. Lu
0e6a3f07f5 ld: Properly override the IR definition
We change the previous definition in the IR object to undefweak only
after all LTO symbols have been read.

include/

	PR ld/26262
	PR ld/26267
	* bfdlink.h (bfd_link_info): Add lto_all_symbols_read.

ld/

	PR ld/26262
	PR ld/26267
	* ldlang.c (lang_process): Set lto_all_symbols_read after all
	LTO IR symbols have been read.
	* plugin.c (plugin_notice): Override the IR definition only if
	all LTO IR symbols have been read or the new definition is
	non-weak and the the IR definition is weak
	* testsuite/ld-plugin/lto.exp: Run PR ld/26262 and ld/26267
	tests.
	* testsuite/ld-plugin/pr26262a.c: New file.
	* testsuite/ld-plugin/pr26262b.c: Likewise.
	* testsuite/ld-plugin/pr26262c.c: Likewise.
	* testsuite/ld-plugin/pr26267.err: Likewise.
	* testsuite/ld-plugin/pr26267a.c: Likewise.
	* testsuite/ld-plugin/pr26267b.c: Likewise.
	* testsuite/ld-plugin/pr26267c.c: Likewise.
2020-07-22 03:49:17 -07:00
Nick Clifton
39326c35dd Fix problem running a few PowerPC linker tests when the .data section is retained.
* testsuite/ld-powerpc/powerpc.exp (ppcelftests): Use section name
	.PPC.EMB.apuinfo instead of section number 2 in apuinfo tests.
2020-07-20 14:57:38 +01:00
Alan Modra
2f5541f384 PR26265, Spurious 'gc-sections requires ... when --init or --fini
bfd/
	* elflink.c (_bfd_elf_gc_keep): Use bfd_is_const_section.
ld/
	PR 26265
	* ldlang.c (undef_from_cmdline): Delete.
	(ldlang_add_undef): Mark "cmdline" param unused.
	(lang_end): Traverse gc_sym_list to determine whether a symbol root
	has been specified.  Update error message.
	* testsuite/ld-gc/noent.d: Adjust for changed error message.
2020-07-20 22:21:11 +09:30
H.J. Lu
98b3697bcd x86: Update PR gas/26263 linker tests
Update and run PR gas/26263 linker tests for all x86 ELF targets to
accept any program header layout.

	PR gas/26263
	* testsuite/ld-i386/pr26263.d: Updated.
	* testsuite/ld-x86-64/pr26263.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run gas/26263 test for all ELF
	targets.
2020-07-20 04:53:58 -07:00
H.J. Lu
2585b7a5ce x86: Change PLT32 reloc against section to PC32
Commit 292676c1 resolved PLT32 reloc aganst local symbol to section.
Since PLT32 relocation must be against symbols, turn such PLT32
relocation into PC32 relocation.

gas/

	PR gas/26263
	* config/tc-i386.c (i386_validate_fix): Change PLT32 reloc
	against section to PC32 reloc.
	* testsuite/gas/i386/relax-5.d: Updated.
	* testsuite/gas/i386/x86-64-relax-4.d: Likewise.

ld/

	PR gas/26263
	* testsuite/ld-i386/i386.exp: Run PR gas/26263 test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr26263.d: New file.
	* testsuite/ld-x86-64/pr26263.d: Likewise.
	* testsuite/ld-x86-64/pr26263.s: Likewise.
2020-07-19 06:51:32 -07:00
Hans-Peter Nilsson
4609ada49f ld: optionally emit _etext last, before .data
So, here's my suggestion for making _init .. __etext cover .text +
.rodata (including things like the read-only exception tables) for
elf64mmix.  A quick web search gives that __etext (and friends) isn't
well defined, so each target can interpret the "end of text segment"
to their own liking.  It seems likely this change is also a better fit
than the default for other ports, at least those with .rodata after
.text in the same segment.

The presence of a separate rodata-segment is optional (and not true
for elf64mmix).  This is reflected in the name as SEPARATE_TEXT /
SEPARATE_CODE isn't considered, to keep it simple; each target has to
make sure their settings of variables make sense.

ld:
	* scripttempl/elf.sc (ETEXT_LAST_IN_RODATA_SEGMENT): New variable.
	* emulparams/elf64mmix.sh (ETEXT_LAST_IN_RODATA_SEGMENT): Define.
	* testsuite/ld-mmix/sec-1.d: Adjust.
2020-07-19 06:08:07 +02:00
Alan Modra
e10a07b32d Power10 stub selection
This patch better supports mixing of power10 and non-power10 code,
as might be seen in a cpu-optimized library using ifuncs to select
functions optimized for a given cpu.  Using -Wl,--no-power10-stubs
isn't that good in this situation since non-power10 notoc stubs are
slower and larger than the power10 variants, which you'd like to use
on power10 code paths.

With this change, power10 pc-relative code that makes calls marked
@notoc uses power10 stubs if stubs are necessary, and other calls use
non-power10 instructions in stubs.  This will mean that if gcc is
generating code for -mcpu=power10 but with pc-rel disabled then you'll
get the older stubs even on power10 (unless you force with
-Wl,--power10-stubs).  That shouldn't be too big a problem: stubs that
use r2 are reasonable.  It's just the ones that set up addressing
using "mflr 12; bcl 20,31,.+4; mflr 11; mtlr 12" that should be
avoided if possible.

bfd/
	* elf64-ppc.c (struct ppc_link_hash_table): Add has_power10_relocs.
	(select_alt_stub): New function.
	(ppc_get_stub_entry): Use it here.
	(ppc64_elf_check_relocs): Set had_power10_relocs rather than
	power10_stubs.
	(ppc64_elf_size_stubs): Clear power10_stubs here instead.  Don't
	merge notoc stubs with other varieties when power10_stubs is "auto".
	Instead dup the stub hash table entry.
	(plt_stub_size, ppc_build_one_stub, ppc_size_one_stub): Adjust
	tests of power10_stubs.
ld/
	* emultempl/ppc64elf.em (power10-stubs): Accept optional "auto" arg.
	* ld.texi (power10-stubs): Update.
	* testsuite/ld-powerpc/callstub-1.d: Force --power10-stubs.
	* testsuite/ld-powerpc/callstub-2.d: Relax branch offset comparison.
	* testsuite/ld-powerpc/callstub-4.d: New test.
	* testsuite/ld-powerpc/notoc.d: Force --no-power10-stubs.
	* testsuite/ld-powerpc/notoc3.d,
	* testsuite/ld-powerpc/notoc3.s,
	* testsuite/ld-powerpc/notoc3.wf: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.  Pass
	--no-power10-stubs for notoc link.
2020-07-19 12:27:47 +09:30
Hans-Peter Nilsson
555a578963 mmix ld: move .init (and _init) first.
This both makes the section layout more similar to that of the general
default for ELF and fixes (makes true) an assumption that code and
rodata is located between _init and __etext, in
libgcc/config/mmix/crti.S.  Sadly, that's not actually true for ELF
(generally and for elf64mmix), where exception-tables and .rodata is
after _etext; I'm pondering what to do about that.

The original mmix simulator behavior is that memory magically appears
on access, initialized with 0, which is not preferable when chasing
bugs by throwing code the size of the gcc test-suite to the simulator.
The code in crti.S compatibly enables simulator machinery to identify
undefined memory and instead stopping the simulator with an error
(going to interactive mode for interactive runs).  See
http://gcc.gnu.org/legacy-ml/gcc-patches/2012-10/msg01871.html for
more, including the mmix-sim.ch "patch file".

This fixes only one error in the gcc testsuite,
gcc.c-torture/execute/pr20621-1.c with LTO, where for some reason
gcc/lto chooses to move (writable) data that is only used to read 0 to
.rodata.  An access (sufficiently far inside a block) in an
unregistered place is flagged as an invalid access.

The bpo-9m test that I had to adjust, actually exposes a wart: mmo
does not have the notion of symbol types (or sections) and the
test-case now has leading zeros at "Main" eventually leading to it
being misdiagnosed as being outside .text and .data, thus here mapped
to BFD as an absolute symbol.  The test is not intended to check the
mmo symbol-type machinery, so I'm just tweaking it to be
symbol-type-neutral for "Main".

Since you have to jump through hoops to see the problem, I don't think
this commit is worth putting on the 2.35-branch.

ld:
	* scripttempt/mmo.sc: Move .init first in .text output section.
	* testsuite/ld-mmix/bpo-9m.d: Adjust accordingly.
2020-07-17 00:56:17 +02:00
Jan Beulich
36938cabf0 x86: avoid attaching suffixes to unambiguous insns
"Unambiguous" is is in particular taking as reference the assembler,
which also accepts certain insns - despite them allowing for varying
operand size, and hence in principle being ambiguous - without any
suffix. For example, from the very beginning of the life of x86-64 I had
trouble understanding why a plain and simple RET had to be printed as
RETQ. In case someone really used the 16-bit form, RETW disambiguates
the two quite fine.
2020-07-15 08:53:55 +02:00
Hans-Peter Nilsson
a8a48c756c mmix bfd: fix bfd_assert for R_MMIX_PUSHJ_STUBBABLE against undef'd symbol
Spotted when inspecting gcc testsuite logs, but this already is
covered by the ld-mmix testsuite, it's just that the assert is ignored
since the regexp match is for a substring and not anchored.

With the anchors added but not the bugfix, the ld.log shows that the
asserts cause a non-match as intended:

Executing on host: sh -c {./ld-new   -LX/src/ld/testsuite/ld-mmix  -m elf64mmix -o tmpdir/dump tmpdir/undef-2.o tmpdir/start.o  2>&1}  /dev/null dump.tmp (timeout = 300)
./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: tmpdir/undef-2.o:(.text+0x0): undefined reference to `undefd'
failed with: <./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: BFD (GNU Binutils) 2.34.50.20200629 assertion fail X/src/bfd/elf64-mmix.c:2845
./ld-new: tmpdir/undef-2.o:(.text+0x0): undefined reference to `undefd'>, expected: <\A[^\n\r]*undefined reference to `undefd'\Z>
FAIL: ld-mmix/undef-2

Gone with the fix of course, leaving just the intended "undefined
reference" like.

I'm not going to add anchors manually for all the "error:" strings in
the test-suite, not even in the mmix parts.  Sorry, but I'll just do
it for *these* specific undefined-reference tests.

Just a thought: maybe the run_dump_test "error:" string should
*automatically* get anchor marks prepended and appended for a single
line match as in the patch, "\A[^\n\r]*" prepended and \Z appended
unless either anchor mark or \r or \n is present in the regexp?

Committed.

bfd:
	* elf64-mmix.c (mmix_elf_relax_section): Improve accounting for
	R_MMIX_PUSHJ_STUBBABLE relocs against undefined symbols.

ld/testsuite:
	* testsuite/ld-mmix/undef-1.d, testsuite/ld-mmix/undef-1m.d,
	testsuite/ld-mmix/undef-2.d, testsuite/ld-mmix/undef-2m.d: Add
	start- and end-anchors to error-string to match just a
	single-line error-message.
2020-07-15 06:22:28 +02:00
Alan Modra
7a34d0ea4d x86_64-cygwin tests
Tests just having "xfail: x86_64-*-cygwin" aren't good, since
presumably if a test fails on x86_64-cygwin then it also fails on
x86_64-*-pe* and x86_64-*-mingw*.

binutils/
	* testsuite/lib/binutils-common.exp (is_pecoff_format): Accept
	optional machine-os arg.
ld/
	* testsuite/ld-scripts/default-script1.d: Don't skip, xfail
	using is_pecoff_format.
	* testsuite/ld-scripts/default-script2.d: Likewise.
	* testsuite/ld-scripts/default-script3.d: Likewise.
	* testsuite/ld-scripts/default-script4.d: Likewise.
	* testsuite/ld-scripts/pr20302.d: Remove x86_64-*-cygwin from notarget.
	* testsuite/ld-scripts/provide-6.d: Remove x86_64-*-cygwin from xfail.
	* testsuite/ld-scripts/provide-8.d: Likewise.
2020-07-13 22:03:59 +09:30
Alan Modra
d882c98893 Document powerpc64 ld options
* ld.texi (PowerPC64 ELF64): Document --no-inline-optimize,
	--power10-stubs and --no-power10-stubs.
2020-07-10 16:59:50 +09:30
Alan Modra
d3b10ee787 PowerPC64 ld --no-power10-stubs
Needed for libraries that use ifuncs or other means to support
cpu-optimized versions of functions, some power10, some not, and those
functions make calls using linkage stubs.

bfd/
	* elf64-ppc.h (struct ppc64_elf_params): Add power10_stubs.
	* elf64-ppc.c (struct ppc_link_hash_table): Delete
	power10_stubs.
	(ppc64_elf_check_relocs): Adjust setting of power10_stubs.
	(plt_stub_size, ppc_build_one_stub, ppc_size_one_stub): Adjust
	uses of power10_stubs.
ld/
	* emultempl/ppc64elf.em (params): Init new field.
	(enum ppc64_opt): Add OPTION_POWER10_STUBS and OPTION_NO_POWER10_STUBS.
	(PARSE_AND_LIST_LONGOPTS): Support --power10-stubs and
	--no-power10-stubs.
	(PARSE_AND_LIST_OPTIONS, PARSE_AND_LIST_ARGS_CASES): Likewise.
	* testsuite/ld-powerpc/callstub-3.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2020-07-10 11:14:38 +09:30
Alan Modra
fe49679d51 Remove powerpc PE support
Plus some leftover powerpc lynxos support.

bfd/
	* coff-ppc.c: Delete.
	* pe-ppc.c: Delete.
	* pei-ppc.c: Delete.
	* Makefile.am (BFD32_BACKENDS, BFD32_BACKENDS_CFILES): Remove PE PPC.
	* coffcode.h (coff_set_arch_mach_hook, coff_set_flags): Remove
	PPCMAGIC code.
	(coff_write_object_contents): Remove PPC_PE code.
	* config.bfd: Move powerpcle-pe to removed targets.
	* configure.ac: Remove powerpc PE entries.
	* libcoff-in.h (ppc_allocate_toc_section): Delete.
	(ppc_process_before_allocation): Delete.
	* peXXigen.c: Remove POWERPC_LE_PE code and comments.
	* targets.c: Remove powerpc PE vectors.
	* po/SRC-POTFILES.in: Regenerate.
	* libcoff.h: Regenerate.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
binutils/
	* dlltool.c: Remove powerpc PE support and comments.
	* configure.ac: Remove powerpc PE dlltool config.
	* configure: Regenerate.
gas/
	* config/obj-coff.h: Remove TE_PE support.
	* config/tc-ppc.c: Likewise.
	* config/tc-ppc.h: Likewise.
	* configure.tgt: Remove powerpc PE and powerpc lynxos.
	* testsuite/gas/cfi/cfi.exp (cfi-common-6): Remove powerpc PE
	condition.
	* testsuite/gas/macros/macros.exp: Don't xfail powerpc PE.
include/
	* coff/powerpc.h: Delete.
ld/
	* emulparams/ppcpe.sh: Delete.
	* scripttempl/ppcpe.sc: Delete.
	* emulparams/ppclynx.sh: Delete.
	* Makefile.am (ALL_EMULATION_SOURCES): Remove ppc PE and lynxos.
	* configure.tgt: Likewise.
	* emultempl/beos.em: Remove powerpc PE support.
	* emultempl/pe.em: Likewise.
	* po/BLD-POTFILES.in: Regenerate.
	* Makefile.in: Regenerate.
2020-07-09 22:58:16 +09:30
Alan Modra
c560184eb2 powerpc garbage collect test
ld's garbage collection test on powerpc64 catered for old compilers
(pre -mcmodel=medium support), setting options that caused the test to
fail.  Which meant the test wasn't really testing anything.  Get rid
of that old compiler support, and avoid -fPIE fails on ppc32.

	* testsuite/ld-gc/gc.exp: Don't set -mminimal-toc for powerpc64,
	and remove powerpc64 xfail.  Use -fno-PIE for ppc32.
2020-07-09 22:58:16 +09:30
Alan Modra
470cd0faa7 pr18841 tests on powerpc64
The PR18841 test does cross-module calls from within an ifunc
resolver, which is nasty, and not supported in general since the
called function may not be relocated.  In this case the called
function (zoo) is just a stub so doesn't need relocating, but on ppc64
the function descriptor for zoo in the executable won't be relocated
at the time the shared library ifunc resolver runs.  That means the
test will fail if your compiler generates PIEs by default.

	PR 18841
	* testsuite/ld-ifunc/ifunc.exp: Run pr18841 tests non-pie.
2020-07-09 22:58:16 +09:30
Alan Modra
babcb2ea89 powerpc-aix5.2 tests
git commit bbd0c8e204 broke many of these tests, and there have been
other changes that caused failures too.

	* testsuite/lib/ld-lib.exp (ar_simple_create): Pass options before
	ar command.
	* testsuite/ld-powerpc/aix52.exp: Run for rs6000-aix5.2.  Update
	match files.
	* testsuite/ld-powerpc/aix-abs-branch-1.dd: Update.
	* testsuite/ld-powerpc/aix-core-sec-1.hd: Update.
	* testsuite/ld-powerpc/aix-gc-1-32.dd: Update.
	* testsuite/ld-powerpc/aix-gc-1-64.dd: Update.
	* testsuite/ld-powerpc/aix-glink-1-32.dd: Update.
	* testsuite/ld-powerpc/aix-glink-1-64.dd: Update.
	* testsuite/ld-powerpc/aix-glink-2-32.dd: Update.
	* testsuite/ld-powerpc/aix-glink-2-64.dd: Update.
	* testsuite/ld-powerpc/aix-no-dup-syms-1-rel.rd: Update.
	* testsuite/ld-powerpc/aix-ref-1-32.od: Update.
	* testsuite/ld-powerpc/aix-ref-1-64.od: Update.
	* testsuite/ld-powerpc/aix-toc-1-32.dd: Update.
	* testsuite/ld-powerpc/aix-toc-1-64.dd: Update.
	* testsuite/ld-powerpc/aix-weak-3-32.dd: Update.
	* testsuite/ld-powerpc/aix-weak-3-64.dd: Update.
	* testsuite/ld-powerpc/aix-abs-branch-1.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-abs-branch-1-32.nd,
	* testsuite/ld-powerpc/aix-abs-branch-1-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-abs-reloc-1.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-abs-reloc-1-32.nd,
	* testsuite/ld-powerpc/aix-abs-reloc-1-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-abs-reloc-1.od: Delete, replace with..
	* testsuite/ld-powerpc/aix-abs-reloc-1-32.od,
	* testsuite/ld-powerpc/aix-abs-reloc-1-64.od: ..these new files.
	* testsuite/ld-powerpc/aix-export-1-all.dd: Delete, replace with..
	* testsuite/ld-powerpc/aix-export-1-all-32.dd,
	* testsuite/ld-powerpc/aix-export-1-all-64.dd: ..these new files.
	* testsuite/ld-powerpc/aix-export-1-full.dd: Delete, replace with..
	* testsuite/ld-powerpc/aix-export-1-full-32.dd,
	* testsuite/ld-powerpc/aix-export-1-full-64.dd: ..these new files.
	* testsuite/ld-powerpc/aix-export-2.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-export-2-32.nd,
	* testsuite/ld-powerpc/aix-export-2-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-gc-1.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-gc-1-32.nd,
	* testsuite/ld-powerpc/aix-gc-1-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-glink-3.dd: Delete, replace with..
	* testsuite/ld-powerpc/aix-glink-3-32.dd,
	* testsuite/ld-powerpc/aix-glink-3-64.dd: ..these new files.
	* testsuite/ld-powerpc/aix-lineno-1a.dd: Delete, replace with..
	* testsuite/ld-powerpc/aix-lineno-1a-32.dd,
	* testsuite/ld-powerpc/aix-lineno-1a-64.dd: ..these new files.
	* testsuite/ld-powerpc/aix-lineno-1a.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-lineno-1a-32.nd,
	* testsuite/ld-powerpc/aix-lineno-1a-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-lineno-1b.dd: Delete, replace with..
	* testsuite/ld-powerpc/aix-lineno-1b-32.dd,
	* testsuite/ld-powerpc/aix-lineno-1b-64.dd: ..these new files.
	* testsuite/ld-powerpc/aix-lineno-1b.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-lineno-1b-32.nd,
	* testsuite/ld-powerpc/aix-lineno-1b-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso.dnd: Delete, replace with..
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-32.dnd,
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-64.dnd: ..these new files.
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso.drd: Delete, replace with..
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-32.drd,
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-64.drd: ..these new files.
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-32.nd,
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso.rd: Delete, replace with..
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-32.rd,
	* testsuite/ld-powerpc/aix-no-dup-syms-1-dso-64.rd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-dso.dnd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-dso-32.dnd,
	* testsuite/ld-powerpc/aix-weak-1-dso-64.dnd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-dso.hd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-dso-32.hd,
	* testsuite/ld-powerpc/aix-weak-1-dso-64.hd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-dso.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-dso-32.nd,
	* testsuite/ld-powerpc/aix-weak-1-dso-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-gcdso.dnd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-gcdso-32.dnd,
	* testsuite/ld-powerpc/aix-weak-1-gcdso-64.dnd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-gcdso.hd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-gcdso-32.hd,
	* testsuite/ld-powerpc/aix-weak-1-gcdso-64.hd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-1-gcdso.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-1-gcdso-32.nd,
	* testsuite/ld-powerpc/aix-weak-1-gcdso-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-2a.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-2a-32.nd,
	* testsuite/ld-powerpc/aix-weak-2a-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-2b.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-2b-32.nd,
	* testsuite/ld-powerpc/aix-weak-2b-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-2c.nd: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-2c-32.nd,
	* testsuite/ld-powerpc/aix-weak-2c-64.nd: ..these new files.
	* testsuite/ld-powerpc/aix-weak-2c.od: Delete, replace with..
	* testsuite/ld-powerpc/aix-weak-2c-32.od,
	* testsuite/ld-powerpc/aix-weak-2c-64.od: ..these new files.
2020-07-08 15:56:28 +09:30
Alan Modra
35097e108a Re: Use is_xcoff_format in ld testsuite
git commit 7193487fa8 took h8300 out of the notarget list, resulting in
h8300-elf  +FAIL: ld-scripts/section-match-1
h8300-linux  +FAIL: ld-scripts/section-match-1

	* testsuite/ld-scripts/section-match-1.d: xfail h8300.
2020-07-07 21:57:13 +09:30
Alan Modra
e553d5b2e7 XCOFF ld testsuite fixes
* testsuite/ld-scripts/align.exp: Don't exclude xcoff.  Pass
	-bnogc ld option for xcoff.
	* testsuite/ld-scripts/provide.exp: Likewise.
	* testsuite/ld-scripts/data.exp: Pass -bnogc ld option for xcoff.
	* testsuite/ld-scripts/default-script.exp: Likewise.
	* testsuite/ld-scripts/defined.exp: Likewise.
	* testsuite/ld-scripts/empty-address.exp: Likewise.
	* testsuite/ld-scripts/expr.exp: Likewise.
	* testsuite/ld-scripts/include.exp: Likewise.
	* testsuite/ld-scripts/script.exp: Likewise.
	* testsuite/ld-scripts/assign-loc.d: Don't exclude xcoff.
	* testsuite/ld-scripts/defined3.d: Likewise.
	* testsuite/ld-scripts/defined4.d: Likewise.
	* testsuite/ld-scripts/pr18963.d: Likewise.
	* testsuite/ld-scripts/sane1.d: Likewise.
	* testsuite/ld-scripts/segment-start.d: Likewise.
	* testsuite/ld-scripts/include-1.d: Likewise, and relax text vma.
	* testsuite/ld-scripts/defined5.d: Update xfail and comment.
	* testsuite/ld-scripts/defined5.s: Tweak "defined" to be at
	non-zero section offset.
	* testsuite/ld-scripts/fill16.d: xfail for xcoff.
	* testsuite/ld-scripts/provide-2.d: Accept more symbols.
	* testsuite/ld-scripts/provide-4.d: Likewise.
	* testsuite/ld-scripts/provide-5.d: Likewise.
	* testsuite/ld-scripts/provide-6.d: Likewise.
	* testsuite/ld-scripts/provide-7.d: Likewise.
	* testsuite/ld-scripts/align.t: Accept xcoff mapped .text and .data.
	* testsuite/ld-scripts/defined3.t: Likewise.
	* testsuite/ld-scripts/defined4.t: Likewise.
	* testsuite/ld-scripts/defined5.t: Likewise.
	* testsuite/ld-scripts/fill.t: Likewise.
	* testsuite/ld-scripts/include-subdata.t: Likewise.
	* testsuite/ld-scripts/provide-1.t: Likewise.
	* testsuite/ld-scripts/provide-2.t: Likewise.
	* testsuite/ld-scripts/provide-3.t: Likewise.
	* testsuite/ld-scripts/provide-4.t: Likewise.
	* testsuite/ld-scripts/provide-5.t: Likewise.
	* testsuite/ld-scripts/provide-6.t: Likewise.
	* testsuite/ld-scripts/provide-7.t: Likewise.
	* testsuite/ld-scripts/provide-8.t: Likewise.
	* testsuite/ld-scripts/assign-loc.t: Add required xcoff sections.
	* testsuite/ld-scripts/sizeof.t: Likewise.
	* testsuite/ld-scripts/align2.t: Likewise, and mapped sections.
	* testsuite/ld-scripts/align5.t: Likewise.
	* testsuite/ld-scripts/default-script.t: Likewise.
	* testsuite/ld-scripts/empty-address-1.t: Likewise.
	* testsuite/ld-scripts/empty-address-2a.t: Likewise.
	* testsuite/ld-scripts/empty-address-2b.t: Likewise.
	* testsuite/ld-scripts/empty-address-3a.t: Likewise.
	* testsuite/ld-scripts/empty-address-3b.t: Likewise.
	* testsuite/ld-scripts/empty-address-3c.t: Likewise.
	* testsuite/ld-scripts/include-sections.t: Likewise.
	* testsuite/ld-scripts/pr14962.t: Likewise.
	* testsuite/ld-scripts/sane1.t: Likewise.
2020-07-07 18:26:34 +09:30
Alan Modra
231b7382c0 Use is_pecoff_format in ld testsuite
--image-base 0 is not just for x86_64 mingw.  This patch fixes that,
and a case where a changed LDFLAGS leaked out of one script to the next.

	* testsuite/ld-scripts/align.exp: Use is_pecoff_format.
	* testsuite/ld-scripts/defined.exp: Likewise.
	* testsuite/ld-scripts/provide.exp: Likewise.
	* testsuite/ld-scripts/weak.exp: Likewise.
	* testsuite/ld-scripts/empty-address.exp: Likewise.  Reset LDFLAGS
	on exit.
	* testsuite/ld-scripts/expr.exp: Set LDFLAGS earlier, and with
	--image-base for PE.
	* testsuite/ld-scripts/include.exp: Set LDFLAGS for PE.
	* testsuite/ld-scripts/script.exp: Use is_pecoff_format, and
	set LDFLAGS as well as flags.
2020-07-07 18:26:34 +09:30
Alan Modra
7193487fa8 Use is_xcoff_format in ld testsuite
* testsuite/ld-checks/checks.exp: Use is_xcoff_format.
	* testsuite/ld-powerpc/powerpc.exp: Likewise.
	* testsuite/ld-scripts/print-memory-usage.exp: Likewise.
	* testsuite/ld-srec/srec.exp: Likewise.
	* testsuite/ld-undefined/require-defined.exp: Likewise.
	* testsuite/ld-scripts/expr2.d: Likewise.
	* testsuite/ld-scripts/section-match-1.d: Only run for ELF.
	* testsuite/ld-elfvers/vers.exp: Delete dead code.
	* testsuite/ld-elfvsb/elfvsb.exp: Likewise.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
2020-07-07 18:26:34 +09:30
Alan Modra
fb3dc21336 XCOFF linker script PROVIDE support
Fixes bit rot from git commit b46a87b160.

	* emultempl/aix.em (gld${EMULATION_NAME}_find_exp_assignment): Handle
	etree_provided.
2020-07-07 18:26:33 +09:30
Alan Modra
3bde5ad1a6 sh vxworks tests
These tests were failing only due to not being updated for readelf
output changes.

	* testsuite/ld-sh/vxworks1-lib.rd: Update expected output.
	* testsuite/ld-sh/vxworks4.d: Likewise.
2020-07-07 18:26:33 +09:30