Commit graph

7428 commits

Author SHA1 Message Date
mengqinggang
be1ebb6710 LoongArch: Add R_LARCH_64_PCREL relocation support
Gas defaults to emit R_LARCH_ADD64/R_LARCH_SUB64 unless explcitly declared
  to emit R_LARCH_64_PCREL.

  The LoongArch ABI at here:
    https://github.com/loongson/la-abi-specs/blob/release/la-abi.adoc

bfd/ChangeLog:

	* bfd-in2.h (not): Add R_LARCH_64_PCREL
	* elfnn-loongarch.c (perform_relocation): Likewise.
	* elfxx-loongarch.c: Likewise.
	* libbfd.h: Likewise.
	* reloc.c: Likewise.

gas/ChangeLog:

	* config/tc-loongarch.c (loongarch_args_parser_can_match_arg_helper):
	(md_apply_fix): Add R_LARCH_64_PCREL.
	* testsuite/gas/loongarch/64_pcrel.d: New test.
	* testsuite/gas/loongarch/64_pcrel.s: New test.

include/ChangeLog:

	* elf/loongarch.h (RELOC_NUMBER): Add R_LARCH_64_PCREL.

ld/ChangeLog:

	* testsuite/ld-loongarch-elf/ld-loongarch-elf.exp: Add test.
	* testsuite/ld-loongarch-elf/64_pcrel.d: New test.
	* testsuite/ld-loongarch-elf/64_pcrel.s: New test.
2023-06-28 16:14:35 +08:00
Alan Modra
0ec2cde4f4 lto test fails with -fno-inline in CFLAGS
Putting -fno-inline in CFLAGS results in these failures.
FAIL: Build liblto-17b.so 1
FAIL: PR ld/12365
FAIL: PR ld/13183

	* ld-plugin/lto.exp: Add -finline to compiler flags in some tests.
2023-06-23 21:02:48 +09:30
Nick Clifton
0ab7005043 For test for PR 29072 when the linker is configured with --enable-default-execstack=no.
PR 29072
  * testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Always return false for linkers configured with the --enable-default-execstack=no option.
2023-06-21 11:47:19 +01:00
Alan Modra
2a4da07308 Correct ld-elf/eh5 test for hppa64
Commit 3c0afdb789 regressed this test for hppa64, because the test
had been enabled for hppa64 in the time between the mips changes and
their reversion.  This patch isn't just a simple reapply, I recreated
the testsuite change by hand for hppa64: Two lines in eh5.d might need
further changes for mips.
2023-06-16 12:46:49 +09:30
Maciej W. Rozycki
13527d85af Revert "MIPS: fix r6 testsuites"
This reverts commit ffc528aed5.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Maciej W. Rozycki
3c0afdb789 Revert "MIPS: fix -gnuabi64 testsuite"
This reverts commit cb81e84c72.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Maciej W. Rozycki
0b46c1ec2d Revert "MIPS: fix some ld testcases with compiler"
This reverts commit a0631c1501.  It was
applied unapproved.
2023-06-15 04:45:03 +01:00
Alan Modra
0749c73cf8 Re: Add some expected failures for bfin linker tests
After commit 7ade0f1582 I was seeing bfin-elf +XPASS: weak symbols,
and on looking into the bfin targets a little, discovered we have two
bfin-linux targets.  One, bfin-uclinux, is like bfin-elf in that
ld -m elf32bfin is the default, and the other, bfin-linux-uclibc where
ld -m elf32bfinfd is the default.  So putting bfin-*-*linux* in test
xfails or elsewhere is wrong.  We want bfin-*-linux* instead to just
select the fdpic bfin target.

This patch corrects wrong bfin target triples in the ld testsuite,
not just the recent change but others I'd added to xfails too.
It also fixes the bfin-linux-uclibc ld-elf/64ksec fail
2023-06-15 11:45:03 +09:30
Nick Clifton
7ade0f1582 Add some expected failures for bfin linker tests 2023-06-14 15:54:29 +01:00
Nick Clifton
fb221fba1a Add --remap-inputs option to the BFD linker.
PR 30374
  * ldfile.c (struct input_remap): New structure. (ldfile_add_remap): New function. (ldfile_remap_input_free): New function. (ldfile_add_remap_file): New function. (ldfile_possibly_remap_input): New function. (ldfile_print_input_remaps): New function. * ldfile.h: Add prototypes for new functions.
  * ldlang.c (new_afile): Call ldfile_possibly_remap_input. (lang_finish): Call ldfile_remap_input_free. (lang_map): Call ldfile_print_input_remaps.
  * ldlex.h (OPTION_REMAP_INPUTS, OPTION_REMAP_INPUTS_FILE): Define.
  * lexsup.c (ld_options): Add --remap-inputs-file and --remap-inputs. (parse_args): Handle new options.
  * NEWS: Mention the new feature.
  * ld.texi: Document the new options.
  * testsuite/ld-misc/input-remap.exp: New test driver.
  * testsuite/ld-misc/remaps.r: New file: Expected linker output.
  * testsuite/ld-misc/remaps.txt: New file.  Input remaps file.
2023-06-14 13:39:03 +01:00
Alan Modra
6f860418d5 asprintf memory leaks
A number of backends want to return bfd_reloc_dangerous messaqes from
relocation special_function, and construct the message using asprintf.
Such messages are not freed anywhere, leading to small memory leaks
inside libbfd.  To limit the leaks, I'd implemented a static buffer in
the ppc backends that was freed before use in asprintf output.  This
patch extends that scheme to other backends using a shared static
buffer and goes further in freeing the buffer on any bfd_close.

The patch also fixes a few other cases where asprintf output was not
freed after use.

bfd/
	* bfd.c (_input_error_msg): Make global and rename to..
	(_bfd_error_buf): ..this.
	(bfd_asprintf): New function.
	(bfd_errmsg): Use bfd_asprintf.
	* opncls.c (bfd_close_all_done): Free _buf_error_buf.
	* elf32-arm.c (find_thumb_glue, find_arm_glue): Use bfd_asprintf.
	* elf32-nios2.c (nios2_elf32_relocate_section): Likewise.
	* elf32-ppc.c (ppc_elf_unhandled_reloc): Likewise.
	* elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise.
	* elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Likewise.
	(riscv_elf_relocate_section): Likewise.
	* libbfd.h: Regenerate.
gas/
	* read.c (read_end): Free current_name and current_label.
	(do_s_func): Likewise on error path.  strdup label.
ld/
	* pe-dll.c (make_head, make_tail, make_one),
	(make_singleton_name_thunk, make_import_fixup_entry),
	(make_runtime_pseudo_reloc),
	(pe_create_runtime_relocator_reference: Free oname after use.
2023-06-14 14:24:50 +09:30
Nick Clifton
064ad3ea5e Add extra linker warning message about discrepancies between normal and common symbols.
PR 30499
  bfd * elflink.c (elf_link_add_object_symbols): Add a message indicating that alignment and size discrepancies between the definition of common symbols and normal symbols are serious and should be investigated.
  ld  * testsuite/ld-elfcomm/elfcomm.exp: Update regexps to match new output from the linker.
2023-06-07 14:30:13 +01:00
Alan Modra
c6cad198b1 ld-elf/eh5 remove xfail hppa64
Commit cb81e84c72 resulted in an xpass for hppa64-hp-hpux11, but the
test still fails on hpp64-linux.  Let's make it pass for hppa64-linux
too, by accepting pcrel sdata8 encoding in the augmentation data.
2023-06-07 19:02:58 +09:30
H.J. Lu
3c5e824b9c ELF: Add "#pass" to ld-elf/pr30508.d
Add "#pass" to ld-elf/pr30508.d to allow extra segments.

	PR binutils/30508
	* testsuite/ld-elf/pr30508.d: Add "#pass".
2023-06-05 09:32:12 -07:00
H.J. Lu
3f60b98298 ELF: Don't warn an empty PT_LOAD with the program headers
When rewriting the program headers, don't warn an empty PT_LOAD with the
program headers.

bfd/

	PR binutils/30508
	* elf.c (rewrite_elf_program_header): Don't warn if an empty
	PT_LOAD contains the program headers.

ld/

	PR binutils/30508
	* testsuite/ld-elf/pr30508.d: New file.
	* testsuite/ld-elf/pr30508.s: Likewise.
2023-06-05 08:21:21 -07:00
YunQiang Su
a0631c1501 MIPS: fix some ld testcases with compiler
1. config/default.exp:
	use -mabi=32 not for -gnuabi64
	xfail_from_runlist: remove an element and mark it xfail.
2. ld-elf/indirect.exp: xfail
	indirect5a indirect5b indirect6a indirect6b
	indirect5c indirect5d indirect6c indirect6d
3. ld-elf/pr23658-2: mips output is not common
4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so
5. ld-elfvers/vers.exp:
	xfail vers4, vers4b
	no-run on mips: vers24a, vers24b, vers24c
6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161
7. ld-mips-elf/mips-elf.exp:
	use noarch for mips16-local-stubs-1, since it use -mips4
8. ld-plugin/lto.exp:
	no-run on mips/linux: PR ld/12982
	add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2)
	xfail PR ld/15323 (4), PR ld/19317 (3)
9. ld-plugin/plugin.exp: xfail
	plugin claimfile lost symbol
	plugin claimfile replace symbol
	plugin claimfile replace symbol
	plugin claimfile lost symbol with source
	plugin claimfile replace symbol with source
	plugin claimfile resolve symbol with source
	plugin 2 with source lib
	load plugin 2 with source
	plugin 3 with source lib
	load plugin 3 with source
11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls
12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so)
2023-06-05 11:00:15 +08:00
YunQiang Su
cb81e84c72 MIPS: fix -gnuabi64 testsuite
Test on:
	mips64-linux-gnuabi64
	mips64el-linux-gnuabi64
	mipsisa64-linux-gnuabi64
	mipsisa64el-linux-gnuabi64
	mipsisa64r2-linux-gnuabi64
	mipsisa64r2el-linux-gnuabi64
	mipsisa64r6-linux-gnuabi64
	mipsisa64r6el-linux-gnuabi64
2023-06-05 11:00:15 +08:00
YunQiang Su
ffc528aed5 MIPS: fix r6 testsuites
Introduce
	run_dump_test_o32l
	run_dump_test_n32l
	run_dump_test_n64l
Which use `-march=from-abi` for pre-R6 testcases,
like micromips/mips16e etc.

For cases doesn't use run_dump_test_*, we use
	-mips32r2 for micromips32
	-mips1 for mips16-32
	-march=from-abi for testcases to o32/n32/n64 both/all.

Replace `addi` with `addiu` for some cases for both r6 and pre-R6.

Introduce some new testcases for r6 with FPXX/FP64.
Introduce new testcase: comdat-reloc-r6.

Skip `default` in mips_arch_list_matching if triple is mipsisa*, due to:
  1)it will cannot match mipsr6@*.d: since mips32rN/mips64rN
    will always be used, it won't be a problem.
  2)some test think -march=mips64rN will alway true for mipsisa64rN,
    which is not true now.

This patch fix testsuite for all r6-default gnu triples:
  mipsisa32r6-linux-gnu
  mipsisa32r6el-linux-gnu
  mips-img-linux-gnu
  mipsel-img-linux-gnu
  mipsisa64r6-linux-gnu
  mipsisa64r6el-linux-gnu
2023-06-05 11:00:14 +08:00
Nick Clifton
35f8b0595f Slight wording improvement for the -Ur documentation 2023-05-30 16:12:18 +01:00
mengqinggang
2bd766d624 LoongArch: ld: Add support for linker relaxation.
Add ld relax support and testsuits.

ld/ChangeLog:

	* emultempl/loongarchelf.em: Regenerated.
	* testsuite/ld-elf/compressed1d.d: Xfail loongarch*-*.
	* testsuite/ld-elf/pr26936.d: Likewise.
	* testsuite/ld-loongarch-elf/disas-jirl.d: Regenerated.
	* testsuite/ld-loongarch-elf/disas-jirl-32.d: Regenerated.
	* testsuite/ld-loongarch-elf/jmp_op.d: Likewise.
	* testsuite/ld-loongarch-elf/macro_op.d: Likewise.
	* testsuite/ld-loongarch-elf/macro_op_32.d: Likewise.
	* testsuite/ld-loongarch-elf/relax-align.dd: New test.
	* testsuite/ld-loongarch-elf/relax-align.s: New test.
	* testsuite/ld-loongarch-elf/relax.exp: New test.
	* testsuite/ld-loongarch-elf/relax.s: New test.
	* testsuite/ld-loongarch-elf/uleb128.dd: New test.
	* testsuite/ld-loongarch-elf/uleb128.s: New test.
2023-05-30 19:56:48 +08:00
Alan Modra
9dc7ab5c01 PR22263 ld test
A number of targets that I test regularly fail the "Build pr22263-1"
test for various reasons.

arm-linux-gnueabi: "undefined reference to `__aeabi_read_tp'"
ia64-linux-gnu: "Explicit stops are ignored in auto mode"
m68k-linux-gnu: "undefined reference to `__m68k_read_tp'"
microblaze-linux-gnu: "undefined reference to `__tls_get_addr'"
nios2-linux-gnu, s390-linux-gnu and sh4-linux-gnu have a tprel reloc in .got
riscv64-linux-gnu has a dynamic relocation in text

So only riscv really fails the pr.  The rest fail due to test issues
or lack of a linker optimisation.  Lack of an optimisation isn't
really a fail, but it's worth keeping the test to ensure those
optimisations don't regress.  The xfail targets may not be an
exhaustive list.  This just tidies test results for those for which I
have cross compilers installed.

	PR 22263
	* testsuite/ld-elf/tls.exp: Split pr22263 test into two parts,
	one to check for -z text errors, the other to check tprel
	linker optimisation.  Supply needed symbols and assembler flags.
	xfail the linker optimisation on targets known to fail.
2023-05-26 12:14:36 +09:30
Andreas Schwab
2f328f5b92 Remove accidentally added file 2023-05-24 13:30:03 +02:00
Michael Matz
13a3cad698 PR30437 aarch64: make RELA relocs idempotent
normally RELA relocs in BFD should not consider the contents of the
relocated place.  The aarch64 psABI is even stricter, it specifies
(section 5.7.16) that all RELA relocs _must_ be idempotent.

Since the inception of the aarch64 BFD backend all the relocs have a
non-zero src_mask, and hence break this invariant.  It's normally not
a very visible problem as one can see it only when the relocated place
already contains a non-zero value, which usually only happens sometimes
when using 'ld -r' (or as in the testcase when jumping through hoops to
generate the relocations).  Or with alternative toolchains that do encode
stuff in the relocated places with the assumption that a relocation
to that place ignores whatever is there (as they can according to
the psABI).

Golang is such a toolchain and https://github.com/golang/go/issues/39927
is ultimately caused by this problem: the testcase testGCData failing
is caused by the garbage collection data-structure to describe a type
containing pointers to be wrong.  It's wrong because a field that's
supposed to contain a file-relative offset (to some gcbits) has a
relocation applied and that relocation has an addend which also is
already part of the go-produced object file (so the addend is
implicitely applied twice).

bfd/
	PR ld/30437
	* elfnn-aarch64.c (elfNN_aarch64_howto_table): Clear src_mask
	if all relocation descriptors.

ld/
	* testsuite/ld-aarch64/rela-idempotent.s: New testcase.
	* testsuite/ld-aarch64/rela-idempotent.d: New.
	* testsuite/ld-aarch64/aarch64-elf.exp: Run it.
2023-05-23 16:43:14 +02:00
Jan Beulich
05d31a0b3f ld: drop stray blank from ld.texi
At least older makeinfo complains about it. Also fix an apparent typo
while touching that line.
2023-05-19 15:25:13 +02:00
Kuan-Lin Chen
f1cd8b94e7 RISC-V: Support subtraction of .uleb128.
96d6e190e9

There are some known limitations for now,

* Do not shrink the length of the uleb128 value, even if the value is reduced
after relaxations.  Also reports error if the length grows up.

* The R_RISCV_SET_ULEB128 needs to be paired with and be placed before the
R_RISCV_SUB_ULEB128.

bfd/
	* bfd-in2.h: Regenerated.
	* elfnn-riscv.c (perform_relocation): Perform R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128 relocations.  Do not shrink the length of the
	uleb128 value, and report error if the length grows up.  Called the
	generic functions, _bfd_read_unsigned_leb128 and _bfd_write_unsigned_leb128,
	to encode the uleb128 into the section contents.
	(riscv_elf_relocate_section): Make sure that the R_RISCV_SET_ULEB128
	must be paired with and be placed before the R_RISCV_SUB_ULEB128.
	* elfxx-riscv.c (howto_table): Added R_RISCV_SUB_ULEB128 and
	R_RISCV_SET_ULEB128.
	(riscv_reloc_map): Likewise.
	(riscv_elf_ignore_reloc): New function.
	* libbfd.h: Regenerated.
	* reloc.c (BFD_RELOC_RISCV_SET_ULEB128, BFD_RELOC_RISCV_SUB_ULEB128):
	New relocations to support .uleb128 subtraction.
gas/
	* config/tc-riscv.c (md_apply_fix): Added BFD_RELOC_RISCV_SET_ULEB128
	and BFD_RELOC_RISCV_SUB_ULEB128.
	(s_riscv_leb128): Updated to allow uleb128 subtraction.
	(riscv_insert_uleb128_fixes): New function, scan uleb128 subtraction
	expressions and insert fixups for them.
	(riscv_md_finish): Called riscv_insert_uleb128_fixes for all sections.
include/
	* elf/riscv.h ((R_RISCV_SET_ULEB128, (R_RISCV_SUB_ULEB128): Defined.
ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
	* testsuite/ld-riscv-elf/uleb128*: New testcase for uleb128 subtraction.
binutils/
	* testsuite/binutils-all/nm.exp: Updated since RISCV supports .uleb128.
2023-05-19 16:24:10 +08:00
Luca Bacci
80d4e113d7 Decorated symbols in import libs (BUG 30421)
PR 30421
  * cofflink.c (_decoration_hash_newfunc): New function. (_bfd_coff_link_hash_table_init): Call it.
  * libcoff-in.h (struct coff_link_hash_table): Add decoration_hash field. (struct decoration_hash_entry): Declare. (_decoration_hash_newfunc): Prototype.
  * libcoff.h: Regenerate.

  * emultempl/pe.em (set_decoration): New function. (pe_fixup_stdcalls): Call the new function.
  * emultempl/pep.em (set_decoration): New function. (pep_fixup_stdcalls): Call the new function.
  * pe-dll.c (make_one): Check for decoated symbols.
2023-05-17 13:38:14 +01:00
Nick Clifton
d1792f72bf Document how to use the linker to create a resource only DLL.
PR 30359
  * ld.texi (WIN32): Document how to create a resource only DLL.
2023-05-16 16:04:58 +01:00
Nick Clifton
0a7dda4f7a -Ur option documentation
* ld.texi (-Ur): Clarify the actions of this option.
2023-05-16 11:20:55 +01:00
mengqinggang
6a1cf1bfed LoongArch: Fix PLT entry generate bug
If a function symbol only get its address by la.global, without
directly called by bl instruction, the PLT entry is not required.

bfd/ChangeLog:

	* elfnn-loongarch.c (loongarch_elf_adjust_dynamic_symbol): Fix PLT
	entry generate bug.

ld/ChangeLog:

	* testsuite/ld-elf/shared.exp: Clear xfail for LoongArch.
2023-05-15 09:22:27 +08:00
Alan Modra
31f1490158 PR28902, -T script with INSERT ordering
The answer to PR28902 may be deduced from the existing INSERT
documentation that says the default script is parsed after the -T
INSERT script, if you assume (correctly) that nothing special is done
when inserting into -T scripts overriding the default script.  In both
cases INSERT handling looks for the specified output section later on
the internal list of parsed script commands.  This isn't obvious
though, so make the ordering explicit, and mention that section
assignments are the same too.

	PR 28902
	* ld.texi (INSERT): Specify ordering when -T is used both to
	override the default script and to augment.
2023-05-13 15:12:48 +09:30
Joseph Myers
b21318bd2c Add LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [GCC PR109128]
This is one part of the fix for GCC PR109128, along with a
corresponding GCC change.  Without this patch, what happens in the
linker, when an unused object in a .a file has offload data, is that
elf_link_is_defined_archive_symbol calls bfd_link_plugin_object_p,
which ends up calling the plugin's claim_file_handler, which then
records the object as one with offload data. That is, the linker never
decides to use the object in the first place, but use of this _p
interface (called as part of trying to decide whether to use the
object) results in the plugin deciding to use its offload data (and a
consequent mismatch in the offload data present at runtime).

The new hook allows the linker plugin to distinguish calls to
claim_file_handler that know the object is being used by the linker
(from ldmain.c:add_archive_element), from calls that don't know it's
being used by the linker (from elf_link_is_defined_archive_symbol); in
the latter case, the plugin should avoid recording the object as one
with offload data.

	bfd/
	* plugin.c (struct plugin_list_entry): Add claim_file_v2.
	(register_claim_file_v2): New.
	(try_load_plugin): Use LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
	(ld_plugin_object_p): Take second argument.
	(bfd_link_plugin_object_p): Update call to ld_plugin_object_p.
	(register_ld_plugin_object_p): Update argument prototype.
	(bfd_plugin_object_p): Update call to ld_plugin_object_p.
	* plugin.h (register_ld_plugin_object_p): Update argument
	prototype.

	include/
	* plugin.api.h (ld_plugin_claim_file_handler_v2)
	(ld_plugin_register_claim_file_v2)
	(LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New.
	(struct ld_plugin_tv): Add tv_register_claim_file_v2.

	ld/
	* plugin.c (struct plugin): Add claim_file_handler_v2.
	(LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New.
	(plugin_object_p): Add second argument.  Update call to
	plugin_call_claim_file.
	(register_claim_file_v2): New.
	(set_tv_header): Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
	(plugin_call_claim_file): Add argument known_used.
	(plugin_maybe_claim): Update call to plugin_object_p.
	* testplug.c, testplug2.c, testplug3.c, testplug4.c: Handle
	LDPT_REGISTER_CLAIM_FILE_HOOK_V2.
	* testsuite/ld-plugin/plugin-1.d, testsuite/ld-plugin/plugin-10.d,
	testsuite/ld-plugin/plugin-11.d, testsuite/ld-plugin/plugin-13.d,
	testsuite/ld-plugin/plugin-14.d, testsuite/ld-plugin/plugin-15.d,
	testsuite/ld-plugin/plugin-16.d, testsuite/ld-plugin/plugin-17.d,
	testsuite/ld-plugin/plugin-18.d, testsuite/ld-plugin/plugin-19.d,
	testsuite/ld-plugin/plugin-2.d, testsuite/ld-plugin/plugin-26.d,
	testsuite/ld-plugin/plugin-3.d, testsuite/ld-plugin/plugin-30.d,
	testsuite/ld-plugin/plugin-4.d, testsuite/ld-plugin/plugin-5.d,
	testsuite/ld-plugin/plugin-6.d, testsuite/ld-plugin/plugin-7.d,
	testsuite/ld-plugin/plugin-8.d, testsuite/ld-plugin/plugin-9.d:
	Update test expectations.
2023-05-11 14:31:09 +00:00
Nick Clifton
496917ce46 Add linker option to include local symbols in the linker map.
PR 16566
  * ldlang.c (ld_is_local_symbol): New function. (print_input_section): Add code to display local symbols in the section.
  * ldlex.h (enum option_values): Add OPTION_PRINT_MAP_LOCALS and OPTION_PRINT_MAP_LOCALS.
  * lexsup.c (ld_options[]): Add entries for --print-map-locals and --no-print-map-locals.
  * NEWS: Mention the new feature.
  * ld.h (struct ld_config_type): Add print_map_locals field.
  * ld.texi: Document the new command line option.
  * testsuite/ld-scripts/sizeof.s: Add a local symbol.
  * testsuite/ld-scripts/map-locals.d: New test control file.
  * testsuite/ld-scripts/map-address.exp: Run the new test.
2023-05-10 10:29:52 +01:00
Alan Modra
5f38307ad5 regen ld/Makefile.in 2023-05-09 09:38:16 +09:30
Alan Modra
f35cc0decd pe.em and pep.em make_import_fixup
This is a little cleanup that I made when looking at pr30343 that
makes it more obvious that make_import_fixup in both files are
identical (and in fact the new pep.em read_addend could be used in
both files).

	* emultempl/pep.em (read_addend): Extract from..
	(make_import_fixup): ..here.
	* emultempl/pe.em (read_addend): Similarly.
	(make_import_fixup): Similarly.  Add debug code from pep.em.
2023-05-08 13:59:35 +09:30
Alan Modra
defb881754 PR30343, LTO ignores linker reference to _pei386_runtime_relocator
Make a reference to _pei386_runtime_relocator before LTO recompilation.
This is done regardless of whether such a reference will be used,
because it can't be known whether it is needed before LTO.

I also found it necessary to enable long section names for the bfd
created in make_runtime_pseudo_reloc, because otherwise when writing
it out to the bfd-in-memory we get the section written as .rdata_r
which when read back in leads to a linker warning ".rdata_r: section
below image base" and likely runtime misbehaviour.

	PR 30343
	* emultempl/pe.em (make_runtime_ref): New function.
	(gld${EMULATION_NAME}_before_plugin_all_symbols_read): New function.
	(LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): Define.
	* emultempl/pep.em: Similarly to pe.em.
	* pe-dll.c (make_runtime_pseudo_reloc): Set long section names.
2023-05-08 10:11:47 +09:30
Nick Clifton
3539414584 Stop the linker from loosing the entry point for COFF/PE code when compiling with LTO enabled.
PR 30300
  * emultempl/pep.em (set_entry_point): Add an undefined reference to the entry point if it has been constructed heuristically.
  * emultempl/pe.em (set_entry_point): Likewise.
2023-05-04 14:24:16 +01:00
Dimitar Dimitrov
35130e73da ld: pru: Place exception-handling sections correctly
* scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable to place at end of DMEM output sections.
  (.data): Use the helper variable.
  (.eh_frame): New output section.
  (.gnu_extab): Ditto.
  (.gcc_except_table): Ditto.
  (.resource_table): Use the helper variable.
2023-05-04 12:41:55 +01:00
H.J. Lu
64b59b6bb2 ld: Use run_cc_link_tests for PR ld/26391 tests
Use run_cc_link_tests for PR ld/26391 tests to compile PR ld/26391 tests
in C.

	PR ld/30002
	* testsuite/ld-elf/elf.exp: Use run_cc_link_tests for PR ld/26391
	tests.
2023-04-28 08:38:17 -07:00
Michael Matz
670c91c0c5 Fix PR30358, performance with --sort-section
since af31506c we only use the binary tree when section sorting is
required.  While its unbalanced and hence can degrade to a linear list
it should otherwise have been equivalent to the old code relying on
insertion sort.  Unfortunately it was not.  The old code directly used
lang_add_section to populate the sorted list, the new code first
populates the tree and only then does lang_add_section on the sorted
result.

In the testcase we have very many linkonce section groups, and hence
lang_add_section won't actually insert anything for most of them.  That
limited the to-be-sorted list length previously.  The tree-sorting code
OTOH first created a tree of all candidates sections, including those
that wouldn't be inserted by lang_add_section, hence increasing the size
of the sorting problem.  In the testcase the chain length went from
about 1500 to 106000, and in the degenerated case (as in the testcase)
that goes in quadratically.

This splits out most of the early-out code from lang_add_section to its
own function and uses the latter to avoid inserting into the tree.  This
refactoring slightly changes the order of early-out tests (the ones
based on section flags is now done last, and only in lang_add_section).
The new function is not a pure predicate: it can give warnings and it
might change output_section, like the old early-out code did.  I have
also added a skip-warning case in the first discard case, whose
non-existence seemed to have been an oversight.

	PR 30358
	* ldlang.c (wont_add_section_p): Split out from ...
	(lang_add_section): ... here.
	(output_section_callback_sort): Use wont_add_section_p to not
	always add sections to the sort tree.
2023-04-27 16:15:26 +02:00
Nick Clifton
c386bf4df5 Add support for %x and %lx formats to the linker's vinfo() function. 2023-04-27 13:02:00 +01:00
Michael Matz
8f5cd47bee section-select: Fix performance problem (PR30367)
when using many wild-statements with non-wildcard filenames we
were running into quadraticness via repeatedly using lookup_name
on a long list of loaded files.  I've originally retained using
lookup_name because that preserved existing behaviour most obviously.
In particular in matching wild-statements when using a non-wildcard
filename it matches against local_sym_name, not the filename member.
If the wildspec would have an archive-spec or a wildcard it would use
the filename member, though.  Also it would load the named file
(and ignore it, as being not equal to the currently considered
input-statement).

Rewrite this to not use lookup_name but retain the comparison
against local_sym_name with a comment to that effect.

	PR 30367
	* ldlang.c (walk_wild_section_match): Don't use lookup_name
	but directly compare spec and local_sym_name.
2023-04-25 14:55:22 +02:00
YunQiang Su
32f1c80375 MIPS: support mips*64 as CPU and gnuabi64 as ABI
For MIPS64r6 ports, Debian as an example, `mipsisa64r6el` is
used as the cpu name in triple.
Let's recognize them by `mips*64*(el)`.

For 64bit Ports, like Debian's mips64el and mips64r6el ports,
`gnuabi64` is used as the abi section.
Let's use N64 abi by default for the triple with gnuabi64.
2023-04-23 14:32:43 +08:00
mengqinggang
fda507e61c LoongArch: Fix loongarch32 test fails
Regenerated macro_op_32.d and add skip loongarch64-*-*.

gas/ChangeLog:

	* testsuite/gas/loongarch/macro_op_32.d: Regenerated.

ld/ChangeLog:

	* testsuite/ld-loongarch-elf/macro_op_32.d: Regenerated.
2023-04-23 10:04:07 +08:00
Lifang Xia
0699f2d795 RISC-V: Optimize relaxation of gp with max_alignment.
This should be the first related issue, which posted in riscv-gnu-toolchain,
https://github.com/riscv-collab/riscv-gnu-toolchain/issues/497

If the output sections are not between gp and the symbol, then their alignments
shouldn't affect the gp relaxation.  However, this patch improves this idea
even more, it limits the range to the gp+-2k, which means only the output
section which are in the [gp-2K, gp+2K) range need to be considered.

Even if the output section candidates may be different for each relax passes,
the symbol that can be relaxed ar this round will not be truncated at next
round.  That is because this round you can do relaxation which means that the
section where the symbol is located is within the [gp-2K, gp+2K) range, so all
the output section alignments between them should be considered.  In other
words, if the alignments between them may cause truncated, then we should
already preserve the size and won't do the gp relaxation this time.

This patch can resolve the github issue which mentioned above, and also passed
all gcc/binutils regressions of riscv-gnu-toolchain, so should be worth and
safe enough to commit.

Originally, this patch also do the same optimization for the call relaxations,
https://sourceware.org/pipermail/binutils/2022-October/123918.html
But just in case there is something that has not been considered, we only
deal with the gp relaxation at this time.

bfd/
	* elfnn-riscv.c (riscv_elf_link_hash_table): Added new bfd_vma,
	max_alignment_for_gp.  It is used to record the maximum alignment of
	the output sections, which are in the [gp-2K, gp+2k) range.
	(riscv_elf_link_hash_table_create): Init max_alignment_for_gp to -1.
	(_bfd_riscv_get_max_alignment): Added new parameter, gp.  If gp is
	zero, then all the output section alignments are possible candidates;
	Otherwise, only the output sections which are in the [gp-2K, gp+2K)
	range need to be considered.
	(_bfd_riscv_relax_lui): Called _bfd_riscv_get_max_alignment with the
	non-zero gp if the max_alignment_for_gp is -1.
	(_bfd_riscv_relax_pc): Likewise.
	(_bfd_riscv_relax_section): Record the first input section, so that
	we can reset the max_alignment_for_gp for each repeated relax passes.
ld/
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
	* testsuite/ld-riscv-elf/relax-max-align-gp.*: New testcase.  It fails
	without this patch.
2023-04-21 15:47:47 +08:00
Jan Beulich
3a117c5887 ld: add missing period after @xref
At least older versions of one of the doc generation tools complain
(warn) about it missing.
2023-04-21 07:54:19 +02:00
Alan Modra
2605f35cda PR30343 infrastructure
Make ldemul_before_plugin_all_symbols_read more useful.

	* ldlang.c (lang_process): Move call to
	ldemul_before_plugin_all_symbols_read outside BFD_SUPPORTS_PLUGINS.
	Allow backends to add to gc_sym_list before handling entry sym.
	* ldelf.c (ldelf_before_plugin_all_symbols_read): Test
	lto_plugin_active.
2023-04-20 09:03:53 +09:30
mengqinggang
a02676b77d Symbols with GOT relocatios do not fix adjustbale
gas
    * config/tc-loongarch.c (loongarch_fix_adjustable): Symbols with GOT relocatios do not fix adjustbale.
    * testsuite/gas/loongarch/macro_op_large_abs.d: Regenerated.
    * testsuite/gas/loongarch/macro_op_large_pc.d: Regenerated.
  ld
     * testsuite/ld-loongarch-elf/macro_op.d: Regenerated. -
2023-04-18 11:49:21 +01:00
Nick Clifton
b29f2fda4f Add support for the .gnu.sgstubs section to the linker for ARM/ELF based targets.
PR 30354
  * emulparams/armelf.sh (OTHER_PLT_SECTIONS): Define in order to handle the .gnu.sgstubs section.
2023-04-17 15:48:45 +01:00
Claudiu Zissulescu
546c7898dc arc: Update ARC specific linker tests.
All the tests are designed for a little-endian ARC system. Thus,
update the arc predicate in arc.exp, improve the matching pattern for
linker relaxation test, and add linker scripts to nps-1x tests.

Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2023-04-13 11:21:01 +03:00
Nick Clifton
93cda40b4c Fix typos in the linker's documentation of the --enable-non-contiguous-regions option. 2023-04-12 09:54:48 +01:00