aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2023-05-26PR22263 ld testAlan Modra1-3/+29
A number of targets that I test regularly fail the "Build pr22263-1" test for various reasons. arm-linux-gnueabi: "undefined reference to `__aeabi_read_tp'" ia64-linux-gnu: "Explicit stops are ignored in auto mode" m68k-linux-gnu: "undefined reference to `__m68k_read_tp'" microblaze-linux-gnu: "undefined reference to `__tls_get_addr'" nios2-linux-gnu, s390-linux-gnu and sh4-linux-gnu have a tprel reloc in .got riscv64-linux-gnu has a dynamic relocation in text So only riscv really fails the pr. The rest fail due to test issues or lack of a linker optimisation. Lack of an optimisation isn't really a fail, but it's worth keeping the test to ensure those optimisations don't regress. The xfail targets may not be an exhaustive list. This just tidies test results for those for which I have cross compilers installed. PR 22263 * testsuite/ld-elf/tls.exp: Split pr22263 test into two parts, one to check for -z text errors, the other to check tprel linker optimisation. Supply needed symbols and assembler flags. xfail the linker optimisation on targets known to fail.
2023-05-24Remove accidentally added fileAndreas Schwab1-6/+0
2023-05-23PR30437 aarch64: make RELA relocs idempotentMichael Matz3-0/+35
normally RELA relocs in BFD should not consider the contents of the relocated place. The aarch64 psABI is even stricter, it specifies (section 5.7.16) that all RELA relocs _must_ be idempotent. Since the inception of the aarch64 BFD backend all the relocs have a non-zero src_mask, and hence break this invariant. It's normally not a very visible problem as one can see it only when the relocated place already contains a non-zero value, which usually only happens sometimes when using 'ld -r' (or as in the testcase when jumping through hoops to generate the relocations). Or with alternative toolchains that do encode stuff in the relocated places with the assumption that a relocation to that place ignores whatever is there (as they can according to the psABI). Golang is such a toolchain and https://github.com/golang/go/issues/39927 is ultimately caused by this problem: the testcase testGCData failing is caused by the garbage collection data-structure to describe a type containing pointers to be wrong. It's wrong because a field that's supposed to contain a file-relative offset (to some gcbits) has a relocation applied and that relocation has an addend which also is already part of the go-produced object file (so the addend is implicitely applied twice). bfd/ PR ld/30437 * elfnn-aarch64.c (elfNN_aarch64_howto_table): Clear src_mask if all relocation descriptors. ld/ * testsuite/ld-aarch64/rela-idempotent.s: New testcase. * testsuite/ld-aarch64/rela-idempotent.d: New. * testsuite/ld-aarch64/aarch64-elf.exp: Run it.
2023-05-19ld: drop stray blank from ld.texiJan Beulich1-1/+1
At least older makeinfo complains about it. Also fix an apparent typo while touching that line.
2023-05-19RISC-V: Support subtraction of .uleb128.Kuan-Lin Chen3-0/+37
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/96d6e190e9fc04a8517f9ff7fb9aed3e9876cbd6 There are some known limitations for now, * Do not shrink the length of the uleb128 value, even if the value is reduced after relaxations. Also reports error if the length grows up. * The R_RISCV_SET_ULEB128 needs to be paired with and be placed before the R_RISCV_SUB_ULEB128. bfd/ * bfd-in2.h: Regenerated. * elfnn-riscv.c (perform_relocation): Perform R_RISCV_SUB_ULEB128 and R_RISCV_SET_ULEB128 relocations. Do not shrink the length of the uleb128 value, and report error if the length grows up. Called the generic functions, _bfd_read_unsigned_leb128 and _bfd_write_unsigned_leb128, to encode the uleb128 into the section contents. (riscv_elf_relocate_section): Make sure that the R_RISCV_SET_ULEB128 must be paired with and be placed before the R_RISCV_SUB_ULEB128. * elfxx-riscv.c (howto_table): Added R_RISCV_SUB_ULEB128 and R_RISCV_SET_ULEB128. (riscv_reloc_map): Likewise. (riscv_elf_ignore_reloc): New function. * libbfd.h: Regenerated. * reloc.c (BFD_RELOC_RISCV_SET_ULEB128, BFD_RELOC_RISCV_SUB_ULEB128): New relocations to support .uleb128 subtraction. gas/ * config/tc-riscv.c (md_apply_fix): Added BFD_RELOC_RISCV_SET_ULEB128 and BFD_RELOC_RISCV_SUB_ULEB128. (s_riscv_leb128): Updated to allow uleb128 subtraction. (riscv_insert_uleb128_fixes): New function, scan uleb128 subtraction expressions and insert fixups for them. (riscv_md_finish): Called riscv_insert_uleb128_fixes for all sections. include/ * elf/riscv.h ((R_RISCV_SET_ULEB128, (R_RISCV_SUB_ULEB128): Defined. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/uleb128*: New testcase for uleb128 subtraction. binutils/ * testsuite/binutils-all/nm.exp: Updated since RISCV supports .uleb128.
2023-05-17Decorated symbols in import libs (BUG 30421)Luca Bacci4-8/+94
PR 30421 * cofflink.c (_decoration_hash_newfunc): New function. (_bfd_coff_link_hash_table_init): Call it. * libcoff-in.h (struct coff_link_hash_table): Add decoration_hash field. (struct decoration_hash_entry): Declare. (_decoration_hash_newfunc): Prototype. * libcoff.h: Regenerate. * emultempl/pe.em (set_decoration): New function. (pe_fixup_stdcalls): Call the new function. * emultempl/pep.em (set_decoration): New function. (pep_fixup_stdcalls): Call the new function. * pe-dll.c (make_one): Check for decoated symbols.
2023-05-16Document how to use the linker to create a resource only DLL.Nick Clifton2-0/+38
PR 30359 * ld.texi (WIN32): Document how to create a resource only DLL.
2023-05-16-Ur option documentationNick Clifton2-8/+16
* ld.texi (-Ur): Clarify the actions of this option.
2023-05-15LoongArch: Fix PLT entry generate bugmengqinggang1-1/+2
If a function symbol only get its address by la.global, without directly called by bl instruction, the PLT entry is not required. bfd/ChangeLog: * elfnn-loongarch.c (loongarch_elf_adjust_dynamic_symbol): Fix PLT entry generate bug. ld/ChangeLog: * testsuite/ld-elf/shared.exp: Clear xfail for LoongArch.
2023-05-13PR28902, -T script with INSERT orderingAlan Modra1-1/+8
The answer to PR28902 may be deduced from the existing INSERT documentation that says the default script is parsed after the -T INSERT script, if you assume (correctly) that nothing special is done when inserting into -T scripts overriding the default script. In both cases INSERT handling looks for the specified output section later on the internal list of parsed script commands. This isn't obvious though, so make the ordering explicit, and mention that section assignments are the same too. PR 28902 * ld.texi (INSERT): Specify ordering when -T is used both to override the default script and to augment.
2023-05-11Add LDPT_REGISTER_CLAIM_FILE_HOOK_V2 linker plugin hook [GCC PR109128]Joseph Myers25-6/+65
This is one part of the fix for GCC PR109128, along with a corresponding GCC change. Without this patch, what happens in the linker, when an unused object in a .a file has offload data, is that elf_link_is_defined_archive_symbol calls bfd_link_plugin_object_p, which ends up calling the plugin's claim_file_handler, which then records the object as one with offload data. That is, the linker never decides to use the object in the first place, but use of this _p interface (called as part of trying to decide whether to use the object) results in the plugin deciding to use its offload data (and a consequent mismatch in the offload data present at runtime). The new hook allows the linker plugin to distinguish calls to claim_file_handler that know the object is being used by the linker (from ldmain.c:add_archive_element), from calls that don't know it's being used by the linker (from elf_link_is_defined_archive_symbol); in the latter case, the plugin should avoid recording the object as one with offload data. bfd/ * plugin.c (struct plugin_list_entry): Add claim_file_v2. (register_claim_file_v2): New. (try_load_plugin): Use LDPT_REGISTER_CLAIM_FILE_HOOK_V2. (ld_plugin_object_p): Take second argument. (bfd_link_plugin_object_p): Update call to ld_plugin_object_p. (register_ld_plugin_object_p): Update argument prototype. (bfd_plugin_object_p): Update call to ld_plugin_object_p. * plugin.h (register_ld_plugin_object_p): Update argument prototype. include/ * plugin.api.h (ld_plugin_claim_file_handler_v2) (ld_plugin_register_claim_file_v2) (LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New. (struct ld_plugin_tv): Add tv_register_claim_file_v2. ld/ * plugin.c (struct plugin): Add claim_file_handler_v2. (LDPT_REGISTER_CLAIM_FILE_HOOK_V2): New. (plugin_object_p): Add second argument. Update call to plugin_call_claim_file. (register_claim_file_v2): New. (set_tv_header): Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2. (plugin_call_claim_file): Add argument known_used. (plugin_maybe_claim): Update call to plugin_object_p. * testplug.c, testplug2.c, testplug3.c, testplug4.c: Handle LDPT_REGISTER_CLAIM_FILE_HOOK_V2. * testsuite/ld-plugin/plugin-1.d, testsuite/ld-plugin/plugin-10.d, testsuite/ld-plugin/plugin-11.d, testsuite/ld-plugin/plugin-13.d, testsuite/ld-plugin/plugin-14.d, testsuite/ld-plugin/plugin-15.d, testsuite/ld-plugin/plugin-16.d, testsuite/ld-plugin/plugin-17.d, testsuite/ld-plugin/plugin-18.d, testsuite/ld-plugin/plugin-19.d, testsuite/ld-plugin/plugin-2.d, testsuite/ld-plugin/plugin-26.d, testsuite/ld-plugin/plugin-3.d, testsuite/ld-plugin/plugin-30.d, testsuite/ld-plugin/plugin-4.d, testsuite/ld-plugin/plugin-5.d, testsuite/ld-plugin/plugin-6.d, testsuite/ld-plugin/plugin-7.d, testsuite/ld-plugin/plugin-8.d, testsuite/ld-plugin/plugin-9.d: Update test expectations.
2023-05-10Add linker option to include local symbols in the linker map.Nick Clifton10-2/+168
PR 16566 * ldlang.c (ld_is_local_symbol): New function. (print_input_section): Add code to display local symbols in the section. * ldlex.h (enum option_values): Add OPTION_PRINT_MAP_LOCALS and OPTION_PRINT_MAP_LOCALS. * lexsup.c (ld_options[]): Add entries for --print-map-locals and --no-print-map-locals. * NEWS: Mention the new feature. * ld.h (struct ld_config_type): Add print_map_locals field. * ld.texi: Document the new command line option. * testsuite/ld-scripts/sizeof.s: Add a local symbol. * testsuite/ld-scripts/map-locals.d: New test control file. * testsuite/ld-scripts/map-address.exp: Run the new test.
2023-05-09regen ld/Makefile.inAlan Modra1-33/+45
2023-05-08pe.em and pep.em make_import_fixupAlan Modra2-40/+76
This is a little cleanup that I made when looking at pr30343 that makes it more obvious that make_import_fixup in both files are identical (and in fact the new pep.em read_addend could be used in both files). * emultempl/pep.em (read_addend): Extract from.. (make_import_fixup): ..here. * emultempl/pe.em (read_addend): Similarly. (make_import_fixup): Similarly. Add debug code from pep.em.
2023-05-08PR30343, LTO ignores linker reference to _pei386_runtime_relocatorAlan Modra3-0/+67
Make a reference to _pei386_runtime_relocator before LTO recompilation. This is done regardless of whether such a reference will be used, because it can't be known whether it is needed before LTO. I also found it necessary to enable long section names for the bfd created in make_runtime_pseudo_reloc, because otherwise when writing it out to the bfd-in-memory we get the section written as .rdata_r which when read back in leads to a linker warning ".rdata_r: section below image base" and likely runtime misbehaviour. PR 30343 * emultempl/pe.em (make_runtime_ref): New function. (gld${EMULATION_NAME}_before_plugin_all_symbols_read): New function. (LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): Define. * emultempl/pep.em: Similarly to pe.em. * pe-dll.c (make_runtime_pseudo_reloc): Set long section names.
2023-05-04Stop the linker from loosing the entry point for COFF/PE code when compiling ↵Nick Clifton3-0/+13
with LTO enabled. PR 30300 * emultempl/pep.em (set_entry_point): Add an undefined reference to the entry point if it has been constructed heuristically. * emultempl/pe.em (set_entry_point): Likewise.
2023-05-04ld: pru: Place exception-handling sections correctlyDimitar Dimitrov2-8/+36
* scripttempl/pru.sc (OUTPUT_SECTION_ALIGN): New helper variable to place at end of DMEM output sections. (.data): Use the helper variable. (.eh_frame): New output section. (.gnu_extab): Ditto. (.gcc_except_table): Ditto. (.resource_table): Use the helper variable.
2023-04-28ld: Use run_cc_link_tests for PR ld/26391 testsH.J. Lu1-11/+4
Use run_cc_link_tests for PR ld/26391 tests to compile PR ld/26391 tests in C. PR ld/30002 * testsuite/ld-elf/elf.exp: Use run_cc_link_tests for PR ld/26391 tests.
2023-04-27Fix PR30358, performance with --sort-sectionMichael Matz1-31/+61
since af31506c we only use the binary tree when section sorting is required. While its unbalanced and hence can degrade to a linear list it should otherwise have been equivalent to the old code relying on insertion sort. Unfortunately it was not. The old code directly used lang_add_section to populate the sorted list, the new code first populates the tree and only then does lang_add_section on the sorted result. In the testcase we have very many linkonce section groups, and hence lang_add_section won't actually insert anything for most of them. That limited the to-be-sorted list length previously. The tree-sorting code OTOH first created a tree of all candidates sections, including those that wouldn't be inserted by lang_add_section, hence increasing the size of the sorting problem. In the testcase the chain length went from about 1500 to 106000, and in the degenerated case (as in the testcase) that goes in quadratically. This splits out most of the early-out code from lang_add_section to its own function and uses the latter to avoid inserting into the tree. This refactoring slightly changes the order of early-out tests (the ones based on section flags is now done last, and only in lang_add_section). The new function is not a pure predicate: it can give warnings and it might change output_section, like the old early-out code did. I have also added a skip-warning case in the first discard case, whose non-existence seemed to have been an oversight. PR 30358 * ldlang.c (wont_add_section_p): Split out from ... (lang_add_section): ... here. (output_section_callback_sort): Use wont_add_section_p to not always add sections to the sort tree.
2023-04-27Add support for %x and %lx formats to the linker's vinfo() function.Nick Clifton2-1/+21
2023-04-25section-select: Fix performance problem (PR30367)Michael Matz1-4/+12
when using many wild-statements with non-wildcard filenames we were running into quadraticness via repeatedly using lookup_name on a long list of loaded files. I've originally retained using lookup_name because that preserved existing behaviour most obviously. In particular in matching wild-statements when using a non-wildcard filename it matches against local_sym_name, not the filename member. If the wildspec would have an archive-spec or a wildcard it would use the filename member, though. Also it would load the named file (and ignore it, as being not equal to the currently considered input-statement). Rewrite this to not use lookup_name but retain the comparison against local_sym_name with a comment to that effect. PR 30367 * ldlang.c (walk_wild_section_match): Don't use lookup_name but directly compare spec and local_sym_name.
2023-04-23MIPS: support mips*64 as CPU and gnuabi64 as ABIYunQiang Su1-2/+10
For MIPS64r6 ports, Debian as an example, `mipsisa64r6el` is used as the cpu name in triple. Let's recognize them by `mips*64*(el)`. For 64bit Ports, like Debian's mips64el and mips64r6el ports, `gnuabi64` is used as the abi section. Let's use N64 abi by default for the triple with gnuabi64.
2023-04-23LoongArch: Fix loongarch32 test failsmengqinggang1-7/+7
Regenerated macro_op_32.d and add skip loongarch64-*-*. gas/ChangeLog: * testsuite/gas/loongarch/macro_op_32.d: Regenerated. ld/ChangeLog: * testsuite/ld-loongarch-elf/macro_op_32.d: Regenerated.
2023-04-21RISC-V: Optimize relaxation of gp with max_alignment.Lifang Xia3-0/+75
This should be the first related issue, which posted in riscv-gnu-toolchain, https://github.com/riscv-collab/riscv-gnu-toolchain/issues/497 If the output sections are not between gp and the symbol, then their alignments shouldn't affect the gp relaxation. However, this patch improves this idea even more, it limits the range to the gp+-2k, which means only the output section which are in the [gp-2K, gp+2K) range need to be considered. Even if the output section candidates may be different for each relax passes, the symbol that can be relaxed ar this round will not be truncated at next round. That is because this round you can do relaxation which means that the section where the symbol is located is within the [gp-2K, gp+2K) range, so all the output section alignments between them should be considered. In other words, if the alignments between them may cause truncated, then we should already preserve the size and won't do the gp relaxation this time. This patch can resolve the github issue which mentioned above, and also passed all gcc/binutils regressions of riscv-gnu-toolchain, so should be worth and safe enough to commit. Originally, this patch also do the same optimization for the call relaxations, https://sourceware.org/pipermail/binutils/2022-October/123918.html But just in case there is something that has not been considered, we only deal with the gp relaxation at this time. bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): Added new bfd_vma, max_alignment_for_gp. It is used to record the maximum alignment of the output sections, which are in the [gp-2K, gp+2k) range. (riscv_elf_link_hash_table_create): Init max_alignment_for_gp to -1. (_bfd_riscv_get_max_alignment): Added new parameter, gp. If gp is zero, then all the output section alignments are possible candidates; Otherwise, only the output sections which are in the [gp-2K, gp+2K) range need to be considered. (_bfd_riscv_relax_lui): Called _bfd_riscv_get_max_alignment with the non-zero gp if the max_alignment_for_gp is -1. (_bfd_riscv_relax_pc): Likewise. (_bfd_riscv_relax_section): Record the first input section, so that we can reset the max_alignment_for_gp for each repeated relax passes. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/relax-max-align-gp.*: New testcase. It fails without this patch.
2023-04-21ld: add missing period after @xrefJan Beulich1-1/+1
At least older versions of one of the doc generation tools complain (warn) about it missing.
2023-04-20PR30343 infrastructureAlan Modra2-9/+10
Make ldemul_before_plugin_all_symbols_read more useful. * ldlang.c (lang_process): Move call to ldemul_before_plugin_all_symbols_read outside BFD_SUPPORTS_PLUGINS. Allow backends to add to gc_sym_list before handling entry sym. * ldelf.c (ldelf_before_plugin_all_symbols_read): Test lto_plugin_active.
2023-04-18Symbols with GOT relocatios do not fix adjustbalemengqinggang2-27/+31
gas * config/tc-loongarch.c (loongarch_fix_adjustable): Symbols with GOT relocatios do not fix adjustbale. * testsuite/gas/loongarch/macro_op_large_abs.d: Regenerated. * testsuite/gas/loongarch/macro_op_large_pc.d: Regenerated. ld * testsuite/ld-loongarch-elf/macro_op.d: Regenerated. -
2023-04-17Add support for the .gnu.sgstubs section to the linker for ARM/ELF based ↵Nick Clifton2-0/+8
targets. PR 30354 * emulparams/armelf.sh (OTHER_PLT_SECTIONS): Define in order to handle the .gnu.sgstubs section.
2023-04-13arc: Update ARC specific linker tests.Claudiu Zissulescu5-5/+12
All the tests are designed for a little-endian ARC system. Thus, update the arc predicate in arc.exp, improve the matching pattern for linker relaxation test, and add linker scripts to nps-1x tests. Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
2023-04-12Fix typos in the linker's documentation of the ↵Nick Clifton2-3/+8
--enable-non-contiguous-regions option.
2023-04-04bfd+ld: when / whether to generate .c filesJan Beulich5-9/+11
Having been irritated by seeing bfd/elf{32,64}-aarch64.c to be re- generated in x86-only builds, I came across 769a27ade588 ("Re: bfd BLD-POTFILES.in dependencies"). I think this went slightly too far, as outside of maintainer mode dependencies will cause the subset of files to be (re-)generated which are actually needed for the build. Generating them all is only needed when wanting to update certain files under bfd/po/, i.e. in maintainer mode. In the course of looking around in an attempt to try to understand how things are meant to work, I further noticed that ld has got things slightly wrong too: BLD-POTFILES.in depending on $(BLD_POTFILES) isn't quite right (the output doesn't change when any of the enumerated files changes; it's the mere presence which matters); like in bfd it looks like we would better extend BUILT_SOURCES accordingly. Furthermore it became apparent that ld fails to enumerate the .c files generated from the .l and .y ones. While in their absence it was benign whether translatable strings in the source files were actually marked as such, this now becomes relevant. Mark respective strings at the same time, but skipping ones which look to be of interest for debugging purposes only (e.g. such used by printf() enclosed in #ifdef TRACE).
2023-03-31lto: Don't add indirect symbols for versioned aliases in IRH.J. Lu3-0/+17
Linker adds indirect symbols for versioned symbol aliases, which are created by ".symver foo, foo@FOO", by checking symbol type, value and section so that references to foo will be replaced by references to foo@FOO if foo and foo@FOO have the same symbol type, value and section. But in IR, since all symbols of the same type have the same value and section, we can't tell if a symbol is an alias of another symbol by their types, values and sections. We shouldn't add indirect symbols for versioned symbol aliases in IR. bfd/ PR ld/30281 * elflink.c (elf_link_add_object_symbols): Don't add indirect symbols for ".symver foo, foo@FOO" aliases in IR. ld/ PR ld/30281 * testsuite/ld-plugin/lto.exp: Add PR ld/30281 test. * testsuite/ld-plugin/pr30281.t: New file. * testsuite/ld-plugin/pr30281.c: Likewise.
2023-03-29Fix typo in ld manual --enable-non-contiguous-regions exampleRoland McGrath1-1/+1
2023-03-30RISC-V: PR28789, Reject R_RISCV_PCREL relocations with ABS symbol in PIC/PIE.Palmer Dabbelt8-0/+70
The non-preemptible SHN_ABS symbol with a pc-relative relocation should be disallowed when generating shared object (pic and pie). Generally, the following cases, which refer to pr25749, will cause a symbol be non-preemptible, * -pie, or -shared with -symbolic * STV_HIDDEN, STV_INTERNAL, STV_PROTECTED * Have dynamic symbol table, but without the symbol * VER_NDX_LOCAL However, PCREL_HI20/LO12 relocs are always bind locally when generating shared object, so not only the non-preemptible absolute symbol need to be disallowed, all absolute symbol references need but except that they are defined in linker script. If we also disallow the absolute symbol in linker script, then the glibc-linux toolchain build failed, so regard them as pc-relative symbols, just like what x86 did. Maybe we should add this check for all pc-relative relocations, rather than just handle in R_RISCV_PCREL relocs. Ideally, since the value of SHN_ABS symbol is a constant, only S - A relocations should be allowed in the shared object, so only BFD_RELOC_8/16/32/64 are allowed, which means R_RISCV_32/R_RISCV_64. bfd/ PR 28789 * elfnn-riscv.c (riscv_elf_check_relocs): The absolute symbol cannot be referneced with pc-relative relocation when generating shared object. ld/ PR 28789 * ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * ld/testsuite/ld-riscv-elf/pcrel-reloc*: New testcases.
2023-03-30RISC-V: Clarify link behaviors of R_RISCV_32/64 relocations with ABS symbol.Nelson Chu13-2/+183
There are two improvements, which are all referenced to aarch64, * R_RISCV_32 with non ABS symbol cannot be used under RV64 when making shard objects. * Don't need dynamic relocation for R_RISCV_32/64 under RV32/RV64 when making shared objects, if the referenced symbol is local ABS symbol. However, considering this link, https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/341 Seems like we should makes all R_RISCV_32/64 relocs with ABS symbol that don't need any dynamic relocations when making the shared objects. But anyway, I just sync the current behavior as aarch64 ld, in case there are any unexpected behaviors happen. Passed the gcc/binutils regressions in riscv-gnu-toolchain. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Only allow R_RISCV_32 with ABS symbol under RV64. (riscv_elf_relocate_section): R_RISCV_32/64 with local ABS symbol under RV32/RV64 doesn't need any dynamic relocation when making shared objects. I just make the implementations similar to other targets, so that will be more easy to mainatain. ld/ * testsuite/ld-riscv-elf/data-reloc*: New testcases. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Added new data-reloc* testcases, and need to make ifunc-seperate* testcases work for rv32. * testsuite/ld-riscv-elf/ifunc-seperate-caller-nonplt.s: Likewise. * testsuite/ld-riscv-elf/ifunc-seperate-caller-plt.s: Likewise.
2023-03-29ld testsuite CFLAGS_FOR_TARGETAlan Modra2-11/+7
run_host_cmd adds $gcc_B_opt and $ld_L_opt to the command line if it detects the program being run is a compiler. Since the program being run in lto.exp linking pr28138 is "sh", we need to add these by hand. This isn't exactly as run_host_cmd does, as it lacks reordering of any user -B option in $CC_FOR_TARGET, but it's better than ignoring gcc_B_opt. This fixes a mips64 testsuite fail. ld_compile adds CFLAGS_FOR_TARGET and other flags as well, so there is no need for the ld_compile command line to include CFLAGS_FOR_TARGET. Fixing this is just a tidy. * testsuite/ld-plugin/lto.exp: Add gcc_B_opt, CFLAGS_FOR_TARGET and $ld_L_opt to pr28138 link line. * testsuite/lib/ld-lib.exp (run_ld_link_tests): Don't pass unnecessary flags to ld_compile. (run_ld_link_exec_tests, run_cc_link_tests): Likewise.
2023-03-27Use stdint types in coff internal_auxentAlan Modra1-1/+1
long is a poor choice of type to store 32-bit values read from objects files by H_GET_32. H_GET_32 doesn't sign extend so tests like that in gdb/coffread.c for "negative" values won't work if long is larger than 32 bits. If long is 32-bit then code needs to be careful to not accidentally index negative array elements. (I'd rather see a segfault on an unmapped 4G array index than silently reading bogus data.) long is also a poor choice for x_sect.s_scnlen, which might have 64-bit values. It's better to use unsigned exact width types to avoid surprises. I decided to change the field names too, which makes most of this patch simply renaming. Besides that there are a few places where casts are no longer needed, and where printf format strings or tests need adjusting. include/ * coff/internal.h (union internal_auxent): Use unsigned stdint types. Rename l fields to u32 and u64 as appropriate. bfd/ * coff-bfd.c, * coff-rs6000.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * coffswap.h, * peXXigen.c, * xcofflink.c: Adjust to suit internal_auxent changes. binutils/ * rdcoff.c: Adjust to suit internal_auxent changes. gas/ * config/obj-coff.h, * config/tc-ppc.c: Adjust to suit internal_auxent changes. gdb/ * coffread.c, * xcoffread.c: Adjust to suit internal_auxent changes. ld/ * pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-23bfd: aarch64: Optimize BTI stubs PR30076Szabolcs Nagy3-0/+207
Don't insert a second stub if the target is already compatible with an indirect branch.
2023-03-23bfd: aarch64: Fix stubs that may break BTI PR30076Szabolcs Nagy5-0/+192
Insert two stubs in a BTI enabled binary when fixing long calls: The first is near the call site and uses an indirect jump like before, but it targets the second stub that is near the call target site and uses a direct jump. This is needed when a single stub breaks BTI compatibility. The stub layout is kept fixed between sizing and building the stubs, so the location of the second stub is known at build time, this may introduce padding between stubs when those are relaxed. Stub layout with BTI disabled is unchanged.
2023-03-20Changed ld and gas BPF testsCupertino Miranda12-99/+3
Recent BPF patch removed and renamed the list of relocations based on the limitations of BPF instruction set. This patch is a correction to the tests.
2023-03-19Regen ld/po/BLD-POTFILES.inAlan Modra1-0/+1
2023-03-17Another source_shAlan Modra1-1/+1
* scripttempl/z80.sc: Use source_sh to source elf.sc.
2023-03-16Re: Add --enable-linker-version optionChristophe Lyon2-2/+2
The recently-added ld-version*.d tests expect .*GNU ld \(GNU Binutils\) 2.* in the .comment section. However, when buidling --with-pkgversion=XXX, we get GNU ld (XXX) 2.[...] instead, leading to a spurious FAIL. This small patch replaces "GNU Binutils" with ".*" instead. I inspected other testcases to see if we already had similar occurrences but I couldn't see any, so I hope this fix is OK for the purpose? Thanks, Christophe
2023-03-16ld/testsuite: disable ilp32 tests for aarch64-qnxClément Chigot39-0/+39
aarch64nto32 emulation isn't supported. The tests will then fall back on aarch64elf32. It does work but some extra warnings are being generated because the "-z relro" being added aarch64nto but ignored by aarch64elf32 emulation. Skip the tests to avoid any problems. ld/ChangeLog: * testsuite/ld-aarch64/emit-relocs-112-overflow.d: Skip for aarch64nto. * testsuite/ld-aarch64/emit-relocs-112.d: Likewise. * testsuite/ld-aarch64/emit-relocs-113.d: Likewise. * testsuite/ld-aarch64/emit-relocs-114-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-114.d: Likewise. * testsuite/ld-aarch64/emit-relocs-115.d: Likewise. * testsuite/ld-aarch64/emit-relocs-116-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-116.d: Likewise. * testsuite/ld-aarch64/emit-relocs-117.d: Likewise. * testsuite/ld-aarch64/emit-relocs-118-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-118.d: Likewise. * testsuite/ld-aarch64/emit-relocs-119.d: Likewise. * testsuite/ld-aarch64/emit-relocs-22.d: Likewise. * testsuite/ld-aarch64/emit-relocs-23.d: Likewise. * testsuite/ld-aarch64/emit-relocs-28.d: Likewise. * testsuite/ld-aarch64/emit-relocs-86-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-86.d: Likewise. * testsuite/ld-aarch64/emit-relocs-87.d: Likewise. * testsuite/ld-aarch64/emit-relocs-88-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-88.d: Likewise. * testsuite/ld-aarch64/emit-relocs-89.d: Likewise. * testsuite/ld-aarch64/emit-relocs-90-overflow.d: Likewise. * testsuite/ld-aarch64/emit-relocs-90.d: Likewise. * testsuite/ld-aarch64/emit-relocs-92.d: Likewise. * testsuite/ld-aarch64/tls-desc-ie-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-all-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-gd-le-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-gdesc-le-2-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-gdesc-le-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-ie-le-2-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-ie-le-3-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-ie-le-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-ld-le-small-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-relax-ld-le-tiny-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-tiny-desc-le-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d: Likewise. * testsuite/ld-aarch64/tls-tiny-gd-le-ilp32.d: Likewise.
2023-03-16ld/testsuite: add aarch64nto to ld-aarch64Clément Chigot1-0/+3
ld/ChangeLog: * testsuite/ld-aarch64/aarch64-elf.exp: Add support for aarch64nto.
2023-03-16ld: add support of QNX stack arguments for aarch64ntoClément Chigot6-1/+220
QNX is handling the stack argument using a .note section. Generate it according to ELF argument -zexecstack, -zstack-size and a new NTO argument --lazy-stack. Another NTO argument --stack mimicking -zstack-size is added in order to ensure compatibility with previously made NTO linkers. This requires a new emultempl nto.em which is applied above the default ${ARCH}elf.em. ld/ChangeLog: * emulparams/aarch64nto.sh: Move to nto.em. * emultempl/nto.em: New file. * testsuite/ld-aarch64/aarch64-nto.exp: New test. * testsuite/ld-aarch64/nto-stack-note-1.d: New test. * testsuite/ld-aarch64/nto-stack-note-2.d: New test. * testsuite/ld-aarch64/start.s: New test.
2023-03-16configure: add new target aarch64-*-nto*Clément Chigot4-0/+49
This target has its own ld emulation based on aarch64elf.em.
2023-03-16Re: Add --enable-linker-verssionAlan Modra38-87/+70
Output sections without any input sections to initialise their flags have their flags initialised by data statements to LOAD, ALLOC, HAS_CONTENTS by default. This is wrong for .comment. Fix that by making the script initialise the section type to INFO, one of the noalloc section types. That also allows the address of .comment to be set to zero, as is usual for non-alloc sections. Also, use source_sh for all of the sourced scripts to set up make dependencies. PR 30187 * scripttempl/misc-sections.sc: Set .comment address to zero and type to INFO. * scripttempl/ft32.sc: Fix breakages from last edit. * scripttempl/arclinux.sc: Use source_sh to source DWARF.sc and misc-sections.sc. * scripttempl/avr.sc: Likewise. * scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. * scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. * scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. * scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. * scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. * scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. * scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/i386beos.sc: Likewise. * scripttempl/i386go32.sc: Likewise. * scripttempl/ia64vms.sc: Likewise. * scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/mmo.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. * scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. * scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. * testsuite/ld-scripts/ld-version-2.d: Don't skip ft32 or pru.
2023-03-15Add --enable-linker-version option to bfd linker to add an entry in the ↵Nick Clifton46-278/+243
.comment section. PR 30187 * NEWS: Mention the new feature. * ld.texi: Document the new feature. * ldgram.y: Handle LINKER_VERSION token. * ldlang.c (lang_add_version): New function. (enable_linker_version): New global variable. * ldlang.h (land_add_version): Prototype. (enable_linker_version): Export. * ldlex.h (OPTION_ENABLE_LINKER_VERSION): Define. (OPTION_DISABLE_LINKER_VERSION): Define. * ldlex.l (LINKER_VERSION): Add token. * lexsup.c (ld_options): Add --enable-linker-version and --disable-linker-version. (parse_args): Handle the new options. * scripttempl/arclinux.sc: Remove stabs and comment sections and replace with inclusion of misc-sections.sc * scripttempl/avr.sc: Likewise. * scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. * scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. * scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. * scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. * scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. * scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. * scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/ft32.sc: Likewise. * scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. * scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. * scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. * testsuite/ld-scripts/script.exp: Run new tests. * scripttempl/misc-sections.sc: New file. * testsuite/ld-scripts/ld-version-2.d: New file. * testsuite/ld-scripts/ld-version.d: New file. * testsuite/ld-scripts/ld-version.t: New file.
2023-03-10Revert ld ASCII supportAlan Modra11-213/+33
Revert "Prevent the ASCII linker script directive from generating huge amounts of padding if the size expression is not a constant." This reverts commit adbe951fc95943016325af08d677f18e8c177ac1. Revert "ld test asciz and ascii fails" This reverts the ascii.d part of commit 5f497256bee624f0fa470949aa41534093bc5b25. Revert "Add support for the ASCII directive inside linker scripts." This mostly reverts commit 9fe129a4105bb59398f73ce96938a94f19265b79 leaving the asciz.d and asciz.t changes in place.