aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
AgeCommit message (Collapse)AuthorFilesLines
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.
2024-08-28x86: Report expected register for elf_x86_tls_error_indirect_callH.J. Lu4-6/+6
Since R_386_TLS_DESC_CALL can only be used with call *variable@TLSCALL(%eax) and R_X86_64_TLSDESC_CALL can only be used with call *variable@TLSCALL(%rax) update TLS transition error report to display the expected register in indirect CALL. bfd/ PR ld/32017 * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize the ax_register field. (_bfd_x86_elf_link_report_tls_transition_error): Report the expected register in elf_x86_tls_error_indirect_call error. * elfxx-x86.h (elf_x86_link_hash_table): Add ax_register. ld/ PR ld/32017 * testsuite/ld-i386/tlsgdesc2.d: Updated. * testsuite/ld-i386/tlsgdesc2.s: Change jmp to call via ECX. * testsuite/ld-x86-64/tlsdesc4.d: Updated. * testsuite/ld-x86-64/tlsdesc4.s: Change jmp to call via RCX. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-28Re: x86: Allow R_386_TLS_LE_32 with KMOVDAlan Modra1-7/+6
Adjust the new test to pass on i686-pc-elf where it failed due to not matching the _start address.
2024-08-27x86: Allow R_386_TLS_LE_32 with KMOVDH.J. Lu3-0/+31
Since there is no TLS IE transition, allow R_386_TLS_LE_32 with KMOVD. gas/ PR gas/28595 * config/tc-i386.c (i386_assemble): Remove BFD_RELOC_386_TLS_LE_32 from TLS code check. * testsuite/gas/i386/inval-tls.s: Remove foo@tpoff(%eax). * testsuite/gas/i386/inval-tls.l: Updated. ld/ PR gas/28595 * testsuite/ld-i386/i386.exp: Run tlsle1. * testsuite/ld-i386/tlsle1.d: New file. * testsuite/ld-i386/tlsle1.s: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-26ld/PDB: handle pointers to membersMark Harmstone3-3/+33
If the CV_PTR_MODE_PMEM or CV_PTR_MODE_PMFUNC flags were set in an LF_POINTER entry's attributes, there's a few extra bytes on the end that we weren't accounting for. Change handle_type so that we remap the containing_class field if it's present, and add a test for this.
2024-08-26LoongArch: Fix wrong relocation handling of symbols defined by PROVIDELulu Cai6-0/+43
If the symbol defined by PROVIDE in the link script is not in SECTION, the symbol is placed in the ABS section. The linker considers that symbols in the ABS section do not need to calculate PC relative offsets. Symbols in ABS sections should calculate PC relative offsets normally based on relocations.
2024-08-23RISC-V: process rs_align_code also when relaxingJan Beulich1-3/+29
riscv_handle_align() runs after all input was processed. Whether relaxation is enabled for any particular piece of code is not recorded anywhere. (This issue was even "worked around" in a gas testcase, which is adjusted accordingly.) Furthermore, as demonstrated by an ld testcase, tail padding in an object file's executable sections depended on whether relaxation was enabled at the end of assembly: NOPs were emitted only when relaxation was off; zeroes were emitted with relaxation enabled. (It could probably be either way, but it should be independent of relaxation state at the end of assembly. Except of course write.c, in a comment ahead of #define-ing SUB_SEGMENT_ALIGN(), explicitly says "proper nop-filling".) While re-indenting, drop the "odd_padding" variable. It's used exactly once, and having the actual expression right in the if() is imo helping readers to understand what the intentions are. While touching the ld testcase, also tighten the expectations for the addresses of the two symbols: The last two digits have to have fixed values.
2024-08-22lto: Add a test for PR ld/32083H.J. Lu3-0/+54
Add a test for PR ld/32083 and xfail the test for GCC without the fix: commit a98dd536b1017c2b814a3465206c6c01b2890998 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Aug 21 07:25:25 2024 -0700 Update LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook PR ld/32083 * testsuite/ld-plugin/common-2a.c: New file. * testsuite/ld-plugin/common-2b.c: Likewise. * testsuite/ld-plugin/lto.exp: Run PR ld/32083 test. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-15Revert "MIPS: correct macro use in gas and ld testsuites"H.J. Lu3-3/+3
This reverts commit c0e9aca554e33e900efbd6425c1830f0a20012f5. commit 6ae8a30d44f016cafb46a75843b5109316eb1996 Author: Jan Beulich <jbeulich@suse.com> Date: Fri Aug 9 11:59:31 2024 +0200 gas: have scrubber retain more whitespace has been reverted to fix PR gas/32073.
2024-08-14ld: Add an LTO test for common symbol overrideH.J. Lu3-0/+30
Linker checks if a symbol in an archive member is a real definition, not common, before including the archive member in the link output so that only a real definition in archive will override the common symbol in object file. Add an LTO test to verify that a real definition in archive overrides the common symbol in object file. * testsuite/ld-plugin/common-1.c: New file. * testsuite/ld-plugin/definition-1.c: Likewise. * testsuite/ld-plugin/lto.exp: Run common tests. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-14LoongArch: Fix assertion failure with DT_RELRXi Ruoyao3-0/+13
In the DT_RELR implementation I missed a code path emiting relative reloc entries. Then the already packed relative reloc entries will be (unnecessarily) pushed into .rela.dyn but we've not allocated the space for them, triggering an assertion failure. Unfortunately I failed to notice the issue until profiled bootstrapping GCC with LTO and -Wl,-z,pack-relative-relocs. The failure can be easily triggered by linking a "hello world" program with -fprofile-generate and LTO: $ PATH=$HOME/ld-test:$PATH gcc hw.c -fprofile-generate -Wl,-z,pack-relative-relocs -flto /home/xry111/git-repos/binutils-build/TEST/ld: BFD (GNU Binutils) 2.43.50.20240802 assertion fail ../../binutils-gdb/bfd/elfnn-loongarch.c:2628 /home/xry111/git-repos/binutils-build/TEST/ld: BFD (GNU Binutils) 2.43.50.20240802 assertion fail ../../binutils-gdb/bfd/elfnn-loongarch.c:2628 collect2: error: ld returned 1 exit status And the reduced test case is just incredibly simple (included in the patch) so it seems I'm just stupid enough to fail to detect it before. Let's fix it now anyway. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-08-10ld: Add PR ld/32067 testsH.J. Lu4-0/+22
Add PR ld/32067 tests with the compiler driver since the -plugin option is needed to trigger this --oformat binary bug. PR ld/32067 * testsuite/ld-i386/i386.exp: Run PR ld/32067 test. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/start.s: Add .note.GNU-stack section. * testsuite/ld-x86-64/pr32067.s: New file. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-07loongarch ld testsuite xpassesAlan Modra2-2/+2
Some tests started passing with commit 3a83f0342e54. 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-05LoongArch: Add support for OUTPUT_FORMAT("binary")mengqinggang3-0/+17
In binary output format, loongarch_elf_hash_table return NULL and result in segment fault. When ld output binary file, it seems that elf related functions should not be called. But loongarch_elf_relax_section be called and loongarch_elf_hash_table cause segment fault. Just redefined loongarch_elf_hash_table and always return link_info->hash. The tests of binutils, glibc and gcc is ok. 0 loongarch_elf_relax_section () 1 0x000055555557ab28 in lang_size_sections_1 () 2 0x000055555557a16c in lang_size_sections_1 () 3 0x000055555557b0a8 in one_lang_size_sections_pass () 4 0x000055555557b478 in lang_size_sections () 5 0x000055555557e65c in lang_relax_sections () 6 0x000055555559f9c8 in ldelf_map_segments () 7 0x000055555559783c in gldelf64loongarch_after_allocation () 8 0x000055555558dac0 in ldemul_after_allocation () 9 0x000055555557f6c0 in lang_process () 10 0x0000555555585314 in main ()
2024-08-03LTO: Restore the wrapper symbol check for standard functionH.J. Lu4-0/+46
Call unwrap_hash_lookup to restore the wrapper symbol check for standard function since reference to standard function may not show up in LTO symbol table: [hjl@gnu-tgl-3 pr31956-3]$ nm foo.o 00000000 T main U __real_malloc 00000000 T __wrap_malloc [hjl@gnu-tgl-3 pr31956-3]$ lto-dump -list foo.o Type Visibility Size Name function default 0 malloc function default 0 __real_malloc function default 3 main function default 5 __wrap_malloc [hjl@gnu-tgl-3 pr31956-3]$ make gcc -O2 -flto -Wall -c -o foo.o foo.c gcc -Wl,--wrap=malloc -O2 -flto -Wall -o x foo.o /usr/local/bin/ld: /tmp/ccsPW0a9.ltrans0.ltrans.o: in function `main': <artificial>:(.text.startup+0xa): undefined reference to `__wrap_malloc' collect2: error: ld returned 1 exit status make: *** [Makefile:22: x] Error 1 [hjl@gnu-tgl-3 pr31956-3]$ Also add a test to verify that the unused wrapper is removed. PR ld/31956 * plugin.c (get_symbols): Restore the wrapper symbol check for standard function. * testsuite/ld-plugin/lto.exp: Run the malloc test and the unused test. * testsuite/ld-plugin/pr31956c.c: New file. * testsuite/ld-plugin/pr31956d.c: New file. * testsuite/ld-plugin/pr31956d.d: New file. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-08-01LoongArch: Fix ld FAIL test casesLulu Cai1-17/+24
To avoid differences in C library paths on different systems use gcc instead of ld to perform the test. Problems caused by adding options to different distributions will not be fixed.
2024-08-01ld/PDB: handle empty LF_FIELDLIST typesMark Harmstone3-3/+24
Empty structs in C++ lead to empty LF_FIELDLIST types in the .debug$T section, but we were mistakenly rejecting these as invalid. Allow CodeView types of two bytes, and add a test for this.
2024-07-31libctf: improve ECTF_NOPARENT error messageNick Alcock1-1/+1
This erorr doesn't just indicate that there is no parent dictionary (that's routine, and true of all dicts that are parents themselves) but that a parent is *needed* but wasn't found. include/ * ctf-api.h (_CTF_ERRORS) [ECTF_NOPARENT]: Improve error message. ld/ * testsuite/ld-ctf/diag-parname.d: Adjust.
2024-07-31fix the framework errorAlan Modra1-18/+5
Running the testsuite for an x86_64-w64-mingw32 target using the Ubuntu package gcc-mingw-w64-x86-64 version 13.2.0-6ubuntu1+26.1 results in a number of messages: ERROR: can't decipher gcc version number, fix the framework! Someone in their wisdom decided this compiler should advertise itself with a version of 13-win32, breaking the ld testsuite version checks. (It is also configured using --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld which renders the -B flag inoperative for testing the newly built gas and ld. You'd need to install binutils over the top of the Ubuntu versions before testing, a rather unsatisfactory process.) * testsuite/lib/ld-lib.exp (at_least_gcc_version): Use preprocessor test of __GNUC__ and __GNUC_MINOR__ rather than output of gcc --version. Correct removal of -Wl options.
2024-07-29Fixes to "PR 31728 testcases"Alan Modra6-23/+55
This brings us down to just these fails for the set of targets I usually test when making testsuite changes. aarch64-pe +FAIL: ld-pe/symbols-ordinals-hints-imports-ld arm-pe +FAIL: ld-pe/symbols-ordinals-hints-exports-dlltool arm-pe +FAIL: ld-pe/symbols-ordinals-hints-imports-dlltool The aarch64 one is likely due to the target missing support somewhere. It is fairly new, I haven't investigated. The arm-pe fails are due to arm-pe being a target that adds underscores to symbol names (see config.bfd) whereas dlltool thinks it does not (see dlltool.c:asm_prefix). arm-wince-pe on the other hand doesn't add underscores. I would guess the right fix for dlltool is to get this symbol info from bfd using bfd_get_target_info. Note I'm not very happy about the creative use of ld_after_inputfile in symbols-ordinals-hints-imports-ld.d, which is likely to break with some future run_dump_test change.
2024-07-29PR 31728 testcasesPali Rohár12-12/+148
2024-07-26Remove srcdir from x86 testcase "source:" linesAlan Modra3-3/+3
It's wrong to have ${srcdir} in run_dump_test "source:" lines, as run_dump_test adds $srcdir/$subdir/ to the line passed to the shell except when the source path starts with "./". The tests work currently because the shell expands ${srcdir} to an empty string. PR 31728 * testsuite/ld-i386/code16.d: Correct "source:". * testsuite/ld-x86-64/code16.d: Likewise. * testsuite/ld-x86-64/rela.d: Likewise.
2024-07-25x86: Improve TLS transition error checkH.J. Lu18-6/+91
Provide detailed TLS transition errors when unsupported instructions are used. Treat R_X86_64_CODE_4_GOTTPOFF and R_X86_64_CODE_6_GOTTPOFF as R_X86_64_GOTTPOFF when performing TLS transition. bfd/ PR ld/32017 * elf32-i386.c (elf_i386_check_tls_transition): Return different enums for different errors. (elf_i386_tls_transition): Change argument from r_symndx to sym. Call _bfd_x86_elf_link_report_tls_transition_error to report TLS transition errors. (elf_i386_scan_relocs): Pass isym instead of r_symndx to elf_i386_tls_transition. (elf_i386_relocate_section): Pass sym instead of r_symndx to elf_i386_tls_transition. * elf64-x86-64.c (elf_x86_64_check_tls_transition): Return different enums for different errors. (elf_x86_64_tls_transition): Change argument from r_symndx to sym. Treat R_X86_64_CODE_4_GOTTPOFF and R_X86_64_CODE_6_GOTTPOFF as R_X86_64_GOTTPOFF. Call _bfd_x86_elf_link_report_tls_transition_error to report TLS transition errors. (elf_x86_64_scan_relocs): Pass isym instead of r_symndx to elf_x86_64_tls_transition. (elf_x86_64_relocate_section): Pass sym instead of r_symndx to elf_x86_64_tls_transition. * elfxx-x86.c (_bfd_x86_elf_link_report_tls_transition_error): New. * elfxx-x86.h (elf_x86_tls_error_type): Likewise. (_bfd_x86_elf_link_report_tls_transition_error): Likewise. ld/ PR ld/32017 * testsuite/ld-i386/i386.exp: Run tlsgdesc1 and tlsgdesc2. * testsuite/ld-i386/tlsie2.d: Updated. * testsuite/ld-i386/tlsie3.d: Likewise. * testsuite/ld-i386/tlsie4.d: Likewise. * testsuite/ld-i386/tlsie5.d: Likewise. * testsuite/ld-x86-64/tlsie2.d: Likewise. * testsuite/ld-x86-64/tlsie3.d: Likewise. * testsuite/ld-i386/tlsgdesc1.d: New file. * testsuite/ld-i386/tlsgdesc1.s: Likewise. * testsuite/ld-i386/tlsgdesc2.d: Likewise. * testsuite/ld-i386/tlsgdesc2.s: Likewise. * testsuite/ld-x86-64/tlsdesc3.d: Likewise. * testsuite/ld-x86-64/tlsdesc3.s: Likewise. * testsuite/ld-x86-64/tlsdesc4.d: Likewise. * testsuite/ld-x86-64/tlsdesc4.s: Likewise. * testsuite/ld-x86-64/tlsie5.d: Likewise. * testsuite/ld-x86-64/tlsie5.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run tlsie5, tlsdesc3 and tlsdesc4. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-07-22Don't trim trailing newline in run_host_cmdAlan Modra28-35/+34
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-20ld/testsuite: add missing definition to PDB testMark Harmstone3-13/+14
The file pdb-syms1a.s was missing a definition for T_VOID, which was causing some types not to be deduplicated. It also meant that the test couldn't be run against LLVM's lld, which throws an error for this. This particular test only tests the symbols stream, not the types stream, which is why the deduplication doesn't result in a change in the file size.
2024-07-20ld/PDB: use correct hashing algorithm in add_globals_refMark Harmstone1-37/+36
add_globals_ref was hashing using CRC32 rather than the hashing algorithm used for symbols, which meant that windbg was unable to put breakpoints against unmangled names.
2024-07-19MIPS: correct macro use in gas and ld testsuitesJan Beulich3-3/+3
Whitespace in macro arguments either needs quoting / parenthesizing to reliably not be mistaken for an argument separator, or respective macro parameters need to be marked as covering all remaining arguments. The former appears more appropriate here, as the macro parameters already have ":req".
2024-07-13Revert "MIPS: Use N64 by default for mips*64*-*-linux-gnuabi64"Maciej W. Rozycki1-7/+2
This reverts commit d49f2dd78b08efa4e1ee51f5df5058846c2eb4fa. It was applied unapproved.
2024-07-13LoongArch: Fix dwarf3 test cases from XPASS to PASSLulu Cai1-5/+0
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-12s390: Avoid reloc overflows on undefined weak symbols (cont)Jens Remus3-1/+38
This complements and reuses logic from Andreas Krebbel's commit 896a639babe2 ("s390: Avoid reloc overflows on undefined weak symbols"). Replace relative long addressing instructions of weak symbols, which will definitely resolve to zero, with either a load address of 0 or a a trapping insn. This prevents the PLT32DBL relocation from overflowing in case the binary will be loaded at 4GB or more. bfd/ * elf64-s390.c (elf_s390_relocate_section): Replace instructions using undefined weak symbols with relative addressing to avoid relocation overflows. ld/ * testsuite/ld-s390/s390.exp: Add new test. * testsuite/ld-s390/weakundef-2.s: New test. * testsuite/ld-s390/weakundef-2.dd: Likewise. Reported-by: Alexander Gordeev <agordeev@linux.ibm.com> Suggested-by: Ilya Leoshkevich <iii@linux.ibm.com> Suggested-by: Andreas Krebbel <krebbel@linux.ibm.com> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-07-12s390: Do not replace brcth referencing undefined weak symbolJens Remus2-4/+3
Branch Relative on Count High (brcth) is a conditional branch relative instruction. It is not guaranteed that it only appears within loops that sooner or later will take the branch. It may very well be used to check a condition that will prevent the branch from ever being taken. bfd/ * elf64-s390.c (elf_s390_relocate_section): Do not replace brcth referencing undefined weak symbol with a trap. ld/ * testsuite/ld-s390/weakundef-1.s: Update test case accordingly. * testsuite/ld-s390/weakundef-1.dd: Likewise. Fixes: 896a639babe2 ("s390: Avoid reloc overflows on undefined weak symbols") Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-07-12MIPS: Use N64 by default for mips*64*-*-linux-gnuabi64YunQiang Su1-2/+7
the ABI section of the triple explicitly asks for N64, and in fact GCC also does so. It can fix the test failure: FAIL: libdep test: did not get expected output from the linker with Debian's mipsisa64r6el-linux-gnuabi64 toolchain.
2024-07-11LoongArch: Not alloc dynamic relocs if symbol is absoluteJinyang He4-0/+17
The absolute symbol should be resolved to const when link to dso or exe. Alloc dynamic relocs will cause extra space and R_LARCH_NONE finally.
2024-07-10x86-64: Skip -z mark-plt tests on MUSLH.J. Lu1-0/+7
Skip -z mark-plt tests, which are specific to glibc, on MUSL. PR ld/31970 * ld/testsuite/ld-x86-64/x86-64.exp: Skip -z mark-plt tests on MUSL. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-07-09LTO: Properly check wrapper symbolH.J. Lu3-0/+42
Add wrapper_symbol to bfd_link_hash_entry and set it to true for wrapper symbol. Set wrap_status to wrapper if wrapper_symbol is true in LTO. Note: Calling unwrap_hash_lookup to check for the wrapper symbol works only when there is a definition for the wrapped symbol since references to the wrapped symbol have been redirected to the wrapper symbol. bfd/ PR ld/31956 * linker.c (bfd_wrapped_link_hash_lookup): Set wrapper_symbol for wrapper symbol. include/ PR ld/31956 * bfdlink.h (bfd_link_hash_entry): Add wrapper_symbol. ld/ PR ld/31956 * plugin.c (get_symbols): Set wrap_status to wrapper if wrapper_symbol is set. * testsuite/ld-plugin/lto.exp: Run PR ld/31956 tests. * testsuite/ld-plugin/pr31956a.c: New file. * testsuite/ld-plugin/pr31956b.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-07-05LoongArch: Add DT_RELR testsXi Ruoyao19-0/+485
Most tests are ported from AArch64. The relr-addend test is added to make sure the addend (link-time address) is correctly written into the relocated section. Doing so is not strictly needed for RELA, but strictly needed for RELR). Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-07-05LoongArch: Make protected function symbols local for -sharedXi Ruoyao4-1/+25
On LoongArch there is no reason to treat STV_PROTECTED STT_FUNC symbols as preemptible. See the comment above LARCH_REF_LOCAL for detailed explanation. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-07-05LoongArch: Fix bad reloc with mixed visibility ifunc symbols in shared librariesXi Ruoyao3-0/+75
With a simple test case: .globl ifunc .globl ifunc_hidden .hidden ifunc_hidden .type ifunc, %gnu_indirect_function .type ifunc_hidden, %gnu_indirect_function .text .align 2 ifunc: ret ifunc_hidden: ret test: bl ifunc bl ifunc_hidden "ld -shared" produces a shared object with one R_LARCH_NONE (instead of R_LARCH_JUMP_SLOT as we expect) to relocate the GOT entry of "ifunc". It's because the indices in .plt and .rela.plt mismatches for STV_DEFAULT STT_IFUNC symbols when another PLT entry exists for a STV_HIDDEN STT_IFUNC symbol, and such a mismatch breaks the logic of loongarch_elf_finish_dynamic_symbol. Fix the issue by reordering .plt so the indices no longer mismatch. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-07-05LoongArch: Reject R_LARCH_32 from becoming a runtime reloc in ELFCLASS64Xi Ruoyao3-0/+8
We were converting R_LARCH_32 to R_LARCH_RELATIVE for ELFCLASS64: $ cat t.s .data x: .4byte x .4byte 0xdeadbeef $ as/as-new t.s -o t.o $ ld/ld-new -shared t.o $ objdump -R a.out: file format elf64-loongarch DYNAMIC RELOCATION RECORDS OFFSET TYPE VALUE 00000000000001a8 R_LARCH_RELATIVE *ABS*+0x00000000000001a8 But this is just wrong: at runtime the dynamic linker will run *(uintptr *)&x += load_address, clobbering the next 4 bytes of data ("0xdeadbeef" in the example). If we keep the R_LARCH_32 reloc as-is in ELFCLASS64, it'll be rejected by the Glibc dynamic linker anyway. And it does not make too much sense to modify Glibc to support it. So we can just reject it like x86_64: relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC or RISC-V: relocation R_RISCV_32 against non-absolute symbol `a local symbol' can not be used in RV64 when making a shared object Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-07-04gas: Skip SFrame FDE if CFI specifies non-FP/SP base registerJens Remus1-1/+0
Do not generate SFrame FDE if DWARF CFI directives .cfi_def_cfa or .cfi_def_cfa_register specify a CFA base register number other than the architecture-specific stack-pointer (SP) or frame-pointer (FP) register numbers. This also causes the assembler to print a warning message, so that skipping of the SFrame FDE does not occur silently. Update the generic ld SFrame test case to be architecture independent. Do not use CFI directive .cfi_def_cfa, as the specified CFA base register number is not a valid SP/FP register number on all architectures. An invalid SP/FP register number will now cause the assembler to print a warning message and skip SFrame FDE generation. Remove the offending CFI directive, that cannot be coded architecture- independent, as the test case requires SFrame information to be generated. This was reported by the Linaro-TCWG-CI for AArch64. gas/ * gen-sframe.c: Skip SFrame generation if CFI specifies non-FP/SP base register. ld/testsuite/ * ld-sframe/discard.s: Update generic SFrame test case to be architecture independent. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-07-04readelf/objdump: Display SFrame fixed RA offset as 'f' in dumpJens Remus2-12/+12
For the SFrame FRE frame-pointer (FP) offset from CFA a 'u' is displayed if it is unavailable. For the SFrame FRE return-address (RA) offset from CFA a 'u' was displayed if the ABI uses a fixed RA offset from CFA. By chance a 'u' was also displayed if the RA offset is unavailable, as the string buffer was not initialized after formatting the FP offset. Note that it could not occur that the FP offset was erroneously displayed as RA offset, as the SFrame format cannot have a FRE with FP offset without RA offset. For the FRE RA offset display 'f' if the ABI uses a fixed RA offset from CFA. Display a 'u' if it is unavailable. libsframe/ * sframe-dump.c: Display SFrame fixed RA offset as 'f' in dump. gas/testsuite/ * gas/cfi-sframe/cfi-sframe-common-4.d: Test for RA displayed either as 'u' (if RA tracking) or as 'f' (fixed RA offset if no RA tracking). * gas/cfi-sframe/cfi-sframe-common-5.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-6.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-7.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-8.d: Likewise. * gas/cfi-sframe/cfi-sframe-x86_64-1.d: Test for RA displayed as 'f' (fixed RA offset), as x86-64 does not use RA tracking. * gas/scfi/x86_64/scfi-cfi-sections-1.d: Likewise. * gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise. ld/testsuite/ * ld-x86-64/sframe-plt-1.d: Test for RA displayed as 'f' (fixed RA offset), as x86-64 does not use RA tracking. * ld-x86-64/sframe-simple-1.d: Likewise. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-07-04readelf/objdump: Dump SFrame CFA fixed FP and RA offsetsJens Remus2-0/+2
The SFrame format allows architectures to specify fixed offsets from the CFA, if any, from which the frame pointer (FP) and/or return address (RA) may be recovered. These offsets are stored in the SFrame header. For instance the SFrame generation in the assembler for x86 AMD64 specifies a fixed offset from the CFA, from which the return address (RA) may be recovered. When dumping the SFrame header, for instance in readelf/objdump with option --sframe, do also dump the specified fixed offsets from the CFA, if any, from which the frame pointer (FP) and return address (RA) may be recovered. Update the common SFrame test case verification patterns to allow for the optional dumping of the CFA fixed FP/RA offsets. Update the x86- specific SFrame and SCFI test case verification patterns to require a CFA fixed RA offset of -8. libsframe/ * sframe-dump.c: Dump CFA fixed FP and RA offsets. gas/testsuite/ * gas/cfi-sframe/cfi-sframe-common-1.d: Test for optional fixed FP and RA offsets. * gas/cfi-sframe/cfi-sframe-common-2.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-3.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-4.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-5.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-6.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-7.d: Likewise. * gas/cfi-sframe/cfi-sframe-common-8.d: Likewise. * gas/cfi-sframe/cfi-sframe-x86_64-1.d: Test for fixed RA offset. * gas/cfi-sframe/common-empty-1.d: Test for optional fixed FP and RA offsets. * gas/cfi-sframe/common-empty-2.d: Likewise. * gas/cfi-sframe/common-empty-3.d: Likewise. * gas/scfi/x86_64/scfi-cfi-sections-1.d: Test for SFrame fixed RA offset. * gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise. ld/testsuite/ * ld-x86-64/sframe-plt-1.d: Test for SFrame fixed RA offset. * ld-x86-64/sframe-simple-1.d: Likewise. Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-07-03x86-64: Support APX NF TLS IE with 2 operandsLingling Kong3-18/+34
Support APX NF TLS IE with 2 operands.Verify it with ld and gold. gas/ * config/tc-i386.c (md_assemble): Allow APX NF TLS IE with 2 operands. * testsuite/gas/i386/x86-64-gottpoff.d: Updated. * testsuite/gas/i386/x86-64-gottpoff.s: Add APX NF TLS IE tests with 2 operands. gold/ * testsuite/x86_64_ie_to_le.s: Add APX NF TLS IE tests with 2 operands. * testsuite/x86_64_ie_to_le.sh: Updated. ld/ * testsuite/ld-x86-64/tlsbindesc.s: Add APX NF TLS IE tests with 2 operands. * testsuite/ld-x86-64/tlsbindesc.d: Updated. * testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
2024-07-01x86-64: Verify that TLS IE works with APX NFkonglin13-18/+50
Verify that {nf} add %reg1, foo@gottpoff(%rip), %reg2 {nf} add foo@gottpoff(%rip), %reg, %reg2 work correctly with ld and gold. gas/ * testsuite/gas/i386/x86-64-gottpoff.d: Updated. * testsuite/gas/i386/x86-64-gottpoff.s: Add tests for "{nf} add %reg1, foo@gottpoff(%rip), %reg2" and "{nf} add foo@gottpoff(%rip), %reg, %reg2". gold/ * testsuite/x86_64_ie_to_le.s: Add tests for "{nf} add %reg1, foo@gottpoff(%rip), %reg2" and "{nf} add foo@gottpoff(%rip), %reg, %reg2". * testsuite/x86_64_ie_to_le.sh: Updated. ld/ * testsuite/ld-x86-64/tlsbindesc.s: Add R_X86_64_CODE_6_GOTTPOFF for APX NF tests. * testsuite/ld-x86-64/tlsbindesc.d: Updated. * testsuite/ld-x86-64/tlsbindesc.rd: Likewise. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-07-01ld: Move foo before delete in dl5.ccH.J. Lu1-1/+1
* testsuite/ld-elf/dl5.cc (main): Move foo before delete. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>