aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2025-01-01Update year range in copyright notice of binutils filesAlan Modra360-414/+414
2024-12-27ld/testsuite: replace aarch64 uses of load_libJan Beulich2-2/+2
Using $srcdir/$subdir directly doesn't work, at least not with expect 5.45, dejagnu 1.6, and an out-of-tree build (I assume it's the latter aspect which is crucial here). Make use of load_file instead.
2024-12-27LoongArch: Reword message for unresolvable relocsXi Ruoyao6-6/+6
For PDE, "recompiling with -fPIE" just makes no sense. For PIE, "recompiling with -fPIE" makes sense for unresolvable absolute relocs, but not unresolveable PC-relative relocs: if the reloc is already PC-relative, the problem is not the reloc is PC-relative or absolute, but the reloc is not applicable for external symbols. If we hit an unresolvable reloc in PDE or an unresolvable PC-relative reloc in PIE, it means the programmer has somehow wrongly instructed the compiler to treat external symbols as local symbols. A misuse of -mdirect-extern-access can cause the issue, so we can suggest -mno-direct-extern-access. And in all cases (DSO/PIE/PDE) a mismatching symbol visibility can also cause the issue, so we should also suggest to check the visibility. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-27LoongArch: Allow R_LARCH_PCALA_HI20 or R_LARCH_PCREL20_S2 against undefined ↵Xi Ruoyao3-0/+22
weak symbols for static PIE In a static PIE, undefined weak symbols should be just resolved to runtime address 0, like those symbols with non-default visibility. This was silently broken in all prior Binutils releases with "-static-pie -mdirect-extern-access": $ cat t.c int x (void) __attribute__ ((weak)); int main (void) { __builtin_printf("%p\n", x); } $ gcc t.c -static-pie -mdirect-extern-access $ ./a.out 0x7ffff1d64000 Since commit 4cb77761d687 ("LoongArch: Check PC-relative relocations for shared libraries), the situation has been improved: the linker errors out instead of silently producing a wrong output file. But logically, using -mdirect-extern-access for a static PIE perfectly makes sense, and we should not prevent that even if the programmer uses weak symbols. Linux kernel is such an example, and Linux < 6.10 now fails to build with Binutils trunk. (The silent breakage with prior Binutils releases was "benign" due to some blind luck.) While since the 6.10 release Linux has removed those potentially undefined weak symbols (due to performance issue), we still should support weak symbols in -mdirect-extern-access -static-pie and unbreak building old kernels. Link: https://lore.kernel.org/loongarch/20241206085810.112341-1-chenhuacai@loongson.cn/ Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-27LoongArch: Fix resolution of undefined weak hidden/protected symbolsXi Ruoyao4-0/+39
An undefined weak hidden/protect symbol should be resolved to runtime address 0, but we were actually resolving it to link-time address 0. So in PIE or DSO the runtime address would be incorrect. Fix the issue by rewriting pcalau12i to lu12i.w, and pcaddi to addi.w. The latter does not always work because the immediate field of addi.w is narrower, report an error in the case the addend is too large. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-12-24PR 32324, Stripping BOLT'ed binaries leads to unwanted behaviourAlan Modra1-2/+2
This patch corrects layout for a PT_LOAD header that doesn't include the ELF file header but does contain PHDRs and sections requiring alignment. The required alignment (which was missing) is placed before the PHDRs.
2024-12-20Fix examples of the use of the linker script TYPE keywordNick Clifton1-3/+3
2024-12-16ld/doc: properly separate @samp from @itemJan Beulich1-9/+9
At least makeinfo 4.13 doesn't tolerate @item@samp, considering it a single command.
2024-12-16LoongArch: Fix bfd ld failed test caseLulu Cai2-25/+15
This test case requires host gcc, and different distributions have different default configurations for gcc, which can cause address value mismatches. Therefore, it is fixed by passing consistent options and using regular expressions.
2024-12-12Revert bfd_use_reserved_id patchAlan Modra1-1/+0
Commit fc1cfaa5f1 and bc110b6e40 were made to avoid testsuite regressions on a number of targets that used bfd id in symbol hashing. Since it no longer seems necessary to start plugin bfd id's from -1 and count down, revert the functional changes in those patches.
2024-12-10LoongArch: Default to a maximum page size of 64KiBWANG Xuerui7-14/+25
As per the spec (Section 7.5.10, LoongArch Reference Manual Vol. 1), LoongArch machines are not limited in page size choices, and currently page sizes of 4KiB, 16KiB and 64KiB are supported by mainline Linux. While 16KiB is the most common, the current BFD code says it is the maximum; this is not correct, and as an effect, almost all existing binaries are incompatible with a 64KiB kernel because the sections are not sufficiently aligned, while being totally fine otherwise. This is needlessly complicating integration testing [1]. This patch fixes the inconsistency, and also brings BFD behavior in line with that of LLD [2]. [1] https://github.com/loongson-community/discussions/issues/47 [2] https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/lld/ELF/Arch/LoongArch.cpp#L174-L183 bfd/ * elfnn-loongarch.c (ELF_MAXPAGESIZE): Bump to 64KiB. (ELF_MINPAGESIZE): Define as 4KiB. (ELF_COMMONPAGESIZE): Define as 16KiB. ld/ * testsuite/ld-loongarch-elf/64_pcrel.d: Update assertions after changing the target max page size to 64KiB. * testsuite/ld-loongarch-elf/data-got.d: Likewise. * testsuite/ld-loongarch-elf/desc-relex.d: Likewise. * testsuite/ld-loongarch-elf/relax-align-ignore-start.d: Likewise. * testsuite/ld-loongarch-elf/tlsdesc_abs.d: Make the fuzzy match work as intended by not checking exact instruction words. * testsuite/ld-loongarch-elf/tlsdesc_extreme.d: Likewise. Signed-off-by: WANG Xuerui <git@xen0n.name>
2024-12-09Add linker diagnostic message about missing static librariesNick Clifton1-0/+6
2024-12-07fix dependencies for ld/emultemp/nto.emAlan Modra1-1/+1
Don't use "." to source .em files, use "source_em".
2024-12-06RISC-V: PR27566, consider ELF_MAXPAGESIZE/COMMONPAGESIZE for gp relaxations.Nelson Chu3-0/+25
For default linker script, if a symbol's value outsides the bounds of the defined section, then it may cross the data segment alignment, so we should reserve more size about MAXPAGESIZE and COMMONPAGESIZE when doing gp relaxations. Otherwise we may meet the truncated errors since the data segment alignment might move the section forward. bfd/ PR 27566 * elfnn-riscv.c (_bfd_riscv_relax_lui): Consider MAXPAGESIZE and COMMONPAGESIZE if the symbol's value outsides the bounds of the defined section. (_bfd_riscv_relax_pc): Likewise. ld/ PR 27566 * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/relax-data-segment-align*: New testcase for pr27566. Without this patch, the rv32 binutils will meet truncated errors for this testcase.
2024-12-05Fix clang compile time warning about optarg parameter shadowing optarg ↵Nick Clifton1-17/+17
global variable.
2024-12-03LoongArch: Fix the infinite loop caused by calling undefweak symbolLulu Cai3-0/+70
The undefweak symbol value of non-default visibility is 0 and does not use plt entry, and will not be relocated in the relocate_secion function. As a result, an infinite loop is generated because bl %plt(sym) => bl 0. Fix this by converting the call into a jump address 0.
2024-12-02aarch64: add tests for combinations of GCS options and marked/unmarked inputsMatthieu Longo25-0/+268
2024-12-02aarch64: add tests to check the correct merge of the GCS feature with others.Matthieu Longo10-5/+80
2024-12-02aarch64: GCS feature check in GNU note properties for input objectsSrinath Parvathaneni2-10/+105
This patch adds support for Guarded Control Stack in AArch64 linker. This patch implements the following: 1) Defines GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit for GCS in GNU_PROPERTY_AARCH64_FEATURE_1_AND macro. 2) Adds readelf support to read and print the GCS feature in GNU properties in AArch64. Displaying notes found in: .note.gnu.property [ ]+Owner[ ]+Data size[ ]+Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: GCS 3) Adds support for the "-z gcs" linker option and document all the values allowed with this option (-z gcs[=always|never|implicit]) where "-z gcs" is equivalent to "-z gcs=always". When '-z gcs' option is omitted from the command line, it defaults to "implicit" and relies on the GCS feature marking in GNU properties. 4) Adds support for the "-z gcs-report" linker option and document all the values allowed with this option (-z gcs-report[=none|warning|error]) where "-z gcs-report" is equivalent to "-z gcs-report=warning". When this option is omitted from the command line, it defaults to "warning". The ABI changes adding GNU_PROPERTY_AARCH64_FEATURE_1_GCS to the GNU property GNU_PROPERTY_AARCH64_FEATURE_1_AND is merged into main and can be found in [1]. [1] https://github.com/ARM-software/abi-aa/blob/main/sysvabi64/sysvabi64.rst Co-authored-by: Matthieu Longo <matthieu.longo@arm.com> Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com>
2024-12-02aarch64: rename BTI error/warning messageMatthieu Longo12-16/+16
The previous message for missing BTI feature in GNU properties was not very clear. The new message explains that a missing GNU property marking is lacking on this specific input.
2024-12-02aarch64: delete duplicated BTI testsMatthieu Longo6-117/+0
2024-12-02aarch64: improve test coverage for combination of BTI optionsMatthieu Longo19-5/+281
2024-12-02aarch64: update ld documentation with bti and pac optionsMatthieu Longo1-0/+28
2024-12-02aarch64: use only one type for feature marking reportMatthieu Longo1-4/+4
2024-12-02aarch64: group software protection options under a same struct.Matthieu Longo1-16/+50
- declare a new struc aarch_protection_opts to store all the configuration options related to software protections (i.e. bti-plt, pac-plt, bti-report level). - add a new option "-z bti-report" to configure the log level of reported issues when BTI PLT is forced. - encapsulate the BTI report inside _bfd_aarch64_elf_check_bti_report.
2024-12-02aarch64: adapt BTI tests to use selectable GNU propertiesMatthieu Longo10-125/+35
2024-12-02aarch64: adapt bti-far* tests to use selectable GNU propertiesMatthieu Longo10-118/+77
2024-12-02aarch64: adapt tests for PAC PLT to use selectable GNU propertiesMatthieu Longo3-4/+43
2024-12-02aarch64: delete old tests for PAC & BTI PLTMatthieu Longo2-70/+0
2024-12-02aarch64: new tests for BTI & PAC PLT to use selectable GNU propertiesMatthieu Longo7-0/+224
2024-12-02aarch64: adapt bti-plt-so to use selectable GNU propertiesMatthieu Longo2-16/+3
2024-12-02aarch64: delete old tests covering the merge of feature markingsMatthieu Longo3-35/+0
2024-12-02aarch64: new tests covering the merge of feature markingsMatthieu Longo13-1/+290
2024-12-02aarch64: move tests for AArch64 protections (BTI, PAC) into a subfolderMatthieu Longo38-64/+122
- moved all the BTI and PAC tests into a new subfolder: "protections". bti-far-* bti-plt-* bti-pac-plt-* - move several procedures used only for AArch64 linker tests to a new exp library file aarch64-elf-lib.exp in ld/testsuite/ld-aarch64/lib. - use aarch64-elf-lib.exp in aarch64-ld.exp and aarch64-protections.exp.
2024-12-02x86: always set ISA_1_BASELINE property for 64-bit objectsJan Beulich20-20/+20
The baseline was, afaik, specifically chosen to align with the baseline ISA of x86-64. It therefore makes no sense to emit that property only conditionally; if anything it confuses tools analyzing the difference between generated object files, which may result from just added / changed / removed (entirely ISA-independent) code, without any change to the enabled extensions. Compilers, after all, are free to use these baseline "extensions" when generating 64-bit code. While changing the one testcase that needs adjustment, also correct its misleading name (to be in sync with the filename).
2024-11-29s390: Fix linker test TLS -fpic and -fno-pic exec transitionsJens Remus1-5/+5
Commit 36bbf8646c8b ("s390: Treat addressing operand sequence as one in disassembler") changed how plain "nop" gets disassembled and missed to update any affected linker tests accordingly. ld/testsuite/ * ld-s390/tlsbin.dd: "nop" disassembles into "nop". Fixes: 36bbf8646c8b ("s390: Treat addressing operand sequence as one in disassembler") Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-11-27PE LD: Merge .CRT .ctors and .dtors into .rdataLiu Hao16-164/+170
PR 32264
2024-11-27Tidy up the default ELF linker scriptNick Clifton1-122/+352
2024-11-27Re: nios2: Remove binutils support for Nios II targetAlan Modra1-2/+0
Remove a now unused config file, regenerate POTFILES to remove nios2 refs, and modify config.bfd to report the target is obsolete.
2024-11-26nios2: Remove binutils support for Nios II target.Sandra Loosemore74-1375/+4
The Nios II architecture has been EOL'ed by the vendor. This patch removes all binutils, bfd, gas, binutils, and opcodes support for this target with the exception of the readelf utility. (The ELF EM_* number remains valid and the relocation definitions from the Nios II ABI will never change in future, so retaining the readelf support seems consistent with its purpose as a utility that tries to parse the headers in any ELF file provided as an argument regardless of target.)
2024-11-25Updated Bulgarian, Romanian and French translations for various ↵Nick Clifton1-2323/+2298
sub-directories. New Georgian translation for the gold sub-directory.
2024-11-22ld/PE: Handle MS style import libraries for files named *.exe tooMartin Storsjö2-14/+44
When handling MS style import libraries (also called short import libraries, or ILF), we need to detect the kind of library. So far, this has been done by looking at the member file names in the import library - in an MS style import library, all the member files for a specific library have the same member file name - the name of the runtime module to link against. Usually this is a DLL - thus we do a case insensitive comparison and check if the suffix is .dll. However, an .exe can also export symbols which can be linked against in the same way. In particular, if linking against WDK (Windows Driver Kit) import libraries, e.g. wdmsec.lib, the import libraries can provide imports for ntoskrnl.exe. Instead of specifically checking for *.dll (and *.exe, etc), invert the condition and skip archive members named *.o and *.obj. For any remaining archive members, that do contain .idata sections, apply the renaming. (The renaming is also mostly harmless if applied where it isn't needed; if archive members already have unique file names, their relative ordering should remain intact except for very contrieved cases.) Signed-off-by: Martin Storsjö <martin@martin.st>
2024-11-19RISC-V: Don't report warnings when linking different privileged spec objects.Nelson Chu7-82/+0
Since only the abandoned privileged spec v1.9.1 will have conflict csrs, to keep the compatible we still report warnings when linking privileged spec v1.9.1 objects with others. But don't report warnings for other compatible cases because it is actually a bit noisy and useless... bfd/ * elfnn-riscv.c (riscv_merge_attributes): Only report warnings when linking the abandoned privileged spec v1.9.1 object with others. ld/ * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Removed. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Removed. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Removed. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Removed. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Removed. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Removed. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2024-11-19LoongArch: Do not relax pcalau12i+ld.d when there is overflowLulu Cai4-0/+129
There is no overflow check for the relaxation of pcalau12i+ld.d => pcalau12i+addi.d. For instruction sequences that can be relaxed, they are directly relaxed to pcalau12i+addi.d. However, when the relative distance between the symbol and the pc exceeds the 32-bit range, the symbol value cannot be obtained correctly. Adds an overflow check for the relaxation of pcalau12i+ld.d. If it is found that the relaxation will overflow, it will not be relaxed.
2024-11-18aarch64: renaming of arm to AArch64Matthieu Longo1-2/+2
2024-11-18ld: Support percent-encoded JSON in --package-metadataBenjamin Drung7-2/+140
Specifying the compiler flag `-Wl,--package-metadata=<JSON>` will not work in case the JSON contains a comma, because compiler drivers eat commas. Example: ``` $ echo "void main() { }" > test.c $ gcc '-Wl,--package-metadata={"type":"deb","os":"ubuntu"}' test.c /usr/bin/ld: cannot find "os":"ubuntu"}: No such file or directory collect2: error: ld returned 1 exit status ``` The quotation marks in the JSON value do not work well with shell nor make. Specifying the `--package-metadata` linker flag in a `LDFLAGS` environment variable might loose its quotation marks when it hits the final compiler call. So support percent-encoded and %[string] encoded JSON data in the `--package-metadata` linker flag. Percent-encoding is used because it is a standard, simple to implement, and does take too many additional characters. %[string] encoding is supported for having a more readable encoding. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32003 Bug-Ubutru: https://bugs.launchpad.net/bugs/2071468 Signed-off-by: Benjamin Drung <benjamin.drung@canonical.com>
2024-11-18ld: fix -std=gnu23 compatibility wrt _BoolSam James1-1/+1
GCC trunk now defaults to -std=gnu23. We return false in a few places which can't work when true/false are a proper type (_Bool). Return NULL where appropriate instead of false. All callers handle this appropriately. ChangeLog: PR ld/32372 * pdb.c (add_stream): Return NULL.
2024-11-16PR 32359, --dependency-file: wrong error message if fopen failsBarnabás Pőcze1-0/+1
Use of %E in ld error messages requires bfd_error to be set.
2024-11-12Re: ld: Move note sections after .rodata sectionAlan Modra1-3/+3
Fix csky-linux-gnu FAIL of ld-elf/pr32341, due to that target having its own .bss directive. PR ld/32341 * testsuite/ld-elf/pr32341.s: Don't use .bss directive. Specify progbits/nobits on all .section directives.
2024-11-11ld: Move note sections after .rodata sectionH.J. Lu4-11/+52
Move note sections after .rodata section so that note sections are placed in the same PT_LOAD segment together with .rodata section, instead of a separate PT_LOAD segment. PR ld/32341 * scripttempl/misc-sections.sc: Move note sections to ... * scripttempl/elf.sc: Here, after .rodata section. * testsuite/ld-elf/pr32341.d: New file. * testsuite/ld-elf/pr32341.s: Likewise. Co-Authored-By: Nick Clifton <nickc@redhat.com> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>