aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
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>
2024-11-11ld, LoongArch: print error about linking without -fPIC or -fPIE flag in more ↵Xin Wang5-0/+16
detail
2024-11-08arm, objdump: Make objdump use bfd's machine detection to drive disassemblyAndre Vieira1-2/+2
For any arm elf target, disable an old piece of code that forced disassembly to disassemble for 'unknown architecture' which once upon a time meant it would disassemble ANY arm instruction. This is no longer true with the addition of Armv8.1-M Mainline, as there are conflicting encodings for different thumb instructions. BFD however can detect what architecture the object file was assembled for using information in the notes section. So if available, we use that, otherwise we default to the old 'unknown' behaviour. With the changes above code, a mode changing 'bx lr' assembled for armv4 with the option --fix-v4bx will result in an object file that is recognized by bfd as one for the armv4 architecture. The disassembler now disassembles this encoding as a BX even for Armv4 architectures, but warns the user when disassembling for Armv4 that this instruction is only valid from Armv4T onwards. Remove the unused and wrongfully defined ARM_ARCH_V8A_CRC, and define and use a ARM_ARCH_V8R_CRC to make sure instructions enabled by -march=armv8-r+crc are disassembled correctly. Patch up some of the tests cases, see a brief explanation for each below. inst.d: This test checks the assembly & disassembly of basic instructions in armv3m. I changed the expected behaviour for teqp, cmnp cmpp and testp instructions to properly print p when disassembling, whereas before, in the 'unknown' case it would disassemble these as UNPREDICTABLE as they were changed in later architectures. nops.d: Was missing an -march, added one to make sure we were testing the right behavior of NOP<c> instructions. unpredictable.d: Was missing an -march, added armv6 as that reproduced the behaviour being tested.
2024-11-01ld: generate SFrame stack trace info for .plt.gotIndu Bhagat4-0/+73
PR/32298 sframe: no SFrame stack trace info generated for .plt.got Add support to generate SFrame stack trace info for .plt.got section. Enhance the current definition of struct elf_x86_sframe_plt to include initialized SFrame FDE/FREs applicable for .plt.got section. There are two variants of .plt.got entries: 16 byte and 8 byte. 8 byte: ff 25 00 00 00 00 jmpq *name@GOTPCREL(%rip) 66 90 xchg %ax,%ax 16 byte: f3 0f 1e fa endbr64 ff 25 66 2f 00 00 jmpq *name@GOTPCREL(%rip) 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) For the testcase, define some application symbols such that their PLT entry is placed in .plt.got and ensure SFrame information is generated with and without -z ibtplt. ChangeLog: PR/32298 * bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): PLT GOT entry size is different for IBT vs non IBT PLTs. * bfd/elfxx-x86.c (enum dynobj_sframe_plt_type): New enum for SFRAME_PLT_GOT. (_bfd_x86_elf_create_sframe_plt): Handle SFRAME_PLT_GOT. (_bfd_x86_elf_write_sframe_plt): Likewise. (_bfd_x86_elf_late_size_sections): Likewise. (_bfd_x86_elf_finish_dynamic_sections): Likewise. * bfd/elfxx-x86.h (struct elf_x86_sframe_plt): Add new members to keep information about PLT GOT entries. (struct elf_x86_link_hash_table): Add support for creating SFrame section for .plt.got. * ld/testsuite/ld-x86-64/x86-64.exp: Add new tests. * ld/testsuite/ld-x86-64/sframe-pltgot-1.d: New test. * ld/testsuite/ld-x86-64/sframe-pltgot-1.s: New test. * ld/testsuite/ld-x86-64/sframe-pltgot-2.d: New test.
2024-11-01ld: fix wrong SFrame info for lazy IBT PLTJosh Poimboeuf2-0/+34
Fix PR/32296 sframe: wrong SFrame info for pltN and .plt.sec for -z ibtplt The x86 psABI defines a 2-PLT scheme for IBT which uses .plt and .plt.sec entries. It was observed that SFrame information for .plt.sec section was incorrect. The erroneous assumption was that SFrame stack trace information for .plt.sec with lazy binding is the same as SFrame stack trace information for .plt with lazy binding. This is corrected now by initializing a new SFrame PLT helper object elf_x86_64_sframe_ibt_plt for lazy PLT with IBT. Add a testcase where linking with -z ibtplt generates .plt.sec entries and ensure correct SFrame information for it. Committed by Indu Bhagat. ChangeLog: PR/32296 * bfd/elf64-x86-64.c (elf_x86_64_sframe_ibt_pltn_fre2): New definition elf_x86_64_sframe_ibt_plt. Use it in elf_x86_64_sframe_plt. (elf_x86_64_link_setup_gnu_properties): Lazy IBT PLT entries are different from lazy PLT. * bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Adjust for SFrame for IBT PLT. * ld/testsuite/ld-x86-64/x86-64.exp: Add new test. * ld/testsuite/ld-x86-64/sframe-ibt-plt-1.d: New test.
2024-11-02x86-64: Add a test for hidden undefined symbolH.J. Lu3-0/+11
Linker should report an error for hidden undefined symbol when building a shared library without the "recompile with -fPIC" message: $ cat x.c extern int foo __attribute__ ((visibility ("hidden"))); int func (void) { return foo; } $ gcc -c -fPIC -O2 x.c $ objdump -dwr x.o x.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <func>: 0: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 6 <func+0x6> 2: R_X86_64_PC32 foo-0x4 6: c3 ret $ ld -shared -o x.so x.o ld: x.o: in function `func': x.c:(.text+0x2): undefined reference to `foo' ld: x.o: relocation R_X86_64_PC32 against undefined hidden symbol `foo' can not be used when making a shared object ld: final link failed: bad value $ since -fPIC has been used. * testsuite/ld-x86-64/hidden6.d: New file. * testsuite/ld-x86-64/hidden6.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run hidden6. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-31ld-elf/pr25207.d: Pass --no-rosegment to ldH.J. Lu1-1/+1
Pass --no-rosegment to ld to support linker configured with --enable-rosegment, PR ld/25207 * ld-elf/pr25207.d: Pass --no-rosegment to ld. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-10-29ld/ELF: Add --image-base command line option to the ELF linkerHakan Candar9-16/+47
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-26PR32300, --dependency-file: link dependencies are not all collectedAlan Modra12-249/+33
PR 32300 PR 31904 Revert patch accidentally committed with 057a2b4c4b
2024-10-24Replace uses of asprintf with xasprintfAlan Modra6-86/+21
xasprintf has a nicer interface and behaves like xmalloc as far as memory is concerned, ie. no need to check a return status and the program exits with an error on OOM. binutils/ * dwarf.c (load_debug_sup_file): Replace asprintf with xasprintf. * nm.c (get_elf_symbol_type, get_coff_symbol_type): Likewise. * objdump.c (dump_ctf_indent_lines): Likewise. * readelf.c (display_lto_symtab, dump_ctf_indent_lines): Likewise. * windres.c (main): Likewise. * configure.ac: Remove asprintf from AC_CHECK_DECLS. * config.in: Regenerate. * configure: Regenerate. gas/ * config/tc-kvx.c (kvx_emit_single_noop): Simplify. * config/tc-riscv.c (md_assemblef): Replace asprintf with xasprintf. * read.c (s_nop, do_s_func): Likewise. * stabs.c (stabs_generate_asm_func): Likewise. (stabs_generate_asm_endfunc): Likewise. * configure.ac: Remove asprintf from AC_CHECK_DECLS. * config.in: Regenerate. * configure: Regenerate. ld/ * ldlang.c (lang_leave_overlay_section): Replace xmalloc+sprintf with xasprintf. Localise vars. * lexsup.c (parse_args): Replace asprintf with xasprintf. * pe-dll.c (make_head, make_tail, make_one): Likewise. (make_singleton_name_thunk, make_import_fixup_entry): Likewise. (make_runtime_pseudo_reloc): Likewise. (pe_create_runtime_relocator_reference): Likewise. * configure.ac: Remove asprintf from AC_CHECK_DECLS. * config.in: Regenerate. * configure: Regenerate.
2024-10-20Report bfd_merge_sections errorAlan Modra1-1/+2
PR 32260 bfd/ * elfxx-target.h (bfd_elfNN_bfd_merge_sections): Default to bfd_generic_merge_sections when using the generic linker. * elflink.c (_bfd_elf_merge_sections): Return error from _bfd_merge_sections. Abort on wrong hash table. ld/ * ldlang.c (lang_process): Report bfd_merge_sections error.
2024-10-17LoongArch: Check PC-relative relocations for shared librariesLulu Cai10-0/+59
Building shared libraries should not be allowed for PC-relative relocations against external symbols. Currently LoongArch has no corresponding checks and silently generates wrong shared libraries. However, In the first version of the medium cmodel, pcalau12i+jirl was used for function calls, in which case PC-relative relocations were allowed.
2024-10-16Add noxfail option to run_dump_testAlan Modra2-3/+3
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-15LoongArch: Add more relaxation support for call36mengqinggang3-0/+172
Add relaxation support for call36 that jump to PLT entry. Add relaxation support for call36 with IFUNC symbol. Add relaxation support for call36 that jump to undefweak symbol. For undefweak symbol, it can always be relaxed if it have no PLT entry. Because we set the address of undefweak symbol without PLT entry to PC like relocate_section.
2024-10-11bfd/ELF: restrict file alignment for object filesJan Beulich1-9/+9
While for executables properly aligning sections within the file can be quite relevant, the same is of pretty little importance for relocatable object files. Avoid passing "true" into _bfd_elf_assign_file_position_for_section() when dealing with object files, but compensate minimally by applying log_file_align in such cases as a cap to the alignment put in place.
2024-10-08Revised "Don't return (null) from bfd_elf_sym_name"Alan Modra1-3/+0
Commit 68bbe1183379 results in a lot of follow up work, much of which likely is still to be done. (And yes, since this is all for corrupted or fuzzed object files, a whole lot of work doesn't much benefit anyone. It was a bad idea to put NULL in asymbol->name.) So I'm changing the approach to instead put a unique empty string for symbols with a corrupted st_name. An empty string won't require much work to ensure nm, objcopy, objdump etc. won't crash, since these tools already must work with unnamed local symbols. The unique empty string is called bfd_symbol_error_name. This patch uses that name string for corrupted symbols in the ELF and COFF backends. Such symbols are displayed by nm and objdump as the translated string "<corrupt>", which is what the COFF backend used to put directly into corrupted symbols. ie. it's the way I should have written the original patch, plus a few tides and cleanups I retained from the reverted patches.
2024-10-08Revert "Don't return "(null)" from bfd_elf_sym_name"Alan Modra1-0/+3
This reverts commit 68bbe118337939aa0b52e007a7415c8a157579a1.
2024-10-03Don't return "(null)" from bfd_elf_sym_nameAlan Modra1-3/+0
A NULL return from bfd_elf_string_from_elf_section indicates an error. That shouldn't be masked by bfd_elf_sym_name but rather passed up to callers such as group_signature. If we want to print "(null)" then that should be done at a higher level. That's what this patch does, except that I chose to print "<null>" instead, like readelf. If we see "(null)" we're probably passing a NULL to printf. I haven't changed aoutx.h or pdp11.c print_symbol functions because they already handle NULL names by omitting the name. I also haven't changed mach-o.c, mmo.c, som.c, srec.c, tekhex.c, vms-alpha.c and wasm-module.c print_symbol function because it looks like they will never have NULL symbol names. bfd/ * elf.c (bfd_elf_sym_name): Don't turn a NULL name into a pointer to "(null)". (bfd_elf_print_symbol): Print "<null>" for NULL symbol names. * coffgen.c (coff_print_symbol): Likewise. * ecoff.c (_bfd_ecoff_print_symbol): Likewise. * pef.c (bfd_pef_print_symbol): Likewise. * syms.c (bfd_symbol_info): Return "<null>" in symbol_info.name if symbol name is NULL. ld/ * ldlang.c (ld_is_local_symbol): Don't check for "(null)" symbol name.
2024-09-30Improve the placement of orphan note sections.Nick Clifton14-13/+71
PR 32219
2024-09-28Move uses_elf_em to ld-lib.expAlan Modra1-0/+9
and add a missing entry from uses_genelf. binutils/ * testsuite/lib/binutils-common.exp (uses_elf_em): Delete. ld/ * testsuite/lib/ld-lib.exp (uses_genelf): Add moxie-*-moxiebox. (uses_elf_em): New.
2024-09-27Enable -z separate-code, -z common and -z text for more targetsAlan Modra4-4/+4
Fix a mis-placed "fi".
2024-09-26ld: Ignore .note.gnu.build-id when placing orphaned notesH.J. Lu13-3/+92
The commits: e8e10743f7b Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments. bf6d7087de0 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-24ld: re-generate configureSimon Marchi1-15/+3
Looks like configure has been generated with a non-upstream autoconf, re-generate it. ld/ChangeLog: * configure: Re-generate. Change-Id: I6774381ad411a190fb93ff260234dd79d8791680
2024-09-24ld: support --build-id=xx modeFrank Ch. Eigler9-54/+228
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-24ld/pdb: Handle DEBUG_S_INLINEELINES dataMark Harmstone6-0/+371
The DEBUG_S_INLINEELINES block in the .debug$S section records the line numbers in a source file covered by inlined functions. It's similar to the DEBUG_S_LINES block, but as it references LF_FUNC_ID types we also need to parse it to remap the type numbers.
2024-09-23ld/PE: enable secrel testcases also for 64-bit CygwinJan Beulich1-0/+16
Plus the others that are grouped there.
2024-09-23ld/PE: no base relocs for section (relative) onesJan Beulich4-5/+53
Even more so than image relative (RVA) relocations, section relative ones as well as section ones should not have base relocations created in the final PE image. Reportedly section relative relocations will want using for TLS support in the (Windows) compiler. While there also correct the names for two of the "image base" relocs.
2024-09-23LD: Document use of SOURCE_DATE_EPOCH in Environment sectionNick Clifton1-0/+7
2024-09-23x86: Turn PLT32 to PC32 only for PC-relative relocationsH.J. Lu2-0/+35
commit 292676c15a615b5a95bede9ee91004d3f7ee7dfd Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Feb 13 13:44:17 2020 -0800 x86: Resolve PLT32 reloc aganst local symbol to section resolved PLT32 relocation against local symbol to section and commit 2585b7a5ce5830e60a089aa2316a329558902f0c Author: H.J. Lu <hjl.tools@gmail.com> Date: Sun Jul 19 06:51:19 2020 -0700 x86: Change PLT32 reloc against section to PC32 turned PLT32 relocation against section into PC32 relocation. But these transformations are valid only for PC-relative relocations. Add fx_pcrel check for PC-relative relocations when performing these transformations to keep PLT32 relocation in `movq $foo@PLT, %rax`. gas/ PR gas/32196 * config/tc-i386.c (tc_i386_fix_adjustable): Return fixP->fx_pcrel for PLT32 relocations. (i386_validate_fix): Turn PLT32 relocation into PC32 relocation only if fixp->fx_pcrel is set. * testsuite/gas/i386/reloc32.d: Updated. * testsuite/gas/i386/reloc64.d: Likewise. * testsuite/gas/i386/reloc32.s: Add PR gas/32196 test. * testsuite/gas/i386/reloc64.s: Likewise. ld/ PR gas/32196 * testsuite/ld-x86-64/plt3.s: New file. * testsuite/ld-x86-64/x86-64.exp: Run plt3. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-21x86: Add tls check in gasCui, Lili13-13/+13
Assembler shouldn't accept invalid TLS instructions, TLS relocations can only be used with specific instructions as specified in TLS psABI and linker issues an error when TLS relocations are used with wrong instructions or format. Since it is inconvenient for gcc to rely on linker to report errors, adding TLS check in the assembler stage so that gcc can know TLS errors earlier. gas/ChangeLog: PR gas/32022 * config.in: Regenerate. * config/tc-i386.c *(enum x86_tls_error_type): New. *(struct _i386_insn): Added has_gotrel to indicate whether TLS relocations need to be checked. (x86_check_tls_relocation): Added a new function to check TLS relocation. (x86_report_tls_error): Created a new function to report TLS error. (i386_assemble): Handle x86_check_tls_relocation. (lex_got): Set i.has_gotrel. (OPTION_MTLS_CHECK): Added a new option to contrl TLS check. (struct option): Ditto. (md_parse_option): Ditto. (md_show_usage): Ditto. * configure.ac: Added a new option to check TLS relocation by default. * configure: Regenerated. * doc/c-i386.texi: Document -mtls-check=. * testsuite/gas/i386/i386.exp: Added new tests. * testsuite/gas/i386/ilp32/ilp32.exp: Ditto. * testsuite/gas/i386/ilp32/reloc64.d: Disable TLS check for it. * testsuite/gas/i386/ilp32/x32-tls.d: Ditto. * testsuite/gas/i386/inval-tls.l: Added more test cases. * testsuite/gas/i386/inval-tls.s: Ditto. * testsuite/gas/i386/reloc32.d: Disable TLS check for it. * testsuite/gas/i386/reloc64.d: Ditto. * testsuite/gas/i386/x86-64-inval-tls.l: Added more test cases. * testsuite/gas/i386/x86-64-inval-tls.s: Ditto. * testsuite/gas/i386/x86-64.exp: Added new tests. * testsuite/gas/i386/ilp32/x32-inval-tls.l: New test. * testsuite/gas/i386/ilp32/x32-inval-tls.s: Ditto. * testsuite/gas/i386/ilp32/x86-64-tls.d: Ditto. * testsuite/gas/i386/tls.d: Ditto. * testsuite/gas/i386/tls.s: Ditto. * testsuite/gas/i386/x86-64-tls.d: Ditto. * testsuite/gas/i386/x86-64-tls.s: Ditto. ld/ChangeLog: PR gas/32022 * testsuite/ld-i386/tlsgdesc1.d: Disable TLS check for it. * testsuite/ld-i386/tlsgdesc2.d: Ditto. * testsuite/ld-i386/tlsie2.d: Ditto. * testsuite/ld-i386/tlsie3.d: Ditto. * testsuite/ld-i386/tlsie4.d: Ditto. * testsuite/ld-i386/tlsie5.d: Ditto. * testsuite/ld-i386/tlsgdesc3.d: Ditto. * testsuite/ld-x86-64/tlsdesc3.d: Ditto. * testsuite/ld-x86-64/tlsdesc4.d: Ditto. * testsuite/ld-x86-64/tlsie2.d: Ditto. * testsuite/ld-x86-64/tlsie3.d: Ditto. * testsuite/ld-x86-64/tlsie5.d: Ditto. * testsuite/ld-x86-64/tlsdesc5.d: Ditto.
2024-09-21ld: Use --no-rosegment to ld for PR ld/22393 testsH.J. Lu6-14/+14
The commit bf6d7087de0 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-20ld: Change -z one-rosegment to --rosegment in commentsH.J. Lu1-30/+30
There is no such linker command-line option, -z one-rosegment. Replace it with --rosegment in comments. * genscripts.sh: Change -z one-rosegment to --rosegment in comments. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-20x86-64: Disable PIE on PR gas/32189 testH.J. Lu1-1/+1
Disable PIE on PR gas/32189 test, which contains the non-PIE assembly source, to support GCC defaulted to PIE. PR gas/32189 * testsuite/ld-x86-64/x86-64.exp: Pass $NOPIE_LDFLAGS to linker on PR gas/32189 test. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-20x86-64: Never make R_X86_64_GOT64 section relativeH.J. Lu2-0/+43
R_X86_64_GOT64 relocation should never be made section relative. Change tc_i386_fix_adjustable to return 0 for BFD_RELOC_X86_64_GOT64. gas/ PR gas/32189 * config/tc-i386.c (tc_i386_fix_adjustable): Return 0 for BFD_RELOC_X86_64_GOT64. * testsuite/gas/i386/reloc64.d: Updated. * testsuite/gas/i386/reloc64.s: Add more tests for R_X86_64_GOT64 and R_X86_64_GOTOFF64. ld/ PR gas/32189 * testsuite/ld-x86-64/x86-64.exp: Run PR gas/32189 test. * testsuite/ld-x86-64/pr32189.s: New file. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-09-19ld: Move the .note.build-id section to near the start of the memory map.Nick Clifton1-2/+37
This helps GDB to locate the debug information associated with a core dump. Core dumps include the first page of an executable's image, and if this page include the .note.build-id section then GDB can find it and then track down a debug info file for that build-id.
2024-09-11arm: Handle undefweak with ST_BRANCH_UNKNOWNChristophe Lyon3-0/+22
A previous patch made ld fail early on Thumb-only where branch_type is ST_BRANCH_UNKNOWN. However, this fails erroneously when the target is undefweak: in that case the branch should be replaced by a branch to the next instruction (or nop.w on thumb2). This patch accepts this case and restores the previous behaviour in such cases. This was reported by failures in the GCC testsuite, where we fail to link executables because __deregister_frame_info is undefweak: (__deregister_frame_info): Unknown destination type (ARM/Thumb) in ...crtbegin.o crtbegin.o: in function `__do_global_dtors_aux': crtstuff.c:(.text+0x52): dangerous relocation: unsupported relocation
2024-09-11ld/testsuite: exclude relocs from section contributions PDB testMark Harmstone2-24/+2
A bug in ld meant that we were erroneously generating image relocations for .secrel32 ops, which we then reflected in our PDB section contributions because the linker was adding a .reloc section. This was incidental to what we were testing for, so pass --disable-reloc-section to ld in order to ensure a consistent output.
2024-09-07Not append rela for absolute symbolXin Wang4-0/+25
LoongArch: Not append rela for absolute symbol Use la.global to get absolute symbol like la.abs. la.global put address of a global symbol into a got entry and append a rela for it, which will be used to relocate by dynamic linker. Dynamic linker should not relocate for got entry of absolute symbol as it stores symval not symbol's address.
2024-09-04arm: Do not insert stubs needing Arm code on Thumb-only cores.Christophe Lyon10-7/+56
We recently fixed a bug in libgcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115360) where a symbol was missing a %function .type decoration. This meant the linker would silently pick the wrong type of 'farcall stub', involving Arm-mode instructions on Thumb-only CPUs. This patch emits an error instead, and warns in some other cases, to encourage users to add the missing '.type foo,%function' directive. In practice: in arm_type_of_stub() we no longer try to infer which stub to use if the destination is of unknown type and the CPU is Thumb-only; so we won't lie to elf32_arm_size_stubs() which does not check branch_type. If branch_type is ST_BRANCH_TO_ARM but the CPU is Thumb-only, we now convert it to ST_BRANCH_TO_THUMB only if the destination is of absolute type. This is to support the case where the destination of the branch is defined by the linker script (see thumb-b-lks-sym.s and thumb-bl-lks-sym.s testcases for instance). The motivating case is covered by the new farcall-missing-type testcase, where we now emit an error message. We do not emit an error when branch_type is ST_BRANCH_UNKNOWN and the CPU supports Arm-mode: a lot of legacy code (e.g. newlib's crt0.S) lacks the corresponding '.type foo, %function' directives and even a (too verbose) warning could be perceived as a nuisance. Existing testcases where such a warning would trigger: arm-static-app.s (app_func, app_func2) arm-rel32.s (foo) arm-app.s (app_func) rel32-reject.s () main) fix-arm1176.s (func_to_branch_to) but this list is not exhaustive. For the sake of clarity, the patch replaces occurrences of sym.st_target_internal = 0; with sym.st_target_internal = ST_BRANCH_TO_ARM; enum arm_st_branch_type is defined in include/elf/arm.h, and relies on ST_BRANCH_TO_ARM==0, as sym.st_target_internal is also initialized to 0 in other target-independent parts of BFD code. (For instance, swapping the ST_BRANCH_TO_ARM and ST_BRANCH_TO_THUMB entries in the enum definition leads to 'interesting' results...) Regarding the testsuite: * new expected warning for thumb-b-lks-sym and thumb-bl-lks-sym * new testcase farcall-missing-type to check the new error case * attr-merge-arch-2b.s, branch-futures (and bfs-1.s) updated to avoid a diagnostic Tested on arm-eabi and arm-pe with no regression.
2024-08-30x86: Check invalid TLS descriptor callH.J. Lu4-0/+12
TLS descriptor call, call *x@tlsdesc(%rax) or call *x@tlsdesc(%eax) calls _dl_tlsdesc_return which expects that RAX/EAX points to the TLS descriptor. Update x86 linker to issue an error with or without TLS transition. bfd/ PR ld/32123 * elf32-i386.c (elf_i386_check_tls_transition): Move R_386_TLS_DESC_CALL to ... (elf_i386_tls_transition): Here. * elf64-x86-64.c (elf_x86_64_check_tls_transition): Move. R_X86_64_TLSDESC_CALL check to ... (elf_x86_64_tls_transition): Here. ld/ PR ld/32123 * testsuite/ld-i386/i386.exp: Run tlsgdesc3. * testsuite/ld-i386/tlsgdesc3.d: New file. * testsuite/ld-x86-64/tlsdesc5.d: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run tlsdesc5. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-29ld testsuite output filesAlan Modra1-0/+15
In many cases the output of one run_cc_link_tests test is used as input for another test. I hit a case where some system change caused errors when compiling object files, but the old .so output from a previous test run was still there, and then was used in following tests. * testsuite/lib/ld-lib.exp (run_ld_link_tests): Delete output file before building. (run_ld_link_exec_tests, run_cc_link_tests): Likewise.