Commit Graph

7651 Commits

Author SHA1 Message Date
Alan Modra
c8d45dbd0a ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGET
The idea here is build tests without sanitizer flags, so they don't
fail due to many not using the compiler to link and thus result in
undefined symbols, since libasan is not supplied.  We definitely do not
want a compiler to perform linking in most cases, and it's complicated
to supply libasan (and would possibly disturb testcase output).

	* testsuite/config/default.exp (CFLAGS_FOR_TARGET),
	(CXXFLAGS_FOR_TARGET): Append NOSANITIZE_CFLAGS.
	* testsuite/ld-bootstrap/bootstrap.exp: Use CC_FOR_TARGET and
	CFLAGS_FOR_TARGET throughout.
2024-04-09 11:21:57 +09:30
H.J. Lu
d05e1a4a6d ld: Add PR ld/31615 tests
PR ld/31615
	* testsuite/ld-plugin/lto.exp: Run ld/31615 tests.
	* testsuite/ld-plugin/pr31615.ver: New file.
	* testsuite/ld-plugin/pr31615a.c: Likewise.
	* testsuite/ld-plugin/pr31615b.c: Likewise.
	* testsuite/ld-plugin/pr31615c.c: Likewise.
	* testsuite/ld-plugin/pr31615d.c: Likewise.
2024-04-08 05:18:24 -07:00
H.J. Lu
c0419c024b elf: Always honor the first definition in shared object and archive
GCC doesn't put builtin function symbol references, which are defined in
the shared C library, in the IR symbol table.  When linker rescans shared
objects and archives for newly added symbol references generated from the
IR inputs, it skips definitions of the builtin functions in shared
objects and archives.

Add first_hash to elf_link_hash_table to track unreferenced definitions
defined first in shared objects and archives.  Always use them to resolve
any references.

bfd/

	PR ld/31482
	PR ld/31489
	* elf-bfd.h (elf_link_hash_table): Add first_hash.
	* elflink.c (elf_link_add_to_first_hash): New function.
	(elf_link_add_object_symbols): Initialize first_hash for an IR
	input.  Always use the first definition in shared object.  Add
	the first unreferenced dynamic definition to first_hash.
	(_bfd_elf_archive_symbol_lookup): Add the first unreferenced
	definition to first_hash..
	(elf_link_add_archive_symbols): Use the symbol definition in
	archive if symbol is defined first in this archive.
	(_bfd_elf_link_hash_table_free): Also free first_hash.

ld/

	PR ld/31482
	PR ld/31489
	* testsuite/ld-plugin/lto.exp: Add PR ld/31482 and PR ld/31489
	tests.
	* testsuite/ld-elf/pr31482a-no-lto.c: New file.
	* testsuite/ld-elf/pr31482b-no-lto.c: Likewise.
	* testsuite/ld-elf/pr31482c-no-lto.c: Likewise.
	* testsuite/ld-elf/pr31482d-no-lto.c: Likewise.
	* testsuite/ld-plugin/pass1.out: Likewise.
	* testsuite/ld-plugin/pr31482a.c: Likewise.
	* testsuite/ld-plugin/pr31482b.c: Likewise.
	* testsuite/ld-plugin/pr31482c.c: Likewise.
2024-04-05 05:02:38 -07:00
Christophe Lyon
54e2d897a6 Add missing install-dvi and install-ps Makefie targets.
For some reason, these targets are missing although others from the
same family are present. This looks like an oversight.

This enables calling 'make install-dvi' from the top-level build
directory.
2024-04-05 07:02:56 +00:00
H.J. Lu
33c58f4844 PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memory
PR 31458
bfd/
	* elf-bfd.h (_bfd_elf_link_read_relocs),
	(_bfd_elf_link_info_read_relocs): Constify section.
	* elflink.c: Likewise.
	* elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read
	relocs again in case --no-keep-memory.
ld/
	* testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory
	version of eh-frame3 test.
2024-04-02 17:29:58 +10:30
Alan Modra
af969b14ae PR 30569, always call elf_backend_size_dynamic_sections
This largely mechanical patch is preparation for a followup patch.

For quite some time I've thought that it would be useful to call
elf_backend_size_dynamic_sections even when no dynamic objects are
seen by the linker.  That's what this patch does, with some renaming.
There are no functional changes to the linker, just a move of the
dynobj test in bfd_elf_size_dynamic_sections to target backend
functions, replacing the asserts/aborts already there.  No doubt some
of the current always_size_sections functions could be moved to
size_dynamic_sections but I haven't made that change.

Because both hooks are now always called, I have renamed
always_size_sections to early_size_sections and size_dynamic_sections
to late_size_sections.  I condisdered calling late_size_sections plain
size_sections, since this is the usual target dynamic section sizing
hook, but decided that searching the sources for "size_sections" would
then hit early_size_sections and other functions.
2024-04-02 10:32:04 +10:30
John David Anglin
a82e3815df hppa: Implement PA 2.0 symbolic relocations for long displacements
The PA 2.0 architecture introduced several new load and store
instructions with long displacements.  These include floating
point loads and stores for word mode, and integer and floating
point loads and stores for double words.  Currently, ld does
not correctly support symbolic relocations for these instructions.

If these are used, ld applies the standard R_PARISC_DPREL14R
relocation and corrupts the instruction.  This change uses
bfd_hppa_insn2fmt to determine the correct relocation format.

We need to check the computed displacement as the immediate
value used in these instruction must be a multiple of 4 or 8
depending on whether the access is for a word or double word.

A misaligned offset can potentially occur if the symbol is not
properly aligned or if $global$ (the global pointer) is not
double word aligned.  $global$ is provided as a .data section
start symbol.  The patch adjusts elf.sc and hppalinux.sh to
align .data to a 8-byte boundary in non-shared and non-pie
links.

2024-04-01  John David Anglin  <danglin@gcc.gnu.org>

	PR ld/31503

bfd/ChangeLog:

	* elf32-hppa.c (final_link_relocate): Output

ld/ChangeLog:

	* emulparams/hppalinux.sh (DATA_SECTION_ALIGNMENT): Define.
	* scripttempl/elf.sc: Align .data section to DATA_SECTION_ALIGNMENT
	when relocating.
2024-04-01 23:00:52 +00:00
Lulu Cai
b67a17aa7c LoongArch: Fix the issue of excessive relocation generated by GD and IE
Currently, whether GD and IE generate dynamic relocation is
determined by SYMBOL_REFERENCES_LOCAL and bfd_link_executable.
This results in dynamic relocations still being generated in some
situations where dynamic relocations are not necessary (such as
the undefined weak symbol in static links).

We use RLARCH_TLS_GD_IE_NEED_DYN_RELOC macros to determine whether
GD/IE needs dynamic relocation. If GD/IE requires dynamic relocation,
set need_reloc to true and indx to be a dynamic index.

At the same time, some test cases were modified to use regular
expression matching instead of complete disassembly matching.
2024-04-01 17:41:56 +08:00
mengqinggang
7918b183ec LoongArch: gas: Ignore .align if it is at the start of a section
Ignore .align if it is at the start of a section and the alignment
can be divided by the section alignment, the section alignment
can ensure this .align has a correct alignment.
2024-04-01 09:38:17 +08:00
mengqinggang
daeda14191 BFD: Fix the bug of R_LARCH_AGLIN caused by discard section
To represent the first and third expression of .align, R_LARCH_ALIGN need to
associate with a symbol. We define a local symbol for R_LARCH_AGLIN.
But if the section of the local symbol is discarded, it may result in
a undefined symbol error.

Instead, we use the section name symbols, and this does not need to
add extra symbols.

During partial linking (ld -r), if the symbol associated with a relocation is
STT_SECTION type, the addend of relocation needs to add the section output
offset. We prevent it for R_LARCH_ALIGN.

The elf_backend_data.rela_normal only can set all relocations of a target to
rela_normal. Add a new function is_rela_normal to elf_backend_data, it can
set part of relocations to rela_normal.
2024-03-31 14:21:00 +08:00
Nelson Chu
8e60ff82b8 RISC-V: Removed privileged spec 1.9.1 support in assembler.
Removed since it's may have lots of conflicts with the newer extensions, but
still keep linker recognizes it in case of linking old objects.

gas/
	* NEWS: Updated.
	* config/tc-riscv.c (riscv_set_default_priv_spec): Regard 1.9.1 as
	an unknown version.
	(md_show_usage): Removed privileged spec 1.9.1 information.
	* testsuite/gas/riscv/attribute-05.s: Updated since privileged spec
	1.9.1 is unsupported.
	* testsuite/gas/riscv/attribute-05.d: Likewise.
	* testsuite/gas/riscv/attribute-12.d: Likewise.
	* testsuite/gas/riscv/attribute-13.d: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.d: Likewise.
	* testsuite/gas/riscv/csr-dw-regnums.s: Likewise.
	* testsuite/gas/riscv/csr.s: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p10.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p11.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.d: Likewise.
	* testsuite/gas/riscv/csr-version-1p12.l: Likewise.
	* testsuite/gas/riscv/csr-version-1p9p1.d: Removed.
	* testsuite/gas/riscv/csr-version-1p9p1.l: Removed.
include/
	* opcode/riscv-opc.h: Updated since privileged spec 1.9.1 is
	unsupported.
ld/
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d: Updated since
	privileged spec 1.9.1 is unsupported.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise.
	* testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise.
	* 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.
2024-03-28 09:26:13 +08:00
H.J. Lu
bb9a951fab Don't claim a fat IR object if no IR object should be claimed
When the linker sees an input object containing nothing but IR during
rescan, it should ignore it (LTO phase is over).  But if the input object
is a fat IR object, which has non-IR code as well, it should be used to
resolve references as if it did not contain any IR at all.  This patch
adds lto_type to bfd and linker avoids claiming a fat IR object if no IR
object should be claimed.

bfd/

	PR ld/23935
	* archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type
	instead of lto_slim_object.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	* bfd.c (bfd_lto_object_type): New.
	(bfd): Remove lto_slim_object and add lto_type.
	(bfd_get_lto_type): New function.
	* elf.c (lto_section): Removed.
	(_bfd_elf_make_section_from_shdr): Don't set lto_slim_object.
	* format.c: (lto_section): New.
	(bfd_set_lto_type): New function.
	(bfd_check_format_matches): Call bfd_set_lto_type.
	* bfd-in2.h: Regenerated.

binutils/

	PR ld/23935
	* nm.c (display_rel_file): Check bfd_get_lto_type instead of
	lto_slim_object.

ld/

	PR ld/23935
	* ldmain.c (add_archive_element): Don't claim a fat IR object if
	no IR object should be claimed.
	* testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test.
	Add PR ld/23935 test.
	* testsuite/ld-plugin/pr23935a.c: New file.
	* testsuite/ld-plugin/pr23935b.c: Likewise.
2024-03-26 07:17:17 -07:00
H.J. Lu
f6080a91c5 ld: Support LD_UNDER_TEST environment variable
Support LD_UNDER_TEST environment variable to test a different linker.
Issue an error if LD_UNDER_TEST isn't an absolute full path.

	* testsuite/config/default.exp: If LD_UNDER_TEST environment
	variable exists, set ld and LD to it and set up tmpdir/ld/ld.
	Issue an error if LD_UNDER_TEST isn't an absolute full path.
2024-03-19 07:07:54 -07:00
Nick Clifton
dcca32c28b Fix typo in previous patch to ld.texi 2024-03-19 11:44:34 +00:00
mengqinggang
97ce787044 LoongArch: Add relaxation for R_LARCH_CALL36
This relaxation is effective for both macro instructions (call36, tail36)
and explicit relocation instructions (pcaddu18i + jirl).

call36 f	  ->	bl f
  R_LARCH_CALL36  ->	  R_LARCH_B26

tail36 $t0, f	  ->	b f
  R_LARCH_CALL36  ->	  R_LARCH_B26
2024-03-19 14:14:47 +08:00
Nick Clifton
ee0fa66270 [PATCH] ld: Improve documentation of -rpath-link search paths 2024-03-18 16:51:49 +00:00
Lulu Cai
d8915f27eb LoongArch: Fix gas and ld test cases
* After adding the old LE relax, all old LE relocations will have
  an R_LARCH_RELAX relocation. Fix the gas test case failure caused
  by the implementation of the old LE relax.

* loongarch64-elf does not support pie and -z norelro options,
  removed in test files.
2024-03-12 17:37:12 +08:00
Lulu Cai
a9859f5ad0 LoongArch: Fix some test cases for TLS transition and relax 2024-03-06 14:47:03 +08:00
Alan Modra
d5c5b27095 PR19871, description of --pie
Say why we even mention shared libraries here (ET_DYN), and clarify
symbol resolution.  There are of course many other ways that PIEs
resemble PDEs more closely than shared libraries.

	PR 19871
	* ld.texi (-pie): Clarify.
2024-03-01 09:22:32 +10:30
Tatsuyuki Ishi
159afbb761 RISC-V: Initial ld.bfd support for TLSDESC.
Only relocation handling for now; relaxation is not implemented yet.

bfd/
    * elfnn-riscv.c (riscv_elf_check_relocs): Record GOT reference and
    paired relocation for TLSDESC_HI20.
    (riscv_elf_adjust_dynamic_symbol): Allocate GOT and reloc slots for
    TLSDESC symbols.
    (riscv_elf_size_dynamic_sections): Likewise but for local symbols.
    (tlsdescoff): New helper to determine static addend for R_TLSDESC.
    (riscv_elf_relocate_section): Ignore TLSDESC_CALL reloc for now (it is
    relaxation only).
    Handle TLSDESC_{LOAD,ADD}_LO12 as paired pcrel relocs.
    For TLS GOT slot generation, generalize the logic to handle any
    combination of (GD, IE, TLSDESC).
    Add TLSDESC Rela generation.
    * ld/testsuite/ld-riscv-elf/tls*: Add TLSDESC instruction sequences
    next to the existing GD and IE sequences. Update expectations.
2024-02-29 15:02:55 +08:00
Vladislav Belov
60856b5cda Fix implementation of SUBALIGN. 2024-02-28 16:36:37 +00:00
Alan Modra
4b72a278f4 PR23881, pdp11 binutils fails if too much debug data
The PR testcase overflows one of the exec header fields, e_syms (the
size of the symbol table), leading to the string table offset being
wrong.  Things go downhill from there.  Fixed by checking for
overflow.  This happens to trigger in the ld testsuite, so xfail that
test.

	PR 23881
bfd/
	* libaout.h (swap_exec_header_out): Return a bool.
	* aoutx.h (swap_exec_header_out): Check for overflow in exec
	header.
	* pdp11.c (swap_exec_header_out): Likewise.
	* i386lynx.c (WRITE_HEADERS): Adjust.
ld/
	* testsuite/ld-scripts/map-address.exp: xfail pdp11.
2024-02-28 21:24:39 +10:30
Andreas Krebbel
896a639bab s390: Avoid reloc overflows on undefined weak symbols
Replace relative long addressing instructions of weak symbols, which
will definitely resolve to zero, with either a load address of 0, a
NOP, or a trapping insn.

This prevents the PC32DBL relocation from overflowing in case the
binary will be loaded at 4GB or more.

bfd/ChangeLog:

	* bfd/elf64-s390.c (elf_s390_relocate_section): Replace
	instructions using undefined weak symbols with relative addressing
	to avoid relocation overflows.

ld/ChangeLog:
	* ld/testsuite/ld-s390/s390.exp:
	* ld/testsuite/ld-s390/8GB.ld: New test.
	* ld/testsuite/ld-s390/weakundef-1.dd: New test.
	* ld/testsuite/ld-s390/weakundef-1.s: New test.
2024-02-27 14:07:17 +01:00
mengqinggang
54af729da1 LoongArch: Run overflow testcases only on LoongArch target 2024-02-27 16:36:19 +08:00
Jinyang He
fb266c9083 Avoid unused space in .rela.dyn if sec was discarded
The relsec size is still increased although sec is discarded, which
cause a lot of unused space allocated. Avoid size increased if sec
was discarded.

bfd/ChangeLog:

	* bfd/elfnn-loongarch.c: (allocate_dynrelocs): Do not increase
	sreloc size when discarded_section.

ld/ChangeLog:

	* ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp: Add test.
	* ld/testsuite/ld-loongarch-elf/pie_discard.d: New test.
	* ld/testsuite/ld-loongarch-elf/pie_discard.s: New test.
	* ld/testsuite/ld-loongarch-elf/pie_discard.t: New test.
2024-02-27 11:58:33 +08:00
Jinyang He
b98da8583a LoongArch: ld: Fix other pop relocs overflow check and add tests
Add reloc_unsign_bits() to fix others sop_pop relocs overflow check.
Then add over/underflow tests for relocs B*, SOP_POP* and PCREL20_S2.

bfd/ChangeLog:

	* bfd/elfxx-loongarch.c: Add reloc_unsign_bits().

ld/ChangeLog:

	* ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp: Add tests.
	* ld/testsuite/ld-loongarch-elf/abi1_max_imm.dd: New test.
	* ld/testsuite/ld-loongarch-elf/abi1_max_imm.s: New test.
	* ld/testsuite/ld-loongarch-elf/abi1_sops.s: New test.
	* ld/testsuite/ld-loongarch-elf/abi2_max_imm.s: New test.
	* ld/testsuite/ld-loongarch-elf/abi2_overflows.s: New test.
	* ld/testsuite/ld-loongarch-elf/max_imm_b16.d: New test.
	* ld/testsuite/ld-loongarch-elf/max_imm_b21.d: New test.
	* ld/testsuite/ld-loongarch-elf/max_imm_b26.d: New test.
	* ld/testsuite/ld-loongarch-elf/max_imm_pcrel20.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_b16.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_b21.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_b26.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_pcrel20.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_0_10_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_0_5_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_10_12.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_10_16.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_10_5.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_s_5_20.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_u.d: New test.
	* ld/testsuite/ld-loongarch-elf/overflow_u_10_12.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_b16.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_b21.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_b26.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_pcrel20.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_0_10_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_0_5_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_10_12.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_10_16.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_10_16_s2.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_10_5.d: New test.
	* ld/testsuite/ld-loongarch-elf/underflow_s_5_20.d: New test.
2024-02-27 11:54:34 +08:00
Alan Modra
9c697157b8 Make is_relocatable_executable only affect dynamic section syms
I believe the only elflink.c specialties for is_relocatable_executable
needed by tic6x are those directly related to dynamic section symbols.
I might be wrong, the code in record_dynamic_symbol and
record_link_assignment predated the tic6x port, but I think these were
symbian specific hacks.

The shlib-app-1* testsuite changes aren't needed for this patch.  I
started making them when trying to remove is_relocatable_executable
completely, but figure it is worth keeping the more permissive address
matching for some future generic linker change.  The static-app-1*
changes also adjust to the fact that an unneeded "c" no longer appears
in the dynamic symbol table.

bfd/
	* elflink.c (bfd_elf_link_record_dynamic_symbol): Don't do anything
	special for is_relocatable_executable.
	(bfd_elf_record_link_assignment): Likewise.
ld/
	* testsuite/ld-tic6x/shlib-app-1.rd: Make some address matching
	more permissive.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise, and adjust expected
	dynamic symbol table.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
2024-02-24 11:53:03 +10:30
Tatsuyuki Ishi
0ac6b8701f RISC-V: Fix local GOT and reloc size calculation for TLS.
The previous code did not account correctly for two cases:
* A TLS symbol can be referenced with multiple TLS types (although rare),
  in which case it only allocated the maximum slot size among the types,
  instead of the sum.
* TLS relocations are only needed for DLLs, unlike normal symbols which
  requires relocations for all PIE code.

Modify the logic to account for the two cases, so this fixes the redundant
dynamic R_RISCV_NONE in .rela.dyn when using --no-pie for TLS GD and IE.

Passed the gcc/binutils regressions of riscv-gnu-toolchain.

bfd/
    * elfnn-riscv.c (riscv_elf_size_dynamic_sections): Handle relocation
    sizing for TLS and non-TLS symbols differently, with the former
    requiring relocs on DLL while the latter requiring on PIE.
    Allocate GOT slots and relocation slots for each TLS type separately,
    accounting for the possibility of a TLS variable getting referenced by
    multiple symbols.
ld/
    * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
    * testsuite/ld-riscv-elf/tls*: New testcase for TLS GD and IE, with
    symbols referred by both types and global and local symbols.
2024-02-21 14:58:43 +08:00
H.J. Lu
d9511b64b8 ld: Add -plugin-save-temps
Add -plugin-save-temps to store plugin intermediate files permanently.
It can be used to exam the final input object files generated from IR
inputs.

	* NEWS: Mention -plugin-save-temps.
	* ld.h (ld_config_type): Add plugin_save_temps.
	* ld.texi: Document -plugin-save-temps.
	* ldlex.h (option_values): Add OPTION_PLUGIN_SAVE_TEMPS.
	* lexsup.c (ld_options): Add -plugin-save-temps.
	(parse_args): Handle OPTION_PLUGIN_SAVE_TEMPS.
	* plugin.c (plugin_call_cleanup): Don't call plugin
	cleanup_handler for -plugin-save-temps.
2024-02-16 05:03:06 -08:00
Alan Modra
b19a0b915f Re: elf_backend_finish_dynamic_symbol returning false
Making a bfd_final_link failure noisy requires testsuite changes.
2024-02-15 21:28:07 +10:30
Alan Modra
19bfbfa665 PR28448, Memory leak in function add_symbols(plugin.c)
PR 28448
	* plugin.c (add_symbols): bfd_alloc memory for symptrs.  Check
	bfd_make_empty_symbol return.
2024-02-15 19:11:42 +10:30
Alan Modra
313f04b6ed Re: elf_backend_finish_dynamic_symbol returning false
I didn't examine ld testsuite logs properly after cf95b909e2.
Replacing one of the "return false" with BFD_ASSERT in
finish_dynamic_symbol was wrong as it causes segmentation faults on
testcases expected to fail.  Revert those changes and instead make
a bfd_final_link failure noisy.
2024-02-15 19:11:42 +10:30
H.J. Lu
5bc71c2a6b x86-64: Add R_X86_64_CODE_6_GOTTPOFF
For

	add	%reg1, name@gottpoff(%rip), %reg2

and

	add	name@gottpoff(%rip), %reg1, %reg2

add

 #define R_X86_64_CODE_6_GOTTPOFF		50

if the instruction starts at 6 bytes before the relocation offset.
They are similar to R_X86_64_GOTTPOFF.  Linker can covert GOTTPOFF to

	add	$name@tpoff, %reg1, %reg2

Rewrite fx_tcbit, fx_tcbit2 and fx_tcbit3 usage to generate
R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX, R_X86_64_CODE_4_GOTPCRELX,
R_X86_64_CODE_4_GOTTPOFF, R_X86_64_CODE_4_GOTPC32_TLSDESC and
R_X86_64_CODE_6_GOTTPOFF.

NB: There is no need to check BFD_RELOC_X86_64_CODE_4_GOTTPOFF in
md_assemble since there is only BFD_RELOC_X86_64_GOTTPOFF at this
stage, which will be converted to BFD_RELOC_X86_64_CODE_4_GOTTPOFF
or BFD_RELOC_X86_64_CODE_6_GOTTPOFF in i386_validate_fix.

5 relocations:

 #define R_X86_64_CODE_5_GOTPCRELX		46
 #define R_X86_64_CODE_5_GOTTPOFF		47
 #define R_X86_64_CODE_5_GOTPC32_TLSDESC	48
 #define R_X86_64_CODE_6_GOTPCRELX		49
 #define R_X86_64_CODE_6_GOTPC32_TLSDESC	51

are added for completeness and they are unused.

bfd/

	* elf64-x86-64.c (x86_64_elf_howto_table): Add
	R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
	R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX,
	R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(R_X86_64_standard): Updated.
	(x86_64_reloc_map): Add R_X86_64_CODE_5_GOTPCRELX,
	R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC,
	R_X86_64_CODE_6_GOTPCRELX, R_X86_64_CODE_6_GOTTPOFF and
	R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(elf_x86_64_check_tls_transition): Handle
	R_X86_64_CODE_6_GOTTPOFF.
	(elf_x86_64_tls_transition): Likewise.
	(elf_x86_64_scan_relocs): Handle R_X86_64_CODE_6_GOTTPOFF.
	Issue an error for R_X86_64_CODE_5_GOTPCRELX,
	R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC,
	R_X86_64_CODE_6_GOTPCRELX and R_X86_64_CODE_6_GOTPC32_TLSDESC.
	(elf_x86_64_relocate_section): Handle R_X86_64_CODE_6_GOTTPOFF.
	* reloc.c (bfd_reloc_code_real): Add
	BFD_RELOC_X86_64_CODE_5_GOTPCRELX,
	BFD_RELOC_X86_64_CODE_5_GOTTPOFF,
	BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC,
	BFD_RELOC_X86_64_CODE_6_GOTPCRELX,
	BFD_RELOC_X86_64_CODE_6_GOTTPOFF and
	BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

elfcpp/

	* x86_64.h (R_X86_64_CODE_5_GOTPCRELX): New.
	(R_X86_64_CODE_5_GOTTPOFF): Likewise.
	(R_X86_64_CODE_5_GOTPC32_TLSDESC): Likewise.
	(R_X86_64_CODE_6_GOTPCRELX): Likewise.
	(R_X86_64_CODE_6_GOTTPOFF): Likewise.
	(R_X86_64_CODE_6_GOTPC32_TLSDESC): Likewise.

gas/

	* config/tc-i386.c (tc_i386_fix_adjustable): Handle
	BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	(md_assemble): Don't check BFD_RELOC_X86_64_CODE_4_GOTTPOFF.
	Allow "add %reg1, foo@gottpoff(%rip), %reg2".
	(output_disp): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.  Rewrite
	setting fx_tcbitX bits for BFD_RELOC_X86_64_GOTTPOFF,
	BFD_RELOC_X86_64_GOTPC32_TLSDESC and BFD_RELOC_32_PCREL.
	(md_apply_fix): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	(i386_validate_fix): Rewrite fx_tcbitX bit checking for
	BFD_RELOC_X86_64_GOTTPOFF, BFD_RELOC_X86_64_GOTPC32_TLSDESC and
	BFD_RELOC_32_PCREL.
	(tc_gen_reloc): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF.
	* testsuite/gas/i386/x86-64-gottpoff.d: Updated.
	* testsuite/gas/i386/x86-64-gottpoff.s: Add tests for
	"add %reg1, foo@gottpoff(%rip), %reg2" and
	"add foo@gottpoff(%rip), %reg, %reg2".

gold/

	* x86_64.cc (Target_x86_64::optimize_tls_reloc): Handle
	R_X86_64_CODE_6_GOTTPOFF.
	(Target_x86_64::Scan::get_reference_flags): Likewise.
	(Target_x86_64::Scan::local): Likewise.
	(Target_x86_64::Scan::global): Likewise.
	(Target_x86_64::Relocate::relocate): Likewise.
	(Target_x86_64::Relocate::relocate_tls): Likewise.
	(Target_x86_64::Relocate::tls_ie_to_le): Handle.
	R_X86_64_CODE_6_GOTTPOFF.
	* testsuite/x86_64_ie_to_le.s: Add tests for
	"add %reg1, foo@gottpoff(%rip), %reg2" and
	"add foo@gottpoff(%rip), %reg, %reg2".
	* testsuite/x86_64_ie_to_le.sh: Updated.

include/

	* elf/x86-64.h (elf_x86_64_reloc_type): Add
	R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF,
	R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX,
	R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC.

ld/

	* testsuite/ld-x86-64/tlsbindesc.s: Add R_X86_64_CODE_6_GOTTPOFF
	tests.
	* testsuite/ld-x86-64/tlsbindesc.d: Updated.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
2024-02-08 03:45:43 -08:00
Alan Modra
60c95acdac Link x86-64 mark-plt-1.so with --no-as-needed
Fixes
FAIL: Build mark-plt-1.so
where gcc is built with default --as-needed.

	* testsuite/ld-x86-64/x86-64.exp (Build mark-plt-1.so): Pass
	--no-as-needed.
2024-02-06 17:32:31 +10:30
Georg-Johann Lay
24f5deb64d PR31124: Addendum: Remove PROVIDE of __flmap_init_label, __flmap.
Supply these symbols as computed by the linker scripts, even when there are weak definitions.
PR 31124
  * scripttempl/avr.sc (__flmap, __flmap_init_label): Remove PROVIDE.
2024-01-31 11:23:20 +00:00
Nick Clifton
fff48b7cb0 Updated French translations for GOLD and LD 2024-01-29 11:32:15 +00:00
H.J. Lu
1b06334552 elf: Rename is_standard_elf to uses_elf_em
Rename is_standard_elf to uses_elf_em for targets which use elf.em.

binutils/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_standard_elf): Renamed
	to ...
	(uses_elf_em): This.

ld/

	PR ld/31289
	* testsuite/ld-elf/fatal-warnings-2a.d: Replace is_standard_elf
	with uses_elf_em.
	* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
2024-01-26 07:32:03 -08:00
Nick Clifton
9c8d5b9a4f Remove -pie from command line of fatal-warnings 1a and 1b tests. 2024-01-26 10:25:04 +00:00
mengqinggang
a0aa6f4abd LoongArch: ld: Add support for TLS LE symbol with addend
Add support for TLS LE symbol with addend, such as:
  lu12i.w $t0, %le_hi20(a + 0x8)
  ori	  $t0, $t0, %le_lo12(a + 0x8)
2024-01-26 16:49:09 +08:00
H.J. Lu
eb12b17047 elf: Add is_standard_elf
PR ld/31289 tests failed for fr30-elf, frv-elf, ft32-elf, iq2000-elf,
mn10200-elf, ms1-elf and msp430-elf targets:

FAIL: ld-elf/fatal-warnings-2a
FAIL: ld-elf/fatal-warnings-2b
FAIL: ld-elf/fatal-warnings-3a
FAIL: ld-elf/fatal-warnings-3b
FAIL: ld-elf/fatal-warnings-4a
FAIL: ld-elf/fatal-warnings-4b

even though PR ld/31289 targets xfail for [is_generic] targets.  These
targets not only don't use the generic_link_hash_table linker, but also
don't use the standard ELF emulation.  Add is_standard_elf for ELF
targets which use the standard ELF emulation and replace [is_generic]
with ![is_standard_elf] in PR ld/31289 tests.

binutils/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_standard_elf): New.

ld/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_generic): Return 1 for
	fr30-*-*, frv-*-elf, ft32-*-*, iq2000-*-*, mn10200-*-*,
	moxie-*-moxiebox*, msp430-*-* and mt-*-*.
	* testsuite/ld-elf/fatal-warnings-2a.d: Replace [is_generic]
	with ![is_standard_elf].
	* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
2024-01-25 10:17:46 -08:00
H.J. Lu
624c610dd4 ld: Always call output_unknown_cmdline_warning
Call output_unknown_cmdline_warning if there are no input files so that

$ ld -z bad-option

reports

ld: warning: -z bad-option ignored
ld: no input files

instead of

ld: no input files

	PR ld/31289
	* ldmain.c (main): Call output_unknown_cmdline_warning if there
	are no input files.
2024-01-25 09:26:25 -08:00
H.J. Lu
3eb33b8875 ld: Improve --fatal-warnings for unknown command-line options
There are 2 problems with --fatal-warnings for unknown command-line
options:

1. --fatal-warnings doesn't trigger an error for an unknown command-line
option when --fatal-warnings is the last command-line option.
2. When --fatal-warnings triggers an error for an unknown command-line
option, the message says that the unknown command-line option is ignored.

This patch queues unknown command-line option warnings and outputs queued
command-line option warnings after all command-line options have been
processed so that --fatal-warnings can work for unknown command-line
options regardless of the order of --fatal-warnings.

When --fatal-warnings is used, the linker message is changed from

ld: warning: -z bad-option ignored

to

ld: error: unsupported option: -z bad-option

The above also applies to "-z dynamic-undefined-weak" when the known
"-z dynamic-undefined-weak" option is ignored.

	PR ld/31289
	* ldelf.c (ldelf_after_parse): Use queue_unknown_cmdline_warning
	to warn the ignored -z dynamic-undefined-weak option.
	* ldmain.c (main): Call output_unknown_cmdline_warnings after
	calling ldemul_after_parse.
	* ldmisc.c (CMDLINE_WARNING_SIZE): New.
	(cmdline_warning_list): Likewise.
	(cmdline_warning_head): Likewise.
	(cmdline_warning_tail): Likewise.
	(queue_unknown_cmdline_warning): Likewise.
	(output_unknown_cmdline_warnings): Likewise.
	* ldmisc.h (queue_unknown_cmdline_warning): Likewise.
	(output_unknown_cmdline_warnings): Likewise.
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Use
	queue_unknown_cmdline_warning to warn unknown -z option.
	* testsuite/ld-elf/fatal-warnings-1a.d: New file.
	* testsuite/ld-elf/fatal-warnings-1b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-2a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
2024-01-25 05:42:04 -08:00
Xi Ruoyao
36176c5d90 [PATCH v2] gas/NEWS, ld/NEWS: Announce LoongArch changes in 2.42 2024-01-23 16:00:32 +00:00
Xi Ruoyao
7b0b94b7b9 LoongArch: Fix some test failures about TLS desc and TLS relaxation
There are two issues causing 11 test failures:

1. The TLS desc tests are matching the entire disassemble of a linked
   executable.  But if ld is configured --enable-default-hash-style=gnu
   (note that most modern distros use this option), the layout of the
   linked executables will be different and the immediate operands in
   the linked executables will also be different.  So we add
   "--hash-style=both" for these tests to cancel the effect of
   --enable-default-hash-style=gnu, like [x86_64 mark-plt tests].
2. By default objdump disassemble uses [pseudo-instructions] so "addi.w"
   is outputed as "li.w", causing mismatches in TLS relaxation tests.
   We can turn off the pseudo-instruction usage in objdump using "-M
   no-aliases" to fix them.

[x86_64 mark-plt tests]: 16666ccc91
[pseudo-instructions]: 17f9439038

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-01-22 17:14:36 +08:00
mengqinggang
32ee2b4b71 LoongArch: Do not emit R_LARCH_RELAX for two register macros
For two register macros (e.g. la.local $t0, $t1, symbol) used in extreme code
model, do not emit R_LARCH_RELAX relocations.
2024-01-21 10:05:38 +08:00
H.J. Lu
c873acc5fe ld: Remove scripttempl/elf_chaos.sc
scripttempl/elf_chaos.sc is unused.  Remove it.

	* scripttempl/elf_chaos.sc: Removed.
2024-01-19 08:05:49 -08:00
H.J. Lu
dbca3300ea Remove hosts/mipsbsd.h and scripttempl/mipsbsd.sc
Remove hosts/mipsbsd.h and scripttempl/mipsbsd.sc which are unused
after

commit 3596d8ceb2
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Apr 18 15:39:34 2018 +0930

    Remove mips aout, coff, and pe support

bfd/

	* hosts/mipsbsd.h: Removed.

ld/

	* scripttempl/mipsbsd.sc: Removed.
2024-01-19 07:25:31 -08:00
Oleg Tolmatcev
d544a1dca2 ld: fix 32-bit mingw DLL symbol export bug
I think there's a bug in ld on 32-bit Windows.  Here is a tiny project for reproducing the problem:
https://github.com/oltolm/ld-mingw32-bug

A 32-bit DLL exports two stdcall functions "myfunc" and "myfunc64". The functions would normally get
exported as "myfunc@0" and "myfunc64@0". The "DEF" file exports them as "myfunc" and "myfunc64"
without the decorations. When you run the executable it shows an error message saying that it cannot
find "myfunc64".

I think it happens because the sorting in ld is wrong. I think it should use the exported names
"myfunc" and "myfunc64", but instead it uses the decorated names "myfunc@0" or "myfunc65@0". The
ordering of functions in the DLL is different depending on which names you use.

My patch changes ld to use undecorated exported names for sorting and it seems to fix the problem.
When I execute ctest in my project, it runs successfully.
2024-01-19 15:02:45 +00:00
H.J. Lu
8d10083c23 ld: Put all emulation options in ldlex.h
For each command line option, parse_args() calls ldemul_parse_args()
to check if the command line option is an emulation option.  But when
there is a conflict between the emulation option value and the default
option value, the default command line option will be processed as if
the emulation option is used.  Remove PARSE_AND_LIST_PROLOGUE and move
all emulation options to ldlex.h to avoid conflicts.

	PR ld/31247
	* ldlex.h (option_values): Add all emulation options.
	* emulparams/elf32mcore.sh (PARSE_AND_LIST_PROLOGUE): Removed.
	* emulparams/plt_unwind.sh (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/aarch64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/alphaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/armelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/avrelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/bfin.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/cskyelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/hppaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ia64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/m68hc1xelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/m68kelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/metagelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/mipself.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/nds32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/nto.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ppc32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ppc64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/riscvelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/rxelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/s390.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/scoreelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/spuelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/tic6xdsbt.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/vxworks.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/aix.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	(gld${EMULATION_NAME}_read_file): Replace lineno with linenumber.
	* emultempl/beos.em (OPTION_XXX): Removed.
	* emultempl/elf.em: Include "ldlex.h".
	Don't check PARSE_AND_LIST_PROLOGUE.
	(OPTION_XXX): Removed.
	* emultempl/msp430.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/pe.em (OPTION_XXX): Removed.
	* emultempl/pep.em (OPTION_XXX): Likewise.
	* emultempl/ticoff.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/vms.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/xtensaelf.em (elf32xtensa_size_opt,
	elf32xtensa_no_literal_movement, elf32xtensa_abi): Moved out of
	PARSE_AND_LIST_PROLOGUE.
	(PARSE_AND_LIST_PROLOGUE): Removed.
2024-01-19 05:35:16 -08:00
Nick Clifton
bfdd2ca621 Updated translations for various sub-directories 2024-01-18 11:23:48 +00:00