aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2024-06-29ld: pass -g for ld-elf testsSam James2-2/+2
The "DWARF parse during linker error" and "Build warn libbar.so" tests require debug information. configure defaults to "-O2 -g" but if overriding *FLAGS when building tests, this might be lost. Explicitly pass -g given these tests require it. Originally reported downstream in Gentoo at https://bugs.gentoo.org/934149. ld/ * testsuite/ld-elf/dwarf.exp: Pass -g for "DWARF parse during linker error". * testsuite/ld-elf/shared.exp: Ditto for "Build warn libbar.so".
2024-06-28RISC-V: PR27180, Update relocation for riscv_zero_pcrel_hi_reloc.Nelson Chu2-0/+27
When pcrel access overflow, the riscv_zero_pcrel_hi_reloc may convert pcrel relocation to absolutly access if possible at the relocate stage. We used to encode the target address into r_sym of R_RISCV_HI20 if it is converted from R_RISCV_PCREL_HI20. But that may cause segfault if --emit-relocs is set, since r_sym becomes an address rather than a symbol index. Although the relocate result is correct, it does not meet the definition, so may cause unexpected behaviors. This patch encodes the target address into r_addend, rather than r_sym, if riscv_zero_pcrel_hi_reloc converts the relocation. Besdies, since the corresponding pcrel_lo relocation are also changed to absolutly access, we should also update them to R_RISCV_LO12_I/S. bfd/ PR 27180 * elfnn-riscv.c (riscv_pcrel_hi_reloc): New boolean `absolute', to inform corresponding pcrel_lo that the pcrel_hi relocation was already converted to hi20 relocation. (riscv_record_pcrel_hi_reloc): Likewise, record `absolute'. (riscv_pcrel_lo_reloc): Removed `const' for Elf_Internal_Rela *reloc, since we may need to convert it from pcrel_lo to lo relocation. (riscv_record_pcrel_lo_reloc): Likewise. Convert pcrel_lo to lo relocation if corresponding pcrel_hi was converted to hi relocation. (riscv_zero_pcrel_hi_reloc): Encode target absolute address into r_addend rather than r_sym. Clear the `addr' to avoid duplicate relocate in the perform_relocation. (riscv_elf_relocate_section): Updated. ld/ PR 27180 * testsuite/ld-riscv-elf/pcrel-lo-addend-3a-emit-relocs.d: New testcase. Segfault without applying this patch. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2024-06-27Fix new libdep test so that if the plugin cannot be located the test fails ↵Nick Clifton1-3/+4
gracefully.
2024-06-26Revert: 35fd2ddeb1d90f1750401cfb6d01fe055656b88dNick Clifton4-0/+142
PR 20814
2024-06-25aarch64: Add DT_RELR tests for ILP32 ABISzabolcs Nagy5-0/+165
2024-06-20LoongArch: TLS IE needs only one dynamic relocXi Ruoyao5-47/+67
As the comment in the code says, TLS_IE needs only one dynamic reloc. But commit b67a17aa7c0c ("LoongArch: Fix the issue of excessive relocation generated by GD and IE") has incorrectly allocated the space for two dynamic relocs, causing libc.so to contain 8 R_LARCH_NONE. Adjust tlsdesc-dso.d for the offset changes and add two tests to ensure there are no R_LARCH_NONE with TLS. Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2024-06-18libctf: dedup: enums with overlapping enumerators are conflictingNick Alcock4-0/+77
The CTF deduplicator was not considering enumerators inside enum types to be things that caused type conflicts, so if the following two TUs were linked together, you would end up with the following in the resulting dict: 1.c: enum foo { A, B }; 2.c: enum bar { A, B }; linked: enum foo { A, B }; enum bar { A, B }; This does work -- but it's not something that's valid C, and the general point of the shared dict is that it is something that you could potentially get from any valid C TU. So consider such types to be conflicting, but obviously don't consider actually identical enums to be conflicting, even though they too have (all) their identifiers in common. This involves surprisingly little code. The deduplicator detects conflicting types by counting types in a hash table of hash tables: decorated identifier -> (type hash -> count) where the COUNT is the number of times a given hash has been observed: any name with more than one hash associated with it is considered conflicting (the count is used to identify the most common such name for promotion to the shared dict). Before now, those identifiers were all the identifiers of types (possibly decorated with their namespace on the front for enumerator identifiers), but we can equally well put *enumeration constant names* in there, undecorated like the identifiers of types in the global namespace, with the type hash being the hash of each enum containing that enumerator. The existing conflicting-type-detection code will then accurately identify distinct enums with enumeration constants in common. The enum that contains the most commonly-appearing enumerators will be promoted to the shared dict. libctf/ * ctf-impl.h (ctf_dedup_t) <cd_name_counts>: Extend comment. * ctf-dedup.c (ctf_dedup_count_name): New, split out of... (ctf_dedup_populate_mappings): ... here. Call it for all * enumeration constants in an enum as well as types. ld/ * testsuite/ld-ctf/enum-3.c: New test CTF. * testsuite/ld-ctf/enum-4.c: Likewise. * testsuite/ld-ctf/overlapping-enums.d: New test. * testsuite/ld-ctf/overlapping-enums-2.d: Likewise.
2024-06-14x86: Add -z isa-level-report=[none|all|needed|used]H.J. Lu16-0/+245
Add -z isa-level-report=[none|all|needed|used] to the x86 ELF linker to report needed and used x86-64 ISA levels. bfd/ PR ld/31868 * elf-linker-x86.h (elf_x86_isa_level_report): New. (elf_linker_x86_params): Add isa_level_report. * elfxx-x86.c (report_isa_level): New. (_bfd_x86_elf_link_setup_gnu_properties): Check -z isa-level-report=[none|all|needed|used] to report needed and used x86-64 ISA level. ld/ PR ld/31868 * NEWS: Mention -z isa-level-report=[none|all|needed|used]. * ld.texi: Document -z isa-level-report=[none|all|needed|used]. * emulparams/elf32_x86_64.sh: Source x86-64-level-report.sh. * emulparams/elf_i386.sh: Likewise. * emulparams/elf_x86_64.sh: Likewise. * emulparams/x86-64-level-report.sh: New file. * testsuite/ld-i386/pr31868a.d: Likewise. * testsuite/ld-i386/pr31868b.d: Likewise. * testsuite/ld-i386/pr31868c.d: Likewise. * testsuite/ld-x86-64/pr31868a-x32.d: Likewise. * testsuite/ld-x86-64/pr31868a.d: Likewise. * testsuite/ld-x86-64/pr31868a.l: Likewise. * testsuite/ld-x86-64/pr31868a.s: Likewise. * testsuite/ld-x86-64/pr31868b-x32.d: Likewise. * testsuite/ld-x86-64/pr31868b.d: Likewise. * testsuite/ld-x86-64/pr31868b.l: Likewise. * testsuite/ld-x86-64/pr31868b.s: Likewise. * testsuite/ld-x86-64/pr31868c-x32.d: Likewise. * testsuite/ld-x86-64/pr31868c.d: Likewise. * testsuite/ld-x86-64/pr31868c.l: Likewise. * testsuite/ld-i386/i386.exp: Run PR ld/31868 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-06-13Adjust linker tests that are sensitive to --rosegmentNick Clifton21-26/+26
2024-06-13Add --rosegment option to BFD linker to stop the '-z separate-code' from ↵Nick Clifton2-0/+29
generating two read-only segments. PR 30907
2024-06-10IBM zSystems: Rewrite l(g)rl @GOTENT to larl for --no-pieIlya Leoshkevich3-0/+35
Regtested on s390x-redhat-linux. Rewriting l(g)rl @GOTENT to larl is unnecessarily guarded by bfd_link_pic(). There were no use cases for this in the past, but since recently the Linux Kernel on s390x is compiled with -fPIE and linked with --no-pie. Remove the unnecessary bfd_link_pic() check. bfd/ChangeLog: * elf32-s390.c (elf_s390_relocate_section): Don't check for bfd_link_pic() when rewriting lrl@GOTENT to larl. (elf_s390_finish_dynamic_symbol): Emit a relative reloc for the above case. * elf64-s390.c (elf_s390_relocate_section): Don't check for bfd_link_pic() when rewriting lgrl@GOTENT to larl. (elf_s390_finish_dynamic_symbol): Emit a relative reloc for the above case. ld/ChangeLog: * testsuite/ld-s390/s390.exp: Hook up the new tests. * testsuite/ld-s390/gotreloc_31-no-pie-1.dd: New test. * testsuite/ld-s390/gotreloc_64-no-pie-1.dd: New test.
2024-06-10ld-aarch64: check support before launching dt_relr testsClément Chigot1-9/+11
Not all aarch64 targets supports dt_relr as this requires some mechanisms on the OS side. Adjust support_dt_relr helper and use it in aarch64-elf.exp.
2024-06-07aarch64: Test DT_RELR with discarded sectionsSzabolcs Nagy5-0/+114
2024-06-06Re: aarch64: Add some DT_RELR ld testsAlan Modra4-20/+20
aarch64-elf fails these tests due to .rela.dyn being at a different address to that expected, and due to the symbol table being different. Unexpected symbol numbering results in a mismatch of reloc r_info field, but these are shown decoded so the raw field doesn't really add anything to the test. * testsuite/ld-aarch64/relr-align.d: Accept any address for .relr.dyn section. Don't match raw r_info field. * testsuite/ld-aarch64/relr-data-shared.d: Likewise. * testsuite/ld-aarch64/relr-got-shared.d: Likewise. * testsuite/ld-aarch64/relr-text-shared.d: Likewise.
2024-06-04LoongArch: Disable linker relaxation if set the address of section or segmentmengqinggang2-0/+25
If set the address of section or segment, the offset from pc to symbol may become bigger and cause overflow.
2024-05-31aarch64: Add some DT_RELR ld testsSzabolcs Nagy12-0/+351
2024-05-28RISC-V: Fixed overwritten IRELATIVE relocs in the .rel.iplt for data reloc.Nelson Chu6-7/+28
This was originally reported by Hau Hsu <hau.hsu@sifive.com>. Similar to commit 51a8a7c2e3cc0730831963651a55d23d1fae624d We shouldn't use riscv_elf_append_rela to add dynamic relocs into .rela.iplt in the riscv_elf_relocate_section when handling ifunc data reloc R_RISCV_32/64. This just like what did in the riscv_elf_finish_dynamic_symbol. bfd/ * elfnn-riscv.c (riscv_elf_relocate_section): We shouldn't use riscv_elf_append_rela to add dynamic relocs into .rela.iplt in the riscv_elf_relocate_section when handling ifunc data reloc. ld/ * testsuite/ld-riscv-elf/ifunc-overwrite.s: Updated and renamed. * testsuite/ld-riscv-elf/ifunc-overwrite-exe.rd: Likewise. * testsuite/ld-riscv-elf/ifunc-overwrite-pic.rd: Likewise. * testsuite/ld-riscv-elf/ifunc-overwrite-pie.rd: Likewise. * testsuite/ld-riscv-elf/ifunc-overwrite.d: Renamed.
2024-05-27LoongArch: Fix relaxation overflow caused by ld -z separate-codemengqinggang6-36/+114
ld -z separate-code let .text and .rodata in two different but read only segment. If the symbol and pc in two segment, the offset from pc to symbol need to consider segment alignment. Add a function 'loongarch_two_sections_in_same_segment' to determine whether two sections are in the same segment.
2024-05-14Improve objdump -p output of PE Import and Export TablesPali Roh?r4-12/+12
PR 31738
2024-05-10Add --section-ordering command line option to the bfd linker.Nick Clifton10-0/+215
2024-05-08ld: Add PR ld/31710 testsH.J. Lu4-0/+63
PR ld/31710 * testsuite/ld-elf/wrap.exp: Run ld/31710 tests. * testsuite/ld-elf/wrap2.h: New file. * testsuite/ld-elf/wrap2a.c: Likewise. * testsuite/ld-elf/wrap2b.c: Likewise.
2024-05-08ld: Run --wrap tests only if supportedH.J. Lu1-19/+15
Run --wrap tests with shared library only if -shared is supported. * testsuite/ld-elf/wrap.exp: Run --wrap tests with shared library only if -shared is supported.
2024-05-08RISC-V: Support B, Zaamo and Zalrsc extensions.Nelson Chu4-4/+4
* https://github.com/riscv/riscv-b/tags Added standard B extension back, which implies Zba, Zbb and Zbs extensions. * https://github.com/riscv/riscv-zaamo-zalrsc/tags Splited standard A extension into two new extensions, Zaamo and Zalrsc. The A extension implies Zaamo and Zalrsc extensions. Not sure if we need to do the similar check as i and zicsr/zifencei. Passed riscv[32|64]-[elf/linux] binutils testcases. bfd/ * elfxx-riscv.c (riscv_implicit_subsets): Added imply rules for A and B extensions. The A implies Zaamo and Zalrsc, the B implies Zba, Zbb and Zbs. (riscv_supported_std_ext): Supported B extension with v1.0. (riscv_supported_std_z_ext): Supported Zaamo and Zalrsc with v1.0. (riscv_multi_subset_supports, riscv_multi_subset_supports_ext): Updated. include/ * opcode/riscv.h (riscv_insn_class): Removed INSN_CLASS_A, Added INSN_CLASS_ZAAMO and INSN_CLASS_ZALRSC. opcodes/ * riscv-opc.c (riscv_opcodes): Splited standard A extension into two new extensions, Zaamo and Zalrsc. gas/ * testsuite/gas/riscv/march-imply-a.d: New testcase. * testsuite/gas/riscv/march-imply-b.d: New testcase. * testsuite/gas/riscv/attribute-01.d: Updated. * testsuite/gas/riscv/attribute-02.d: Updated. * testsuite/gas/riscv/attribute-03.d: Updated. * testsuite/gas/riscv/attribute-04.d: Updated. * testsuite/gas/riscv/attribute-05.d: Updated. * testsuite/gas/riscv/attribute-10.d: Updated. * testsuite/gas/riscv/mapping-symbols.d: Updated. * testsuite/gas/riscv/march-imply-g.d: Updated. * testsuite/gas/riscv/march-imply-unsupported.d: Updated. * testsuite/gas/riscv/march-ok-reorder.d: Updated. ld/ * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated. * testsuite/ld-riscv-elf/attr-merge-arch-02.d: Updated. * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Updated. * testsuite/ld-riscv-elf/attr-merge-user-ext-01.d: Updated.
2024-05-07LoongArch: Fix ld test failures caused by using instruction aliasesLulu Cai1-1/+1
Different versions of objdump may take different forms of output for instructions. Use -M no-aliases to avoid the failure of ld test cases caused by objdump using aliases.
2024-04-29Fix initiali state of DWARF v5 line number table in BFD libraryNick Clifton1-1/+1
PR 30783
2024-04-25LoongArch: Add bad static relocation check and output more information to userLulu Cai7-0/+45
Absolute address symbols cannot be used with -shared. We output more information to the user than just BFD_ASSETR.
2024-04-24Update readelf's display of RELR sections to include the number of locations ↵Nick Clifton13-13/+13
relocated
2024-04-23ignore some symbols in elf.c:swap_out_symsAlan Modra1-1/+1
The reason behind this patch was noticing that generic ELF targets fail to remove "bar" in the recently committed ld-elf/undefweak-1 test. (Despite that, those targets pass the test due to it being too strict when matching symbols. "bar" gets turned into a local weak defined absolute symbol.) swap_out_syms currently drops local section syms that are defined in discarded sections. Extend that to also drop other symbols in discarded sections too, even global symbols. The linker goes to quite a lot of effort to ensure globals in discarded section take a definition from the kept linkonce or comdat group section. So the global sym change should only affect cases where something is quite wrong about the set of linkonce or comdat group sections. However that change to elf_map_symbols meant we dropped _DYNAMIC_LINK / _DYNAMIC_LINKING for mips, a global absolute symbol given STT_SECTION type for some reason. That problem is fixed by reverting the pr14493 change which is no longer needed due to a) BSF_SECTION_SYM_USED on x86, and b) fixing objcopy to use copy_private_symbol_data. bfd/ PR 14493 * elf.c (ignore_sym): Rename from ignore_section_sym. Return true for any symbol without a section or in a discarded section. Revert pr14493 change. (elf_map_symbols): Tidy. Use ignore_sym on all symbols. (swap_out_syms): Tidy. ld/ * testsuite/ld-elf/undefweak-1.rd: Match any "bar".
2024-04-23xfail undefweak-1 test for alphaAlan Modra1-1/+1
".set" has a different meaning on alpha. Changing it to ".equ" runs into ".equ" having a different meaning on hppa, and changing it to "=" runs into trouble on bfin. * testsuite/ld-elf/elf.exp (undefweak-1): xfail on alpha, don't xfail for genelf.
2024-04-20LoongArch: Add -mignore-start-align optionmengqinggang7-2/+43
Ignore .align at the start of a section may result in misalignment when partial linking. Manually add -mignore-start-align option without partial linking. Gcc -falign-functions add .align 5 to the start of a section, it causes some error message mismatch. Set these testcases to xfail on LoongArch target.
2024-04-18elf: Strip unreferenced weak undefined symbolsH.J. Lu8-0/+87
Linker will resolve an undefined symbol only if it is referenced by relocation. Unreferenced weak undefined symbols serve no purpose. Weak undefined symbols appear in the dynamic symbol table only when they are referenced by dynamic relocation. Mark symbols with relocation and strip undefined weak symbols if they don't have relocation and aren't in the dynamic symbol table. bfd/ PR ld/31652 * elf-bfd.h (elf_link_hash_entry): Add has_reloc. * elf-vxworks.c (elf_vxworks_emit_relocs): Set has_reloc. * elflink.c (_bfd_elf_link_output_relocs): Likewise. (elf_link_output_extsym): Strip undefined weak symbols if they don't have relocation and aren't in the dynamic symbol table. ld/ PR ld/31652 * testsuite/ld-elf/elf.exp: Run undefweak tests. * testsuite/ld-elf/undefweak-1.rd: New file. * testsuite/ld-elf/undefweak-1a.s: Likewise. * testsuite/ld-elf/undefweak-1b.s: Likewise. * testsuite/ld-x86-64/weakundef-1.nd: Likewise. * testsuite/ld-x86-64/weakundef-1a.s: Likewise. * testsuite/ld-x86-64/weakundef-1b.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run undefweak tests.
2024-04-16elf: Skip the archive if the symbol isn't referencedH.J. Lu4-0/+49
Also skip the archive if the symbol isn't referenced by a regular object. bfd/ PR ld/31644 * elflink.c (elf_link_add_archive_symbols): Also skip the archive if the symbol isn't referenced by a regular object. ld/ PR ld/31644 * testsuite/ld-plugin/lto.exp: Run PR ld/31644 tests. * testsuite/ld-plugin/pr31644a.c: New test. * testsuite/ld-plugin/pr31644b.c: Likewise. * testsuite/ld-plugin/pr31644c.c: Likewise.
2024-04-16Simplify readelf's RELR relocation display.Fangrui Song13-26/+26
2024-04-11Improve readelf's display of RELR relocs.Nick Clifton13-39/+53
2024-04-10Re: ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGETAlan Modra1-4/+4
Don't use CC_FOR_TARGET in the bootstrap test, a silly idea aiming at consistency that made things worse. The objects being linked were built using $CC, so $CC should be used to link. * testsuite/ld-bootstrap/bootstrap.exp: Revert last change.
2024-04-09LoongArch: ld: Move .got .got.plt before .data and protect .got with relromengqinggang3-0/+23
Move .got .got.plt before .data so .got can be protected with -zrelro. And the first two entries of .got.plt (_dl_runtime_resolve and link map) are placed within the relro region.
2024-04-09ld testsuite: Append NOSANITIZE_CFLAGS to CFLAGS_FOR_TARGETAlan Modra2-4/+7
The idea here is build tests without sanitizer flags, so they don't fail due to many not using the compiler to link and thus result in undefined symbols, since libasan is not supplied. We definitely do not want a compiler to perform linking in most cases, and it's complicated to supply libasan (and would possibly disturb testcase output). * testsuite/config/default.exp (CFLAGS_FOR_TARGET), (CXXFLAGS_FOR_TARGET): Append NOSANITIZE_CFLAGS. * testsuite/ld-bootstrap/bootstrap.exp: Use CC_FOR_TARGET and CFLAGS_FOR_TARGET throughout.
2024-04-08ld: Add PR ld/31615 testsH.J. Lu6-0/+66
PR ld/31615 * testsuite/ld-plugin/lto.exp: Run ld/31615 tests. * testsuite/ld-plugin/pr31615.ver: New file. * testsuite/ld-plugin/pr31615a.c: Likewise. * testsuite/ld-plugin/pr31615b.c: Likewise. * testsuite/ld-plugin/pr31615c.c: Likewise. * testsuite/ld-plugin/pr31615d.c: Likewise.
2024-04-05elf: Always honor the first definition in shared object and archiveH.J. Lu10-0/+137
GCC doesn't put builtin function symbol references, which are defined in the shared C library, in the IR symbol table. When linker rescans shared objects and archives for newly added symbol references generated from the IR inputs, it skips definitions of the builtin functions in shared objects and archives. Add first_hash to elf_link_hash_table to track unreferenced definitions defined first in shared objects and archives. Always use them to resolve any references. bfd/ PR ld/31482 PR ld/31489 * elf-bfd.h (elf_link_hash_table): Add first_hash. * elflink.c (elf_link_add_to_first_hash): New function. (elf_link_add_object_symbols): Initialize first_hash for an IR input. Always use the first definition in shared object. Add the first unreferenced dynamic definition to first_hash. (_bfd_elf_archive_symbol_lookup): Add the first unreferenced definition to first_hash.. (elf_link_add_archive_symbols): Use the symbol definition in archive if symbol is defined first in this archive. (_bfd_elf_link_hash_table_free): Also free first_hash. ld/ PR ld/31482 PR ld/31489 * testsuite/ld-plugin/lto.exp: Add PR ld/31482 and PR ld/31489 tests. * testsuite/ld-elf/pr31482a-no-lto.c: New file. * testsuite/ld-elf/pr31482b-no-lto.c: Likewise. * testsuite/ld-elf/pr31482c-no-lto.c: Likewise. * testsuite/ld-elf/pr31482d-no-lto.c: Likewise. * testsuite/ld-plugin/pass1.out: Likewise. * testsuite/ld-plugin/pr31482a.c: Likewise. * testsuite/ld-plugin/pr31482b.c: Likewise. * testsuite/ld-plugin/pr31482c.c: Likewise.
2024-04-02PR31458, FAIL: MIPS eh-frame 3 with --no-keep-memoryH.J. Lu1-0/+1
PR 31458 bfd/ * elf-bfd.h (_bfd_elf_link_read_relocs), (_bfd_elf_link_info_read_relocs): Constify section. * elflink.c: Likewise. * elfxx-mips.c (_bfd_mips_elf_eh_frame_address_size): Read relocs again in case --no-keep-memory. ld/ * testsuite/ld-mips-elf/mips-elf.exp: Run --no-keep-memory version of eh-frame3 test.
2024-04-01LoongArch: Fix the issue of excessive relocation generated by GD and IELulu Cai2-49/+49
Currently, whether GD and IE generate dynamic relocation is determined by SYMBOL_REFERENCES_LOCAL and bfd_link_executable. This results in dynamic relocations still being generated in some situations where dynamic relocations are not necessary (such as the undefined weak symbol in static links). We use RLARCH_TLS_GD_IE_NEED_DYN_RELOC macros to determine whether GD/IE needs dynamic relocation. If GD/IE requires dynamic relocation, set need_reloc to true and indx to be a dynamic index. At the same time, some test cases were modified to use regular expression matching instead of complete disassembly matching.
2024-04-01LoongArch: gas: Ignore .align if it is at the start of a sectionmengqinggang3-0/+29
Ignore .align if it is at the start of a section and the alignment can be divided by the section alignment, the section alignment can ensure this .align has a correct alignment.
2024-03-31BFD: Fix the bug of R_LARCH_AGLIN caused by discard sectionmengqinggang3-0/+33
To represent the first and third expression of .align, R_LARCH_ALIGN need to associate with a symbol. We define a local symbol for R_LARCH_AGLIN. But if the section of the local symbol is discarded, it may result in a undefined symbol error. Instead, we use the section name symbols, and this does not need to add extra symbols. During partial linking (ld -r), if the symbol associated with a relocation is STT_SECTION type, the addend of relocation needs to add the section output offset. We prevent it for R_LARCH_ALIGN. The elf_backend_data.rela_normal only can set all relocations of a target to rela_normal. Add a new function is_rela_normal to elf_backend_data, it can set part of relocations to rela_normal.
2024-03-28RISC-V: Removed privileged spec 1.9.1 support in assembler.Nelson Chu11-22/+11
Removed since it's may have lots of conflicts with the newer extensions, but still keep linker recognizes it in case of linking old objects. gas/ * NEWS: Updated. * config/tc-riscv.c (riscv_set_default_priv_spec): Regard 1.9.1 as an unknown version. (md_show_usage): Removed privileged spec 1.9.1 information. * testsuite/gas/riscv/attribute-05.s: Updated since privileged spec 1.9.1 is unsupported. * testsuite/gas/riscv/attribute-05.d: Likewise. * testsuite/gas/riscv/attribute-12.d: Likewise. * testsuite/gas/riscv/attribute-13.d: Likewise. * testsuite/gas/riscv/csr-dw-regnums.d: Likewise. * testsuite/gas/riscv/csr-dw-regnums.s: Likewise. * testsuite/gas/riscv/csr.s: Likewise. * testsuite/gas/riscv/csr-version-1p10.d: Likewise. * testsuite/gas/riscv/csr-version-1p10.l: Likewise. * testsuite/gas/riscv/csr-version-1p11.d: Likewise. * testsuite/gas/riscv/csr-version-1p11.l: Likewise. * testsuite/gas/riscv/csr-version-1p12.d: Likewise. * testsuite/gas/riscv/csr-version-1p12.l: Likewise. * testsuite/gas/riscv/csr-version-1p9p1.d: Removed. * testsuite/gas/riscv/csr-version-1p9p1.l: Removed. include/ * opcode/riscv-opc.h: Updated since privileged spec 1.9.1 is unsupported. ld/ * testsuite/ld-riscv-elf/attr-merge-priv-spec-01.d: Updated since privileged spec 1.9.1 is unsupported. * testsuite/ld-riscv-elf/attr-merge-priv-spec-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-a.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-b.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-01.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-04.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-05.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-priv-spec-failed-06.d: Likewise.
2024-03-26Don't claim a fat IR object if no IR object should be claimedH.J. Lu3-2/+37
When the linker sees an input object containing nothing but IR during rescan, it should ignore it (LTO phase is over). But if the input object is a fat IR object, which has non-IR code as well, it should be used to resolve references as if it did not contain any IR at all. This patch adds lto_type to bfd and linker avoids claiming a fat IR object if no IR object should be claimed. bfd/ PR ld/23935 * archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type instead of lto_slim_object. * elflink.c (elf_link_add_object_symbols): Likewise. * bfd.c (bfd_lto_object_type): New. (bfd): Remove lto_slim_object and add lto_type. (bfd_get_lto_type): New function. * elf.c (lto_section): Removed. (_bfd_elf_make_section_from_shdr): Don't set lto_slim_object. * format.c: (lto_section): New. (bfd_set_lto_type): New function. (bfd_check_format_matches): Call bfd_set_lto_type. * bfd-in2.h: Regenerated. binutils/ PR ld/23935 * nm.c (display_rel_file): Check bfd_get_lto_type instead of lto_slim_object. ld/ PR ld/23935 * ldmain.c (add_archive_element): Don't claim a fat IR object if no IR object should be claimed. * testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test. Add PR ld/23935 test. * testsuite/ld-plugin/pr23935a.c: New file. * testsuite/ld-plugin/pr23935b.c: Likewise.
2024-03-19ld: Support LD_UNDER_TEST environment variableH.J. Lu1-4/+26
Support LD_UNDER_TEST environment variable to test a different linker. Issue an error if LD_UNDER_TEST isn't an absolute full path. * testsuite/config/default.exp: If LD_UNDER_TEST environment variable exists, set ld and LD to it and set up tmpdir/ld/ld. Issue an error if LD_UNDER_TEST isn't an absolute full path.
2024-03-19LoongArch: Add relaxation for R_LARCH_CALL36mengqinggang5-0/+122
This relaxation is effective for both macro instructions (call36, tail36) and explicit relocation instructions (pcaddu18i + jirl). call36 f -> bl f R_LARCH_CALL36 -> R_LARCH_B26 tail36 $t0, f -> b f R_LARCH_CALL36 -> R_LARCH_B26
2024-03-12LoongArch: Fix gas and ld test casesLulu Cai6-5/+12
* After adding the old LE relax, all old LE relocations will have an R_LARCH_RELAX relocation. Fix the gas test case failure caused by the implementation of the old LE relax. * loongarch64-elf does not support pie and -z norelro options, removed in test files.
2024-03-06LoongArch: Fix some test cases for TLS transition and relaxLulu Cai27-122/+292
2024-02-29RISC-V: Initial ld.bfd support for TLSDESC.Tatsuyuki Ishi3-1/+22
Only relocation handling for now; relaxation is not implemented yet. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Record GOT reference and paired relocation for TLSDESC_HI20. (riscv_elf_adjust_dynamic_symbol): Allocate GOT and reloc slots for TLSDESC symbols. (riscv_elf_size_dynamic_sections): Likewise but for local symbols. (tlsdescoff): New helper to determine static addend for R_TLSDESC. (riscv_elf_relocate_section): Ignore TLSDESC_CALL reloc for now (it is relaxation only). Handle TLSDESC_{LOAD,ADD}_LO12 as paired pcrel relocs. For TLS GOT slot generation, generalize the logic to handle any combination of (GD, IE, TLSDESC). Add TLSDESC Rela generation. * ld/testsuite/ld-riscv-elf/tls*: Add TLSDESC instruction sequences next to the existing GD and IE sequences. Update expectations.