summaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)Author
2022-01-12ld: Add simple DT_RELR testsH.J. Lu
* testsuite/ld-elf/dt-relr-1.s: New file. * testsuite/ld-elf/dt-relr-1a.d: Likewise. * testsuite/ld-elf/dt-relr-1b.d: Likewise. * testsuite/ld-elf/dt-relr-1c.d: Likewise. * testsuite/ld-elf/dt-relr-2.s: Likewise. * testsuite/ld-elf/dt-relr-2a.d: Likewise. * testsuite/ld-elf/dt-relr-2b.d: Likewise. * testsuite/ld-elf/dt-relr-2c.d: Likewise. * testsuite/ld-elf/dt-relr-2d.d: Likewise. * testsuite/ld-elf/dt-relr-2e.d: Likewise. * testsuite/ld-elf/dt-relr-2f.d: Likewise. * testsuite/ld-elf/dt-relr-2g.d: Likewise. * testsuite/ld-elf/dt-relr-2h.d: Likewise. * testsuite/ld-elf/dt-relr-3.s: Likewise. * testsuite/ld-elf/dt-relr-3a.d: Likewise. * testsuite/ld-elf/dt-relr-3b.d: Likewise. * testsuite/ld-i386/dt-relr-1.s: Likewise. * testsuite/ld-i386/dt-relr-1a.d: Likewise. * testsuite/ld-i386/dt-relr-1b.d: Likewise. * testsuite/ld-x86-64/dt-relr-1a-x32.d: Likewise. * testsuite/ld-x86-64/dt-relr-1a.d: Likewise. * testsuite/ld-x86-64/dt-relr-1b-x32.d: Likewise. * testsuite/ld-x86-64/dt-relr-1b.d: Likewise. * testsuite/ld-x86-64/dt-relr-1.s: Likewise. * testsuite/ld-i386/i386.exp: Run dt-relr-1a and dt-relr-1b. * testsuite/ld-x86-64/x86-64.exp: Run dt-relr-1a, dt-relr-1a-x32 dt-relr-1b and dt-relr-1b-x32.
2022-01-12elf: Support DT_RELR in linker testsH.J. Lu
Allow eabling and disabling DT_RELR in linker tests. Disable DT_RELR in linker tests which don't expect DT_RELR in linker outputs. binutils/ * testsuite/lib/binutils-common.exp (run_dump_test): Make DT_RELR_LDFLAGS and NO_DT_RELR_LDFLAGS global. ld/ * testsuite/config/default.exp (DT_RELR_LDFLAGS): New. (DT_RELR_CC_LDFLAGS): Likewise. (NO_DT_RELR_LDFLAGS): Likewise. (NO_DT_RELR_CC_LDFLAGS): Likewise. * testsuite/ld-elf/shared.exp: Pass $NO_DT_RELR_LDFLAGS to linker for some tests. * testsuite/ld-i386/export-class.exp: Likewise. * testsuite/ld-i386/i386.exp: Likewise. * testsuite/ld-i386/ibt-plt-2a.d: Pass $NO_DT_RELR_LDFLAGS to linker. * testsuite/ld-i386/ibt-plt-3a.d: Likewise. * testsuite/ld-i386/ibt-plt-3c.d: Likewise. * testsuite/ld-i386/pr26869.d: Likewise. * testsuite/ld-i386/report-reloc-1.d: Likewise. * testsuite/ld-ifunc/ifunc-2-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-local-i386-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-local-x86-64-now.d: Likewise. * testsuite/ld-ifunc/ifunc-2-x86-64-now.d: Likewise. * testsuite/ld-ifunc/pr17154-x86-64.d: Likewise. * testsuite/ld-x86-64/bnd-branch-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-2-now.d: Likewise. * testsuite/ld-x86-64/bnd-ifunc-2.d: Likewise. * testsuite/ld-x86-64/bnd-plt-1-now.d: Likewise. * testsuite/ld-x86-64/bnd-plt-1.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2a.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a-x32.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a.d: Likewise. * testsuite/ld-x86-64/ilp32-4.d: Likewise. * testsuite/ld-x86-64/load1c.d: Likewise. * testsuite/ld-x86-64/load1d.d: Likewise. * testsuite/ld-x86-64/pr13082-2b.d: Likewise. * testsuite/ld-x86-64/pr14207.d: Likewise. * testsuite/ld-x86-64/pr18176.d: Likewise. * testsuite/ld-x86-64/pr19162.d: Likewise. * testsuite/ld-x86-64/pr19636-2d.d: Likewise. * testsuite/ld-x86-64/pr19636-2l.d: Likewise. * testsuite/ld-x86-64/pr20253-1d.d: Likewise. * testsuite/ld-x86-64/pr20253-1f.d: Likewise. * testsuite/ld-x86-64/pr20253-1j.d: Likewise. * testsuite/ld-x86-64/pr20253-1l.d: Likewise. * testsuite/ld-x86-64/report-reloc-1-x32.d: Likewise. * testsuite/ld-x86-64/report-reloc-1.d: Likewise. * testsuite/ld-x86-64/export-class.exp (x86_64_export_class_test): Pass $NO_DT_RELR_LDFLAGS to linker. * testsuite/ld-x86-64/x86-64.exp: Pass $NO_DT_RELR_LDFLAGS to linker for some tests.
2022-01-12ld: Initial DT_RELR supportH.J. Lu
Add a -z pack-relative-relocs option to enable DT_RELR and create a relr.dyn section for DT_RELR. DT_RELR is implemented with the linker relaxation infrastructure, but it doesn't require the --relax option enabled. -z pack-relative-relocs implies -z combreloc. -z nocombreloc implies -z nopack-relative-relocs. -z pack-relative-relocs is chosen over the similar option in lld, --pack-dyn-relocs=relr, to implement a glibc binary lockout mechanism with a special glibc version symbol, to avoid random crashes of DT_RELR binaries with the existing glibc binaries. bfd/ * elf-bfd.h (elf_link_hash_table): Add srelrdyn. * elflink.c (_bfd_elf_link_create_dynamic_sections): Create a .relr.dyn section for DT_RELR. include/ * bfdlink.h (bfd_link_info): Add enable_dt_relr. ld/ * News: Mention -z pack-relative-relocs and -z nopack-relative-relocs. * ld.texi: Document -z pack-relative-relocs and -z nopack-relative-relocs. * ldelf.c (ldelf_after_parse): Disable DT_RELR if not building PIE nor shared library. Add 3 spare dynamic tags for DT_RELR, DT_RELRSZ and DT_RELRENT. * ldlang.c (lang_relax_sections): Also enable relaxation if DT_RELR is enabled. * emulparams/elf32_x86_64.sh: Source dt-relr.sh. * emulparams/elf_i386.sh: Likewise. * emulparams/elf_x86_64.sh: Likewise. * emulparams/dt-relr.sh: New file. * scripttempl/elf.sc: Support .relr.dyn.
2022-01-12elf: Pass need_layout to _bfd_elf_map_sections_to_segmentsH.J. Lu
On some targets, the DT_RELR section size can be computed only after all symbols addresses can be determined. Update ldelf_map_segments to pass need_layout to _bfd_elf_map_sections_to_segments which will size DT_RELR section and set need_layout to true if the DT_RELR section size is changed. bfd/ * elf-bfd.h (_bfd_elf_map_sections_to_segments): Add a bool pointer argument. * elf.c (_bfd_elf_map_sections_to_segments): Add a bool pointer argument to indicate if section layout needs update. (assign_file_positions_for_load_sections): Pass NULL to _bfd_elf_map_sections_to_segments. * elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): Pass NULL to _bfd_elf_map_sections_to_segments. ld/ * ldelfgen.c (ldelf_map_segments): Pass &need_layout to _bfd_elf_map_sections_to_segments.
2022-01-12ld: add hidden and internal visibility support for XCOFFClément Chigot
This patch adds a primary support for hidden and internal visibility in GNU linker for XCOFF format. The protected visibility isn't yet supported. PR 22085 bfd/ChangeLog: * xcofflink.c (xcoff_dynamic_definition_p): Add hidden and internal visibility support. (xcoff_link_add_symbols): Likewise. (xcoff_auto_export_p): Likewise. (bfd_xcoff_export_symbol): Likewise. (xcoff_link_input_bfd): Likewise. ld/ChangeLog: * testsuite/ld-vsb/main.c: Adapt for XCOFF. * testsuite/ld-vsb/sh1.c: Likewse. * testsuite/ld-vsb/vsb.exp: Likewise. * testsuite/ld-vsb/visibility-1-xcoff-32.d: New test. * testsuite/ld-vsb/visibility-1-xcoff-64.d: New test. * testsuite/ld-vsb/visibility-2-xcoff-32.d: New test. * testsuite/ld-vsb/visibility-2-xcoff-64.d: New test. * testsuite/ld-vsb/xcoffvsb.dat: New test.
2022-01-12ld/testsuite: prepare ld-elfvsb to support XCOFFClément Chigot
A following patch will add visibility support in ld for XCOFF. Thus, ld-elfvsb is renamed ld-vsb and a suffix is added to files targeting only ELF format. ld/ChangeLog: * testsuite/ld-elfvsb: rename as ld-vsb. * testsuite/ld-elfvsb/hidden0.d: move to ld-vsb and rename with suffix -elf.d. * testsuite/ld-elfvsb/hidden1.d: Likewise. * testsuite/ld-elfvsb/hidden2.d: Likewise. * testsuite/ld-elfvsb/internal0.d: Likewise. * testsuite/ld-elfvsb/internal1.d: Likewise. * testsuite/ld-elfvsb/protected0.d: Likewise. * testsuite/ld-elfvsb/protected1.d: Likewise.
2022-01-12gas: add visibility support for XCOFFClément Chigot
XCOFF assembly defines the visibility using an additional argument on several pseudo-ops: .globl, .weak, .extern and .comm. This implies that .globl and .weak syntax is different than the usual GNU syntax. But we want to provide compatibility with AIX assembler, especially because GCC is generating the visibility using this XCOFF syntax. PR 22085 bfd/ChangeLog: * coffcode.h (coff_write_object_contents): Change XCOFF header vstamp field to 2. * coffgen.c (coff_print_symbol): Increase the size for n_type. gas/ChangeLog: * config/tc-ppc.c (ppc_xcoff_get_visibility): New function. (ppc_globl): New function. (ppc_weak): New function. (ppc_comm): Add visibility field support. (ppc_extern): Likewise. * testsuite/gas/all/cofftag.d: Adjust to new n_type size providing by objdump. * testsuite/gas/ppc/test1xcoff32.d: Likewise. * testsuite/gas/ppc/aix.exp: Add new tests. * testsuite/gas/ppc/xcoff-visibility-1-32.d: New test. * testsuite/gas/ppc/xcoff-visibility-1-64.d: New test. * testsuite/gas/ppc/xcoff-visibility-1.s: New test. include/ChangeLog: * coff/internal.h (SYM_V_INTERNAL, SYM_V_HIDDEN, SYM_V_PROTECTED, SYM_V_EXPORTED, SYM_V_MASK): New defines. * coff/xcoff.h (struct xcoff_link_hash_entry): Add visibility field. ld/ChangeLog: * testsuite/ld-pe/pr19803.d: Adjust to new n_type size providing by objdump.
2022-01-12Set SEC_ELF_REVERSE_COPY earlierAlan Modra
For the sake of DT_RELR. bfd/ * elflink.c (elf_link_input_bfd): Don't set SEC_ELF_REVERSE_COPY here. Move sanity checks to reverse copying code. ld/ * ldlang.c (lang_add_section): Set SEC_ELF_REVERSE_COPY for .ctors/.dtors in .init_array/.fini_array.
2022-01-11Fix multiple problems with DLL generation.Martin Storsj
ld * pe-dll.c (make_head): Prefix the symbol name with the dll name. (make_tail, make_one, make_singleton_name_thunk): Likewise. (make_import_fixup_entry, make_runtime_pseudo_reloc): Likewise. (pe_create_runtime_relocator_reference): Likewise. (pe_dll_generate_implib): Set dll_symname_len. (pe_process_import_defs): Likewise. binutils * dlltool.c (main): If a prefix has not been provided, attempt to use a deterministic one based upon the dll name.
2022-01-10XCOFF: add support for TLS relocations on hidden symbolsClément Chigot
This patch adds support for TLS relocation targeting C_HIDEXT symbols. In gas, TLS relocations, except R_TLSM and R_TLMSL, must keep the value of their target symbol. In ld, it simply ensures that internal TLS symbols are added to the linker hash table for xcoff_reloc_type_tls. It also improves the tests made by both. bfd/ChangeLog: * coff-rs6000.c (xcoff_howto_table): Fix name of R_TLSML. (xcoff_reloc_type_tls): Replace the error when h is NULL by an assert. (xcoff_complain_overflow_unsigned_func): Adjust comments. * coff64-rs6000.c (xcoff64_howto_table): Fix name of R_TLSML. * xcofflink.c (xcoff_link_add_symbols_to_hash_table): New function. (xcoff_link_add_symbols): Add C_HIDEXT TLS symbols to the linker hash table. gas/ChangeLog: * config/tc-ppc.c (md_apply_fix): Enable support for TLS relocation over internal symbols. * testsuite/gas/ppc/aix.exp: Replace xcoff-tlms by xcoff-tls. * testsuite/gas/ppc/xcoff-tlsm-32.d: Removed. * testsuite/gas/ppc/xcoff-tlsm-64.d: Removed. * testsuite/gas/ppc/xcoff-tlsm.s: Removed. * testsuite/gas/ppc/xcoff-tls-32.d: New test. * testsuite/gas/ppc/xcoff-tls-64.d: New test. * testsuite/gas/ppc/xcoff-tls.s: New test. ld/ChangeLog: * testsuite/ld-powerpc/aix52.exp: Improve aix-tls-reloc test. * testsuite/ld-powerpc/aix-tls-reloc.s: Likewise. * testsuite/ld-powerpc/aix-tls-reloc-32.d: Removed. * testsuite/ld-powerpc/aix-tls-reloc-64.d: Removed. * testsuite/ld-powerpc/aix-tls-reloc-32.dd: New test. * testsuite/ld-powerpc/aix-tls-reloc-32.dt: New test. * testsuite/ld-powerpc/aix-tls-reloc-64.dd: New test. * testsuite/ld-powerpc/aix-tls-reloc-64.dt: New test.
2022-01-07ld: Extract _bfd_elf_link_iterate_on_relocsH.J. Lu
DT_RELR encodes consecutive R_*_RELATIVE relocations in GOT (the global offset table) and data sections in a compact format: https://groups.google.com/g/generic-abi/c/bX460iggiKg On some targets, R_*_RELATIVE relocations are counted and the GOT offsets are allocated when setting the dynamic section sizes after seeing all relocations. R_*_RELATIVE relocations are generated while relocating sections after section layout has been finalized. To prepare for DT_RELR implementation on these targets, extract _bfd_elf_link_iterate_on_relocs from _bfd_elf_link_check_relocs so that a backend can scan relocations in elf_backend_always_size_sections For x86 targets, the old check_relocs is renamed to scan_relocs and a new check_relocs is added to chek input sections and create dynamic relocation sections so that they will be mapped to output sections. scan_relocs is now called from elf_backend_always_size_sections. Since relocations are scanned after __start, __stop, .startof. and .sizeof. symbols have been finalized on x86, __[start|stop]_SECNAME for --gc-sections -z start-stop-gc are now zero when all SECNAME sections been garbage collected. This is no need for elf_x86_start_stop_gc_p. bfd/ * elf-bfd.h (_bfd_elf_link_iterate_on_relocs): New. * elf32-i386.c (elf_i386_convert_load_reloc): Don't call elf_x86_start_stop_gc_p. (elf_i386_check_relocs): Renamed to ... (elf_i386_scan_relocs): This. Don't call _bfd_elf_make_dynamic_reloc_section. (elf_i386_always_size_sections): New. (elf_backend_check_relocs): Removed. (elf_backend_always_size_sections): New. * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Don't call elf_x86_start_stop_gc_p. (elf_x86_64_check_relocs): Renamed to ... (elf_x86_64_scan_relocs): This. Don't call _bfd_elf_make_dynamic_reloc_section. (elf_x86_64_always_size_sections): New. (elf_backend_check_relocs): Removed. (elf_backend_always_size_sections): New. * elflink.c (elf_link_check_or_scan_relocs): New. Extracted from _bfd_elf_link_check_relocs. (_bfd_elf_link_check_relocs): Call elf_link_check_or_scan_relocs. * elfxx-x86.c (_bfd_x86_elf_check_relocs): New. * elfxx-x86.h (X86_64_NEED_DYNAMIC_RELOC_TYPE_P): New. (I386_NEED_DYNAMIC_RELOC_TYPE_P): Likewise. (X86_NEED_DYNAMIC_RELOC_TYPE_P): Likewise. (_bfd_x86_elf_check_relocs): Likewise. (elf_backend_check_relocs): Likewise. (elf_backend_always_size_sections): Removed. (elf_x86_start_stop_gc_p): Likewise. ld/ * testsuite/ld-i386/pr27491-1a.d: Updated. * testsuite/ld-x86-64/pr27491-1a.d: Likewise.
2022-01-07RISC-V: Updated the default ISA spec to 20191213.Nelson Chu
Update the default ISA spec from 2.2 to 20191213 will change the default version of i from 2.0 to 2.1. Since zicsr and zifencei are separated from i 2.1, users need to add them in the architecture string if they need fence.i and csr instructions. Besides, we also allow old ISA spec can recognize zicsr and zifencei, but we won't output them since they are already included in the i extension when i's version is less than 2.1. bfd/ * elfxx-riscv.c (riscv_parse_add_subset): Allow old ISA spec can recognize zicsr and zifencei. gas/ * config/tc-riscv.c (DEFAULT_RISCV_ISA_SPEC): Updated to 20191213. * testsuite/gas/riscv/csr-version-1p10.d: Added zicsr to -march since the default version of i is 2.1. * testsuite/gas/riscv/csr-version-1p11.d: Likewise. * testsuite/gas/riscv/csr-version-1p12.d: Likewise. * testsuite/gas/riscv/csr-version-1p9p1.d: Likewise. * testsuite/gas/riscv/option-arch-03.d: Updated i's version to 2.1. * testsuite/gas/riscv/option-arch-03.s: Likewise. ld/ * testsuite/ld-riscv-elf/call-relax.d: Added zicsr to -march since the default version of i is 2.1. * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Updated i's version to 2.1. * testsuite/ld-riscv-elf/attr-merge-arch-01a.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-01b.: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-02a.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-02b.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-03a.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-03b.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Added zifencei into Tag_RISCV_arch since it is added implied when i's version is larger than 2.1.
2022-01-06ldelfgen.c: Add missing newlines when calling einfoH.J. Lu
* ldelfgen.c (ldelf_map_segments): Add the missing newline to einfo.
2022-01-05elf: Set p_align to the minimum page size if possibleH.J. Lu
Currently, on 32-bit and 64-bit ARM, it seems that ld generates p_align values of 0x10000 even if no section alignment is greater than 0x1000. The issue is more general and probably affects other targets with multiple page sizes. While file layout absolutely must take 64K page size into account, that does not have to be reflected in the p_align value. If running on a 64K kernel, the file will be loaded at a 64K page boundary by necessity. On a 4K kernel, 64K alignment is not needed. The glibc loader has been fixed to honor p_align: https://sourceware.org/bugzilla/show_bug.cgi?id=28676 similar to kernel: commit ce81bb256a224259ab686742a6284930cbe4f1fa Author: Chris Kennelly <ckennelly@google.com> Date: Thu Oct 15 20:12:32 2020 -0700 fs/binfmt_elf: use PT_LOAD p_align values for suitable start address This means that on 4K kernels, we will start to do extra work for 64K p_align, but this pointless for pretty much all binaries (whose section alignment rarely exceeds 16). The minimum page size is used, instead of the maximum section alignment due to this glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28688 It has been fixed in glibc 2.35. But linker output must work on existing glibc binaries. 1. Set p_align to the minimum page size while laying out segments aligning to the maximum page size or section alignment. The run-time loader can align segments to the minimum page size or above, depending on system page size. 2. If -z max-page-size=NNN is used, p_align will be set to the maximum page size or the largest section alignment. 3. If a section requires alignment higher than the minimum page size, don't set p_align to the minimum page size. 4. If a section requires alignment higher than the maximum page size, set p_align to the section alignment. 5. For objcopy, when the minimum page size != the maximum page size, p_align may be set to the minimum page size while segments are aligned to the maximum page size. In this case, the input p_align will be ignored and the maximum page size will be used to align the ouput segments. 6. Update linker to disallow the common page size > the maximum page size. 7. Update linker to avoid the common page size > the maximum page size. 8. Adjust pru_irq_map-1.d to expect p_align == sh_addralign: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 20000000 00007c 000004 00 AX 0 0 4 ... Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000074 0x00000000 0x00000000 0x00008 0x00008 RW 0x1 LOAD 0x00007c 0x20000000 0x20000000 0x00004 0x00004 R E 0x4 vs. Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 20000000 00007c 000004 00 AX 0 0 4 ... Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000074 0x00000000 0x00000000 0x00008 0x00008 RW 0x1 LOAD 0x00007c 0x20000000 0x20000000 0x00004 0x00004 R E 0x1 To enable this linker optimization, the backend should define ELF_P_ALIGN to ELF_MINPAGESIZE. bfd/ PR ld/28689 PR ld/28695 * elf-bfd.h (elf_backend_data): Add p_align. * elf.c (assign_file_positions_for_load_sections): Set p_align to the default p_align value while laying out segments aligning to maximum page size or section alignment. (elf_is_p_align_valid): New function. (copy_elf_program_header): Call elf_is_p_align_valid to determine if p_align is valid. * elfxx-target.h (ELF_P_ALIGN): New. Default to 0. (elfNN_bed): Add ELF_P_ALIGN. * elfxx-x86.h (ELF_P_ALIGN): New. Set to ELF_MINPAGESIZE. include/ PR ld/28689 PR ld/28695 * bfdlink.h (bfd_link_info): Add maxpagesize_is_set. ld/ PR ld/28689 PR ld/28695 * emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Set link_info.maxpagesize_is_set for -z max-page-size=NNN. * ldelf.c (ldelf_after_parse): Disallow link_info.commonpagesize > link_info.maxpagesize. * testsuite/ld-elf/elf.exp: Pass -z max-page-size=0x4000 to linker to build mbind2a and mbind2b. * testsuite/ld-elf/header.d: Add -z common-page-size=0x100. * testsuite/ld-elf/linux-x86.exp: Add PR ld/28689 tests. * testsuite/ld-elf/p_align-1.c: New file. * testsuite/ld-elf/page-size-1.d: New test. * testsuite/ld-elf/pr26936.d: Add -z common-page-size=0x1000. * testsuite/ld-elf/seg.d: Likewise. * testsuite/ld-scripts/rgn-at5.d: Likewise. * testsuite/ld-pru/pru_irq_map-1.d: Append 1 to name. Adjust expected PT_LOAD segment alignment. * testsuite/ld-pru/pru_irq_map-2.d: Append 2 to name. * testsuite/ld-scripts/pr23571.d: Add -z max-page-size=0x1000.
2022-01-04ld/x86: Update -z report-relative-relocH.J. Lu
Use 0x%v, instead of bfd_sprintf_vma, to report relative relocations. Change linker relative relocations report from tmpdir/dump: R_X86_64_IRELATIVE (offset: 0x0000000000002000, info: 0x0000000000000025, addend: 0x0000000000001007) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o to tmpdir/dump: R_X86_64_IRELATIVE (offset: 0x2000, info: 0x25, addend: 0x1007) against 'ifunc' for section '.data.rel.ro.local' in tmpdir/report-reloc-1.o bfd/ * elfxx-x86.c (_bfd_x86_elf_link_report_relative_reloc): Use 0x%v instead of bfd_sprintf_vma. ld/ * testsuite/ld-i386/report-reloc-1.l: Updated. * testsuite/ld-x86-64/report-reloc-1.l: Likewise.
2022-01-02Update year range in copyright notice of binutils filesAlan Modra
The result of running etc/update-copyright.py --this-year, fixing all the files whose mode is changed by the script, plus a build with --enable-maintainer-mode --enable-cgen-maint=yes, then checking out */po/*.pot which we don't update frequently. The copy of cgen was with commit d1dd5fcc38ead reverted as that commit breaks building of bfp opcodes files.
2022-01-01unify 64-bit bfd checksMike Frysinger
Move the 64-bit bfd logic out of bfd/configure.ac and into bfd64.m4 under config so it can be shared between all the other subdirs. This replaces want64 with enable_64_bit_bfd which was already being declared, but not used directly.
2021-12-31ld-x86-64: Pass options to linker with "-Wl,"H.J. Lu
* testsuite/ld-x86-64/x86-64.exp: Pass options to linker with "-Wl,".
2021-12-28ld: Fix testcase errors due to -shared not support.jiawei
Reviewed-by: Jim Wilson <jim.wilson.gcc@gmail.com> ld/ChangeLog: * testsuite/ld-ctf/ctf.exp: Add shared lib check. * testsuite/ld-plugin/lto.exp: Add lto shared check.
2021-12-27ld: Remove emultempl/linux.emH.J. Lu
Remove emultempl/linux.em whose last usage was removed by commit c65c21e1ffd1e02d9970a4bca0b7e384788a50f0 Author: Alan Modra <amodra@gmail.com> Date: Mon Apr 16 22:14:01 2018 +0930 various i386-aout and i386-coff target removal Also tidies some other aout leftovers in binutils-common.exp.
2021-12-21Obsolete m32c-rtems and m32r-rtemsJoel Sherrill
2020-12-20 Joel Sherrill <joel@rtems.org> bfd/ * config.bfd (m32c-*-rtems*): Remove target. ld/ * configure.tgt (m32c-*-rtems*): Remove target. * configure.tgt (m32r-*-rtems*): Remove target.
2021-12-16Fix AVR assembler so that it creates relocs that will work with linker ↵Nick Clifton
relaxation. PR 28686 gas * config/tc-avr.h (tc_fix_adjustable): Define. * config/tc-avr.c (avr_fix_adjustable): New function. * testsuite/gas/all/gas.exp: Skip tests that need adjustable fixups. * testsuite/gas/elf/elf.exp: Likewise. * testsuite/gas/avr/diffreloc_withrelax.d: Adjust expected output. * testsuite/gas/avr/pc-relative-reloc.d: Adjust expected output. ld * testsuite/ld-avr/avr-prop-7.d: Adjust expected output. * testsuite/ld-avr/avr-prop-8.d: Likewise. * testsuite/ld-avr/pr13402.d: Likewise.
2021-12-16Adjust compare_link_order for unstable qsortSandra Loosemore
In a cross toolchain for nios2-elf target and x86_64-w64-mingw32 host using binutils 2.37, we observed a failure that didn't show up on x86_64-linux-gnu host: testcase pr25490-5.s was failing with C:\path\to\nios2-elf-ld.exe: looping in map_segments FAIL: __patchable_function_entries section 5 * ldelfgen.c (compare_link_order): Don't use section id in sorting. Keep original ordering instead. Update comments.
2021-12-14RISC-V: Added ld testcases for the medlow and medany code models.Nelson Chu
There are two linker scripts, code-model-01.ld and code-model-02.ld, which are corresponding to the two different memory layouts, * code-model-01.ld: the text section is in the 32-bit address range, but the data section is far away from the text section, which means the data section is over the 32-bit address range. * code-model-02.ld: the text section is over the 32-bit address range, but the data section is placed nearly zero address. We use the two linker scripts, to test the current medlow and medany behaviors of GNU ld, including the weak symbol references and the relaxations behaviors. Besides, these testcases also show the limits of the current medlow and medany code models, that is - we may get the truncated to fit errors when linking with the above two linker scripts. ld/ * testsuite/ld-riscv-elf/code-model-01.ld: New testcases to test the behaviors of the current medlow and medany code models. * testsuite/ld-riscv-elf/code-model-02.ld: Likewise. * testsuite/ld-riscv-elf/code-model-medany-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medany-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-medlow-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medany-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-02.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-01.d: Likewise. * testsuite/ld-riscv-elf/code-model-relax-medlow-weakref-02.d: Likewise. * testsuite/ld-riscv-elf/code-model.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2021-12-13x86: Adjust linker tests for --disable-separate-codeH.J. Lu
Adjust linker tests for linker configured with --disable-separate-code: 1. Update expected outputs. 2. Pass -z max-page-size=0x1000 -z separate-code" to linker. * testsuite/ld-i386/report-reloc-1.l: Updated. * testsuite/ld-x86-64/report-reloc-1.l: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Pass "-z max-page-size=0x1000 -z separate-code" to linker. * testsuite/ld-x86-64/pr19609-4e.d: Likewise. * testsuite/ld-x86-64/pr19609-6a.d: Likewise. * testsuite/ld-x86-64/pr19609-6b.d: Likewise. * testsuite/ld-x86-64/pr19609-7b.d: Likewise. * testsuite/ld-x86-64/pr19609-7d.d: Likewise.
2021-12-08PR28673, input file 'gcov' is the same as output fileAlan Modra
PR 28673 * ldlang.c (open_output): Use local_sym_name when checking output against input files rather than filename.
2021-12-07Error on ld output file name matching input file nameAlan Modra
It's not foolproof, for example we don't catch output to a linker script, to a library specified with -l, or to an element of a thin archive. * ldlang.c (open_output): Exit with error on output file matching an input file. * testsuite/ld-misc/just-symbols.exp: Adjust ld -r test to suit.
2021-12-06ld: improve shared tests for AIXClément Chigot
It's now possible to refer symbols in the main program from the shared library. However, it still impossible to have the same overriden features between shared objects and mains than ELF, without using the runtime linking feature which isn't yet fully available. ld/ChangeLog: * testsuite/ld-shared/shared.exp: Improve XCOFF support * testsuite/ld-shared/main.c: Likewise. * testsuite/ld-shared/sh1.c: Likewise. * testsuite/ld-shared/xcoff.dat: Likewise.
2021-12-02x86: Skip __[start|stop]_SECNAME for --gc-sections -z start-stop-gcH.J. Lu
Don't convert memory load to immediate load on __start_SECNAME and __stop_SECNAME for --gc-sections -z start-stop-gc if all SECNAME sections been garbage collected. bfd/ PR ld/27491 * elf32-i386.c (elf_i386_convert_load_reloc): Skip __start_SECNAME and __stop_SECNAME for --gc-sections -z start-stop-gc if the input section been garbage collected. * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise. * elfxx-x86.h (elf_x86_start_stop_gc_p): New function. ld/ PR ld/27491 * testsuite/ld-i386/i386.exp: Run PR ld/27491 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr27491-1.s: New file. * testsuite/ld-i386/pr27491-1a.d: Likewise. * testsuite/ld-i386/pr27491-1b.d: Likewise. * testsuite/ld-i386/pr27491-1c.d: Likewise. * testsuite/ld-i386/pr27491-2.d: Likewise. * testsuite/ld-i386/pr27491-2.s: Likewise. * testsuite/ld-i386/pr27491-3.d: Likewise. * testsuite/ld-i386/pr27491-3.s: Likewise. * testsuite/ld-i386/pr27491-4.d: Likewise. * testsuite/ld-i386/pr27491-4a.s: Likewise. * testsuite/ld-i386/pr27491-4b.s: Likewise. * testsuite/ld-x86-64/pr27491-1.s: Likewise. * testsuite/ld-x86-64/pr27491-1a.d: Likewise. * testsuite/ld-x86-64/pr27491-1b.d: Likewise. * testsuite/ld-x86-64/pr27491-1c.d: Likewise. * testsuite/ld-x86-64/pr27491-2.d: Likewise. * testsuite/ld-x86-64/pr27491-2.s: Likewise. * testsuite/ld-x86-64/pr27491-3.d: Likewise. * testsuite/ld-x86-64/pr27491-3.s: Likewise. * testsuite/ld-x86-64/pr27491-4.d: Likewise. * testsuite/ld-x86-64/pr27491-4a.s: Likewise. * testsuite/ld-x86-64/pr27491-4b.s: Likewise.
2021-12-01elf: Discard input .note.gnu.build-id sectionsH.J. Lu
1. Discard input .note.gnu.build-id sections. 2. Clear the build ID field before writing. 3. Use bfd_make_section_anyway_with_flags to create the output .note.gnu.build-id section. PR ld/28639 * ldelf.c (ldelf_after_open): Discard input .note.gnu.build-id sections, excluding the first one. (write_build_id): Clear the build ID field before writing. (ldelf_setup_build_id): Use bfd_make_section_anyway_with_flags to create the output .note.gnu.build-id section. * testsuite/ld-elf/build-id.exp: New file. * testsuite/ld-elf/pr28639a.rd: Likewise. * testsuite/ld-elf/pr28639b.rd: Likewise. * testsuite/ld-elf/pr28639c.rd: Likewise. * testsuite/ld-elf/pr28639d.rd: Likewise.
2021-11-30ld: pru: Add pru_irq_map output sectionNick Clifton
* scripttempl/pru.sc (.pru_irq_map): Define output section. * testsuite/ld-pru/pru_irq_map-1.d: New test. * testsuite/ld-pru/pru_irq_map-2.d: New test. * testsuite/ld-pru/pru_irq_map.s: New test.
2021-11-29ld: enable silent build rulesMike Frysinger
Also add $(AM_V_xxx) to various manual rules in here.
2021-11-26Fix ifunc test fails on hppa*-*-*John David Anglin
2021-11-26 John David Anglin <danglin@gcc.gnu.org> PR ld/27442 ld/ChangeLog: * ld/testsuite/ld-ifunc/ifunc.exp (contains_irelative_reloc): Adjust regexp. Skip static ifunc-using executable test on hppa*-*-*.
2021-11-25ld: fix POSIX shell test usageMike Frysinger
POSIX test uses = for compares, not == which is a bashism.
2021-11-25ld: fix --disable-multiple-abs-defs alignment in helpMike Frysinger
2021-11-25ld/testsuite/ld-elfvsb: correctly test "weak hidden symbol DSO last"Clément Chigot
The test must be done with the shared object and not with the object file which is already being tested above. ld/ * testsuite/ld-elfvsb/elfvsb.exp: use .so file in "weak hidden symbol DSO last"
2021-11-23Update bug reporting addressAlan Modra
https://sourceware.org/bugzilla/ everywhere bfd/ * configure.ac (ACX_BUGURL): Set to https://sourceware.org/bugzilla/ * po/Make-in (msgid-bugs-address): Likewise. * README: Report bugs to the above. * configure: Regenerate. binutils/ * po/Make-in (msgid-bugs-address): Update. gas/ * README: Update bug address. Delete mention of gcc. * po/Make-in: Update bug address. gold/ * po/Make-in: Update bug address. gprof/ * po/Make-in: Update bug address. ld/ * po/Make-in: Update bug address. opcodes/ * po/Make-in: Update bug address.
2021-11-19RISC-V: Support STO_RISCV_VARIANT_CC and DT_RISCV_VARIANT_CC.Nelson Chu
This is the original discussion, https://github.com/riscv/riscv-elf-psabi-doc/pull/190 And here is the glibc part, https://sourceware.org/pipermail/libc-alpha/2021-August/129931.html For binutils part, we need to support a new direcitve: .variant_cc. The function symbol marked by .variant_cc means it need to be resolved directly without resolver for dynamic linker. We also add a new dynamic entry, STO_RISCV_VARIANT_CC, to indicate there are symbols with the special attribute in the dynamic symbol table of the object. I heard that llvm already have supported this in their mainline, so I think it's time to commit this. bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): Added variant_cc flag. It is used to check if relocations for variant CC symbols may be present. (allocate_dynrelocs): If the symbol has STO_RISCV_VARIANT_CC flag, then raise the variant_cc flag of riscv_elf_link_hash_table. (riscv_elf_size_dynamic_sections): Added dynamic entry for variant_cc. (riscv_elf_merge_symbol_attribute): New function, used to merge non-visibility st_other attributes, including STO_RISCV_VARIANT_CC. binutils/ * readelf.c (get_riscv_dynamic_type): New function. (get_dynamic_type): Called get_riscv_dynamic_type for riscv targets. (get_riscv_symbol_other): New function. (get_symbol_other): Called get_riscv_symbol_other for riscv targets. gas/ * config/tc-riscv.c (s_variant_cc): Marked symbol that it follows a variant CC convention. (riscv_elf_copy_symbol_attributes): Same as elf_copy_symbol_attributes, but without copying st_other. If a function symbol has special st_other value set via directives, then attaching an IFUNC resolver to that symbol should not override the st_other setting. (riscv_pseudo_table): Support variant_cc diretive. * config/tc-riscv.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Defined. * testsuite/gas/riscv/variant_cc-set.d: New testcase. * testsuite/gas/riscv/variant_cc-set.s: Likewise. * testsuite/gas/riscv/variant_cc.d: Likewise. * testsuite/gas/riscv/variant_cc.s: Likewise. include/ * elf/riscv.h (DT_RISCV_VARIANT_CC): Defined to (DT_LOPROC + 1). (STO_RISCV_VARIANT_CC): Defined to 0x80. ld/ * testsuite/ld-riscv-elf/variant_cc-1.s: New testcase. * testsuite/ld-riscv-elf/variant_cc-2.s: Likewise. * testsuite/ld-riscv-elf/variant_cc-now.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-r.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-shared.d: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2021-11-18elf/x86: Issue an error on discarded output .plt sectionH.J. Lu
Issue an error, instead of crash, on discarded output .plt section. bfd/ PR ld/28597 * elf32-i386.c (elf_i386_finish_dynamic_sections): Issue an error on discarded output .plt section. * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise. ld/ PR ld/28597 * testsuite/ld-elf/pr28597.d: New file. * testsuite/ld-elf/pr28597.s: Likewise. * testsuite/ld-elf/pr28597.t: Likewise.
2021-11-17Set the default DLL chracteristics to 0 for Cygwin based targets.Jeremy Drake
* emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Set to 0 for Cygwin targets. * emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Likewise.
2021-11-17Fix the linker script parser so that it will recognise the PT_GNU_RELRO ↵Nick Clifton
segment type, and the linker itself so that it will gracefully handle being unable to assign any sections to such a segment. PR 28452 bfd * elf.c (assign_file_positions_for_non_load_sections): Replace assertion with a warning message. ld * ldgram.y: Add support for PT_GNU_RELRO and PT_GNU_PROPERTY. * ldgram.c: Regenerate.
2021-11-15ld: Fix testsuite failures under --enable-textrel-check=errorRoland McGrath
ld/ * testsuite/ld-aarch64/dt_textrel.d: Pass explicit -z notext in case ld was configured with --enable-textrel-check=error. * testsuite/ld-aarch64/pr22764.d: Likewise. * testsuite/ld-aarch64/pr20402.d: Likewise.
2021-11-15PowerPC64 @notoc in non-power10 codeAlan Modra
R_PPC64_REL24_P9NOTOC is a variant of R_PPC64_REL24_NOTOC for use on @notoc cals from non-power10 code in the rare case that using such a construct is useful. R_PPC64_REL24_P9NOTOC will be emitted by gas rather than R_PPC64_REL24_NOTOC when @notoc is used in a branch instruction if power10 instructions are not enabled at that point. The new relocation tells the linker to not use power10 instructions on any stub emitted for that branch, unless overridden by --power10-stubs=yes. The current linker heuristic of only generating power10 instructions for stubs if power10-only relocations are detected, continues to be used. include/ * elf/ppc64.h (R_PPC64_REL24_P9NOTOC): Define. bfd/ * reloc.c (BFD_RELOC_PPC64_REL24_P9NOTOC): Define. * elf64-ppc.c (ppc64_elf_howto_raw): Add entry for new reloc. (ppc64_elf_reloc_type_lookup): Handle it. (enum ppc_stub_type): Delete. (enum ppc_stub_main_type, ppc_stub_sub_type): New. (struct ppc_stub_type): New. (struct ppc_stub_hash_entry): Use the above new type. (struct ppc_link_hash_table): Update stub_count. (is_branch_reloc, ppc64_elf_check_relocs), (toc_adjusting_stub_needed): Handle new reloc. (stub_hash_newfunc, select_alt_stub, ppc_merge_stub), (ppc_type_of_stub, plt_stub_size, build_plt_stub), (build_tls_get_addr_head, build_tls_get_addr_tail), (ppc_build_one_stub, ppc_size_one_stub, ppc64_elf_size_stubs), (ppc64_elf_build_stubs, ppc64_elf_relocate_section): Handle new reloc. Modify stub handling to suit new scheme. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): When power10 is not enabled return BFD_RELOC_PPC64_REL24_P9NOTOC for @notoc. (fixup_size, ppc_force_relocation, ppc_fix_adjustable): Handle BFD_RELOC_PPC64_REL24_P9NOTOC. ld/ * testsuite/ld-powerpc/callstub-2.s: Add .machine power10.
2021-11-15Regenerate a couple of filesAlan Modra
A couple of files changed on my latest --enable-maintainer-mode build. ld/Makefile.in had a missing dependency but better sorting of the loongson entries. intl/ * configure: Regenerate. ld/ * Makefile.am: Sort loongson entries. * Makefile.in: Regenerate.
2021-11-10ld: set correct flags for AIX shared testsClément Chigot
Previous flags were aimed to be run with XLC. Nowadays, only GCC is being tested with GNU toolchain. Moreover, recent XLC versions might also accept "-shared". * testsuite/ld-shared/shared.exp: Adjust shared flags.
2021-11-08Correct ld script wildcard matching descriptionAlan Modra
Goes with commit 68bbb9f788d0 * ld.texi (Input Section Wildcards): Delete paragraph incorrectly saying '*' does not match '/'.
2021-11-06Modernise yyerrorAlan Modra
Newer versions of bison emit a prototype for yyerror void yyerror (const char *); This clashes with some of our old code that declares yyerror to return an int. Fix that in most cases by modernizing yyerror. bfin-parse.y uses the return value all over the place, so for there disable generation of the prototype as specified by posix. binutils/ * arparse.y (yyerror): Return void. * dlltool.c (yyerror): Likewise. * dlltool.h (yyerror): Likewise. * sysinfo.y (yyerror): Likewise. * windmc.h (yyerror): Likewise. * mclex.c (mc_error): Extract from .. (yyerror): ..here, both now returning void. gas/ * config/bfin-parse.y (yyerror): Define. (yyerror): Make static. * itbl-parse.y (yyerror): Return void. ld/ * deffilep.y (def_error): Return void.
2021-11-03asan: dlltool buffer overflow: embedded NUL in stringAlan Modra
yyleng gives the pattern length, xstrdup just copies up to the NUL. So it is quite possible writing at an index of yyleng-2 overflows the xstrdup allocated string buffer. xmemdup quite handily avoids this problem, even writing the terminating NUL over the trailing quote. Use it in ldlex.l too where we'd already had a report of this problem and fixed it by hand, and to implement xmemdup0 in gas. binutils/ * deflex.l (single and double quote strings): Use xmemdup. gas/ * as.h (xmemdup0): Use xmemdup. ld/ PR 20906 * ldlex.l (double quote string): Use xmemdup.
2021-10-28ASSERT in empty output section with addressAlan Modra
* ldlang.c (lang_do_assignments_1): Correct "dot" inside ignored sections. * testsuite/ld-scripts/empty-address-4.d, * testsuite/ld-scripts/empty-address-4.s, * testsuite/ld-scripts/empty-address-4.t: New test. * testsuite/ld-scripts/empty-address.exp: Run it.
2021-10-25libctf, ld: handle nonrepresentable types betterNick Alcock
ctf_type_visit (used, among other things, by the type dumping code) was aborting when it saw a nonrepresentable type anywhere: even a single structure member with a nonrepresentable type caused an abort with ECTF_NONREPRESENTABLE. This is not useful behaviour, given that the abort comes from a type-resolution we are only doing in order to determine whether the type is a structure or union. We know nonrepresentable types can't be either, so handle that case and pass the nonrepresentable type down. (The added test verifies that the dumper now handles this case and prints nonrepresentable structure members as it already does nonrepresentable top-level types, rather than skipping the whole structure -- or, without the previous commit, skipping the whole types section.) ld/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/nonrepresentable-member.*: New test. libctf/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * ctf-types.c (ctf_type_rvisit): Handle nonrepresentable types.