Commit 8bf4b69718 ("LoongArch: Fix relaxation alignment with ld -r (PR
33236)") has broken the kernel modules on Debian sid. The expectation
of the kernel is all the source files which would be linked into a
module are compiled with -mno-relax so the module should not contain
R_LARCH_ALIGN, thus the module loader rejects any module containing
R_LARCH_ALIGN.
To restore the correctness of the expectation, only insert the align
section if an input has R_LARCH_ALIGN or R_LARCH_ALIGN (i.e. bytes may
be removed from that input). Regardless of the kernel modules, it also
does not make too much sense to bloat the output with NOPs and
R_LARCH_ALIGN if no input ever contains R_LARCH_ALIGN and R_LARCH_ALIGN
anyway.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
H8/300H uses 32-bit addresses in its default advanced mode, whereas
H8/300 uses 16-bit addresses. Updates affected test cases accordingly.
bfd/
* cpu-h8300.c: Set H8/300H as the default architecture
for the H8 family.
gas/
* config/tc-h8300.c: Set H8/300H as the default architecture
for the H8 family.
* NEWS: Add info about the above change.
ld/
* configure.tgt: Set H8/300H as the default architecture
for the H8 family.
* NEWS: Add info about the above change.
* testsuite/ld-elf/elf.exp: Expect 32-bit addresses/pointers
for H8 on __patchable_function_entries tests.
Signed-off-by: Jan Dubiec <jdx@o2.pl>
Simplify R_LARCH_TLS_DTPREL32/64 relocations processing.
Return the offset to TLS block for symbol.
Change R_LARCH_TLS_DTPREL32/64 partial_inplace to false since
LoongArch uses RELA relocations.
Mark the frag and section to indicate if they have a relaxed instruction.
For label subtraction, if there are no relaxed instructions between addsy
and subsy, do not emit relocations.
The linker validates the arch of each input when parsing it, but never
checks the merged arch as a whole, so conflicting extensions could
silently slip through. The merge can even imply extensions that
neither input implies alone, e.g. `c' from one input and `d' from
another imply `zcd', which conflicts with `zcmp'.
After merging the input archs, add the implicit extensions to the
merged arch, then run the conflict checks on it and reject the merge
if any conflict is found. Add tests for such merges.
LoongArch has the same issue as RISC-V for PR 33236 [1].
Section alignment can't be adjusted for objects generated by ld -r.
If previous sections are relaxed, the subsequent section maybe misaligned.
To fix this, add an align section and an align relocation before each
section when ld -r. And change the section alignment to 4 to disable
the default section start address calculation.
ld.lld has fixed this issue in the following two patches [2] [3].
[1] https://sourceware.org/bugzilla/show_bug.cgi?id=33236
[2] https://github.com/llvm/llvm-project/pull/151639
[3] https://github.com/llvm/llvm-project/pull/198147
When linking multiple objects, relaxation can cause alignment issues.
Input section's output_offset is updated in relaxation without considering
alignment. Update section output_offset by align_opwer.
Count DT_RELR relocations using dynamic tags when section header isn't
used. Ignore section sh_offset and sh_size if they are larger than file
size.
One side effect is that we now display
readelf: Warning: Ignore the out of range sh_offset value of 2199023261148 for section 17
readelf: Warning: Ignore the out of range sh_size value of 13 for section 17 with sh_offset value of 2199023261148
...
[17] .fini PROGBITS 00000000000015dc 000000 000000 00 AX 0 0 4
...
instead of
...
[17] .fini PROGBITS 00000000000015dc 200000015dc 00000d 00 AX 0 0 4
...
and segfault.
binutils/
PR binutils/34326
PR binutils/34339
* readelf.c (update_all_relocations): Skip if nentries == 0.
(validate_section_info): New.
(get_32bit_section_headers): Call validate_section_info.
(get_64bit_section_headers): Likewise.
(process_relocs): Call count_relr_relocations for relocations
from dynamic tags. Skip if values in DT_RELENT/DT_RELAENT
are larger than values in DT_RELSZ/DT_RELASZ.
(process_got_section_contents): Skip if all_relocations_count
== 0.
ld/
PR binutils/34339
* testsuite/ld-x86-64/binutils.exp: Run PR binutils/34339 tests.
* testsuite/ld-x86-64/got-2.s: New file.
* testsuite/ld-x86-64/libgot-2.rd: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This converts the existing to code to use "remote_load" allowing
execution on both native and remote targets.
The "diff" between the output and the expected result has been
transformed to the usual regexp_diff. The previous could have been
transformed into `remote_exec build diff` but tends to be fickled with
new lines.
Add tests covering the full matrix of weak/strong symbol interactions
for PE COFF weak externals, based on testcases by Martin Storsjo.
The archive test covers PE weak externals whose public name is backed
by a real fallback definition, and ensures weak declarations with the
null fallback are not advertised as archive providers.
ld/testsuite/
* ld-pe/pe-compile.exp (weak_ext_test): New proc. Compiles
source files, links via gcc, and runs natively if possible.
(weak_ext_archive_test): New proc.
Add tests: normal, weak-undef, weak-defined,
weak-decl-weak-def, strong-undef-weak-def-archive, weak-use,
weak-override, weak-duplicate, weak-def-override, weak-def-use.
* ld-pe/weak-ext-main.c: New file.
* ld-pe/weak-ext-main-weak.c: New file.
* ld-pe/weak-ext-main-weak-def.c: New file.
* ld-pe/weak-ext-add2.c: New file.
* ld-pe/weak-ext-add1-weak-chained.c: New file.
* ld-pe/weak-ext-dummy.c: New file.
* ld-pe/weak-ext-expected1.c: New file.
* ld-pe/weak-ext-expected3.c: New file.
* ld-pe/weak-ext-expected5.c: New file.
* ld-pe/weak-ext-expected3-add1-weak.c: New file.
This is how alpha can use -Ttext-segment on just those tests that need
it. And since the way run_dump_test uses $opts(ld) allows tcl procs to
be embedded, there is no need to specially expand [big_or_little_endian].
binutils/
* testsuite/lib/binutils-common.exp (run_dump_test <opts(ld)>): No
need to handle big_or_little_endian specially.
ld/
* testsuite/ld-elf/elf.exp (alpha_ld_flags): New proc.
(LDFLAGS): Don't set -Ttext-segment for alpha globally.
* testsuite/ld-elf/compress1a.d: Add alpha_ld_flags.
* testsuite/ld-elf/compressed1a.d: Likewise.
* testsuite/ld-elf/eh5.d: Likewise.
When generating Position Dependent Executable for ELF with the maximum
page size set on command-line, set the default image base address to the
maximum page size to avoid segfault if it is lower than the maximum page
size and issue an warning if the image base address set on command-line
is lower than the maximum page size.
PR ld/34184
* ldexp.c (fold_binary): Set the default image base address to
the maximum page size for ELF PDE output if it is lower than
the maximum page size set on command-line and issue an warning
if the image base address set on command-line is lower than the
maximum page size.
* testsuite/ld-elf/elf.exp: Add ld/34184 tests for PDE, PIE
static PDE and static PIE.
* testsuite/ld-elf/pr34184.c: New file.
* testsuite/ld-elf/textaddr3.d: Change -Ttext-segment address
to 0x200100 so that it > the maximum page size.
* testsuite/ld-elf/textaddr5.d: Likewise.
* testsuite/ld-elf/textaddr8.d: New test.
* testsuite/ld-elf/textaddr9.d: Likewise.
* testsuite/ld-elf/textaddr10.d: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
After the removal of all Solaris configurations but Solaris 10/11
(*-*-solaris2.1[01]), the 32-bit-only configurations can no longer be
matched. This patch removes them.
Tested on {amd64,i386}-pc-solaris2.11 and sparc{v9,}-sun-solaris2.11.
2026-06-28 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
bfd:
* config.bfd <i[3-7]86-*-solaris*>: Remove.
<sparc*-*-solaris*>: Likewise.
ld:
* configure.tgt <i[3-7]86-*-solaris*>: Remove.
<sparc*-*-solaris*>: Likewise.
Remove $options in readelf log since it isn't passed to readelf.
* testsuite/ld-elf/linux-x86.exp (elfedit_test): Remove $options
in readelf log.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
In the source code extracted from glibc:
extern void _dl_sysinfo_int80 (void)
__attribute__ ((visibility ("hidden")));
asm (".text\n\t"
".type _dl_sysinfo_int80,@function\n"
"_dl_sysinfo_int80:\n\t"
"int $0x80;\n\t"
"ret");
uintptr_t
foo ()
{
return (uintptr_t) _dl_sysinfo_int80;
}
_dl_sysinfo_int80 is a local function, but it is defined in an asm
statement. Since it is referenced in C, it is declared as hidden,
which leads to an assembler warning:
Warning: local symbol `_dl_sysinfo_int80' has non-default visibility
Symbol binding and visiblity are orthogonal. One is for link-editing,
the other for runtime linking. In principle, all combinations are "okay"
(if questionable), and have obvious implementations. But it's only that
specific combination STB_LOCAL+STV_PROTECTED that is explicitely made
ill-formed in the spec (despite it being also obviously implementable).
Warning on that combination can be done on the grounds of following the
spec. But no other combination is so spelled out, so there's no basis
for trying to disallow them.
Partially revert:
commit c4150acbda
Author: Jan Beulich <jbeulich@suse.com>
Date: Fri May 8 11:45:04 2026 +0200
gas/ELF: warn upon non-default visibility of local symbols
and update elf_adjust_symtab to only warn local symbol with protected
visibility.
binutils/
PR gas/34312
* testsuite/binutils-all/localize-hidden-1.l: Adjusted.
* testsuite/binutils-all/nm-ver.s: Revert commit c4150acbda.
gas/
PR gas/34312
* config/obj-elf.c (elf_adjust_symtab): Allow local symbol with
non-protected visibility.
* testsuite/gas/elf/visibility.l: Adjusted.
* testsuite/gas/i386/tlsnopic.s: Revert commit c4150acbda.
ld/
PR gas/34312
* testsuite/ld-aarch64/ifunc-21.s: Revert commit c4150acbda.
* testsuite/ld-aarch64/ifunc-21.s: Likewise.
* testsuite/ld-tic6x/shlib-1.rd: Likewise.
* testsuite/ld-tic6x/shlib-1.s: Likewise.
* testsuite/ld-tic6x/shlib-1b.rd: Likewise.
* testsuite/ld-tic6x/shlib-1r.dd: Likewise.
* testsuite/ld-tic6x/shlib-1r.rd: Likewise.
* testsuite/ld-tic6x/shlib-1rb.dd: Likewise.
* testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
* testsuite/ld-tic6x/static-app-1.rd: Likewise.
* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
* testsuite/ld-tic6x/static-app-1r.dd: Likewise.
* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
* testsuite/ld-tic6x/static-app-1rb.dd: Likewise.
* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This patch adds pattern rules for .gnu.linkonce.t* and .gnu.linkone.b*
to the .text resp. .bss output sections. Though that's probably
not needed any more since G++ is using COMDAT today.
.gnu.linkonce.d* for .data and .gnu.linkone.r* for .rodata are
already there.
PR ld/17107
ld/
* scripttempl/avr.sc (.bss) [RELOCATING]: Add *(.gnu.linkonce.b*).
(.text) [RELOCATING]: Add *(.gnu.linkonce.t*).
PR ld/25754 tests verify that relocations against absolute symbol are
properly handled, using 42 as the absolute symbol value. But GCC 17
treats 42 as the impossible symbol address, which is the absolute symbol
value and optimize out the symbol address check:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125869
Use 0x10000, instead of 42, as absolute symbol value to work with GCC 17.
PR ld/34298
* testsuite/ld-elf/pr25754-1a.c (main): Check against 0x10000
instead of 42.
* testsuite/ld-elf/pr25754-1b.s (bar): Replace 42 with 0x10000.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Apparently some libraries (Qt5 is called out in PR 29655) want to know
if one of their functions has been overridden, and do so by comparing
the address of the function with the address of a local hidden alias.
This is a bug in every such library that tries that trick, because if
the main program is non-PIC and calls the function in question then
the globally visible address of the function is set to the PLT call
stub code for that function in the main executable. This will happen
even when there is no real overriding of the function.
On the other hand if the main executable is PIC then there should be
no need to define function addresses on PLT call stub code, but some
linker target support still does so. This is a minor bug in the
linker as it results in more work in ld.so and sligntly slower
startup. However, I don't think it is an important issue if target
maintainers can't fix the problem.
* testsuite/ld-elf/shared.exp (pr29655): xfail more targets.
As described in PR ld/34151, the recent "Build pr29655" test FAILs on
SPARC, both Solaris and Linux.
Until this is fixed, this patch xfail's the test.
Tested on sparc{v9,}-sun-solaris2.11, sparc{64,}-unknown-linux-gnu, and
amd64-pc-solaris2.11.
2026-06-14 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
ld:
* testsuite/ld-elf/shared.exp (Build pr29655): xfail on SPARC.
It seems like the 'i386 PE targeted' phrasing probably predates x86_64
PE support in binutils, and should have been touched when that was
added.
Even loosely interpreting that phrase to mean 'those two Intel
architectures, you know what I mean', this is less than helpful now that
PE aarch64 is a possibility.
Change the use of various phrases like '[This is an i386 PE specific
option]' to conistently use '[This option is specific to PE targeted
ports of the linker]' nearly everywhere.
The only options that really are specific in this way are
'--large-address-aware' (PE only) and '--high-entropy-va' (PE+ only), so
annotate those appropriately.
Do an editing pass of the various other mentions of 'PE'.
Also, add the 'PE only' annotation to the description of
'--leading-underscore' in the 'Options Specific to PE Targets' section,
to be consistent with all the others.
Also, since we've already mentioned that all the DllCharacteristics
flags are PE-specific, don't awkwardly mention it (again) as part of the
note about what Windows version support for that flag was introduced in.
Future work: the phrase 'PE targeted port of the linker' seems a bit
off, since cross-tools are a thing. Should it just be 'PE targeted linker'?
2026-06-01 Jon Turney <jon.turney@dronecode.org.uk>
* ld.texi (Options): Use consistent language for 'PE target'-only
options.
Functions that are always passed a non-NULL bfd_link_info* and are not
called by BFD_SEND using the output bfd, need not pass the output bfd
as a parameter. It can be accessed via info->output_bfd. Removing
the excess parameters result in a small code size reduction on
x86_64-linux --enable-targets=all ld built with a static libbfd, from
9896133 to 9893805 bytes.
When configuring with
'--enable-targets=x86_64-w64-mingw32,aarch64-w64-mingw32', many
duplicate symbol errors are produced:
> /usr/lib/gcc/x86_64-pc-cygwin/16/../../../../x86_64-pc-cygwin/bin/ld: pep-dll-aarch64.o: in function `pep_dll_id_target':
> /wip/binutils-gdb/build/ld/../../ld/pe-dll.c:493: multiple definition of `pep_dll_id_target'; pep-dll.o:/wip/binutils-gdb/build/ld/../../ld/pe-dll.c:493: first defined here
> /usr/lib/gcc/x86_64-pc-cygwin/16/../../../../x86_64-pc-cygwin/bin/ld: pep-dll-aarch64.o: in function `pep_dll_add_excludes':
> /wip/binutils-gdb/build/ld/../../ld/pe-dll.c:586: multiple definition of `pep_dll_add_excludes'; pep-dll.o:/wip/binutils-gdb/build/ld/../../ld/pe-dll.c:586: first defined here
> /usr/lib/gcc/x86_64-pc-cygwin/16/../../../../x86_64-pc-cygwin/bin/ld: pep-dll-aarch64.o: in function `pep_find_data_imports':
> /wip/binutils-gdb/build/ld/../../ld/pe-dll.c:1444: multiple definition of `pep_find_data_imports'; pep-dll.o:/wip/binutils-gdb/build/ld/../../ld/pe-dll.c:1444: first defined here
> /usr/lib/gcc/x86_64-pc-cygwin/16/../../../../x86_64-pc-cygwin/bin/ld: pep-dll-aarch64.o: in function `pep_dll_generate_def_file':
> /wip/binutils-gdb/build/ld/../../ld/pe-dll.c:1877: multiple definition of `pep_dll_generate_def_file'; pep-dll.o:/wip/binutils-gdb/build/ld/../../ld/pe-dll.c:1877: first defined here
> /usr/lib/gcc/x86_64-pc-cygwin/16/../../../../x86_64-pc-cygwin/bin/ld: pep-dll-aarch64.o: in function `pep_create_import_fixup':
> etc.
On investigation, this is unsurprising, since we're compiling the same code twice. In
fact, configure.tgt has:
> arch64-*-pe* | aarch64-*-mingw*)
> targ_extra_ofiles="deffilep.o pep-dll-aarch64.o pe-dll.o pdb.o"
> x86_64-*-pe | x86_64-*-pep) targ_emul=i386pep ;
> targ_extra_ofiles="deffilep.o pdb.o pep-dll-x86_64.o pe-dll.o"
> x86_64-*-cygwin) targ_emul=i386pep ;
> targ_extra_ofiles="deffilep.o pdb.o pep-dll.o pe-dll.o"
> x86_64-*-mingw*) targ_emul=i386pep ;
> targ_extra_ofiles="deffilep.o pdb.o pep-dll.o pe-dll.o"
... so we're potentially including pep-dll.c compiled under three
different names!
I can't see anything in pe{,p}-dll.c which depends on the
COFF_WITH_peAArch64 or COFF_WITH_pex64 defines, so just remove all this.
(Neither pep-dll-aarch64.o or pep-dll-x86_64.o are listed in
ALL_EMUL_EXTRA_OFILES, so this multiple definition problem doesn't show
up when configured --enable-targets=all', but this seems like another
source of subtle bugs if those defines did do anything here...)
Cc'ed Evgeny (Hi!), because I think this crosses with not-yet-submitted
patches of his which do add some code conditional on COFF_WITH_peAArch64.
I imagine it's possible in code which *does* need to depend on the
output target to replace build time checks of COFF_WITH_pe{AArch64,x64}
with a runtime check of the output architecture (via
pe_details->pe_arch?).
Cc: Evgeny Karpov <evgeny.karpov@arm.com>
Fixes: c60b380679 ("aarch64-pe support for LD, GAS and BFD")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2026-05-29 Jon Turney <jon.turney@dronecode.org.uk>
* Makefile.am (EXTRA_ld_new_SOURCES): Update.
* Makefile.in: Regenerate.
* configure.tgt (tar_extra_ofiles): Update.
* pep-dll-aarch64.c: Remove.
* pep-dll-x86_64.c: Remove.
Remove the local symbol ldh definitions with hidden visibility from the
relax-call36-*.s tests. The hidden visibility is meaningless for local
defined symbols and makes the test cases error.
This fixes a bug with the .note.spu_name section flags, which were
made SEC_LOAD without SEC_ALLOC. That combination doesn't really make
sense and led to odd layout behaviour. In addition .note.spu_name
now uses the normal note alignment, with some tweaks to keep its file
offset 16 byte aligned. This tends to work better in the testsuite
when the standard scripts are not used and the note is merged with
other notes.
bfd/
* elf32-spu.c (spu_elf_create_sections): Remove SEC_LOAD from
.note.spu_name, and align to 4 bytes.
(spu_elf_fake_sections): Tweak .note.spu_name output section
alignment for layout.
(spu_elf_final_write_processing): New function.
(elf_backend_final_write_processing): Define.
binutils/
* testsuite/binutils-all/objcopy.exp (pr25662): Don't xfail spu.
ld/
* testsuite/ld-elf/orphan-region.d: Don't xfail spu.
* testsuite/ld-elf/pr23658-1e.d: Likewise.
* testsuite/ld-scripts/provide-8.d: Likewise.
* testsuite/ld-spu/ovl.d: Remove commented out old matches.
Adjust expected overlay file offset.
* testsuite/ld-spu/ovl2.d: Likewise.
Since the local undefined TLS symbol address isn't mapped to any TLS
storage, it isn't usable. Set its value to 0 to avoid relocation overflow.
When processing TLS relocations, elf_hash_table (info)->tls_sec can be
NULL if all TLS symbols are weak, hidden and undefined. Don't assert
elf_hash_table (info)->tls_sec != NULL. Always set dtp_base and tp_base
to 0 if elf_hash_table (info)->tls_sec == NULL.
bfd/
PR ld/34165
* * elf-bfd.h (elf_link_local_undefweak_p): New function.
* elf64-alpha.c (elf64_alpha_relax_got_load): Set dtp_base and
tp_base to 0 if elf_hash_table (info)->tls_sec == NULL.
(elf64_alpha_relocate_section): Set the local undefined TLS
symbol value to 0. Don't assert elf_hash_table (info)->tls_sec
!= NULL.
ld/
PR ld/34165
* testsuite/ld-alpha/alpha.exp: Run $srcdir/$subdir/*.d.
* testsuite/ld-alpha/tlsbin-undef.d: New file.
* testsuite/ld-alpha/tlsbin-undef.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef1.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef1.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef2.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef2.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef3.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef3.s: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef4.d: Likewise.
* testsuite/ld-alpha/tlsbin-weak-undef4.s: Likewise.
* testsuite/ld-alpha/tlspic-undef.d: Likewise.
* testsuite/ld-alpha/tlspic-undef.s: Likewise.
* testsuite/ld-alpha/tlspic-weak-undef1.d: Likewise.
* testsuite/ld-alpha/tlspic-weak-undef1.s: Likewise.
* testsuite/ld-elf/pr34165.c: Likewise.
* testsuite/ld-elf/tls.exp: Run PR ld/34165 test.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
On cross builds, this fixes numerous test fails due to the milli.a
archive not being found. On hppa*64*-*-hpux*, this fixes four fails
due to undefined symbols in the HP milli.a archive.
The change to objcopy.exp causes the "objcopy executable (pr25662)"
test to fail. Previously, it didn't run because milli.a wasn't
found.
2026-05-24 John David Anglin <danglin@gcc.gnu.org>
binutils/ChangeLog:
* testsuite/binutils-all/objcopy.exp: Append LDFLAGS to
ldflags for milli.a archive.
* testsuite/config/default.exp: Create dummy milli.a archive
in tmpdir/hppa. Append " -Ltmpdir/hppa" to LDFLAGS.
ld/ChangeLog:
* testsuite/config/default.exp: Likewise.
elf32_arm_create_dynamic_sections was used to set plt_header_size and
plt_entry_size. This necessitated a hack for using_thumb_only() as
the output file attributes used by that function are not set until
lang_check calls bfd_merge_private_bfd_data. Now the earliest use of
plt_header_size and plt_entry_size is in elf32_arm_late_size_sections,
called from bfd_elf_size_dynamic_sections. So this patch moves the
initialisation of these variables to elf32_arm_late_size_sections.
Initialising them there is after lang_check runs, and also guarantees
they are initialised for all later uses too.
The patch also moves initialisation of htab->stub_bfd earlier, and
calls to add_glue_sections_to_bfd and get_bfd_for_interworking from
ld/armelf.em to bfd/elf32-arm.c. I removed an abort in
elf32_arm_create_dynamic_sections too. It really doesn't improve
confidence that much to check that a function you have just called to
create dynamic sections has done its job.
PR 16017
bfd/
* elf32-arm.c (elf32_arm_plt_needs_thumb_stub_p): Formatting.
(elf32_arm_create_dynamic_sections): Remove abort. Move
initialisation of plt_header_size and plt_entry_size to..
(elf32_arm_late_size_sections): ..here.
(bfd_elf32_arm_add_glue_sections_to_bfd),
(bfd_elf32_arm_get_bfd_for_interworking): Make static.
(bfd_elf32_arm_set_target_params): Add stub_bfd param. Remove
output_bfd param. Make params const. Init globals->stub_bfd.
Set flags and EI_CLASS for stub_bfd. Call
add_glue_sections_to_bfd and get_bfd_for_interworking.
* elf32-arm.h (bfd_elf32_arm_add_glue_sections_to_bfd),
(bfd_elf32_arm_get_bfd_for_interworking): Delete declarations.
(bfd_elf32_arm_set_target_params): Update prototype.
ld/
* emultempl/armelf.em (arm_elf_create_output_section_statements):
Don't set stub bfd flags here, or call
add_glue_sections_to_bfd and get_bfd_for_interworking. Pass
stub bfd to set_target_params.
The file ld.texi contains two space-separated terms: 'subseque nt'. It was probably meant to be 'subsequent'.
Manual documentation in html format also contains this error. I submitted a patch for it too, which can be
viewed at this archive link: https://sourceware.org/pipermail/binutils/2026-May/149206.html
Signed-off-by: PranavRJoshi <pranavrjoshi1@gmail.com>
The spec explicitly precludes STB_LOCAL together with STV_PROTECTED (and,
implicity, STV_HIDDEN or STV_INTERNAL), so we better wouldn't entirely
silently write out symbols violating this.
LoongArch's tc_symbol_new_hook() simply needs dropping. If FAKE_LABEL_NAME
symbols can end up global, marking them hidden would need doing elsewhere.
There not being a need to make any testsuite adjustments suggests though
that this won't normally (ever?) happen.
A couple of testcases then also need adjustment.
The following change is needed to fix errors trying to load the
milli.a archive for the hppa*64*-*-hpux* target when the host
system isn't hpux.
We need to create a dummy milli.a archive for this target and
append the directory of this archive to LDFLAGS.
This assumes the testsuite takes the LDFLAGS environment variable
into account. However, some tests in the ld testsuite use the
low-level `ld-link' procedure and it fails to take LDFLAGS into
account.
This change modifies the `default_ld_link' procedure to append
$LDFLAGS to the flags variable and fix the above issue.
This change potentially affects the `alpha*-*-*vms*' target but
currently no tests run for it make direct use of `ld-link'.
Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
2026-04-27 John David Anglin <danglin@gcc.gnu.org>
ld/ChangeLog:
* testsuite/lib/ld-lib.exp (default_ld_link): Append
LDFLAGS to `flags' variable. Also use the append command
to append the board flags.
The previous change to elf_hppa_final_link_relocate didn't eliminate
relocatios with invalid offsets. Here we take a different approach
to handle invalid offsets on hpux. We allocate 16 bytes at the start
of the .data section for the linker. If we encounter a relocation
with an invalid offset, we set the relocation's offset to the start
of the data section. As a result, the HP dynamic linker is happy
and we can re-enable -gc-section support.
2026-05-07 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
* elf64-hppa.c (elf_hppa_final_link_relocate): Rework
handling of relocations with invalid offsets on hpux.
(elf_backend_can_gc_sections): Set to one on hpux.
ld/ChangeLog:
* emulparams/elf64hppa.sh (DATA_START_SYMBOLS): Define.
* testsuite/ld-elf/group8a.d: Revert commit d6ce0aa3f8.
* testsuite/ld-elf/group8b.d: Likewise.
* testsuite/ld-elf/group9a.d: Likewise.
* testsuite/ld-elf/group9b.d: Likewise.
* testsuite/ld-elf/pr12851.d: Likewise.
* testsuite/ld-elf/pr22677.d: Likewise.
The HP-UX dynamic linker on hppa generates an error if it detects
a dynamic relocation with the R_PARISC_NONE type. As a result,
there is no way to handle relocations in sections that are garbage
collected. Although these can mostly be avoided, I think it best
to disable -gc-section support.
2026-05-06 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
* elf64-hppa.c (elf_hppa_final_link_relocate): Rework
BFD_ASSERT to only trigger on hpux. Zero rela if the
new offset is invalid.
(elf_backend_can_gc_sections): Set to zero on hpux.
ld/ChangeLog:
* testsuite/ld-elf/group8a.d: xfail hppa*64*-*-hpux*.
* testsuite/ld-elf/group8b.d: Likewise.
* testsuite/ld-elf/group9a.d: Likewise.
* testsuite/ld-elf/group9b.d: Likewise.
* testsuite/ld-elf/pr12851.d: Likewise.
* testsuite/ld-elf/pr22677.d: Likewise.
* ld/emultempl/pe.em (pe_fixup_stdcalls): Make at a const char *.
(gldEMULATION_NAME_after_open): Make pnt a const char *.
(gldEMULATION_NAME_place_orphan): Make dollar a const char *.
* ld/emultempl/pep.em (pep_fixup_stdcalls): Make at a
const char *. Introduce at2 as non-const char *.
(gldEMULATION_NAME_after_open): Make pnt a const char *.
(gldEMULATION_NAME_place_orphan): Make dollar a const char *.
* ld/emultempl/spuelf.em (spu_elf_load_ovl_mgr): Make p a
const char *. Introduce np as char *.
* ld/ldelf.c (ldelf_search_needed): Call strchr on freeme, so
slash is non-const, then assign freeme to replacement.
Assign strchr return to a const char* to match its arg in a couple of
places. archive_path now returns a const char*, and
input_statement_is_archive_path now has a const char* sep arg. If
you follow where these args come from in ldgram.y it can be seen that
they are in fact in writable memory, so it isn't necessary to copy
file_spec to poke in a zero which is restored before the function
returns.
Signed-off-by: Calvin Owens <calvin@wbinvd.org>
Signed-off-by: Alan Modra <amodra@gmail.com>
After commit 5c3261b0e8 there was no need for this flag. Remove it
and tidy places that used it.
include/
* bfdlink.h (struct bfd_link_info): Delete
check_relocs_after_open_input.
ld/
* emultempl/aarch64elf.em (before_parse): Don't set
link_info.check_relocs_after_open_input.
* emultempl/armelf.em (before_parse): Likewise.
* emultempl/elf.em (before_parse): Likewise.
* emultempl/scoreelf.em (before_parse): Likewise.
* emultempl/mmix-elfnmmo.em (mmix_before_parse): Delete.
(LDEMUL_BEFORE_PARSE): Don't define.
* emultempl/mmixelf.em (elfmmix_before_parse): Call elf.em
before_parse.
* ldlang.c (lang_check_relocs): Don't test
link_info.check_relocs_after_open_input.
Since PR ld/34088 test requires libm.a, which has feclearexcept, as a
linker script like
GROUP ( /usr/lib64/libm-2.42.a /usr/lib64/libmvec.a )
which is implemented for Linux/x86-64 and Linux/aarch64, limit such test
to Linux/x86-64 and Linux/aarch64.
PR ld/34088
* testsuite/ld-plugin/lto.exp: Limit PR ld/34088 test to
Linux/x86-64 and Linux/aarch64.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
When adding a new input archive, which comes from a linker script file
and isn't referenced by any inputs, ld appends it to the input file list.
On Linux, when -lm is used with /usr/lib64/libm.a:
GROUP ( /usr/lib64/libm-2.42.a /usr/lib64/libmvec.a )
the input file order looks like
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/15/crtbeginT.o
x.o (symbol from plugin)
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libm.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc_eh.a
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libc.a
/usr/lib/gcc/x86_64-redhat-linux/15/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crtn.o
/usr/lib64/libm-2.42.a
/usr/lib64/libmvec.a
since the compiler may not add compiler builtin functions to the LTO
symbol table as it doesn't really know if builtin functions will have
real symbols. When ld extracts an element from the archive later during
LTO rescan, the final input file order is
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/15/crtbeginT.o
x.o (symbol from plugin)
/tmp/ccHN6O4n.ltrans0.ltrans.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libm.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc_eh.a
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libc.a
/usr/lib/gcc/x86_64-redhat-linux/15/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crtn.o
fclrexcpt.o
where x.o references the builtin function, feclearexcept which is defined
in fclrexcpt.o from /usr/lib64/libm-2.42.a.
As the result, the .eh_frame section terminator in crtn.o is placed before
fclrexcpt.o and the .eh_frame section in the output isn't terminated. The
output crashes when it runs over the .eh_frame section during EH frame
registration. Insert the new input file before the current input file to
maintain the same input file order:
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/15/crtbeginT.o
x.o (symbol from plugin)
/usr/lib64/libm-2.42.a
/usr/lib64/libmvec.a
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libm.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc.a
/usr/lib/gcc/x86_64-redhat-linux/15/libgcc_eh.a
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/libc.a
/usr/lib/gcc/x86_64-redhat-linux/15/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../lib64/crtn.o
as the non-LTO input to properly terminate the .eh_frame section.
Add a static LTO test to reference feclearexcept which is a compiler
builtin function and isn't in the LTO symbol table when GCC is used.
It triggers the run-time crash on glibc targets of a linker script
libm.a without this fix when GCC 13 or above is used:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124869
Also add a debug function, debug_input_files, to display the input file
chain. It is optimized out when compiler optimization is turned on.
PR ld/34088
* ldlang.c (current_input_file): Changed to the pointer to
lang_input_statement_type.
(new_afile): Insert the new input file before the current input
file to maintain the input file order.
(lang_add_input_file): Updated.
(load_symbols): Likewise.
(debug_input_files): New function.
(lang_process): Reference it.
* testsuite/ld-plugin/lto.exp: Run PR ld/34088 test.
* testsuite/ld-plugin/pr34088.c: New file.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Since "-O 0" option is added to binutils 2.47, move it to binutils 2.47
section.
* NEWS: Move "-O 0" option to binutils 2.47 section.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
This patch allows R_AARCH64_TLS_DTPREL64 relocations in non-allocated
sections, which is required for DWARF debug information when using
Thread Local Storage. This matches the behavior in LLD.
Also a new syntax to parse dtprel operator use to describe tls
location in debug information. Please see the reference 3 below.
References:
- https://github.com/llvm/llvm-project/pull/146572
[AArch64] Support TLS variables in debug info
- https://github.com/llvm/llvm-project/pull/183962
[LLD][AArch64] Handle R_AARCH64_TLS_DTPREL64 in non-alloc sections
- https://github.com/ARM-software/abi-aa/pull/330
[AAELF64] Allow R_AARCH64_TLS_DTPREL to be used statically.
bfd/
* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Handle
BFD_RELOC_AARCH64_TLS_DTPREL.
gas/
* config/tc-aarch64.c (s_aarch64_cons): Parse %dtprel(var) syntax.
* testsuite/gas/aarch64/tls-debug.s: New test.
* testsuite/gas/aarch64/tls-debug.d: Run the test.
ld/
* testsuite/ld-aarch64/tls-debug.s: New test.
* testsuite/ld-aarch64/tls-debug.d: Run the test.
Bug: https://sourceware.org/PR28351
Signed-off-by: Shivam Gupta <shivam98.tkg@gmail.com>
This also fixes the alignment of the data segment on Linux target.
It must be page aligned to avoid inequivalent aliases.
2026-04-04 John David Anglin <danglin@gcc.gnu.org>
PR ld/12376
bfd/ChangeLog:
* elf64-hppa.c (elf_backend_modify_segment_map): Don't
use HP-UX specific routine on Linux.
(elf_backend_want_dynrelro): Define to 1 on Linux.
ld/ChangeLog:
* emulparams/hppa64linux.sh (COMMONPAGESIZE): Define.
(DATA_SEGMENT_ALIGN, DATA_SEGMENT_END,
DATA_SEGMENT_RELRO_END): Define if $LD_FLAG != "N".
(DATA_SECTION_ALIGNMENT): Define.
* scripttempl/elf64hppa.sc: Revise handling of data
segment.
* testsuite/ld-elf/orphan-region.d: Remove xfail on
Linux.