2
0
mirror of https://sourceware.org/git/binutils-gdb.git synced 2024-12-27 04:52:05 +08:00
Commit Graph

943 Commits

Author SHA1 Message Date
Hakan Candar
f4e363cae2 ld/ELF: Add --image-base command line option to the ELF linker
LLD has dropped the option -Ttext-segment for specifying image base
addresses, instead forcing the use of the --image-base option for both
ELF and PE targets. As it stands, GNU LD and LLVM LLD are incompatible,
having two different options for the same functionality.

This patch enables the use of --image-base on ELF targets, advancing
consistency and compatibility.

See: https://reviews.llvm.org/D70468
     https://maskray.me/blog/2020-11-15-explain-gnu-linker-options#address-related
     https://sourceware.org/bugzilla/show_bug.cgi?id=25207

Moreover, a new test has been added to ensure -z separate-code behaviour
when used with -Ttext-segment stays the same. When this combination is
used, -Ttext-segment sets the address of the first segment (R), not the
text segment (RX), and like with -z noseparate-code, no segments lesser
than the specified address are created. If this behaviour was to change,
the first (R) segment of the ELF file would begin in a lesser address
than the specified text (RX) segment, breaking traditional use of this
option for specifying image base address.
2024-10-29 19:38:39 +10:30
Alan Modra
bc85bc665a Add noxfail option to run_dump_test
The noxfail option is useful in situations like pr23658-1e which
fails on all microblaze ELF targets except microblaze-linux.  This was
possible to handle by writing a small proc and use that as an xfail
predicate, or painstakingly listing all microblaze ELF targets, but
this is simpler.  The patch also fixes some other FAILs and XPASSes of
the pr23658 tests.

binutils/
	* testsuite/lib/binutils-common.exp (run_dump_test): Support
	noxfail.
ld/
	* testsuite/ld-elf/pr23658-1a.d: Don't xfail m68hc12.
	* testsuite/ld-elf/pr23658-1e.d: Likewise.  xfail xstormy16
	and correct microblaze xfails.
2024-10-16 14:54:00 +10:30
Nick Clifton
7ecf0250f7
Improve the placement of orphan note sections.
PR 32219
2024-09-30 14:41:11 +01:00
Alan Modra
428f3561bc Enable -z separate-code, -z common and -z text for more targets
Fix a mis-placed "fi".
2024-09-27 10:02:14 +09:30
H.J. Lu
052940eba6 ld: Ignore .note.gnu.build-id when placing orphaned notes
The commits:

e8e10743f7 Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.
bf6d7087de ld: Move the .note.build-id section to near the start of the memory map

place .note.gnu.build-id before text sections when --rosegment is used.
Ignore .note.gnu.build-id when placing orphaned notes if --rosegment and
-z separate-code are used together to avoid putting any note sections
between .note.gnu.build-id and text sections in the same PT_LOAD segment.

	PR ld/32191
	* ldlang.c (lang_insert_orphan): Ignore .note.gnu.build-id when
	placing orphaned notes.
	* testsuite/ld-elf/pr23658-1a.d: Pass --no-rosegment to ld.
	* testsuite/ld-elf/pr23658-1c.d: Likewise.
	* testsuite/ld-elf/pr23658-1e.d: New file.
	* testsuite/ld-elf/pr23658-1f.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run PR ld/32191 test.
	* testsuite/ld-i386/pr32191.d: New file.
	* testsuite/ld-x86-64/lam-u48.rd: Updated.
	* testsuite/ld-x86-64/lam-u57.rd: Likewise.
	* testsuite/ld-x86-64/pr32191-x32.d: New file.
	* testsuite/ld-x86-64/pr32191.d: Likewise.
	* testsuite/ld-x86-64/pr32191.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/32191 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-26 19:43:08 +08:00
Frank Ch. Eigler
2299dfd4ba ld: support --build-id=xx mode
The is patch adds a new ld build-id computation mode, "xx", using
xxhash in its 128-bit mode.  The patch prereqs the xxhash-devel
headers being installed, and uses the "all-inlined" model, so no
run-time or link-time library dependence exists.

The xxhash mode performs well, saving roughly 20% of total userspace
run time from an ld job over a 800MB shared library relative to sha1.
128 bits of good hash should be collision-resistant to a number of
distinct binaries that numbers in the 2**32 - 2**64 range, even if not
"crypto" level hash.  Confirmations of this are in progress.

         ld/configury: add --with-xxhash mode, different from gdb case
                       because only using it in inline mode

         ld/ldbuildid.c: add "xx" mode, #if WITH_XXHASH

         ld/NEWS, ld.texi: mention new option

         ld/lexsup.c: add enumeration of --build-id STYLES to --help

         ld/testsuite/ld-elf/build-id.exp: add test case for 0xHEX case
                                           and conditional for xx case;
                                           also, simply tcl list syntax

https://inbox.sourceware.org/binutils/20240917201509.GB26396@redhat.com/

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2024-09-24 09:59:42 -04:00
H.J. Lu
ae6a4c3f1d ld: Use --no-rosegment to ld for PR ld/22393 tests
The commit

bf6d7087de ld: Move the .note.build-id section to near the start of the memory map

moves the .note.build-id section before text sections.  When --rosegment
and -z separate-code are used together, the .note.gnu.property section
is placed between the .note.build-id section and text sections in the
same PT_LOAD segment by orphan placement.  Pass --no-rosegment to ld for
PR ld/22393 tests to avoid linker test failures.

	PR ld/32190
	* testsuite/ld-elf/pr22393-2a.rd: Pass --no-rosegment to ld.
	* testsuite/ld-elf/pr22393-2b.rd: Likewise.
	* testsuite/ld-elf/shared.exp: Pass --no-rosegment to ld when
	building pr22393-2 tests.
	* testsuite/ld-x86-64/pr22393-3a.rd: Pass --no-rosegment to ld.
	* testsuite/ld-x86-64/pr22393-3b.rd: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Pass --no-rosegment to ld when
	building pr22393-3 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-21 05:03:18 +08:00
Alan Modra
b93dcd1cdd loongarch ld testsuite xpasses
Some tests started passing with commit 3a83f0342e.  However,
supporting a changed ld output format is not so simple, and the change
to the loongarch_elf_hash_table macro needs further changes to the
rest of the code.  It is true that some uses of
loongarch_elf_hash_table do not need to check the type of the hash
table, but others like loongarch_elf_relax_section do need to check.
bfd_relax_section is called in lang_size_sections using the input bfd,
not the output bfd.  If the input bfd may be of different type to the
output, then the hash table type must be checked before accessing
elements of the hash table.  This patch corrects
loongarch_elf_relax_section.  I haven't checked all the uses of the
hash table throughout the loongarch backend.

bfd/
	* elfnn-loongarch.c (loongarch_elf_relax_section): Don't relax
	unless the hash table is loongarch_elf_link_hash_table.
	Move variable declarations.  Formatting.
ld/
	* testsuite/ld-elf/pr21884.d: Don't xfail loongarach.
	* testsuite/ld-unique/pr21529.d: Likewise.
2024-08-07 09:37:12 +09:30
Alan Modra
79937804a5 Don't trim trailing newline in run_host_cmd
Testcases like ld-elf/pr19719a.c that
    printf ("PASS\n");
on success ought to see the whole output for "string match".
Similarly, the ld-pe/ pdb*.d files shouldn't need to remove the last
newline to match.  For most of the testsuite it doesn't matter whether
the trailing newline is present or not, and there are only a few cases
where we need to remove it.

	* testsuite/lib/ld-lib.exp (run_host_cmd): Don't regsub away
	output trailing newline.  Do string trim for gcc/ld version checks.
	* testsuite/config/default.exp (plug_so): Do string trim output of
	run_host_cmd.
	* testsuite/ld-elf/shared.exp (mix_pic_and_non_pic): Adjust
	string match to include trailing newline.
	* testsuite/ld-i386/i386.exp (undefined_weak): Likewise.
	* testsuite/ld-x86-64/x86-64.exp (undefined_weak): Likewise.
	* testsuite/ld-plugin/libdep.exp (run_test): Likewise.
	* testsuite/ld-plugin/lto.exp (PR ld/28138 run): Likewise.
	* testsuite/ld-pe/pdb-strings.d,
	* testsuite/ld-pe/pdb-syms1-globals.d,
	* testsuite/ld-pe/pdb-syms1-records.d,
	* testsuite/ld-pe/pdb-syms1-symbols1.d,
	* testsuite/ld-pe/pdb-syms1-symbols2.d,
	* testsuite/ld-pe/pdb-syms2-symbols1.d,
	* testsuite/ld-pe/pdb-types1-hashlist.d,
	* testsuite/ld-pe/pdb-types1-skiplist.d,
	* testsuite/ld-pe/pdb-types1-typelist.d,
	* testsuite/ld-pe/pdb-types2-hashlist.d,
	* testsuite/ld-pe/pdb-types2-skiplist.d,
	* testsuite/ld-pe/pdb-types2-typelist.d,
	* testsuite/ld-pe/pdb-types3-hashlist.d,
	* testsuite/ld-pe/pdb-types3-skiplist.d,
	* testsuite/ld-pe/pdb-types3-typelist.d,
	* testsuite/ld-pe/pdb1-publics.d,
	* testsuite/ld-pe/pdb1-sym-record.d,
	* testsuite/ld-pe/pdb2-section-contrib.d,
	* testsuite/ld-pe/pdb3-c13-info1.d,
	* testsuite/ld-pe/pdb3-c13-info2.d,
	* testsuite/ld-pe/pdb3-source-info.d: Add trailing newline.
2024-07-22 08:08:18 +09:30
Lulu Cai
7478277414 LoongArch: Fix dwarf3 test cases from XPASS to PASS
In the past, the .align directive generated a label that did not match
the regular expression, and we set it to XFAIL.
But now it matches fine so it becomes XPASS. We fix it with PASS.
2024-07-13 10:00:02 +08:00
H.J. Lu
2539602136 ld: Move foo before delete in dl5.cc
* testsuite/ld-elf/dl5.cc (main): Move foo before delete.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-07-01 02:22:45 -07:00
H.J. Lu
adf584eb92 ld: Avoid folding new and delete pairs
GCC 15 may fold new and delete pairs, like

  A *bb = new A[10];
  delete [] bb;
  bb = new (std::nothrow) A [10];
  delete [] bb;

as shown in

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

Avoid folding new and delete pairs by adding a function call between new
and delete.

	* testsuite/ld-elf/dl5.cc: Include "dl5.h".
	(A): Removed.
	Call foo between new and delete.
	* testsuite/ld-elf/dl5.h: New file.
	* testsuite/ld-elf/new.cc: Include "dl5.h".
	(foo): New function.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-06-30 15:43:58 -07:00
Sam James
17c78a2349
ld: pass -g for ld-elf tests
The "DWARF parse during linker error" and "Build warn libbar.so" tests
require debug information.

configure defaults to "-O2 -g" but if overriding *FLAGS when building
tests, this might be lost. Explicitly pass -g given these tests require
it.

Originally reported downstream in Gentoo at https://bugs.gentoo.org/934149.

ld/
	* testsuite/ld-elf/dwarf.exp: Pass -g for "DWARF parse during linker error".
	* testsuite/ld-elf/shared.exp: Ditto for "Build warn libbar.so".
2024-06-29 17:13:14 +01:00
Nick Clifton
54904469f7 Adjust linker tests that are sensitive to --rosegment 2024-06-13 17:00:29 +01:00
Nick Clifton
e8e10743f7 Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.
PR 30907
2024-06-13 15:10:15 +01:00
H.J. Lu
1509f0c231 ld: Add PR ld/31710 tests
PR ld/31710
	* testsuite/ld-elf/wrap.exp: Run ld/31710 tests.
	* testsuite/ld-elf/wrap2.h: New file.
	* testsuite/ld-elf/wrap2a.c: Likewise.
	* testsuite/ld-elf/wrap2b.c: Likewise.
2024-05-08 07:01:24 -07:00
H.J. Lu
1dfd6a2f93 ld: Run --wrap tests only if supported
Run --wrap tests with shared library only if -shared is supported.

	* testsuite/ld-elf/wrap.exp: Run --wrap tests with shared library
	only if -shared is supported.
2024-05-08 07:00:49 -07:00
Nick Clifton
3b3e209011 Update readelf's display of RELR sections to include the number of locations relocated 2024-04-24 12:45:04 +01:00
Alan Modra
ef1c830f00 ignore some symbols in elf.c:swap_out_syms
The reason behind this patch was noticing that generic ELF targets
fail to remove "bar" in the recently committed ld-elf/undefweak-1
test.  (Despite that, those targets pass the test due to it being too
strict when matching symbols.  "bar" gets turned into a local weak
defined absolute symbol.)

swap_out_syms currently drops local section syms that are defined in
discarded sections.  Extend that to also drop other symbols in
discarded sections too, even global symbols.  The linker goes to quite
a lot of effort to ensure globals in discarded section take a
definition from the kept linkonce or comdat group section.  So the
global sym change should only affect cases where something is quite
wrong about the set of linkonce or comdat group sections.  However
that change to elf_map_symbols meant we dropped _DYNAMIC_LINK /
_DYNAMIC_LINKING for mips, a global absolute symbol given STT_SECTION
type for some reason.  That problem is fixed by reverting the pr14493
change which is no longer needed due to a) BSF_SECTION_SYM_USED on
x86, and b) fixing objcopy to use copy_private_symbol_data.

bfd/
	PR 14493
	* elf.c (ignore_sym): Rename from ignore_section_sym.  Return
	true for any symbol without a section or in a discarded section.
	Revert pr14493 change.
	(elf_map_symbols): Tidy.  Use ignore_sym on all symbols.
	(swap_out_syms): Tidy.
ld/
	* testsuite/ld-elf/undefweak-1.rd: Match any "bar".
2024-04-23 22:07:00 +09:30
Alan Modra
6197c6f3a6 xfail undefweak-1 test for alpha
".set" has a different meaning on alpha.  Changing it to ".equ" runs
into ".equ" having a different meaning on hppa, and changing it to "="
runs into trouble on bfin.

	* testsuite/ld-elf/elf.exp (undefweak-1): xfail on alpha,
	don't xfail for genelf.
2024-04-23 22:06:41 +09:30
mengqinggang
20eee7540b LoongArch: Add -mignore-start-align option
Ignore .align at the start of a section may result in misalignment when
partial linking. Manually add -mignore-start-align option without partial
linking.

Gcc -falign-functions add .align 5 to the start of a section, it causes some
error message mismatch. Set these testcases to xfail on LoongArch target.
2024-04-20 12:10:40 +08:00
H.J. Lu
eebad48efe elf: Strip unreferenced weak undefined symbols
Linker will resolve an undefined symbol only if it is referenced by
relocation.  Unreferenced weak undefined symbols serve no purpose.
Weak undefined symbols appear in the dynamic symbol table only when they
are referenced by dynamic relocation.  Mark symbols with relocation and
strip undefined weak symbols if they don't have relocation and aren't
in the dynamic symbol table.

bfd/

	PR ld/31652
	* elf-bfd.h (elf_link_hash_entry): Add has_reloc.
	* elf-vxworks.c (elf_vxworks_emit_relocs): Set has_reloc.
	* elflink.c (_bfd_elf_link_output_relocs): Likewise.
	(elf_link_output_extsym): Strip undefined weak symbols if they
	don't have relocation and aren't in the dynamic symbol table.

ld/

	PR ld/31652
	* testsuite/ld-elf/elf.exp: Run undefweak tests.
	* testsuite/ld-elf/undefweak-1.rd: New file.
	* testsuite/ld-elf/undefweak-1a.s: Likewise.
	* testsuite/ld-elf/undefweak-1b.s: Likewise.
	* testsuite/ld-x86-64/weakundef-1.nd: Likewise.
	* testsuite/ld-x86-64/weakundef-1a.s: Likewise.
	* testsuite/ld-x86-64/weakundef-1b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run undefweak tests.
2024-04-18 19:17:17 -07:00
Fangrui Song
21061c384c Simplify readelf's RELR relocation display. 2024-04-16 13:17:35 +01:00
Nick Clifton
fcf8f3237c Improve readelf's display of RELR relocs. 2024-04-11 16:57:18 +01: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
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
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
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
H.J. Lu
c9eb960580 ld: Adjust x86 and x86-64 tests for -z mark-plt
To support -z mark-plt enabled by default, adjust x86 tests to accept
non-zero r_addend for JUMP_SLOT relocation and pass -z nomark-plt to
x86-64 tests if -z mark-plt changes the expected outputs.

	* testsuite/ld-elf/indirect-extern-access-2.rd: Allow non-zero
	r_addend for JUMP_SLOT relocation.
	* testsuite/ld-elf/pr23161d.rd: Likewise.
	* testsuite/ld-ifunc/ifunc-25c-x86.d: Likewise.
	* testsuite/ld-ifunc/ifunc-16-x86-64-now.d: Pass -z nomark-plt
	to linker.
	* testsuite/ld-ifunc/ifunc-16-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-local-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/ifunc-2-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-20-x86-64.d: Likewise.
	* testsuite/ld-ifunc/ifunc-5b-x86-64.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64-now.d: Likewise.
	* testsuite/ld-ifunc/pr17154-x86-64.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1a-x32.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1a.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1b-x32.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2d.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2e.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2f.d: Likewise.
	* testsuite/ld-x86-64/pr19636-2l.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Pass -z nomark-plt to linker
	in 6 tests.
2024-01-06 07:10:15 -08:00
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
mengqinggang
c3d507aba3 LoongArch: Add support for the third expression of .align for R_LARCH_ALIGN
If the symbol index is not zero, the addend is used to represent
the first and the third expressions of the .align.

The lowest 8 bits are used to represent the first expression.
Other bits are used to represent the third expression.

The addend of R_LARCH_ALIGN for ".align 5, ,4" is 0x405.
The addend of R_LARCH_ALIGN for ".balign 32, ,4" is 0x405.
2023-12-22 14:20:18 +08:00
Nick Clifton
e922d1eaa3 Add ability to change linker warning messages into errors when reporting executable stacks and/or executable segments.
include
  * bfdlink.h (struct bfd_link_info): Update descriptions of the 'execstack', 'noexecstack' and 'warn_execstack' fields. Add 'error_exectack' and 'warn_is_error_for_rwx_segments' fields.

  bfd
  * elf.c (assign_file_positions_except_relocs): Turn warnings about executable segments into errors if so requested.
  * elflink.c (bfd_elf_size_dynamic_sections): Turn warnings about executable stacks into errors if so requested.

  ld
  * ldlex.h (enum option_values): Add OPTION_ERROR_EXECSTACK, OPTION_NO_ERROR_EXECSTACK, OPTION_WARN_EXECSTACK_OBJECTS, OPTION_ERROR_RWX_SEGMENTS and OPTION_NO_ERROR_RWX_SEGMENTS. (struct ld_option): Add new long options. (parse_args): Parse new long options. (elf_static_list_options): Display the new options.
  * ld.texi: Document the new command line options.
  * configure.ac (error-execstack): New configuration option. (error-rwx-segments): New configuration option.
  * emultempl/elf.em (_before_parse): Initialse the new linkinfo fields.
  * NEWS: Mention the new features.
  * config.in: Regenerate.
  * configure: Regenerate.
  * testsuite/ld-elf/commonpage2.d: Disable errors for RWX segments and/or executable stacks.
  * testsuite/ld-elf/elf.exp: Likewise.
  * testsuite/ld-elf/header.d: Likewise.
  * testsuite/ld-elf/loadaddr1.d: Likewise.
  * testsuite/ld-elf/loadaddr2.d: Likewise.
  * testsuite/ld-elf/maxpage4.d: Likewise.
  * testsuite/ld-elf/nobits-1.d: Likewise.
  * testsuite/ld-elf/note-1.d: Likewise.
  * testsuite/ld-elf/orphan-10.d: Likewise.
  * testsuite/ld-elf/orphan-11.d: Likewise.
  * testsuite/ld-elf/orphan-12.d: Likewise.
  * testsuite/ld-elf/orphan-5.d: Likewise.
  * testsuite/ld-elf/orphan-7.d: Likewise.
  * testsuite/ld-elf/orphan-8.d: Likewise.
  * testsuite/ld-elf/orphan-9.d: Likewise.
  * testsuite/ld-elf/orphan-region.d: Likewise.
  * testsuite/ld-elf/orphan.d: Likewise.
  * testsuite/ld-elf/pr19539.d: Likewise.
  * testsuite/ld-elf/pr26256-1a.d: Likewise.
  * testsuite/ld-elf/pr26907.d: Likewise.
  * testsuite/ld-elf/pr28597.d: Likewise.
  * testsuite/ld-elf/retain2.d: Likewise.
  * testsuite/ld-elf/shared.exp: Likewise.
  * testsuite/ld-elf/size-1.d: Likewise.
  * testsuite/ld-elf/textaddr7.d: Likewise.
  * testsuite/ld-elf/warn1.d: Likewise.
  * testsuite/ld-elf/warn2.d: Likewise.
  * testsuite/ld-i386/discarded1.d: Likewise.
  * testsuite/ld-i386/pr19175.d: Likewise.
  * testsuite/ld-i386/pr19539.d: Likewise.
  * testsuite/ld-i386/pr23189.d: Likewise.
  * testsuite/ld-plugin/lto-3r.d: Likewise.
  * testsuite/ld-plugin/lto-5r.d: Likewise.
  * testsuite/ld-plugin/lto.exp: Likewise.
  * testsuite/ld-powerpc/ppc476-shared.d: Likewise.
  * testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
  * testsuite/ld-powerpc/pr28827-2.d: Likewise.
  * testsuite/ld-s390/s390.exp: Likewise.
  * testsuite/ld-scripts/align2a.d: Likewise.
  * testsuite/ld-scripts/align2b.d: Likewise.
  * testsuite/ld-scripts/align5.d: Likewise.
  * testsuite/ld-scripts/alignof.exp: Likewise.
  * testsuite/ld-scripts/crossref.exp: Likewise.
  * testsuite/ld-scripts/defined2.d: Likewise.
  * testsuite/ld-scripts/defined3.d: Likewise.
  * testsuite/ld-scripts/defined5.d: Likewise.
  * testsuite/ld-scripts/pr14962.d: Likewise.
  * testsuite/ld-scripts/pr18963.d: Likewise.
  * testsuite/ld-scripts/pr20302.d: Likewise.
  * testsuite/ld-scripts/print-memory-usage.exp: Likewise.
  * testsuite/ld-scripts/rgn-at1.d: Likewise.
  * testsuite/ld-scripts/rgn-at10.d: Likewise.
  * testsuite/ld-scripts/rgn-at4.d: Likewise.
  * testsuite/ld-scripts/rgn-at6.d: Likewise.
  * testsuite/ld-scripts/rgn-at8.d: Likewise.
  * testsuite/ld-scripts/rgn-at9.d: Likewise.
  * testsuite/ld-scripts/rgn-over1.d: Likewise.
  * testsuite/ld-scripts/rgn-over2.d: Likewise.
  * testsuite/ld-scripts/rgn-over4.d: Likewise.
  * testsuite/ld-scripts/rgn-over5.d: Likewise.
  * testsuite/ld-scripts/rgn-over6.d: Likewise.
  * testsuite/ld-scripts/script.exp: Likewise.
  * testsuite/ld-scripts/sizeof.exp: Likewise.
  * testsuite/ld-scripts/sort-file.d: Likewise.
  * testsuite/ld-x86-64/discarded1.d: Likewise.
  * testsuite/ld-x86-64/pr19175.d: Likewise.
  * testsuite/ld-x86-64/pr19539a.d: Likewise.
  * testsuite/ld-x86-64/pr19539b.d: Likewise.
  * testsuite/ld-x86-64/pr23189.d: Likewise.
2023-11-10 11:37:27 +00:00
A. Wilcox
1499719e6d Fix: ld: Test case pr28158 fails on x86_64-linux-musl when index is > 19
PR 30905
  * testsuite/ld-elf/pr28158.rd: Adjust regexp to allow for section indicies larger than 9.
2023-10-05 15:05:15 +01:00
A. Wilcox
8838ac1c9e Fix: ld testsuite: glibc-specific DT_RELR tests should not be run on musl systems
PR 30917
  * testsuite/ld-elf/dt-relr.exp: Skip for MUSL targets.
2023-10-05 14:26:32 +01:00
Andreas Schwab
7345d05aaf RISC-V: Protect .got with relro
Move .got before .data so that it can be protected with -zrelro.  Also
separate .got.plt from .got if -znow is not in effect; the first two words
of .got.plt are placed within the relro region.

ld:
	PR ld/30877
	* emulparams/elf32lriscv-defs.sh (DATA_GOT, SEPARATE_GOTPLT):
	Define.
	* emulparams/elf64lriscv-defs.sh (SEPARATE_GOTPLT): Define.
	* testsuite/ld-elf/binutils.exp (binutils_test): Remove riscv*-*-*
	from relro_got expression.
2023-09-25 12:36:58 +02:00
H.J. Lu
12123021f1 elf: Adjust PR ld/30791 tests
Adjust PR ld/30791 tests:

1. Generic linker targets don't comply with all orhpan section merging
rules.
2. z80 fails since a, b, c, d are registers for z80.
3. hppa fails since .text sections aren't merged for relocatable link.

	PR ld/30791
	* testsuite/ld-elf/pr30791a.d: Xfail for generic and z80
	targets.
	* testsuite/ld-elf/pr30791b.d: Xfail for hppa and z80 targets.
2023-08-31 16:21:17 -07:00
H.J. Lu
68a2d9bf87 elf: Don't merge sections with different SHF_LINK_ORDER
For relocatable link, don't merge 2 SHF_LINK_ORDER sections if output
sections of their linked to sections are different.

	* ldelf.c (elf_orphan_compatible): Don't merge sections with
	different SHF_LINK_ORDER.
	* testsuite/ld-elf/pr30791a.d: New file.
	* testsuite/ld-elf/pr30791a.s: Likewise.
	* testsuite/ld-elf/pr30791b.d: Likewise.
	* testsuite/ld-elf/pr30791b.s: Likewise.
	* testsuite/ld-elf/pr30791c.s: Likewise.
	* testsuite/ld-elf/pr30791d.s: Likewise.
2023-08-30 17:17:31 -07:00
Paul Iannetta
6e712424f5 kvx: New port. 2023-08-16 14:22:54 +01:00
Sam James
3b23a5ea69
ld: fix relocatable, retain7a target pattens for HPPA
Fix issue reported by Dave and Alan.

Put back the old pattern for hppa-*-linux* and add hppa[12]*-*-linux* to cover
Gentoo's hppa1.1 and hppa2.0 without including hppa64 inadvertently like I did
before.

ld/
	PR 30733
	PR 30734
	* ld/testsuite/ld-elf/relocatable.d: Use better pattern to exclude hppa64
          but include hppa1.1, hppa2.0.
	* ld/testsuite/ld-elf/retain7a.d: Ditto.

Fixes: 0e339f6b4f
Fixes: e3b6618719
Signed-off-by: Sam James <sam@gentoo.org>
2023-08-14 04:32:33 +01:00
Sam James
e3b6618719 ld: Fix retain7a.d XFAIL/notarget entry for hppa
PR 30733
* ld/testsuite/ld-elf/retain7a.d: Fix XFAIL entry for hppa to match
  hppa{1.1,2.0}*, like hppa2.0-unknown-linux-gnu which Gentoo uses.

Signed-off-by: Sam James <sam@gentoo.org>
2023-08-08 18:48:44 +01:00
Sam James
0e339f6b4f ld: Fix relocatable.d XFAIL/notarget entry for hppa
PR 30734
* ld/testsuite/ld-elf/relocatable.d: Fix notarget entry for hppa to match
  hppa{1.1,2.0}*, like hppa2.0-unknown-linux-gnu which Gentoo uses.

Signed-off-by: Sam James <sam@gentoo.org>
2023-08-08 18:48:44 +01:00
Sam James
b5c37946cc Revert "2.41 Release sources"
This reverts commit 675b9d612c.

See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-02 12:06:23 +01:00
Nick Clifton
675b9d612c 2.41 Release sources 2023-08-02 09:23:36 +01:00
YunQiang Su
60ec8306db testsuite: Also discard the `.MIPS.options' section
Also discard the `.MIPS.options' section, used with n64 MIPS binaries,
along with similar other MIPS sections (`.reginfo', `.MIPS.abiflags')
not relevant for the test cases concerned, fixing these regressions:

mips64-openbsd  -FAIL: ld-elf/group3a
mips64-openbsd  -FAIL: ld-elf/group3b
mips64-openbsd  -FAIL: Place orphan sections (map file check)
mips64-openbsd  -FAIL: ld-elf/orphan-region
mips64-openbsd  -FAIL: ld-elf/orphan
mips64-openbsd  -FAIL: overlay size (map file check)
mips64-openbsd  -FAIL: overlay size
mips64el-openbsd  -FAIL: ld-elf/group3a
mips64el-openbsd  -FAIL: ld-elf/group3b
mips64el-openbsd  -FAIL: Place orphan sections (map file check)
mips64el-openbsd  -FAIL: ld-elf/orphan-region
mips64el-openbsd  -FAIL: ld-elf/orphan
mips64el-openbsd  -FAIL: overlay size (map file check)
mips64el-openbsd  -FAIL: overlay size

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>

	binutils/
	* testsuite/binutils-all/strip-3.d: Add `-R .MIPS.options' to
	the `strip' tag.

	ld/
	* testsuite/ld-elf/group.ld: Also discard `.MIPS.options'.
	* testsuite/ld-elf/orphan-region.ld: Likewise.
	* testsuite/ld-elf/orphan.ld: Likewise.
	* testsuite/ld-mips-elf/got-page-1.ld: Likewise.
	* testsuite/ld-scripts/overlay-size.t: Likewise.
2023-07-28 06:00:36 +01:00
Alan Modra
2902e6682d /DISCARD/ in ld testsuite
The canonical form to discard all sections not mentioned earlier in
the script is
  /DISCARD/ : { *(*) }
not
  /DISCARD/ : { *(.*) }
".*" happens to work with the usual section names starting with a dot,
but let's not promote something not quite right.
2023-07-27 23:38:14 +09:30
Alan Modra
02d2a36902 PR10957, Missing option to really print section+offset
Many of the reloc error messages have already been converted from
using %C to using %H in ld.bfd, to print section+offset as well as
file/line/function.  This catches a few remaining, and changes gold to
do the same.

	PR 10957
bfd/
	* elf32-sh.c (sh_elf_relocate_section): Use %H in error messages.
gold/
	* object.cc (Relocate_info::location): Always report section+offset.
	* testsuite/debug_msg.sh: Adjust to suit.
	* testsuite/x32_overflow_pc32.sh: Likewise.
	* testsuite/x86_64_overflow_pc32.sh: Likewise.
ld/
	* emultempl/pe.em (read_addend): Use %H in error message.
	* emultempl/pep.em (read_addend): Likewise.
	* ldcref.c (check_reloc_refs): Likewise.
	* ldmain.c (warning_find_reloc, undefined_symbol): Likewise.
	* pe-dll.c (pe_create_import_fixup): Likewise.
	* testsuite/ld-cris/undef2.d: Adjust expected output to suit.
	* testsuite/ld-cris/undef3.d: Likewise.
	* testsuite/ld-elf/shared.exp: Likewise.
	* testsuite/ld-i386/compressed1.d: Likewise.
	* testsuite/ld-ia64/line.exp: Likewise.
	* testsuite/ld-plugin/lto.exp: Likewise.
	* testsuite/ld-undefined/undefined.exp: Likewise.
	* testsuite/ld-x86-64/compressed1.d: Likewise.
	* testsuite/ld-x86-64/line.exp: Likewise.
	* testsuite/ld-x86-64/pr27587.err: Likewise.
2023-07-17 08:17:44 +09:30
Alan Modra
46f51ac38b Use run_host_cmd to run $CC and other no-section-header test fixes
We should be using run_host_cmd everywhere we invoke a compiler in the
ld testsuite, if we want to use ld/ld-new just built.  run_host_cmd
properly inserts $gcc_B_opt in cases where a user wants to test
binutils with a newly built compiler, ie. when $CC specifies -B itself.

Also, it is not good practice to exclude tests when non-native except
of course those tests that run a target binary.  Compiling and linking
often shows up problems.

	* testsuite/ld-elf/no-section-header.exp (binutils_run_test):
	Use run_host_cmd to invoke $CC_FOR_TARGET.  Run all tests
	non-native too, except for attempting to run the binaries.
	Run tests for ELF in general, not just linux.
	* testsuite/ld-elf/pr25617-1-no-sec-hdr.rd: Allow localentry
	symbol decoration, and support either sorting of symbols.
	* testsuite/ld-elf/pr25617-1a-no-sec-hdr.rd: Likewise.
	* testsuite/ld-elf/pr25617-1a-sec-hdr.rd: Likewise.
	* testsuite/ld-elf/pr25617-1a-no-sec-hdr.nd: Accept D function syms.
	* testsuite/ld-elf/start-shared-noheader-sysv.rd: Accept
	mips-sgi-irix symbol output.
	* testsuite/ld-elf/start-shared-noheader.nd: Likewise.
2023-07-06 10:39:40 +09:30
YunQiang Su
0f5cb49f68 ld: Use run_host_cmd_yesno in indirect.exp instead of catch exec
Catch "exec $CC_FOR_TARGET" won't use the gas/ld that we just build,
and in fact run_host_cmd_yesno is a better choice for it.

ld/ChangeLog:

	* testsuite/ld-elf/indirect.exp: use run_host_cmd_yesno
	instead of handwrite catch exec $CC_FOR_TARGET.
2023-07-06 09:04:53 +08:00
YunQiang Su
96a73f2cb2 ld: Use [list ] syntax to define run_tests in indirect.exp
Currently, the var run_tests is defined by syntax {{}},
while in this case, variables cannot be used.
Thus $NOPIE_CFLAGS and $NOPIE_LDFLAGS are passed to cmd as names
instead of values:
  gcc ... $NOPIE_CFLAGS -c .../indirect5a.c -o tmpdir/indirect5a.o

Let's use [list [list ]] syntax instead.

ld/ChangeLog:

	* testsuite/ld-elf/indirect.exp(run_tests): use [list [list]]
	syntax instead of {{}}.
2023-07-06 09:04:23 +08:00