aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2022-08-03elf: Reset alignment for each PT_LOAD segmentH.J. Lu2-0/+17
Reset alignment for each PT_LOAD segment to avoid using alignment from the previous PT_LOAD segment. bfd/ PR ld/29435 * elf.c (assign_file_positions_for_load_sections): Reset alignment for each PT_LOAD segment. ld/ PR ld/29435 * testsuite/ld-elf/pr29435.d: New file. * testsuite/ld-elf/pr29435.s: Likewise.
2022-08-02ld: aarch64: Adjust TLS relaxation conditionMatthew Malcomson28-77/+232
In aarch64_tls_transition_without_check and elfNN_aarch64_tls_relax we choose whether to perform a relaxation to an IE access model or an LE access model based on whether the symbol itself is marked as local (i.e. `h == NULL`). This is problematic in two ways. The first is that sometimes a global dynamic access can be relaxed to an initial exec access when creating a shared library, and if that happens on a local symbol then we currently relax it to a local exec access instead. This usually does not happen since we only relax an access if aarch64_can_relax_tls returns true and aarch64_can_relax_tls does not have the same problem. However, it can happen when we have seen both an IE and GD access on the same symbol. This case is exercised in the newly added testcase tls-relax-gd-ie-2. The second problem is that deciding based on whether the symbol is local misses the case when the symbol is global but is still non-interposable and known to be located in the executable. This happens on all global symbols in executables. This case is exercised in the newly added testcase tls-relax-ie-le-4. Here we adjust the condition we base our relaxation on so that we relax to local-exec if we are creating an executable and the relevant symbol we're accessing is stored inside that executable. -- Updating tests for new relaxation criteria Many of the tests added to check our relaxation to IE were implemented by taking advantage of the fact that we did not relax a global symbol defined in an executable. Since a global symbol defined in an executable is still not interposable, we know that a TLS version of such a symbol will be in the main TLS block. This means that we can perform a stronger relaxation on such symbols and relax their accesses to a local-exec access. Hence we have to update all tests that relied on the older suboptimal decision making. The two cases when we still would want to relax a general dynamic access to an initial exec one are: 1) When in a shared library and accessing a symbol which we have already seen accessed with an initial exec access sequence. 2) When in an executable and accessing a symbol defined in a shared library. Both of these require shared library support, which means that these tests are now only available on targets with that. I have chosen to switch the existing testcases from a plain executable to one dynamically linked to a shared object as that doesn't require changing the testcases quite so much (just requires accessing a different variable rather than requiring adding another code sequence). The tls-relax-all testcase was an outlier to the above approach, since it included a general dynamic access to both a local and global symbol and inspected for the difference accordingly.
2022-08-02ld: aarch64: Update test linker scripts relocs.ld and relocs-ilp32.ldMatthew Malcomson2-0/+8
The updates are to ensure that the .data section exists. This means that we always have a data section. That means that we don't create a RWX segment and avoid the corresponding warning. We get this warning when testing aarch64-none-elf with -mcmodel=tiny. N.b. this changes quite a few testcases from fail to pass.
2022-08-01ld: Support the -exclude-symbols option via COFF def files, with the ↵Martin Storsjö6-0/+48
EXCLUDE_SYMBOLS keyword This was requested in review.
2022-08-01ld: Add support for a new option, -exclude-symbols, in COFF object file ↵Martin Storsjö5-0/+53
directives This maps to the same as ld's --exclude-symbols command line option, but allowing specifying the option via directives embedded in the object files instead of passed manually on the command line.
2022-08-01opcodes: LoongArch: add "ret" instruction to reduce typingWANG Xuerui2-0/+2
This syntactic sugar is present in both classical and emerging architectures, like Alpha, SPARC and RISC-V, and assembler macros doing the same thing can already be found in the wild e.g. [1], proving the feature's popularity. It's better to provide support directly in the assembler so downstream users wouldn't have to re-invent this over and over again. [1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/loongarch/sysdep.h;h=c586df819cd90;hb=HEAD#l28
2022-08-01opcodes: LoongArch: make all non-native jumps desugar to canonical ↵WANG Xuerui1-21/+21
b{lt/ge}[u] forms Also re-order the jump/branch opcodes while at it, so that insns are sorted in ascending order according to opcodes, and the label form preceding the real definition.
2022-08-01LoongArch: Set defaults to exec stack 0.liuzhensong1-0/+1
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-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-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-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 Modra1-2/+2
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-27drop XC16x bitsJan Beulich11-257/+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 Modra1-2/+2
.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 Modra6-22/+22
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-21Default to disabling the linker warnings about execstack and RWX segments if ↵Nick Clifton1-2/+11
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-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-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 Modra1-2/+0
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 Boccassi3-0/+57
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-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. Lu2-0/+27
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.
2022-05-03Add a linker warning when creating potentially dangerous executable ↵Nick Clifton8-13/+67
segments. Add tests, options to disabke and configure switches to choose defaults.
2022-04-28x86: Properly handle function pointer referenceH.J. Lu2-0/+59
Update commit ebb191adac4ab45498dec0bfaac62f0a33537ba4 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Feb 9 15:51:22 2022 -0800 x86: Disallow invalid relocation against protected symbol to allow function pointer reference and make sure that PLT entry isn't used for function reference due to function pointer reference. bfd/ PR ld/29087 * elf32-i386.c (elf_i386_scan_relocs): Don't set pointer_equality_needed nor check non-canonical reference for function pointer reference. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. ld/ PR ld/29087 * testsuite/ld-x86-64/x86-64.exp: Run PR ld/29087 tests. * testsuite/ld-x86-64/protected-func-3.c: New file.
2022-04-28libctf: impose an ordering on conflicting typesNick Alcock6-1/+78
When two types conflict and they are not types which can have forwards (say, two arrays of different sizes with the same name in two different TUs) the CTF deduplicator uses a popularity contest to decide what to do: the type cited by the most other types ends up put into the shared dict, while the others are relegated to per-CU child dicts. This works well as long as one type *is* most popular -- but what if there is a tie? If several types have the same popularity count, we end up picking the first we run across and promoting it, and unfortunately since we are working over a dynhash in essentially arbitrary order, this means we promote a random one. So multiple runs of ld with the same inputs can produce different outputs! All the outputs are valid, but this is still undesirable. Adjust things to use the same strategy used to sort types on the output: when there is a tie, always put the type that appears in a CU that appeared earlier on the link line (and if there is somehow still a tie, which should be impossible, pick the type with the lowest type ID). Add a testcase -- and since this emerged when trying out extern arrays, check that those work as well (this requires a newer GCC, but since all GCCs that can emit CTF at all are unreleased this is probably OK as well). Fix up one testcase that has slight type ordering changes as a result of this change. libctf/ChangeLog: * ctf-dedup.c (ctf_dedup_detect_name_ambiguity): Use cd_output_first_gid to break ties. ld/ChangeLog: * testsuite/ld-ctf/array-conflicted-ordering.d: New test, using... * testsuite/ld-ctf/array-char-conflicting-1.c: ... this... * testsuite/ld-ctf/array-char-conflicting-2.c: ... and this. * testsuite/ld-ctf/array-extern.d: New test, using... * testsuite/ld-ctf/array-extern.c: ... this. * testsuite/ld-ctf/conflicting-typedefs.d: Adjust for ordering changes.
2022-04-27x86: Disable 2 tests with large memory requirementH.J. Lu1-2/+2
gas/ * testsuite/gas/i386/i386.exp: Disable rept. ld/ * testsuite/ld-x86-64/x86-64.exp: Disable pr17618.
2022-04-27Revert pr29072 lto test changesAlan Modra3-4/+4
Revert commit 65daf5bed6 testsuite changes in ld-plugin/. -z isn't supported for non-ELF targets, and isn't needed since we now prune the exec stack warning (commit 333cd559ba). PR 29072
2022-04-26i386: Pass -z noexecstack to linker testsH.J. Lu1-2/+4
PR ld/29072 * testsuite/ld-i386/i386.exp: Pass -z noexecstack to gotpc1 and property-6.
2022-04-25Emit a note warning the user that creating an executable stack because of a ↵Nick Clifton1-0/+1
missing .note.GNU-stack section is deprecated. PR 29072 bfd * elflink.c (bfd_elf_size_dynamic_sections): Display a note to the user that the current ehaviour of creating an executable stack because of a missing .note.GNU-stack section is deprecated and will be changed in a future release. binutils* testsuite/lib/binutils-common.exp (prune_warnings_extra): Filter out notes about the executable stacjk behaviour beign deprecated. ld * testsuite/ld-elf/pr29072.b.warn: Update to include the note about the linker's behaviour being depreccated.