Commit Graph

7107 Commits

Author SHA1 Message Date
H.J. Lu
68c4956b14 x86: Properly handle function pointer reference
Update

commit ebb191adac
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Feb 9 15:51:22 2022 -0800

    x86: Disallow invalid relocation against protected symbol

to allow function pointer reference and make sure that PLT entry isn't
used for function reference due to function pointer reference.

bfd/

	PR ld/29087
	* elf32-i386.c (elf_i386_scan_relocs): Don't set
	pointer_equality_needed nor check non-canonical reference for
	function pointer reference.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.

ld/

	PR ld/29087
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/29087 tests.
	* testsuite/ld-x86-64/protected-func-3.c: New file.
2022-04-28 09:20:30 -07:00
Nick Alcock
95ade9a5f4 libctf: impose an ordering on conflicting types
When two types conflict and they are not types which can have forwards
(say, two arrays of different sizes with the same name in two different
TUs) the CTF deduplicator uses a popularity contest to decide what to
do: the type cited by the most other types ends up put into the shared
dict, while the others are relegated to per-CU child dicts.

This works well as long as one type *is* most popular -- but what if
there is a tie?  If several types have the same popularity count,
we end up picking the first we run across and promoting it, and
unfortunately since we are working over a dynhash in essentially
arbitrary order, this means we promote a random one.  So multiple
runs of ld with the same inputs can produce different outputs!
All the outputs are valid, but this is still undesirable.

Adjust things to use the same strategy used to sort types on the output:
when there is a tie, always put the type that appears in a CU that
appeared earlier on the link line (and if there is somehow still a tie,
which should be impossible, pick the type with the lowest type ID).

Add a testcase -- and since this emerged when trying out extern arrays,
check that those work as well (this requires a newer GCC, but since all
GCCs that can emit CTF at all are unreleased this is probably OK as
well).

Fix up one testcase that has slight type ordering changes as a result
of this change.

libctf/ChangeLog:

	* ctf-dedup.c (ctf_dedup_detect_name_ambiguity): Use
	cd_output_first_gid to break ties.

ld/ChangeLog:

	* testsuite/ld-ctf/array-conflicted-ordering.d: New test, using...
	* testsuite/ld-ctf/array-char-conflicting-1.c: ... this...
	* testsuite/ld-ctf/array-char-conflicting-2.c: ... and this.
	* testsuite/ld-ctf/array-extern.d: New test, using...
	* testsuite/ld-ctf/array-extern.c: ... this.
	* testsuite/ld-ctf/conflicting-typedefs.d: Adjust for ordering
	changes.
2022-04-28 11:47:12 +01:00
H.J. Lu
0d29b1a462 x86: Disable 2 tests with large memory requirement
gas/

	* testsuite/gas/i386/i386.exp: Disable rept.

ld/

	* testsuite/ld-x86-64/x86-64.exp: Disable pr17618.
2022-04-27 11:51:35 -07:00
Nick Clifton
639d467b08 Fix potential buffer overruns when creating DLLs.
PR 29006
	* pe-dll.c (make_head): Use asprintf to allocate and populate a
	buffer containing the temporary name.
	(make_tail, make_one, make_singleton_name_thunk): Likewise.
	(make_import_fixup_mark, make_import_fixup_entry): Likewise.
	(make_runtime_pseudo_reloc): Likewise.
	(pe_create_runtime_relocator_reference): Likewise.
2022-04-27 08:35:18 +01:00
Alan Modra
16538271c8 Revert pr29072 lto test changes
Revert commit 65daf5bed6 testsuite changes in ld-plugin/.  -z isn't
supported for non-ELF targets, and isn't needed since we now prune the
exec stack warning (commit 333cd559ba).

	PR 29072
2022-04-27 12:13:29 +09:30
H.J. Lu
f93c6e0a2e i386: Pass -z noexecstack to linker tests
PR ld/29072
	* testsuite/ld-i386/i386.exp: Pass -z noexecstack to gotpc1
	and property-6.
2022-04-26 09:28:24 -07:00
Nick Clifton
0d38576a34 Emit a note warning the user that creating an executable stack because of a missing .note.GNU-stack section is deprecated.
PR 29072
bfd	* elflink.c (bfd_elf_size_dynamic_sections): Display a note to the
	user that the current ehaviour of creating an executable stack
	because of a missing .note.GNU-stack section is deprecated and
	will be changed in a future release.

binutils* testsuite/lib/binutils-common.exp (prune_warnings_extra): Filter
	out notes about the executable stacjk behaviour beign deprecated.

ld	* testsuite/ld-elf/pr29072.b.warn: Update to include the note
	about the linker's behaviour being depreccated.
2022-04-25 12:53:08 +01:00
Alan Modra
333cd559ba prune .note.GNU-stack warning from testsuite
binutils/
	* testsuite/lib/binutils-common.exp (prune_warnings_extra): Remove
	.note.GNU-stack warning.
	(run_dump_test): Call prune_warnings for ld and objcopy output.
ld/
	* testsuite/ld-elf/elf.exp: Disable prune_warnings_extra temporarily
	around test for absent .note.GNU-stack
	* testsuite/ld-cris/globsymw2.s,
	* testsuite/ld-cris/warn3.d: Modify "is not implemented" message
	to avoid dejagnu prune_warnings.
2022-04-21 15:31:39 +09:30
Alan Modra
afa7150c8d ld testsuite xcoff XPASS
* testsuite/ld-scripts/defined5.d: Don't xfail xcoff targets.
2022-04-21 15:30:50 +09:30
Cl?ment Chigot
2d23f9656c xcoff: implement linker relaxation
bfd/ChangeLog:

	* coff-rs6000.c (xcoff_reloc_type_noop): Add info argument.
	(xcoff_reloc_type_fail): Likewise.
	(xcoff_reloc_type_pos): Likewise.
	(xcoff_reloc_type_neg): Likewise.
	(xcoff_reloc_type_rel): Likewise.
	(xcoff_reloc_type_toc): Likewise.
	(xcoff_reloc_type_ba): Likewise.
	(xcoff_reloc_type_crel): Likewise.
	(xcoff_reloc_type_tls): Likewise.
	(xcoff_reloc_type_br): Add stub handler.
	(xcoff_ppc_relocate_section): Add info to
	xcoff_calculate_relocation.
	(xcoff_stub_indirect_call_code): New constant.
	(xcoff_stub_shared_call_code): Likewise.
	(bfd_xcoff_backend_data): Add stub code fields.
	(bfd_pmac_xcoff_backend_data): Likewise.
	* coff64-rs6000.c (xcoff64_reloc_type_br): Add stub handler.
	(xcoff64_ppc_relocate_section): Add info to
	xcoff64_calculate_relocation.
	(xcoff64_stub_indirect_call_code): New constant.
	(xcoff64_stub_shared_call_code): Likewise.
	(bfd_xcoff_backend_data): Add stub code fields.
	(bfd_xcoff_aix5_backend_data): Likewise.
	* libxcoff.h (struct xcoff_backend_data_rec): Add stub fields.
	(bfd_xcoff_stub_indirect_call_code): New define.
	(bfd_xcoff_stub_indirect_call_size): New define.
	(bfd_xcoff_stub_shared_call_code): New define.
	(bfd_xcoff_stub_shared_call_size): New define.
	(xcoff_reloc_function): Add info argument.
	(enum xcoff_stub_type): New enum.
	(struct xcoff_stub_hash_entry): New structure.
	* xcofflink.c (struct xcoff_link_hash_table): Add stub hash
	table and params fields.
	(xcoff_stub_hash_entry): New define.
	(xcoff_stub_hash_lookup): New define.
	(stub_hash_newfunc): New function.
	(_bfd_xcoff_bfd_link_hash_table_free): Free the new stub hash
	table.
	(_bfd_xcoff_bfd_link_hash_table_create): Create the new stub
	hash table.
	(xcoff_link_add_symbols): Save rawsize for XTY_SD.
	(bfd_xcoff_link_init): New function.
	(xcoff_stub_csect_name): New function.
	(xcoff_stub_get_csect_in_range): New function.
	(xcoff_stub_name): New function.
	(bfd_xcoff_get_stub_entry): New function.
	(bfd_xcoff_type_of_stub): New function.
	(xcoff_add_stub): New function.
	(xcoff_build_one_stub): New function.
	(bfd_xcoff_size_stubs): New function.
	(bfd_xcoff_build_stubs): New function.
	(xcoff_stub_create_relocations): New function.
	(xcoff_link_input_bfd): Adapt relocations to stub.
	(xcoff_write_global_symbol): Adapt to new TOC entries generated
	for stubs.
	(_bfd_xcoff_bfd_final_link): Handle stub file.
	* xcofflink.h (struct bfd_xcoff_link_params): New structure.

ld/ChangeLog:

	* emultempl/aix.em (params): New variable.
	(stub_file): New variable.
	(xcoff_add_stub_section): New function.
	(xcoff_layout_sections_again): New function
	(hook_in_stub): New function.
	(_after_allocation): Add stub creation.
	(_create_output_section_statements): Allocate stub file and
	pass params to backend.
2022-04-20 15:11:47 +01:00
Cl?ment Chigot
1876a54217 Stubs (added in a later patch) will generate new .loader symbols, once the allocations have been done. Thus, the .loader section cannot be layout before that.
bfd/ChangeLog:

	* coff-rs6000.c (_bfd_xcoff_put_ldsymbol_name): Write len in
	  ldinfo->strings instead of directly in the output_bfd.
	* coff64-rs6000.c (_bfd_xcoff64_put_ldsymbol_name): Likewise.
	* xcofflink.c (struct xcoff_link_hash_table): Remove ldrel_count
	  field. Add ldinfo field.
	(xcoff_mark_symbol): Adjust to new ldinfo field.
	(xcoff_mark): Likewise.
	(bfd_xcoff_link_count_reloc): Likewise.
	(xcoff_build_loader_section): Split into two functions: one that
	build the loader section (this function) and one that only size
	it...
	(xcoff_size_loader_section): ... (this function).
	(bfd_xcoff_size_dynamic_sections): Adapt to new ldinfo field.
	Move the part where the dynamic sections are build to ...
	(bfd_xcoff_build_dynamic_sections): ... this function.
	* xcofflink.h: Add bfd_xcoff_build_dynamic_sections prototype.

include/ChangeLog:

	* coff/xcoff.h (struct xcoff_loader_info): Add ldrel_count and
	libpath fields.

ld/ChangeLog:

	* emultempl/aix.em (_after_allocation): New function.
2022-04-20 15:07:50 +01:00
Nick Clifton
65daf5bed6 Add linker warning for when it creates an executable stack.
PR 29072
2022-04-20 13:39:05 +01:00
Alan Modra
10c0005660 ubsan: member access within null pointer of union
Add some nonsense to cover "undefined behaviour".

	* ldlang.c (section_for_dot): Avoid UB.
2022-04-13 10:07:21 +09:30
Mark Harmstone
145667f8d9 Add support for COFF secidx relocations
bfd	* coff-i386.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_i386_relocation_section): Add support for R_SECTION.
	(coff_i386_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* coff-x86_64.c (in_reloc_p): Add R_SECTION.
	(howto_table): Add R_SECTION.
	(coff_pe_amd64_relocation_section): Add support for R_SECTION.
	(coff_amd64_reloc_type_lookup): Add support for
	BFD_RELOC_16_SECCIDX.
	* reloc.c: Add BFD_RELOC_16_SECIDX.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.

gas	* config/tc-i386.c (pe_directive_secidx): New function.
	(md_pseudo_table): Add support for secidx.
	(x86_cons_fix_new): Likewise.
	(tc_gen_reloc): Likewise.
	* expr.c (op_rank): Add O_secidx.
	* expr.h (operatorT): Likewise.
	* symbols.c (resolve_symbol_value): Add support for O_secidx.
	* testsuite/gas/i386/secidx.s: New test source file.
	* testsuite/gas/i386/secidx.d: New test driver file.
	* testsuite/gas/i386/i386.exp: Run new test.

include	* coff/i386.h: Define R_SECTION.
	* coff/x86_64.h: Likewise.

ld	* testsuite/ld-pe/secidx1.s: New test source file.
	* testsuite/ld-pe/secidx2.s: New test source file.
	* testsuite/ld-pe/secidx.d: New test driver file.
	* testsuite/ld-pe/secidx_64.d: New test driver file.
	* testsuite/ld-pe/pe.exp: Add new tests.
2022-04-07 14:47:17 +01:00
Nick Alcock
caf606c90d libtool.m4: fix the NM="/nm/over/here -B/option/with/path" case
My previous nm patch handled all cases but one -- if the user set NM in
the environment to a path which contained an option, libtool's nm
detection tries to run nm against a copy of nm with the options in it:
e.g. if NM was set to "nm --blargle", and nm was found in /usr/bin, the
test would try to run "/usr/bin/nm --blargle /usr/bin/nm --blargle".
This is unlikely to be desirable: in this case we should run
"/usr/bin/nm --blargle /usr/bin/nm".

Furthermore, as part of this nm has to detect when the passed-in $NM
contains a path, and in that case avoid doing a path search itself.
This too was thrown off if an option contained something that looked
like a path, e.g. NM="nm -B../prev-gcc"; libtool then tries to run
"nm -B../prev-gcc nm" which rarely works well (and indeed it looks
to see whether that nm exists, finds it doesn't, and wrongly concludes
that nm -p or whatever does not work).

Fix all of these by clipping all options (defined as everything
including and after the first " -") before deciding whether nm
contains a path (but not using the clipped value for anything else),
and then removing all options from the path-modified nm before
looking to see whether that nm existed.

NM=my-nm now does a path search and runs e.g.
  /usr/bin/my-nm -B /usr/bin/my-nm

NM=/usr/bin/my-nm now avoids a path search and runs e.g.
  /usr/bin/my-nm -B /usr/bin/my-nm

NM="my-nm -p../wombat" now does a path search and runs e.g.
  /usr/bin/my-nm -p../wombat -B /usr/bin/my-nm

NM="../prev-binutils/new-nm -B../prev-gcc" now avoids a path search:
  ../prev-binutils/my-nm -B../prev-gcc -B ../prev-binutils/my-nm

This seems to be all combinations, including those used by GCC bootstrap
(which, before this commit, fails to bootstrap when configured
--with-build-config=bootstrap-lto, because the lto plugin is now using
--export-symbols-regex, which requires libtool to find a working nm,
while also using -B../prev-gcc to point at the lto plugin associated
with the GCC just built.)

Regenerate all affected configure scripts.

	* libtool.m4 (LT_PATH_NM): Handle user-specified NM with
	options, including options containing paths.
2022-03-25 12:02:35 +00:00
Jan Beulich
f1a4558586 x86: mention dropped L1OM/K1OM support in ld/ as well
This amends e961c696dc ("x86: drop L1OM/K1OM support from ld"). Also
remove the marker that I mistakenly added in c085ab00c7 ("x86: drop
L1OM/K1OM support from gas").
2022-03-24 15:27:28 +01:00
Jan Beulich
e961c696dc x86: drop L1OM/K1OM support from ld
This was only rudimentary support anyway; none of the sub-architecture
specific insns were ever supported.
2022-03-24 09:38:55 +01:00
Nick Alcock
84f5c557a4 libctf, ld: diagnose corrupted CTF header cth_strlen
The last section in a CTF dict is the string table, at an offset
represented by the cth_stroff header field.  Its length is recorded in
the next field, cth_strlen, and the two added together are taken as the
size of the CTF dict.  Upon opening a dict, we check that none of the
header offsets exceed this size, and we check when uncompressing a
compressed dict that the result of the uncompression is the same length:
but CTF dicts need not be compressed, and short ones are not.
Uncompressed dicts just use the ctf_size without checking it.  This
field is thankfully almost unused: it is mostly used when reserializing
a dict, which can't be done to dicts read off disk since they're
read-only.

However, when opening an uncompressed foreign-endian dict we have to
copy it out of the mmaped region it is stored in so we can endian-
swap it, and we use ctf_size when doing that.  When the cth_strlen is
corrupt, this can overrun.

Fix this by checking the ctf_size in all uncompressed cases, just as we
already do in the compressed case.  Add a new test.

This came to light because various corrupted-CTF raw-asm tests had an
incorrect cth_strlen: fix all of them so they produce the expected
error again.

libctf/
	PR libctf/28933
	* ctf-open.c (ctf_bufopen_internal): Always check uncompressed
	CTF dict sizes against the section size in case the cth_strlen is
	corrupt.

ld/
	PR libctf/28933
	* testsuite/ld-ctf/diag-strlen-invalid.*: New test,
	derived from diag-cttname-invalid.s.
	* testsuite/ld-ctf/diag-cttname-invalid.s: Fix incorrect cth_strlen.
	* testsuite/ld-ctf/diag-cttname-null.s: Likewise.
	* testsuite/ld-ctf/diag-cuname.s: Likewise.
	* testsuite/ld-ctf/diag-parlabel.s: Likewise.
	* testsuite/ld-ctf/diag-parname.s: Likewise.
2022-03-23 13:48:32 +00:00
Nick Alcock
203bfa2f6b include, libctf, ld: extend variable section to contain functions too
The CTF variable section is an optional (usually-not-present) section in
the CTF dict which contains name -> type mappings corresponding to data
symbols that are present in the linker input but not in the output
symbol table: the idea is that programs that use their own symbol-
resolution mechanisms can use this section to look up the types of
symbols they have found using their own mechanism.

Because these removed symbols (mostly static variables, functions, etc)
all have names that are unlikely to appear in the ELF symtab and because
very few programs have their own symbol-resolution mechanisms, a special
linker flag (--ctf-variables) is needed to emit this section.

Historically, we emitted only removed data symbols into the variable
section.  This seemed to make sense at the time, but in hindsight it
really doesn't: functions are symbols too, and a C program can look them
up just like any other type.  So extend the variable section so that it
contains all static function symbols too (if it is emitted at all), with
types of kind CTF_K_FUNCTION.

This is a little fiddly.  We relied on compiler assistance for data
symbols: the compiler simply emits all data symbols twice, once into the
symtypetab as an indexed symbol and once into the variable section.

Rather than wait for a suitably adjusted compiler that does the same for
function symbols, we can pluck unreported function symbols out of the
symtab and add them to the variable section ourselves.  While we're at
it, we do the same with data symbols: this is redundant right now
because the compiler does it, but it costs very little time and lets the
compiler drop this kludge and save a little space in .o files.

include/
	* ctf.h: Mention the new things we can see in the variable
	section.

ld/
	* testsuite/ld-ctf/data-func-conflicted-vars.d: New test.

libctf/
	* ctf-link.c (ctf_link_deduplicating_variables): Duplicate
	symbols into the variable section too.
	* ctf-serialize.c (symtypetab_delete_nonstatic_vars): Rename
	to...
	(symtypetab_delete_nonstatics): ... this.  Check the funchash
	when pruning redundant variables.
	(ctf_symtypetab_sect_sizes): Adjust accordingly.
	* NEWS: Describe this change.
2022-03-23 13:48:32 +00:00
Nick Alcock
a12c988767 ld, testsuite: improve CTF-availability test
The test for -gctf support in the compiler is used to determine when to
run the ld-ctf tests and most of those in libctf.  Unfortunately,
because it uses check_compiler_available and compile_one_cc, it will
fail whenever the compiler emits anything on stderr, even if it
actually does support CTF perfectly well.

So, instead, ask the compiler to emit assembler output and grep it for
references to ".ctf": this is highly unlikely to be present if the
compiler does not support CTF.  (This will need adjusting when CTF grows
support for non-ELF platforms that don't dot-prepend their section
names, but right now the linker doesn't link CTF on any such platforms
in any case.)

With this in place we can do things like run all the libctf tests under
leak sanitizers etc even if those spray warnings on simple CTF
compilations, rather than being blocked from doing so just when we would
most like to.

ld/
	* testsuite/lib/ld-lib.exp (check_ctf_available): detect CTF
	even if a CTF-capable compiler emits warnings.
2022-03-23 13:38:16 +00:00
liuzhensong
2be64de603 ld:LoongArch: Add test cases to adapt to LoongArch32 and LoongArch64
ld/testsuite/ld-loongarch-elf

  *  ld-loongarch-elf.exp:  Test LoongArch32 and LoongArch64 testcases respectively.
  *  jmp_op.d: Fix bug in test LoongArch32.
  *  disas-jirl-32.d: New test case for LoongArch32.
  *  disas-jirl-32.s: New test case for LoongArch32.
  *  disas-jirl.d: Skip test case LoongArch32.
  *  macro_op_32.d: New test case for LoongArch32.
  *  macro_op_32.s: New test case for LoongArch32.
  *  macro_op.d: Skip test case LoongArch32.
2022-03-20 09:37:13 +08:00
liuzhensong
2a04204dff ld: loongarch: Skip unsupport test cases.
ld/testsuite/ld-elf/
    * eh5.d		Skip loongarch64 target.
    * pr21884.d		Skip loongarch* targets.
    * pr26936.d		Skip loongarch* targets.
2022-03-20 09:37:12 +08:00
Jan Beulich
c085ab00c7 x86: drop L1OM/K1OM support from gas
This was only rudimentary support anyway; none of the sub-architecture
specific insns were ever supported.
2022-03-17 11:02:42 +01:00
Alan Modra
42952a9605 PowerPC64 extended instructions in powerpc_macros
The extended instructions implemented in powerpc_macros aren't used by
the disassembler.  That means instructions like "sldi r3,r3,2" appear
in disassembly as "rldicr r3,r3,2,61", which is annoying since many
other extended instructions are shown.

Note that some of the instructions moved out of the macro table to the
opcode table won't appear in disassembly, because they are aliases
rather than a subset of the underlying raw instruction.  If enabled,
rotrdi, extrdi, extldi, clrlsldi, and insrdi would replace all
occurrences of rotldi, rldicl, rldicr, rldic and rldimi.  (Or many
occurrences in the case of clrlsldi if n <= b was added to the extract
functions.)

The patch also fixes a small bug in opcode sanity checking.

include/
	* opcode/ppc.h (PPC_OPSHIFT_SH6): Define.
opcodes/
	* ppc-opc.c (insert_erdn, extract_erdn, insert_eldn, extract_eldn),
	(insert_crdn, extract_crdn, insert_rrdn, extract_rrdn),
	(insert_sldn, extract_sldn, insert_srdn, extract_srdn),
	(insert_erdb, extract_erdb, insert_csldn, extract_csldb),
	(insert_irdb, extract_irdn): New functions.
	(ELDn, ERDn, ERDn, RRDn, SRDn, ERDb, CSLDn, CSLDb, IRDn, IRDb):
	Define and add associated powerpc_operands entries.
	(powerpc_opcodes): Add "rotrdi", "srdi", "extrdi", "clrrdi",
	"sldi", "extldi", "clrlsldi", "insrdi" and corresponding record
	(ie. dot suffix) forms.
	(powerpc_macros): Delete same from here.
gas/
	* config/tc-ppc.c (insn_validate): Don't modify value passed
	to operand->insert for PPC_OPERAND_PLUS1 when calculating mask.
	Handle PPC_OPSHIFT_SH6.
	* testsuite/gas/ppc/prefix-reloc.d: Update.
	* testsuite/gas/ppc/simpshft.d: Update.
ld/
	* testsuite/ld-powerpc/elfv2so.d: Update.
	* testsuite/ld-powerpc/notoc.d: Update.
	* testsuite/ld-powerpc/notoc3.d: Update.
	* testsuite/ld-powerpc/tlsdesc2.d: Update.
	* testsuite/ld-powerpc/tlsget.d: Update.
	* testsuite/ld-powerpc/tlsget2.d: Update.
	* testsuite/ld-powerpc/tlsopt5.d: Update.
	* testsuite/ld-powerpc/tlsopt6.d: Update.
2022-03-16 09:59:07 +10:30
Alan Modra
d7c448293a Re: ld: Add a before_plugin_all_symbols_read hook
* testsuite/ld-plugin/pr28849.d: Adjust for powerpc64 function
	descriptors.
2022-03-10 16:06:12 +10:30
H.J. Lu
320fdefef1 ld: Add a before_plugin_all_symbols_read hook
Add a before_plugin_all_symbols_read hook to load symbol references from
DT_NEEDED entries, included from --copy-dt-needed-entries, before reading
plugin symbols to properly resolve plugin symbol references.

bfd/

	PR ld/28849
	* elf-bfd.h (elf_link_hash_table): Add handling_dt_needed.
	* elflink.c (_bfd_elf_merge_symbol): Don't set non_ir_ref_dynamic
	before plugin 'all symbols read' hook is called.

ld/

	PR ld/28849
	* ldelf.c (ldelf_handle_dt_needed): New function.
	(ldelf_before_plugin_all_symbols_read): Likewise.
	(ldelf_after_open): Call ldelf_handle_dt_needed.
	* ldelf.h (ldelf_before_plugin_all_symbols_read): New.
	* ldemul.c (ldemul_before_plugin_all_symbols_read): Likewise.
	* ldemul.h (ldemul_before_plugin_all_symbols_read): Likewise.
	(ld_emulation_xfer_struct): Add before_plugin_all_symbols_read.
	* ldlang.c (lang_process): Call
	ldemul_before_plugin_all_symbols_read before calling
	plugin_call_all_symbols_read.
	* emultempl/elf.em
	(gld${EMULATION_NAME}_before_plugin_all_symbols_read): New.
	(LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): New.
	* emultempl/emulation.em (ld_${EMULATION_NAME}_emulation):
	Initialize the before_plugin_all_symbols_read field.
	* testsuite/ld-plugin/lto.exp: Run PR ld/28849 tests.
	* testsuite/ld-plugin/pr28849.d: New file.
	* testsuite/ld-plugin/pr28849a.c: Likewise.
	* testsuite/ld-plugin/pr28849b.c: Likewise.
2022-03-09 18:23:43 -08:00
Alan Modra
db120fb808 Adjust ld ctf test for 32-bit targets
powerpc-linux, and I suspect other 32-bit targets, report "aligned at
0x4" for this test.

	* testsuite/ld-ctf/nonrepresentable.d: Accept any alignment.
2022-03-04 00:28:07 +10:30
Nick Clifton
95e96e052a Fix linker tests to compile with gcc-12.
PR 21964
	* testsuite/ld-elf/pr21964-1a.c: Fix array comparisons.
	* testsuite/ld-elf/pr21964-1b.c: Likewise.
	* testsuite/ld-elf/pr21964-1c.c: Likewise.
	* testsuite/ld-elf/pr21964-2a.c: Likewise.
	* testsuite/ld-elf/pr21964-2b.c: Likewise.
	* testsuite/ld-elf/pr21964-3a.c: Likewise.
2022-03-01 10:10:20 +00:00
Roland McGrath
5c14cc552d Fix typo in ld.texi
ld/
	* ld.texi (Output Section Type): Fix typo in @code syntax.
2022-02-18 11:42:09 -08:00
Nick Clifton
36d285b9da Updated Serbian translations for the bfd, gold, ld and opcodes directories 2022-02-17 15:18:59 +00:00
Fangrui Song
c212f39d9a ld: Support customized output section type
bfd/
    PR ld/28841
    * bfd-in2.h (struct bfd_section): Add type.
    (discarded_section): Add field.
    * elf.c (elf_fake_sections): Handle bfd_section::type.
    * section.c (BFD_FAKE_SECTION): Add field.
    * mri.c (mri_draw_tree): Update function call.

ld/
    PR ld/28841
    * ld.texi: Document new output section type.
    * ldlex.l: Add new token TYPE.
    * ldgram.y: Handle TYPE=exp.
    * ldlang.h: Add type_section to list of section types.
    * ldlang.c (lang_add_section): Handle type_section.
    (map_input_to_output_sections): Handle type_section.
    * testsuite/ld-scripts/output-section-types.t: Add tests.
    * testsuite/ld-scripts/output-section-types.d: Update.
2022-02-16 17:41:23 +00:00
H.J. Lu
3319ba7a8d i386: Update I386_NEED_DYNAMIC_RELOC_TYPE_P for DT_TEXTREL
Update I386_NEED_DYNAMIC_RELOC_TYPE_P to allow R_386_TLS_IE for relocation
in read-only section.

bfd/

	PR ld/28894
	* elfxx-x86.h (I386_NEED_DYNAMIC_RELOC_TYPE_P): Allow
	R_386_TLS_IE.

ld/
	PR ld/28894
	* testsuite/ld-i386/i386.exp: Run pr28894.
	* testsuite/ld-i386/pr28894.d: New file.
	* testsuite/ld-i386/pr28894.s: Likewise.
2022-02-15 15:08:17 -08:00
H.J. Lu
3c4c0a18c8 x86-64: Use MAXPAGESIZE for the relro segment alignment
Adjust x86-64 linker tests after reverting

commit 31b4d3a16f
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Feb 3 08:57:47 2022 +1030

    PR28824, relro security issues, x86 keep COMMONPAGESIZE relro

to use MAXPAGESIZE for the end of the relro segment alignment, like other
ELF targets.

	* testsuite/ld-x86-64/plt-main-bnd.dd: Updated.
	* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt.dd: Likewise.
	* testsuite/ld-x86-64/pr14207.d: Likewise.
	* testsuite/ld-x86-64/pr18176.d: Likewise.
	* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830b.d: Likewise.
	* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038b.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-02-14 17:39:34 -08:00
H.J. Lu
a1faa5ea86 Revert "PR28824, relro security issues, x86 keep COMMONPAGESIZE relro"
This reverts commit 31b4d3a16f.
2022-02-14 17:39:34 -08:00
H.J. Lu
20ea3acc72 ld: Keep indirect symbol from IR if referenced from shared object
Don't change indirect symbol defined in IR to undefined if it is
referenced from shared object.

bfd/

	PR ld/28879
	* elflink.c (_bfd_elf_merge_symbol): Don't change indirect
	symbol defined in IR to undefined if it is referenced from
	shared object.

ld/

	PR ld/28879
	* testsuite/ld-plugin/lto.exp: Run PR ld/28879 tests.
	* testsuite/ld-plugin/pr28879a.cc: New file.
	* testsuite/ld-plugin/pr28879b.cc: Likewise.
2022-02-13 20:31:44 -08:00
Alan Modra
2085ee2650 Don't pass around expld.dataseg pointer
The better to see any code that accesses expld.dataseg.

	* ldexp.c (fold_segment_end): Remove seg parameter.  Adjust calls.
	(fold_segment_align, fold_segment_relro_end): Likewise.
	* ldlang.c (lang_size_segment): Likewise.
	(lang_size_relro_segment_1, lang_find_relro_sections_1): Likewise.
2022-02-13 14:00:56 +10:30
Alan Modra
7d6aa4b321 Remove bfd ELF_RELROPAGESIZE
Now that ld properly aligns the end of the relro segment, the hack to
make relro work on powerpc can disappear.

bfd/
	* bfd.c (bfd_emul_get_commonpagesize): Remove relro param.
	Don't return bed->relropagesize.
	* elf-bfd.h (struct elf_backend_data): Remove relropagesize.
	* elfxx-target.h (ELF_RELROPAGESIZE): Remove.
	* elf32-ppc.c (ELF_RELROPAGESIZE): Don't define.
	* elf64-ppc.c: Likewise.
	* bfd-in2.h: Regenerate.
ld/
	* ldemul.c (after_parse_default): Adjust
	bfd_emul_get_commonpagesize call.
2022-02-13 14:00:56 +10:30
Alan Modra
31b4d3a16f PR28824, relro security issues, x86 keep COMMONPAGESIZE relro
x86 treats MAXPAGESIZE as a memory optimisation parameter, actual
hardware paging is always COMMPAGESIZE of 4k.  Use COMMONPAGESIZE for
the end of the relro segment alignment.

The previous patch regresses pr18176, increasing the testcase file
size from 322208 to 2099872 bytes.  Fixing this on x86 will require
introducing a gap after the end of the relro segment (of up to
relropagesize-1 bytes).

	PR 28824
	PR 18176
	* ld.h (ld_config_type): Add relro_use_commonpagesize field.
	* ldexp.c (fold_segment_align): Set relropagesize depending on
	relro_use_commonpagesize.
	* emultempl/elf-x86.em (elf_x86_create_output_section_statements):
	Set relro_use_commonpagesize.
	* testsuite/ld-x86-64/pr18176.d: xfail.
2022-02-13 14:00:56 +10:30
Alan Modra
9833b7757d PR28824, relro security issues
Background
==========
There are constraints on layout of binaries to meet demand paging and
memory protection requirements.  Demand paged binaries must have file
offset mod pagesize equal to vma mod pagesize.  Memory protection
(executable, read, write status) can only change at page boundaries.
The linker's MAXPAGESIZE variable gives the page size for these layout
constraints.

In a typical basic executable with two memory segments, text (RE) and
data (RW), the data segment must start on a different page to the
last text segment page.  For example, with 64k pages and a small
executable of 48k text and 1k data, the text segment might start at
address 0x10000 and data at 0x20000 for a total of two 64k memory
pages.  Demand paging would require the image on disk to be 64k+1k
in size.  We can do better than that.  If the data segment instead
starts at 0x2c000 (the end of the text segment plus one 64k page) then
there are still only two memory pages, but the disk image is now
smaller, 48k+1k in size.  This is why the linker normally starts the
data segment at the end of the text segment plus one page.  That
simple heuristic isn't ideal in all cases.  Changing our simple
example to one with 64k-1 text size, following that heuristic would
result in data starting at 0x2ffff.  Now we have two 64k memory data
pages for a data segment of 1k!  If the data segment instead started
at 0x30000 we'd get a single data segment page at the cost of 1 byte
extra in the disk image, which is likely a good trade-off.  So the
linker does adjust the simple heuristic.  Just how much disk image
size increase is allowed is controlled by the linker's COMMONPAGESIZE
variable.

A PT_GNU_RELRO segment overlays the initial part of the data segment,
saying that those pages should be made read-only after relocation by
the dynamic loader.  Page granularity for memory protection means that
the end of the relro segment must be at a page boundary.

The problem
===========
Unfortunately most targets currently only align the end of the relro
segment to COMMONPAGESIZE.  That results in only partial relro
protection if an executable is running with MAXPAGESIZE pages, since
any part of the relro segment past the last MAXPAGESIZE boundary can't
be made read-only without also affecting sections past the end of the
relro segment.  I believe this problem arose because x86 always runs
with 4k (COMMPAGESIZE) memory pages, and therefore using a larger
MAXPAGESIZE on x86 is for reasons other than the demand paging and
memory page protection boundary requirements.

The solution
============
Always end the relro segment on a MAXPAGESIZE boundary, except for
x86.  Note that the relro segment, comprising of sections at the start
of the data segment, is sized according to how those sections are laid
out.  That means the start of the relro segment is fixed relative to
its end.  Which also means the start of the data segment must be at a
fixed address mod MAXPAGESIZE.  So for relro the linker can't play
games with the start of the data segment to save disk space.  At
least, not without introducing gaps between the relro sections.  In
fact, because the linker was starting layout using its simple
heuristic of starting the data segment at the end of the text segment
plus one page, it was sometimes introducing page gaps for no reason.
See pr28743.

	PR 28824
	PR 28734
	* ldexp.c (fold_segment_align): When relro, don't adjust up by
	offset within page.  Set relropagesize.
	(fold_segment_relro_end): Align to relropagesize.
	* ldexp.h (seg_align_type): Rename pagesize to commonpagesize.
	Add relropagesize.  Comment.
	* ldlang.c (lang_size_segment): Adjust to suit field renaming.
	(lang_size_relro_segment_1): Align relro_end using relropagesize.
2022-02-13 14:00:56 +10:30
H.J. Lu
ebb191adac x86: Disallow invalid relocation against protected symbol
I am checking this into master and will backport it to 2.38 branch.

H.J
----
On x86, GCC 12 supports -mno-direct-extern-access to enable canonical
reference to protected function and disable copy relocation.  With
-mno-direct-extern-access, the canonical protected function symbols must
be accessed via canonical reference and the protected data symbols in
shared libraries are non-copyable. Under glibc 2.35, non-canonical
reference to the canonical protected function will get the run-time error:

./y: internal_f: ./libfoo.so: non-canonical reference to canonical protected function

and copy relocations against the non-copyable protected symbols will get
the run-time error:

./x: internal_i: ./libfoo.so: copy relocation against non-copyable protected symbol

Update x86 linker to disallow non-canonical reference to the canonical
protected function:

ld: plt.o: non-canonical reference to canonical protected function `internal_f' in libfoo.so
ld: failed to set dynamic section sizes: bad value

and copy relocation against the non-copyable protected symbol:

ld: main.o: copy relocation against non-copyable protected symbol `internal_i' in libfoo.so

at link-time.

bfd/

	PR ld/28875
	* elf-properties.c (_bfd_elf_parse_gnu_properties): Don't skip
	shared libraries for GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
	* elf32-i386.c (elf_i386_scan_relocs): Disallow non-canonical
	reference to canonical protected function.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
	* elfxx-x86.c (elf_x86_allocate_dynrelocs): Don't allow copy
	relocation against non-copyable protected symbol.

ld/

	PR ld/28875
	* testsuite/ld-i386/i386.exp: Check non-canonical reference to
	canonical protected function and check copy relocation against
	non-copyable protected symbol.
	* testsuite/ld-i386/pr21997-1.err: New file.
	* testsuite/ld-i386/pr28875.err: Likewise.
	* testsuite/ld-i386/pr28875a.c: Likewise.
	* testsuite/ld-i386/pr28875b.c: Likewise.
	* testsuite/ld-x86-64/pr21997-1a.err: Updated.
	* testsuite/ld-x86-64/pr21997-1b.err: Likewise.
	* testsuite/ld-x86-64/pr28875-data.err: New file.
	* testsuite/ld-x86-64/pr28875-func.err: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Check non-canonical reference
	to canonical protected function and check copy relocation against
	non-copyable protected symbol.
2022-02-11 10:24:54 -08:00
Palmer Dabbelt
87fdd7ac09
RISC-V: Stop reporting warnings for mismatched extension versions
The extension version checking logic is really just too complicated to
encode into the linker, trying to do so causes more harm than good.
This removes the checks and the associated tests, leaving the logic to
keep the largest version of each extension linked into the target.

bfd/

	* elfnn-riscv.c (riscv_version_mismatch): Rename to
	riscv_update_subset_version, and stop reporting warnings on
	version mismatches.
	(riscv_merge_std_ext): Adjust calls to riscv_version_mismatch.
	(riscv_merge_multi_letter_ext): Likewise.

ld/
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Remove
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s: Likewise
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s: Likewise
	* testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Likewise
	* 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/attr-merge-user-ext-01.d: New test.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p0.s:
	Likewise.
	* testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p1.s:
	Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Remove obselete
	attr-merge-arch-failed-{01,02}, replace with
	attr-merge-user-ext-01.

Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2022-02-08 08:23:28 -08:00
Alan Modra
cb5a1d7db9 Re: elf: Check symbol version without any symbols
* testsuite/ld-elf/pr24718-1.d: Don't xfail for hppa64.
2022-02-08 20:28:52 +10:30
H.J. Lu
30a954525f i386: Allow GOT32 relocations against ABS symbols
GOT32 relocations are allowed since absolute value + addend is stored in
the GOT slot.

Tested on glibc 2.35 build with GCC 11.2 and -Os.

bfd/

	PR ld/28870
	* elfxx-x86.c (_bfd_elf_x86_valid_reloc_p): Also allow GOT32
	relocations.

ld/

	PR ld/28870
	* testsuite/ld-i386/i386.exp: Run pr28870.
	* testsuite/ld-i386/pr28870.d: New file.
	* testsuite/ld-i386/pr28870.s: Likewise.
2022-02-07 16:04:10 -08:00
Alan Modra
6a9d08661b Revert "elf: Remove the 1-page gap before the RELRO segment"
This reverts commit 2f83249c13.

	PR ld/28743
	* ldlang.c (lang_size_relro_segment_1): Revert 2022-01-10 changes.
	* testsuite/ld-i386/pr20830.d: Likewise.
	* testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise.
	* testsuite/ld-x86-64/pr14207.d: Likewise.
	* testsuite/ld-x86-64/pr18176.d: Likewise.
	* testsuite/ld-x86-64/pr20830a-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830a.d: Likewise.
	* testsuite/ld-x86-64/pr20830b-now.d: Likewise.
	* testsuite/ld-x86-64/pr20830b.d: Likewise.
	* testsuite/ld-x86-64/pr21038a-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038a.d: Likewise.
	* testsuite/ld-x86-64/pr21038b-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c-now.d: Likewise.
	* testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-02-07 13:42:41 +10:30
Alan Modra
5197c88e2a Revert "ld: Rewrite lang_size_relro_segment_1"
This reverts commit c804c6f98d.

	PR ld/28743
	PR ld/28819
	* ldlang.c (lang_size_relro_segment_1): Revert 2022-01-14 change.
	* testsuite/ld-x86-64/pr28743-1.d: Likewise.
	* testsuite/ld-x86-64/pr28743-1.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
2022-02-07 13:42:41 +10:30
Alan Modra
a03c7c40b7 A more elegant pr28827-1 testcase
Use .irpc macros in pr28827-1.s

	* testsuite/ld-powerpc/pr28827-1.s: Make the testcase more
	elegant.  Comment.
2022-02-07 09:36:19 +10:30
H.J. Lu
a92613915e ld: Add emultempl/emulation.em
Add emultempl/emulation.em to define ld_${EMULATION_NAME}_emulation so
that new emulation hooks can be added easily.

	* emultempl/aix.em (LDEMUL_AFTER_OPEN): New.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_CHOOSE_TARGET): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PARSE_ARGS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_PRINT_SYMBOL): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/beos.em (gld_${EMULATION_NAME}_before_parse):
	Renamed to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_OPEN): New.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/elf.em (LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_PLACE_ORPHANS): Likewise.
	(LDEMUL_AFTER_ALLOCATION): Likewise.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/emulation.em: New file.
	* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/msp430.em (LDEMUL_AFTER_OPEN): New.
	(LDEMUL_AFTER_ALLOCATION): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_FINISH): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Renamed
	to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_list_options): Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_parse): Renamed to ...
	(gld${EMULATION_NAME}_after_parse): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
	(gld${EMULATION_NAME}_unrecognized_file): This.
	(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
	(gld${EMULATION_NAME}_recognized_file): This.
	(gld_${EMULATION_NAME}_finish): Renamed to ...
	(gld${EMULATION_NAME}_finish): This.
	(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
	(gld${EMULATION_NAME}_place_orphan): This.
	(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
	(gld${EMULATION_NAME}_open_dynamic_archive): This.
	(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
	(gld${EMULATION_NAME}_find_potential_libraries): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_FINISH=): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_RECOGNIZED_FILE): Likewise.
	(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/pep.em (gld_${EMULATION_NAME}_before_parse): Renamed
	to ...
	(gld${EMULATION_NAME}_before_parse): This.
	(gld_${EMULATION_NAME}_list_options): Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_set_symbols): Renamed to ...
	(gld${EMULATION_NAME}_set_symbols): This.
	(gld_${EMULATION_NAME}_after_parse): Renamed to ...
	(gld${EMULATION_NAME}_after_parse): This.
	(gld_${EMULATION_NAME}_after_open): Renamed to ...
	(gld${EMULATION_NAME}_after_open): This.
	(gld_${EMULATION_NAME}_before_allocation): Renamed to ...
	(gld${EMULATION_NAME}_before_allocation): This.
	(gld_${EMULATION_NAME}_unrecognized_file): Renamed to ...
	(gld${EMULATION_NAME}_unrecognized_file): This.
	(gld_${EMULATION_NAME}_recognized_file): Renamed to ...
	(gld${EMULATION_NAME}_recognized_file): This.
	(gld_${EMULATION_NAME}_finish): Renamed to ...
	(gld${EMULATION_NAME}_finish): This.
	(gld_${EMULATION_NAME}_place_orphan): Renamed to ...
	(gld${EMULATION_NAME}_place_orphan): This.
	(gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ...
	(gld${EMULATION_NAME}_open_dynamic_archive): This.
	(gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ...
	(gld${EMULATION_NAME}_find_potential_libraries): This.
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_AFTER_PARSE): New.
	(LDEMUL_AFTER_OPEN): Likewise.
	(LDEMUL_BEFORE_ALLOCATION): Likewise.
	(LDEMUL_FINISH=): Likewise.
	(LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise.
	(LDEMUL_PLACE_ORPHAN): Likewise.
	(LDEMUL_SET_SYMBOLS): Likewise.
	(LDEMUL_ADD_OPTIONS): Likewise.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_UNRECOGNIZED_FILE): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(LDEMUL_RECOGNIZED_FILE): Likewise.
	(LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/ticoff.em (gld_${EMULATION_NAME}_list_options):
	Renamed to ...
	(gld${EMULATION_NAME}_list_options): This.
	(gld_${EMULATION_NAME}_before_parse): Renamed to ...
	(gld_${EMULATION_NAME}_get_script): Renamed to ...
	(gld${EMULATION_NAME}_get_script): This.
	(LDEMUL_ADD_OPTIONS): New.
	(LDEMUL_HANDLE_OPTION): Likewise.
	(LDEMUL_LIST_OPTIONS): Likewise.
	(ld_${EMULATION_NAME}_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
	* emultempl/vanilla.em (LDEMUL_BEFORE_PARSE): New.
	(LDEMUL_SET_OUTPUT_ARCH): Likewise.
	(LDEMUL_GET_SCRIPT): Likewise.
	(EMULATION_NAME): Likewise.
	(OUTPUT_FORMAT): Likewise.
	(ld_vanilla_emulation): Removed.
	Source ${srcdir}/emultempl/emulation.em.
2022-02-06 06:25:41 -08:00
Alan Modra
0acf434a23 Tweak assembler invocation for pr28827-1 test
PR 28827
	* testsuite/ld-powerpc/pr28827-1.d: Pass -a64 to gas.
2022-02-05 18:21:34 +10:30
Alan Modra
9810db10f7 PR28827 testcase
This testcase triggers a stub sizing error with the patches applied
for PR28743 (commit 2f83249c13 and c804c6f98d).

	PR 28827
	* testsuite/ld-powerpc/pr28827-1.s,
	* testsuite/ld-powerpc/pr28827-1.d: New test.
	* testsuite/ld-powerpc/powerpc.exp: Run it.
2022-02-05 17:37:19 +10:30
Alan Modra
cd8adbf301 Enable "size" as a dumpprog in ld
binutils/
	* testsuite/lib/binutils-common.exp (run_dump_test): Reference
	global SIZE and SIZEFLAGS.
ld/
	* testsuite/config/default.exp: Define SIZE and SIZEFLAGS.
2022-02-05 17:37:19 +10:30