aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2022-07-29ld: Extend ac_default_ld_warn_rwx_segments to all SPARC targets [PR29411]Rainer Orth2-3/+9
As discussed in PR ld/29411, the ld warning [...] has a LOAD segment with RWX permissions needs to be disabled on all SPARC targets, not just Solaris/SPARC: the .plt section is required to be RWX by the 32-bit SPARC ELF psABI and the 64-bit SPARC Compliance Definition 2.4.1. Given that ld only supports SPARC ELF targets, this patch implements this. Tested on sparc64-unknown-linux-gnu and sparc-sun-solaris2.11. 2022-07-28 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> ld: PR ld/29411 * configure.tgt (ac_default_ld_warn_rwx_segments): Extend to all sparc targets. Expand comment.
2022-07-26Stop the linker from complaining about RWX segments in sparc-solaris targets.Nick Clifton2-0/+7
PR 29411 * configure.tgt (ac_default_ld_warn_rwx_segments): Disable for sparc-solaris configurations.
2022-07-26PowerPC32 ld test fails with --enable-targets=allAlan Modra3-17/+11
Three pppc32 ld tests fail when spe support is included in the linker due to this snippet in ld/emulparams/elf32ppc.sh. if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then DATA_START_SYMBOLS="${RELOCATING+*crt1.o(.data .data.* .gnu.linkonce.d.*) PROVIDE (__spe_handle = .); *(.data.spehandle) . += 4 * (DEFINED (__spe_handle) || . != 0);}" fi * testsuite/ld-powerpc/tlsexe32.r: Pass with .data section present. * testsuite/ld-powerpc/tlsexe32no.r: Likewise. * testsuite/ld-powerpc/tlsso32.r: Likewise.
2022-07-26Updated translations for various sub-directoriesNick Clifton2-3601/+3750
2022-07-25ld: Compile 2 CTF tests with -O2H.J. Lu2-0/+2
When GCC 12 is used to build binutils with -O0, the following 2 tests failed: FAIL: Conflicted data syms, partially indexed, stripped, with variables FAIL: Conflicted data syms, partially indexed, stripped Compile 2 tests with -O2 to avoid test failures. PR ld/29378 * testsuite/ld-ctf/data-func-conflicted-vars.d: Compile with -O2. * testsuite/ld-ctf/data-func-conflicted.d: Likewise.
2022-07-25LoongArch: Add testcases for new relocate types.liuzhensong38-1607/+2285
gas/testsuite/gas/all/ gas.exp gas/testsuite/gas/loongarch/ jmp_op.d jmp_op.s macro_op.d macro_op.s macro_op_32.d macro_op_32.s macro_op_large_abs.d macro_op_large_abs.s macro_op_large_pc.d macro_op_large_pc.s reloc.d reloc.s ld/testsuite/ld-elf/ pr26936.d shared.exp ld/testsuite/ld-loongarch-elf/ attr-ifunc-4.c attr-ifunc-4.out disas-jirl.d ifunc.exp jmp_op.d jmp_op.s libnopic-global.s macro_op.d macro_op.s macro_op_32.d macro_op_32.s nopic-global-so.rd nopic-global-so.sd nopic-global.out nopic-global.s nopic-global.sd nopic-global.xd nopic-local.out nopic-local.rd nopic-local.s nopic-local.sd nopic-local.xd nopic-weak-global-so.rd nopic-weak-global-so.sd nopic-weak-global.out nopic-weak-global.s nopic-weak-global.sd nopic-weak-global.xd nopic-weak-local.out nopic-weak-local.rd nopic-weak-local.s nopic-weak-local.sd nopic-weak-local.xd pic.exp pic.ld
2022-07-25bfd: Delete R_LARCH_NONE from dyn info of LoongArch.liuzhensong1-1/+1
Some R_LARCH_64 in section .eh_frame will to generate R_LARCH_NONE, we change relocation to R_LARCH_32_PCREL from R_LARCH_64 in setction .eh_frame and not generate dynamic relocation for R_LARCH_32_PCREL. Add New relocate type R_LARCH_32_PCREL for .eh_frame. include/elf/ loongarch.h bfd/ bfd/bfd-in2.h libbfd.h reloc.c elfxx-loongarch.c elfnn-loongarch.c gas/config/ tc-loongarch.c binutils/ readelf.c ld/testsuite/ld-elf/ eh5.d
2022-07-25Re: PowerPC64 .branch_lt addressAlan Modra2-2/+21
On seeing PR29369 my suspicion was naturally on a recent powerpc64 change, commit 0ab80031430e. Without a reproducer, I spent time wondering what could have gone wrong, and while I doubt this patch would have fixed the PR, there are some improvements that can be made to cater for user silliness. I also noticed that when -z relro -z now sections are created out of order, with .got before .plt in the section headers but .got is laid out at a higher address. That's due to the address expression for .branch_lt referencing SIZEOF(.got) and so calling init_os (which creates a bfd section) for .got before the .plt section is created. Fix that by ignoring SIZEOF in exp_init_os. Unlike ADDR and LOADADDR which need to reference section vma and lma respectively, SIZEOF can and does cope with a missing bfd section by returning zero for its size, which of course is correct. PR 29369 * ldlang.c (exp_init_os): Don't create a bfd section for SIZEOF. * emulparams/elf64ppc.sh (OTHER_RELRO_SECTIONS_2): Revise .branch_lt address to take into account possible user sections with alignment larger than 8 bytes.
2022-07-22PR17122, OSX 10.9 build failureAlan Modra3-20/+3
sbrk hasn't been used in binutils/ or ld/ for quite some time (so the PR was fixed a while ago). Tidy up configury. PR 17122 binutils/ * configure.ac: Don't check for sbrk. * sysdep.h (sbrk): Don't supply fallback declaration. * config.in: Regenerate. * configure: Regenerate. ld/ * configure.ac: Don't check for sbrk. * config.in: Regenerate. * configure: Regenerate.
2022-07-21i386: Don't allow GOTOFF relocation against IFUNC symbol for PICH.J. Lu6-10/+6
We can't use the PLT entry as the function address for PIC since the PIC register may not be set up properly for indirect call. bfd/ PR ld/27998 * elf32-i386.c (elf_i386_relocate_section): Don't allow GOTOFF relocation against IFUNC symbol for PIC. ld/ PR ld/27998 * testsuite/ld-i386/pr27998a.d: Replace -shared with -e bar. * testsuite/ld-i386/pr27998b.d: Expect a linker error. * testsuite/ld-ifunc/ifunc-2-i386-now.d: Updated. * testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-i386.s: Replace @GOTOFF with @GOT. * testsuite/ld-ifunc/ifunc-2-local-i386.s: Likewise.
2022-07-19x86: Disallow invalid relocations against protected symbolsH.J. Lu7-11/+23
Since glibc 2.36 will issue warnings for copy relocation against protected symbols and non-canonical reference to canonical protected functions, change the linker to always disallow such relocations. bfd/ * elf32-i386.c (elf_i386_scan_relocs): Remove check for elf_has_indirect_extern_access. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. (elf_x86_64_relocate_section): Remove check for elf_has_no_copy_on_protected. * elfxx-x86.c (elf_x86_allocate_dynrelocs): Check for building executable instead of elf_has_no_copy_on_protected. (_bfd_x86_elf_adjust_dynamic_symbol): Disallow copy relocation against non-copyable protected symbol. * elfxx-x86.h (SYMBOL_NO_COPYRELOC): Remove check for elf_has_no_copy_on_protected. ld/ * testsuite/ld-i386/i386.exp: Expect linker error for PR ld/17709 test. * testsuite/ld-i386/pr17709.rd: Removed. * testsuite/ld-i386/pr17709.err: New file. * testsuite/ld-x86-64/pr17709.rd: Removed. * testsuite/ld-x86-64/pr17709.err: New file. * testsuite/ld-x86-64/pr28875-func.err: Updated. * testsuite/ld-x86-64/x86-64.exp: Expect linker error for PR ld/17709 test. Add tests for function pointer against protected function.
2022-07-19x86: Make protected symbols local for -sharedFangrui Song10-36/+23
Call _bfd_elf_symbol_refs_local_p with local_protected==true. This has 2 noticeable effects for -shared: * GOT-generating relocations referencing a protected data symbol no longer lead to a GLOB_DAT (similar to a hidden symbol). * Direct access relocations (e.g. R_X86_64_PC32) no longer has the confusing diagnostic below. __attribute__((visibility("protected"))) void *foo() { return (void *)foo; } // gcc -fpic -shared -fuse-ld=bfd relocation R_X86_64_PC32 against protected symbol `foo' can not be used when making a shared object The new behavior matches arm, aarch64 (commit 83c325007c5599fa9b60b8d5f7b84842160e1d1b), and powerpc ports, and other linkers: gold and ld.lld. Note: if some code tries to use direct access relocations to take the address of foo, the pointer equality will break, but the error should be reported on the executable link, not on the innocent shared object link. glibc 2.36 will give a warning at relocation resolving time. With this change, `#define elf_backend_extern_protected_data 1` is no longer effective. Just remove it. Remove the test "Run protected-func-1 without PIE" since -fno-pic address taken operation in the executable doesn't work with protected symbol in a shared object by default. Similarly, remove protected-data-1a and protected-data-1b. protected-data-1b can be made working by removing HAVE_LD_PIE_COPYRELOC from GCC (https://sourceware.org/pipermail/gcc-patches/2022-June/596678.html).
2022-07-18ld: Pass -nostdlib to compiler with -rH.J. Lu1-1/+1
Pass -nostdlib to compiler with -r to avoid unnecessary .o file and libraries. PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Pass -nostdlib with -r.
2022-07-18x86: Properly check invalid relocation against protected symbolH.J. Lu3-0/+31
Only check invalid relocation against protected symbol defined in shared object. bfd/ PR ld/29377 * elf32-i386.c (elf_i386_scan_relocs): Only check invalid relocation against protected symbol defined in shared object. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. ld/ PR ld/29377 * testsuite/ld-elf/linux-x86.exp: Run PR ld/29377 tests. * testsuite/ld-elf/pr29377a.c: New file. * testsuite/ld-elf/pr29377b.c: Likewise.
2022-07-08Fix regeneration of ld configure and makefilesNick Clifton3-1487/+626
2022-07-08Update version to 2.39.50 and regenerate filesNick Clifton4-2411/+3369
2022-07-08Add markers for 2.39 branchNick Clifton2-0/+6
2022-06-29Re: ld/x86: skip p_align-1 tests with unsuitable compilerAlan Modra1-3/+11
commit d0e0f9c87a3e results "ERROR: i586-linux-cc does not exist" if cross-building an i586-linux target without a target compiler installed. * testsuite/ld-elf/linux-x86.exp (compiler_honours_aligned): New. Use it after first testing check_compiler_available.
2022-06-28ld/x86: skip p_align-1 tests with unsuitable compilerJan Beulich1-36/+46
When the compiler doesn't properly arrange for foo's alignment, there's no point even trying these tests. Report the situation as a single "unsupported" test.
2022-06-28PowerPC64: align plt_branch stubsAlan Modra5-47/+44
plt_branch stubs are similar to plt_call stubs in that they branch via bctr. Align them too. bfd/ * elf64-ppc.c (ppc_size_one_stub): Align plt_branch stubs as for plt_call stubs. ld/ * testsuite/ld-powerpc/elfv2exe.d: Adjust for plt_branch changes. * testsuite/ld-powerpc/notoc.d: Likewise. * testsuite/ld-powerpc/notoc.wf: Likewise. * testsuite/ld-powerpc/notoc3.d: Likewise. * testsuite/ld-powerpc/pr23937.d: Likewise.
2022-06-28Re: Disable execstack and rwx segments warnings for MIPS targets.Alan Modra2-3/+3
PR 29263 * configure.ac: Fix typo. * testsuite/ld-elf/elf.exp: Add mips to targets that need --warn-execstack to pass first pr29072 test.
2022-06-27Disable execstack and rwx segments warnings for MIPS targets.Nick Clifton4-29/+48
PR 29263 * configure.ac: Move HPPA specific code from here... * configure.tgt: ... to here. Add similar code for MIPS. Move code for CRIS, MIPS and HPPA to block at start of file. * configure: Regenerate.
2022-06-27drop XC16x bitsJan Beulich21-543/+3
Commit 04f096fb9e25 ("Move the xc16x target to the obsolete list") moved the architecture from the "obsolete but still available" to the "obsolete / support removed" list in config.bfd, making the architecture impossible to enable (except maybe via "enable everything" options"). Note that I didn't touch */po/*.po{,t} on the assumption that these would be updated by some (half)automatic means.
2022-06-27PowerPC64 .branch_lt addressAlan Modra2-3/+3
.branch_lt is really an extension of .plt, as is .iplt. We'd like all of the PLT sections to be fixed relative to .TOC. after stub sizing, because changes in offset to PLT entries might mean a change in stub sizes. When -z relro, the relro layout does this by laying out sections from the end of the relro segment. So for example, a change in .eh_frame (which happens after stub sizing) will keep the same GOT to PLT offset when -z relro. Not so when -z norelro, because then the usual forward layout of section is done and .got is more aligned than .branch_lt. * emulparams/elf64ppc.sh: Set .branch_lt address fixed relative to .got. * testsuite/ld-powerpc/elfv2exe.d: Adjust to suit.
2022-06-27-z relro relaxation and ld script SIZEOFAlan Modra8-26/+33
A number of targets use assignments like: . = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 12 ? 12 : 0, .); (from i386) in linker scripts to put the end of the relro segment past the header in .got.plt. Examination of testcases like those edited by this patch instead sees the end of the relro segment being placed at the start of .got.plt. For the i386 pie1 test: [ 9] .got.plt PROGBITS 00002000 001000 00000c 04 WA 0 0 4 GNU_RELRO 0x000f90 0x00001f90 0x00001f90 0x00070 0x00070 R 0x1 A map file shows: .dynamic 0x0000000000001f90 0x70 *(.dynamic) .dynamic 0x0000000000001f90 0x70 tmpdir/pie1.o 0x0000000000001f90 _DYNAMIC .got 0x0000000000002000 0x0 *(.got) .got 0x0000000000002000 0x0 tmpdir/pie1.o *(.igot) 0x0000000000002ff4 . = DATA_SEGMENT_RELRO_END (., (SIZEOF (.got.plt) >= 0xc)?0xc:0x0) .got.plt 0x0000000000002000 0xc *(.got.plt) .got.plt 0x0000000000002000 0xc tmpdir/pie1.o 0x0000000000002000 _GLOBAL_OFFSET_TABLE_ The DATA_SEGMENT_RELRO_END value in the map file is weird too. All of this is triggered by SIZEOF (.got.plt) being evaluated wrongly as zero. Fix it by taking into account the action of lang_reset_memory_regions during relaxation. * ldexp.c (fold_name <SIZEOF>): Use rawsize if size has been reset. * ldlang.c (lang_size_sections_1): Don't reset processed_vma here. * testsuite/ld-i386/pie1.d: Adjust to suit. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-06-25arm: Define elf_backend_extern_protected_data to 0 [PR 18705]Fangrui Song1-1/+1
Similar to commit 4fb55bf6a9606eb7b626c30a9f4e71d6c2d4fbb2 for aarch64. Commit b68a20d6675f1360ea4db50a9835c073675b9889 changed ld to produce R_ARM_GLOB_DAT but that defeated the purpose of protected visibility as an optimization. Restore the previous behavior (which matches ld.lld) by defining elf_backend_extern_protected_data to 0.
2022-06-23aarch64: Allow PC-relative relocations against protected STT_FUNC for -sharedFangrui Song3-0/+19
__attribute__((visibility("protected"))) void *foo() { return (void *)foo; } gcc -fpic -shared -fuse-ld=bfd fails with the confusing diagnostic: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `foo' which may bind externally can not be used when making a shared object; recompile with -fPIC Call _bfd_elf_symbol_refs_local_p with local_protected==true to suppress the error. The new behavior matches gold and ld.lld. Note: if some code tries to use direct access relocations to take the address of foo (likely due to -fno-pic), the pointer equality will break, but the error should be reported on the executable link, not on the innocent shared object link. glibc 2.36 will give a warning at relocation resolving time.
2022-06-23aarch64: Define elf_backend_extern_protected_data to 0 [PR 18705]Fangrui Song1-1/+1
Follow-up to commit 90b7a5df152a64d2bea20beb438e8b81049a5c30 ("aarch64: Disallow copy relocations on protected data"). Commit 32f573bcb3aaa1c9defcad79dbb5851fcc02ae2d changed ld to produce R_AARCH64_GLOB_DAT but that defeated the purpose of protected visibility as an optimization. Restore the previous behavior (which matches ld.lld) by defining elf_backend_extern_protected_data to 0.
2022-06-22aarch64: Disallow copy relocations on protected dataFangrui Song3-0/+19
If an executable has copy relocations for extern protected data, that can only work if the shared object containing the definition is built with assumptions (a) the compiler emits GOT-generating relocations (b) the linker produces R_*_GLOB_DAT instead of R_*_RELATIVE. Otherwise the shared object uses its own definition directly and the executable accesses a stale copy. Note: the GOT relocations defeat the purpose of protected visibility as an optimization, and it turns out this never worked perfectly. glibc 2.36 will warn on copy relocations on protected data. Let's produce a warning at link time, matching ld.lld which has been used on many aarch64 OSes. Note: x86 requires GNU_PROPERTY_NO_COPY_ON_PROTECTED to have the error. This is to largely due to GCC 5's "x86-64: Optimize access to globals in PIE with copy reloc" which started to use direct access relocations for external data symbols in -fpie mode. GCC's aarch64 port does not have the change. Nowadays with most builds switching to -fpie/-fpic, aarch64 mostly doesn't need to worry about copy relocations. So for aarch64 we simply don't check GNU_PROPERTY_NO_COPY_ON_PROTECTED.
2022-06-21ld: regenerate configure after recent misgenerationNick Alcock1-118/+103
Things work again after this. ld/ChangeLog: * configure: Regenerate.
2022-06-21Default to disabling the linker warnings about execstack and RWX segments if ↵Nick Clifton4-109/+164
the target is the HPPA architecture. PR 29263 * configure.ac (ac_default_ld_warn_execstack): Default to 'no' for HPPA targets. (ac_default_ld_warn_rwx_segments): Likewise. * configure: Regenerate. * testsuite/ld-elf/elf.exp: Add the --warn-execstack command line option to the command line when running execstack tests for the HPPA target.
2022-06-18Fix the sorting algorithm for reloc entriesTomoaki Kawada3-0/+31
The optimized insertion sort algorithm in `elf_link_adjust_relocs` incorrectly assembled "runs" from unsorted entries and inserted them to an already-sorted prefix, breaking the loop invariants of insertion sort. This commit updates the run assembly loop to break upon encountering a non-monotonic change in the sort key. PR 29259 bfd/ * elflink.c (elf_link_adjust_relocs): Ensure run being inserted is sorted. ld/ * testsuite/ld-elf/pr29259.d, * testsuite/ld-elf/pr29259.s, * testsuite/ld-elf/pr29259.t: New test.
2022-06-16Always free matching vector from bfd_check_format_matchesAlan Modra1-1/+6
At least one place calling list_matching_formats failed to free the "matching" vector from bfd_check_format_matches afterwards. Fix that by calling free inside list_matching_formats. binutils/ * bucomm.c (list_matching_formats): Free arg. * addr2line.c (process_file): Adjust to suit. * ar.c (open_inarch, ranlib_touch): Likewise. * coffdump.c (main): Likewise. * nm.c (display_archive, display_file): Likewise. * objcopy.c (copy_file): Likewise. * objdump.c (display_object_bfd): Likewise. * size.c (display_bfd): Likewise. * srconv.c (main): Likewise. ld/ * ldlang.c (load_symbols): Free "matching".
2022-06-14BFD_RELOC_MIPS_16Alan Modra2-9/+6
MIPS should not be using BFD_RELOC_16 for its R_MIPS_16 relocation, since R_MIPS_16 specifies a 16-bit field in a 32-bit word. BFD_RELOC_16, emitted by generic code to handle fixups on 16-bit data directives, expects fixups to operate on the whole of a 16-bit word. This patch corrects the problem by using BFD_RELOC_MIPS_16, a new bfd reloc that is used to generate R_MIPS_16. BFD_RELOC_16 is handled in md_apply_fix for cases where the fixup can be applied at assembly time. Like BFD_RELOC_8, BFD_RELOC_16 now has no corresponding object file relocation, and thus .half, .hword, .short and .dc.w must be resolved at assembly time. BFD_RELOC_MIPS_REL16 is removed by this patch since it isn't used. PR 3243 PR 26542 * reloc.c (BFD_RELOC_MIPS_16): Rename from BFD_RELOC_MIPS_REL16. * elf32-mips.c (mips_reloc_map): Map BFD_RELOC_MIPS_16 to R_MIPS_16. * elf64-mips.c (mips_reloc_map): Likewise, delete BFD_RELOC_MIPS_REL16. * elfn32-mips.c (mips_reloc_map): Likewise. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. gas/ * config/tc-mips.c (append_insn): Handle BFD_RELOC_MIPS_16. (macro_build): Likewise. (mips_percent_op <%half>): Generate BFD_RELOC_MIPS_16. (md_apply_fix): Handle BFD_RELOC_16 and BFD_RELOC_MIPS_16 when fx_done. ld/ * testsuite/ld-mips-elf/reloc-local-overflow.d, * testsuite/ld-mips-elf/reloc-local-overflow.s: Rewrite.
2022-05-31x86: Properly handle IFUNC function pointer referenceH.J. Lu2-0/+71
Update commit 68c4956b1401de70173848a6bdf620cb42fa9358 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Apr 26 09:08:54 2022 -0700 x86: Properly handle function pointer reference to properly handle IFUNC function pointer reference. Since IFUNC symbol value is only known at run-time, set pointer_equality_needed for IFUNC function pointer reference in PDE so that it will be resolved to its PLT entry directly. bfd/ PR ld/29216 * elf32-i386.c (elf_i386_scan_relocs): Set pointer_equality_needed for IFUNC function pointer reference in PDE. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. ld/ PR ld/29216 * testsuite/ld-ifunc/ifunc.exp: Run PR ld/29216 test. * testsuite/ld-ifunc/pr29216.c: New file.
2022-05-31i386: Ajdust more tests for opcodes/i386: remove trailing whitespaceH.J. Lu13-19/+19
This fixes: FAIL: Build ifunc-1a with -z ibtplt FAIL: Build ifunc-1a with PIE -z ibtplt FAIL: Build libno-plt-1b.so FAIL: No PLT (dynamic 1a) FAIL: No PLT (dynamic 1b) FAIL: No PLT (dynamic 1c) FAIL: No PLT (static 1d) FAIL: No PLT (PIE 1e) FAIL: No PLT (PIE 1f) FAIL: No PLT (PIE 1g) FAIL: No PLT (dynamic 1h) FAIL: No PLT (dynamic 1i) FAIL: No PLT (static 1j) * ld-i386/libno-plt-1b.dd: Remove trailing whitespaces. * ld-i386/no-plt-1a.dd: Likewise. * ld-i386/no-plt-1b.dd: Likewise. * ld-i386/no-plt-1c.dd: Likewise. * ld-i386/no-plt-1d.dd: Likewise. * ld-i386/no-plt-1e.dd: Likewise. * ld-i386/no-plt-1f.dd: Likewise. * ld-i386/no-plt-1g.dd: Likewise. * ld-i386/no-plt-1h.dd: Likewise. * ld-i386/no-plt-1i.dd: Likewise. * ld-i386/no-plt-1j.dd: Likewise. * ld-i386/plt-main-ibt.dd: Likewise. * ld-i386/plt-pie-ibt.dd: Likewise.
2022-05-31Ajdust more tests for opcodes/i386: remove trailing whitespaceAlan Modra2-4/+4
git commit 202be274a4 also missed adjusting a few testsuite files. This fixes i686-vxworks +FAIL: VxWorks shared library test 1 i686-vxworks +FAIL: VxWorks executable test 1 (dynamic)
2022-05-31Trailing spaces in objdump -r headerAlan Modra99-99/+99
git commit 202be274a4 went a little wild in removing trailing spaces in gas/testsuite/gas/i386/{secidx.d,secrel.d}, causing x86_64-w64-mingw32 +FAIL: i386 secrel reloc x86_64-w64-mingw32 +FAIL: i386 secidx reloc I could have just replaced the trailing space, but let's fix the objdump output instead. Touches lots of testsuite files.
2022-05-27opcodes/i386: remove trailing whitespace from insns with zero operandsAndrew Burgess67-164/+164
While working on another patch[1] I had need to touch this code in i386-dis.c: ins->obufp = ins->mnemonicendp; for (i = strlen (ins->obuf) + prefix_length; i < 6; i++) oappend (ins, " "); oappend (ins, " "); (*ins->info->fprintf_styled_func) (ins->info->stream, dis_style_mnemonic, "%s", ins->obuf); What this code does is add whitespace after the instruction mnemonic and before the instruction operands. The problem I ran into when working on this code can be seen by assembling this input file: .text nop retq Now, when I disassemble, here's the output. I've replaced trailing whitespace with '_' so that the issue is clearer: Disassembly of section .text: 0000000000000000 <.text>: 0: 90 nop 1: c3 retq___ Notice that there's no trailing whitespace after 'nop', but there are three spaces after 'retq'! What happens is that instruction mnemonics are emitted into a buffer instr_info::obuf, then instr_info::mnemonicendp is setup to point to the '\0' character at the end of the mnemonic. When we emit the whitespace, this is then added starting at the mnemonicendp position. Lets consider 'retq', first the buffer is setup like this: 'r' 'e' 't' 'q' '\0' Then we add whitespace characters at the '\0', converting the buffer to this: 'r' 'e' 't' 'q' ' ' ' ' ' ' '\0' However, 'nop' is actually an alias for 'xchg %rax,%rax', so, initially, the buffer is setup like this: 'x' 'c' 'h' 'g' '\0' Then in NOP_Fixup we spot that we have an instruction that is an alias for 'nop', and adjust the buffer to this: 'n' 'o' 'p' '\0' '\0' The second '\0' is left over from the original buffer contents. However, when we rewrite the buffer, we don't afjust mnemonicendp, which still points at the second '\0' character. Now, when we insert whitespace we get: 'n' 'o' 'p' '\0' ' ' ' ' ' ' ' ' '\0' Notice the whitespace is inserted after the first '\0', so, when we print the buffer, the whitespace is not printed. The fix for this is pretty easy, I can change NOP_Fixup to adjust mnemonicendp, but now a bunch of tests start failing, we now produce whitespace after the 'nop', which the tests don't expect. So, I could update the tests to expect the whitespace.... ...except I'm not a fan of trailing whitespace, so I'd really rather not. Turns out, I can pretty easily update the whitespace emitting code to spot instructions that have zero operands and just not emit any whitespace in this case. So this is what I've done. I've left in the fix for NOP_Fixup, I think updating mnemonicendp is probably a good thing, though this is not really required any more. I've then updated all the tests that I saw failing to adjust the expected patterns to account for the change in whitespace. [1] https://sourceware.org/pipermail/binutils/2022-April/120610.html
2022-05-27ld: cris*-elf: Default to --no-warn-rwx-segmentHans-Peter Nilsson1-0/+5
ld: configure.tgt (cris-*-*, crisv32-*-* sans *-aout and *-linux): Unless specified through the --enable-* -option, default to --no-warn-rwx-segment. Change-Id: I846bcd3e6762da807b17215a9fe337461ea0d710
2022-05-27cris: bfd: Correct default to no execstackHans-Peter Nilsson1-0/+1
In the now-historical CRIS glibc port, the default stack permission was no-exec as in "#define DEFAULT_STACK_PERMS (PF_R|PF_W)", and the gcc port only emits the executable-stack marker when needed; when emitting code needing it. In other words, the binutils setting mismatches. It doesn't matter much, except being confusing and defaulting to "off" is more sane. ld: * testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Switch to 0 for cris*-*-*. bfd: * elf32-cris.c (elf_backend_default_execstack): Define to 0. Change-Id: I52f37598f119b19111c7a6546c00a627fca0f396
2022-05-26bit-rot in target before_parse functionAlan Modra4-2/+12
Copy initialisation over from the elf.em before_parse. Commit ba951afb999 2022-05-03 changed behaviour on arm and score regarding exec stack. This patch restores the previous behaviour. * emultempl/aarch64elf.em (before_parse): Init separate_code, warn_execstack, no_warn_rwx_segments and default_execstack. * emultempl/armelf.em (before_parse): Likewise. * emultempl/scoreelf.em (before_parse): Likewise. * testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Return true for arm and nacl.
2022-05-26ld: add --package-metadataLuca Boccassi15-10/+531
Generate a .note.package FDO package metadata ELF note, following the spec: https://systemd.io/ELF_PACKAGE_METADATA/ If the jansson library is available at build time (and it is explicitly enabled), link ld to it, and use it to validate that the input is correct JSON, to avoid writing garbage to the file. The configure option --enable-jansson has to be used to explicitly enable it (error out when not found). This allows bootstrappers (or others who are not interested) to seamlessly skip it without issues.
2022-05-23ld: use definitions in generate_reloc rather than raw literalsMark Harmstone1-7/+8
2022-05-20Tidy warn-execstack handlingAlan Modra4-15/+13
Make ld and bfd values consistent by swapping values 0 and 2 in link_info.warn_execstack. This has the benefit of making the value an "extended" boolean, with 0 meaning no warning, 1 meaning warn, other values a conditional warning. Yes, this patch introduces fails on arm/aarch64. Not a problem with this patch but an arm/aarch64 before_parse problem. bfd/ * elflink.c (bfd_elf_size_dynamic_sections): Adjust warn_execstack test. include/ * bfdlink.h (warn_execstack): Swap 0 and 2 meaning. ld/ * configure.ac (DEFAULT_LD_WARN_EXECSTACK): Use values of 0, 1, 2 consistent with link_info.warn_execstack. * ld.texi: Typo fixes. * lexsup.c (parse_args): Adjust setting of link_info.warn_execstack. (elf_static_list_options): Adjust help message conditions. * configure: Regenerate.
2022-05-12Fix an illegal memory access when creating DLLs.Alan Modra2-123/+130
PR 29006 * pe-dll.c (dll_name): Delete, replacing with.. (dll_filename): ..this, moved earlier in file. (generate_edata): Delete parameters. Don't set up dll_name here.. (pe_process_import_defs): ..instead set up dll_filename and dll_symname here before returning. (dll_symname_len): Delete write-only variable. (pe_dll_generate_implib): Don't set up dll_symname here.
2022-05-07Re: Fix new linker testsuite failures due to rwx segment test problemsAlan Modra1-2/+1
Fix it some more. bfd/ * elfnn-loongarch.c: Remove commented out elf_backend_* defines. ld/ * testsuite/ld-elf/elf.exp (target_defaults_to_execstack): Match arm*. Delete loongarch.
2022-05-06Fix new linker testsuite failures due to rwx segment test problemsNick Clifton3-1/+6
2022-05-04LTO: Handle __real_SYM reference in IRH.J. Lu3-2/+32
When an IR symbol SYM is referenced in IR via __real_SYM, its resolution should be LDPR_PREVAILING_DEF, not PREVAILING_DEF_IRONLY, since LTO doesn't know that __real_SYM should be resolved by SYM. bfd/ PR ld/29086 * linker.c (bfd_wrapped_link_hash_lookup): Mark SYM is referenced via __real_SYM. include/ PR ld/29086 * bfdlink.h (bfd_link_hash_entry): Add ref_real. ld/ PR ld/29086 * plugin.c (get_symbols): Resolve SYM definition to LDPR_PREVAILING_DEF for __real_SYM reference. * testsuite/ld-plugin/lto.exp: Run PR ld/29086 test. * testsuite/ld-plugin/pr29086.c: New file.
2022-05-04PowerPC32 treatment of absolute symbolsAlan Modra8-0/+138
As already done for PowerPC64, fix dynamic relocs for absolute symbols. The patch also tidies the dynamic reloc handling code in check_relocs, removing leftover comments and code from when check_relocs was called as each object file was read in. bfd/ * elf32-ppc.c (ppc_elf_check_relocs): Set isym and ifunc earlier. Rearrange tests for dynamic relocs, handling absolute symbols. (allocate_dynrelocs): Don't allocate dynamic relocs for locally defined absolute symbols. (ppc_elf_size_dynamic_sections): Similarly. (ppc_elf_relocate_section): Similarly. ld/ * testsuite/ld-powerpc/abs32-pie.d, * testsuite/ld-powerpc/abs32-pie.r, * testsuite/ld-powerpc/abs32-reloc.s, * testsuite/ld-powerpc/abs32-shared.d, * testsuite/ld-powerpc/abs32-shared.r, * testsuite/ld-powerpc/abs32-static.d, * testsuite/ld-powerpc/abs32-static.r: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.