aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2022-03-10Re: ld: Add a before_plugin_all_symbols_read hookAlan Modra1-1/+1
* testsuite/ld-plugin/pr28849.d: Adjust for powerpc64 function descriptors.
2022-03-09ld: Add a before_plugin_all_symbols_read hookH.J. Lu11-175/+274
Add a before_plugin_all_symbols_read hook to load symbol references from DT_NEEDED entries, included from --copy-dt-needed-entries, before reading plugin symbols to properly resolve plugin symbol references. bfd/ PR ld/28849 * elf-bfd.h (elf_link_hash_table): Add handling_dt_needed. * elflink.c (_bfd_elf_merge_symbol): Don't set non_ir_ref_dynamic before plugin 'all symbols read' hook is called. ld/ PR ld/28849 * ldelf.c (ldelf_handle_dt_needed): New function. (ldelf_before_plugin_all_symbols_read): Likewise. (ldelf_after_open): Call ldelf_handle_dt_needed. * ldelf.h (ldelf_before_plugin_all_symbols_read): New. * ldemul.c (ldemul_before_plugin_all_symbols_read): Likewise. * ldemul.h (ldemul_before_plugin_all_symbols_read): Likewise. (ld_emulation_xfer_struct): Add before_plugin_all_symbols_read. * ldlang.c (lang_process): Call ldemul_before_plugin_all_symbols_read before calling plugin_call_all_symbols_read. * emultempl/elf.em (gld${EMULATION_NAME}_before_plugin_all_symbols_read): New. (LDEMUL_BEFORE_PLUGIN_ALL_SYMBOLS_READ): New. * emultempl/emulation.em (ld_${EMULATION_NAME}_emulation): Initialize the before_plugin_all_symbols_read field. * testsuite/ld-plugin/lto.exp: Run PR ld/28849 tests. * testsuite/ld-plugin/pr28849.d: New file. * testsuite/ld-plugin/pr28849a.c: Likewise. * testsuite/ld-plugin/pr28849b.c: Likewise.
2022-03-04Adjust ld ctf test for 32-bit targetsAlan Modra1-1/+1
powerpc-linux, and I suspect other 32-bit targets, report "aligned at 0x4" for this test. * testsuite/ld-ctf/nonrepresentable.d: Accept any alignment.
2022-03-01Fix linker tests to compile with gcc-12.Nick Clifton7-6/+16
PR 21964 * testsuite/ld-elf/pr21964-1a.c: Fix array comparisons. * testsuite/ld-elf/pr21964-1b.c: Likewise. * testsuite/ld-elf/pr21964-1c.c: Likewise. * testsuite/ld-elf/pr21964-2a.c: Likewise. * testsuite/ld-elf/pr21964-2b.c: Likewise. * testsuite/ld-elf/pr21964-3a.c: Likewise.
2022-02-18Fix typo in ld.texiRoland McGrath2-5/+9
ld/ * ld.texi (Output Section Type): Fix typo in @code syntax.
2022-02-17Updated Serbian translations for the bfd, gold, ld and opcodes directoriesNick Clifton2-1583/+1687
2022-02-16ld: Support customized output section typeFangrui Song10-24/+111
bfd/ PR ld/28841 * bfd-in2.h (struct bfd_section): Add type. (discarded_section): Add field. * elf.c (elf_fake_sections): Handle bfd_section::type. * section.c (BFD_FAKE_SECTION): Add field. * mri.c (mri_draw_tree): Update function call. ld/ PR ld/28841 * ld.texi: Document new output section type. * ldlex.l: Add new token TYPE. * ldgram.y: Handle TYPE=exp. * ldlang.h: Add type_section to list of section types. * ldlang.c (lang_add_section): Handle type_section. (map_input_to_output_sections): Handle type_section. * testsuite/ld-scripts/output-section-types.t: Add tests. * testsuite/ld-scripts/output-section-types.d: Update.
2022-02-15i386: Update I386_NEED_DYNAMIC_RELOC_TYPE_P for DT_TEXTRELH.J. Lu3-0/+11
Update I386_NEED_DYNAMIC_RELOC_TYPE_P to allow R_386_TLS_IE for relocation in read-only section. bfd/ PR ld/28894 * elfxx-x86.h (I386_NEED_DYNAMIC_RELOC_TYPE_P): Allow R_386_TLS_IE. ld/ PR ld/28894 * testsuite/ld-i386/i386.exp: Run pr28894. * testsuite/ld-i386/pr28894.d: New file. * testsuite/ld-i386/pr28894.s: Likewise.
2022-02-14x86-64: Use MAXPAGESIZE for the relro segment alignmentH.J. Lu15-59/+59
Adjust x86-64 linker tests after reverting commit 31b4d3a16f200bf04db8439a63b72bba7af4e1be Author: Alan Modra <amodra@gmail.com> Date: Thu Feb 3 08:57:47 2022 +1030 PR28824, relro security issues, x86 keep COMMONPAGESIZE relro to use MAXPAGESIZE for the end of the relro segment alignment, like other ELF targets. * testsuite/ld-x86-64/plt-main-bnd.dd: Updated. * testsuite/ld-x86-64/plt-main-ibt-x32.dd: Likewise. * testsuite/ld-x86-64/plt-main-ibt.dd: Likewise. * testsuite/ld-x86-64/pr14207.d: Likewise. * testsuite/ld-x86-64/pr18176.d: Likewise. * testsuite/ld-x86-64/pr20830a-now.d: Likewise. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b-now.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a-now.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038b.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-02-14Revert "PR28824, relro security issues, x86 keep COMMONPAGESIZE relro"H.J. Lu4-10/+1
This reverts commit 31b4d3a16f200bf04db8439a63b72bba7af4e1be.
2022-02-13ld: Keep indirect symbol from IR if referenced from shared objectH.J. Lu3-0/+41
Don't change indirect symbol defined in IR to undefined if it is referenced from shared object. bfd/ PR ld/28879 * elflink.c (_bfd_elf_merge_symbol): Don't change indirect symbol defined in IR to undefined if it is referenced from shared object. ld/ PR ld/28879 * testsuite/ld-plugin/lto.exp: Run PR ld/28879 tests. * testsuite/ld-plugin/pr28879a.cc: New file. * testsuite/ld-plugin/pr28879b.cc: Likewise.
2022-02-13Don't pass around expld.dataseg pointerAlan Modra2-20/+28
The better to see any code that accesses expld.dataseg. * ldexp.c (fold_segment_end): Remove seg parameter. Adjust calls. (fold_segment_align, fold_segment_relro_end): Likewise. * ldlang.c (lang_size_segment): Likewise. (lang_size_relro_segment_1, lang_find_relro_sections_1): Likewise.
2022-02-13Remove bfd ELF_RELROPAGESIZEAlan Modra1-2/+1
Now that ld properly aligns the end of the relro segment, the hack to make relro work on powerpc can disappear. bfd/ * bfd.c (bfd_emul_get_commonpagesize): Remove relro param. Don't return bed->relropagesize. * elf-bfd.h (struct elf_backend_data): Remove relropagesize. * elfxx-target.h (ELF_RELROPAGESIZE): Remove. * elf32-ppc.c (ELF_RELROPAGESIZE): Don't define. * elf64-ppc.c: Likewise. * bfd-in2.h: Regenerate. ld/ * ldemul.c (after_parse_default): Adjust bfd_emul_get_commonpagesize call.
2022-02-13PR28824, relro security issues, x86 keep COMMONPAGESIZE relroAlan Modra4-1/+10
x86 treats MAXPAGESIZE as a memory optimisation parameter, actual hardware paging is always COMMPAGESIZE of 4k. Use COMMONPAGESIZE for the end of the relro segment alignment. The previous patch regresses pr18176, increasing the testcase file size from 322208 to 2099872 bytes. Fixing this on x86 will require introducing a gap after the end of the relro segment (of up to relropagesize-1 bytes). PR 28824 PR 18176 * ld.h (ld_config_type): Add relro_use_commonpagesize field. * ldexp.c (fold_segment_align): Set relropagesize depending on relro_use_commonpagesize. * emultempl/elf-x86.em (elf_x86_create_output_section_statements): Set relro_use_commonpagesize. * testsuite/ld-x86-64/pr18176.d: xfail.
2022-02-13PR28824, relro security issuesAlan Modra3-13/+17
Background ========== There are constraints on layout of binaries to meet demand paging and memory protection requirements. Demand paged binaries must have file offset mod pagesize equal to vma mod pagesize. Memory protection (executable, read, write status) can only change at page boundaries. The linker's MAXPAGESIZE variable gives the page size for these layout constraints. In a typical basic executable with two memory segments, text (RE) and data (RW), the data segment must start on a different page to the last text segment page. For example, with 64k pages and a small executable of 48k text and 1k data, the text segment might start at address 0x10000 and data at 0x20000 for a total of two 64k memory pages. Demand paging would require the image on disk to be 64k+1k in size. We can do better than that. If the data segment instead starts at 0x2c000 (the end of the text segment plus one 64k page) then there are still only two memory pages, but the disk image is now smaller, 48k+1k in size. This is why the linker normally starts the data segment at the end of the text segment plus one page. That simple heuristic isn't ideal in all cases. Changing our simple example to one with 64k-1 text size, following that heuristic would result in data starting at 0x2ffff. Now we have two 64k memory data pages for a data segment of 1k! If the data segment instead started at 0x30000 we'd get a single data segment page at the cost of 1 byte extra in the disk image, which is likely a good trade-off. So the linker does adjust the simple heuristic. Just how much disk image size increase is allowed is controlled by the linker's COMMONPAGESIZE variable. A PT_GNU_RELRO segment overlays the initial part of the data segment, saying that those pages should be made read-only after relocation by the dynamic loader. Page granularity for memory protection means that the end of the relro segment must be at a page boundary. The problem =========== Unfortunately most targets currently only align the end of the relro segment to COMMONPAGESIZE. That results in only partial relro protection if an executable is running with MAXPAGESIZE pages, since any part of the relro segment past the last MAXPAGESIZE boundary can't be made read-only without also affecting sections past the end of the relro segment. I believe this problem arose because x86 always runs with 4k (COMMPAGESIZE) memory pages, and therefore using a larger MAXPAGESIZE on x86 is for reasons other than the demand paging and memory page protection boundary requirements. The solution ============ Always end the relro segment on a MAXPAGESIZE boundary, except for x86. Note that the relro segment, comprising of sections at the start of the data segment, is sized according to how those sections are laid out. That means the start of the relro segment is fixed relative to its end. Which also means the start of the data segment must be at a fixed address mod MAXPAGESIZE. So for relro the linker can't play games with the start of the data segment to save disk space. At least, not without introducing gaps between the relro sections. In fact, because the linker was starting layout using its simple heuristic of starting the data segment at the end of the text segment plus one page, it was sometimes introducing page gaps for no reason. See pr28743. PR 28824 PR 28734 * ldexp.c (fold_segment_align): When relro, don't adjust up by offset within page. Set relropagesize. (fold_segment_relro_end): Align to relropagesize. * ldexp.h (seg_align_type): Rename pagesize to commonpagesize. Add relropagesize. Comment. * ldlang.c (lang_size_segment): Adjust to suit field renaming. (lang_size_relro_segment_1): Align relro_end using relropagesize.
2022-02-11x86: Disallow invalid relocation against protected symbolH.J. Lu10-21/+63
I am checking this into master and will backport it to 2.38 branch. H.J ---- On x86, GCC 12 supports -mno-direct-extern-access to enable canonical reference to protected function and disable copy relocation. With -mno-direct-extern-access, the canonical protected function symbols must be accessed via canonical reference and the protected data symbols in shared libraries are non-copyable. Under glibc 2.35, non-canonical reference to the canonical protected function will get the run-time error: ./y: internal_f: ./libfoo.so: non-canonical reference to canonical protected function and copy relocations against the non-copyable protected symbols will get the run-time error: ./x: internal_i: ./libfoo.so: copy relocation against non-copyable protected symbol Update x86 linker to disallow non-canonical reference to the canonical protected function: ld: plt.o: non-canonical reference to canonical protected function `internal_f' in libfoo.so ld: failed to set dynamic section sizes: bad value and copy relocation against the non-copyable protected symbol: ld: main.o: copy relocation against non-copyable protected symbol `internal_i' in libfoo.so at link-time. bfd/ PR ld/28875 * elf-properties.c (_bfd_elf_parse_gnu_properties): Don't skip shared libraries for GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS. * elf32-i386.c (elf_i386_scan_relocs): Disallow non-canonical reference to canonical protected function. * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise. * elfxx-x86.c (elf_x86_allocate_dynrelocs): Don't allow copy relocation against non-copyable protected symbol. ld/ PR ld/28875 * testsuite/ld-i386/i386.exp: Check non-canonical reference to canonical protected function and check copy relocation against non-copyable protected symbol. * testsuite/ld-i386/pr21997-1.err: New file. * testsuite/ld-i386/pr28875.err: Likewise. * testsuite/ld-i386/pr28875a.c: Likewise. * testsuite/ld-i386/pr28875b.c: Likewise. * testsuite/ld-x86-64/pr21997-1a.err: Updated. * testsuite/ld-x86-64/pr21997-1b.err: Likewise. * testsuite/ld-x86-64/pr28875-data.err: New file. * testsuite/ld-x86-64/pr28875-func.err: Likewise. * testsuite/ld-x86-64/x86-64.exp: Check non-canonical reference to canonical protected function and check copy relocation against non-copyable protected symbol.
2022-02-08RISC-V: Stop reporting warnings for mismatched extension versionsPalmer Dabbelt12-46/+12
The extension version checking logic is really just too complicated to encode into the linker, trying to do so causes more harm than good. This removes the checks and the associated tests, leaving the logic to keep the largest version of each extension linked into the target. bfd/ * elfnn-riscv.c (riscv_version_mismatch): Rename to riscv_update_subset_version, and stop reporting warnings on version mismatches. (riscv_merge_std_ext): Adjust calls to riscv_version_mismatch. (riscv_merge_multi_letter_ext): Likewise. ld/ * testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Remove * testsuite/ld-riscv-elf/attr-merge-arch-failed-01a.s: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-01b.s: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-02a.s: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-02b.s: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-02c.s: Likewise * testsuite/ld-riscv-elf/attr-merge-arch-failed-02d.s: Likewise * testsuite/ld-riscv-elf/attr-merge-user-ext-01.d: New test. * testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p0.s: Likewise. * testsuite/ld-riscv-elf/attr-merge-user-ext-rv32i21_m2p1.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Remove obselete attr-merge-arch-failed-{01,02}, replace with attr-merge-user-ext-01. Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2022-02-08Re: elf: Check symbol version without any symbolsAlan Modra1-2/+2
* testsuite/ld-elf/pr24718-1.d: Don't xfail for hppa64.
2022-02-07i386: Allow GOT32 relocations against ABS symbolsH.J. Lu3-0/+17
GOT32 relocations are allowed since absolute value + addend is stored in the GOT slot. Tested on glibc 2.35 build with GCC 11.2 and -Os. bfd/ PR ld/28870 * elfxx-x86.c (_bfd_elf_x86_valid_reloc_p): Also allow GOT32 relocations. ld/ PR ld/28870 * testsuite/ld-i386/i386.exp: Run pr28870. * testsuite/ld-i386/pr28870.d: New file. * testsuite/ld-i386/pr28870.s: Likewise.
2022-02-07Revert "elf: Remove the 1-page gap before the RELRO segment"Alan Modra14-110/+57
This reverts commit 2f83249c13d86065b4c7cdb198ea871017b4bba1. PR ld/28743 * ldlang.c (lang_size_relro_segment_1): Revert 2022-01-10 changes. * testsuite/ld-i386/pr20830.d: Likewise. * testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise. * testsuite/ld-x86-64/pr14207.d: Likewise. * testsuite/ld-x86-64/pr18176.d: Likewise. * testsuite/ld-x86-64/pr20830a-now.d: Likewise. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b-now.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a-now.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-02-07Revert "ld: Rewrite lang_size_relro_segment_1"Alan Modra4-118/+44
This reverts commit c804c6f98d342c3d46f73d7a7ec6229d5ab1c9f3. PR ld/28743 PR ld/28819 * ldlang.c (lang_size_relro_segment_1): Revert 2022-01-14 change. * testsuite/ld-x86-64/pr28743-1.d: Likewise. * testsuite/ld-x86-64/pr28743-1.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Likewise.
2022-02-07A more elegant pr28827-1 testcaseAlan Modra1-6799/+54
Use .irpc macros in pr28827-1.s * testsuite/ld-powerpc/pr28827-1.s: Make the testcase more elegant. Comment.
2022-02-06ld: Add emultempl/emulation.emH.J. Lu10-372/+165
Add emultempl/emulation.em to define ld_${EMULATION_NAME}_emulation so that new emulation hooks can be added easily. * emultempl/aix.em (LDEMUL_AFTER_OPEN): New. (LDEMUL_SET_OUTPUT_ARCH): Likewise. (LDEMUL_CHOOSE_TARGET): Likewise. (LDEMUL_BEFORE_ALLOCATION): Likewise. (LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS): Likewise. (LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise. (LDEMUL_PARSE_ARGS): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_UNRECOGNIZED_FILE): Likewise. (LDEMUL_PRINT_SYMBOL): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/beos.em (gld_${EMULATION_NAME}_before_parse): Renamed to ... (gld${EMULATION_NAME}_before_parse): This. (gld_${EMULATION_NAME}_set_symbols): Renamed to ... (gld${EMULATION_NAME}_set_symbols): This. (gld_${EMULATION_NAME}_after_open): Renamed to ... (gld${EMULATION_NAME}_after_open): This. (gld_${EMULATION_NAME}_before_allocation): Renamed to ... (gld${EMULATION_NAME}_before_allocation): This. (gld_${EMULATION_NAME}_get_script): Renamed to ... (gld${EMULATION_NAME}_get_script): This. (LDEMUL_AFTER_OPEN): New. (LDEMUL_BEFORE_ALLOCATION): Likewise. (LDEMUL_PLACE_ORPHAN): Likewise. (LDEMUL_SET_SYMBOLS): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/elf.em (LDEMUL_AFTER_PARSE): New. (LDEMUL_AFTER_OPEN): Likewise. (LDEMUL_BEFORE_PLACE_ORPHANS): Likewise. (LDEMUL_AFTER_ALLOCATION): Likewise. (LDEMUL_SET_OUTPUT_ARCH): Likewise. (LDEMUL_BEFORE_ALLOCATION): Likewise. (LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise. (LDEMUL_PLACE_ORPHAN): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_LIST_OPTIONS): Likewise. (LDEMUL_UNRECOGNIZED_FILE): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/emulation.em: New file. * emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/msp430.em (LDEMUL_AFTER_OPEN): New. (LDEMUL_AFTER_ALLOCATION): Likewise. (LDEMUL_PLACE_ORPHAN): Likewise. (LDEMUL_FINISH): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_LIST_OPTIONS): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/pe.em (gld_${EMULATION_NAME}_before_parse): Renamed to ... (gld${EMULATION_NAME}_before_parse): This. (gld_${EMULATION_NAME}_list_options): Renamed to ... (gld${EMULATION_NAME}_list_options): This. (gld_${EMULATION_NAME}_set_symbols): Renamed to ... (gld${EMULATION_NAME}_set_symbols): This. (gld_${EMULATION_NAME}_after_parse): Renamed to ... (gld${EMULATION_NAME}_after_parse): This. (gld_${EMULATION_NAME}_after_open): Renamed to ... (gld${EMULATION_NAME}_after_open): This. (gld_${EMULATION_NAME}_before_allocation): Renamed to ... (gld${EMULATION_NAME}_before_allocation): This. (gld_${EMULATION_NAME}_unrecognized_file): Renamed to ... (gld${EMULATION_NAME}_unrecognized_file): This. (gld_${EMULATION_NAME}_recognized_file): Renamed to ... (gld${EMULATION_NAME}_recognized_file): This. (gld_${EMULATION_NAME}_finish): Renamed to ... (gld${EMULATION_NAME}_finish): This. (gld_${EMULATION_NAME}_place_orphan): Renamed to ... (gld${EMULATION_NAME}_place_orphan): This. (gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ... (gld${EMULATION_NAME}_open_dynamic_archive): This. (gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ... (gld${EMULATION_NAME}_find_potential_libraries): This. (gld_${EMULATION_NAME}_get_script): Renamed to ... (gld${EMULATION_NAME}_get_script): This. (LDEMUL_AFTER_PARSE): New. (LDEMUL_AFTER_OPEN): Likewise. (LDEMUL_BEFORE_ALLOCATION): Likewise. (LDEMUL_FINISH=): Likewise. (LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise. (LDEMUL_PLACE_ORPHAN): Likewise. (LDEMUL_SET_SYMBOLS): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_UNRECOGNIZED_FILE): Likewise. (LDEMUL_LIST_OPTIONS): Likewise. (LDEMUL_RECOGNIZED_FILE): Likewise. (LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/pep.em (gld_${EMULATION_NAME}_before_parse): Renamed to ... (gld${EMULATION_NAME}_before_parse): This. (gld_${EMULATION_NAME}_list_options): Renamed to ... (gld${EMULATION_NAME}_list_options): This. (gld_${EMULATION_NAME}_set_symbols): Renamed to ... (gld${EMULATION_NAME}_set_symbols): This. (gld_${EMULATION_NAME}_after_parse): Renamed to ... (gld${EMULATION_NAME}_after_parse): This. (gld_${EMULATION_NAME}_after_open): Renamed to ... (gld${EMULATION_NAME}_after_open): This. (gld_${EMULATION_NAME}_before_allocation): Renamed to ... (gld${EMULATION_NAME}_before_allocation): This. (gld_${EMULATION_NAME}_unrecognized_file): Renamed to ... (gld${EMULATION_NAME}_unrecognized_file): This. (gld_${EMULATION_NAME}_recognized_file): Renamed to ... (gld${EMULATION_NAME}_recognized_file): This. (gld_${EMULATION_NAME}_finish): Renamed to ... (gld${EMULATION_NAME}_finish): This. (gld_${EMULATION_NAME}_place_orphan): Renamed to ... (gld${EMULATION_NAME}_place_orphan): This. (gld_${EMULATION_NAME}_open_dynamic_archive): Renamed to ... (gld${EMULATION_NAME}_open_dynamic_archive): This. (gld_${EMULATION_NAME}_find_potential_libraries): Renamed to ... (gld${EMULATION_NAME}_find_potential_libraries): This. (gld_${EMULATION_NAME}_get_script): Renamed to ... (gld${EMULATION_NAME}_get_script): This. (LDEMUL_AFTER_PARSE): New. (LDEMUL_AFTER_OPEN): Likewise. (LDEMUL_BEFORE_ALLOCATION): Likewise. (LDEMUL_FINISH=): Likewise. (LDEMUL_OPEN_DYNAMIC_ARCHIVE): Likewise. (LDEMUL_PLACE_ORPHAN): Likewise. (LDEMUL_SET_SYMBOLS): Likewise. (LDEMUL_ADD_OPTIONS): Likewise. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_UNRECOGNIZED_FILE): Likewise. (LDEMUL_LIST_OPTIONS): Likewise. (LDEMUL_RECOGNIZED_FILE): Likewise. (LDEMUL_FIND_POTENTIAL_LIBRARIES): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/ticoff.em (gld_${EMULATION_NAME}_list_options): Renamed to ... (gld${EMULATION_NAME}_list_options): This. (gld_${EMULATION_NAME}_before_parse): Renamed to ... (gld_${EMULATION_NAME}_get_script): Renamed to ... (gld${EMULATION_NAME}_get_script): This. (LDEMUL_ADD_OPTIONS): New. (LDEMUL_HANDLE_OPTION): Likewise. (LDEMUL_LIST_OPTIONS): Likewise. (ld_${EMULATION_NAME}_emulation): Removed. Source ${srcdir}/emultempl/emulation.em. * emultempl/vanilla.em (LDEMUL_BEFORE_PARSE): New. (LDEMUL_SET_OUTPUT_ARCH): Likewise. (LDEMUL_GET_SCRIPT): Likewise. (EMULATION_NAME): Likewise. (OUTPUT_FORMAT): Likewise. (ld_vanilla_emulation): Removed. Source ${srcdir}/emultempl/emulation.em.
2022-02-05Tweak assembler invocation for pr28827-1 testAlan Modra1-0/+1
PR 28827 * testsuite/ld-powerpc/pr28827-1.d: Pass -a64 to gas.
2022-02-05PR28827 testcaseAlan Modra3-0/+6833
This testcase triggers a stub sizing error with the patches applied for PR28743 (commit 2f83249c13d8 and c804c6f98d34). PR 28827 * testsuite/ld-powerpc/pr28827-1.s, * testsuite/ld-powerpc/pr28827-1.d: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2022-02-05Enable "size" as a dumpprog in ldAlan Modra1-0/+8
binutils/ * testsuite/lib/binutils-common.exp (run_dump_test): Reference global SIZE and SIZEFLAGS. ld/ * testsuite/config/default.exp: Define SIZE and SIZEFLAGS.
2022-02-04ld: Remove emultempl/armcoff.emH.J. Lu1-293/+0
Remove emultempl/armcoff.em which has been unused after commit 2ac93be706418f3b2aebeb22159a328023faed52 Author: Alan Modra <amodra@gmail.com> Date: Mon Apr 16 20:33:36 2018 +0930 Remove arm-aout and arm-coff support This also removes arm-netbsd (not arm-netbsdelf!), arm-openbsd, and arm-riscix. Those targets weren't on the obsolete list but they are all aout, and it doesn't make all that much sense to remove arm-aout without removing them too. * emultempl/armcoff.em: Removed.
2022-02-03PowerPC64 treatment of absolute symbolsAlan Modra12-0/+290
Supporting -static-pie on PowerPC64 requires the linker to properly treat SHN_ABS symbols for cases like glibc's _nl_current_LC_CTYPE_used absolute symbol. I've been slow to fix the linker on powerpc because there is some chance that this will break some shared libraries or PIEs. bfd/ * elf64-ppc.c (ppc64_elf_check_relocs): Consolidate local sym handling code. Don't count dyn relocs against non-dynamic absolute symbols. (dec_dynrel_count): Adjust to suit. (ppc64_elf_edit_toc): Don't remove entries for absolute symbols when pic. (allocate_got): Don't allocate space for got relocs against non-dynamic absolute syms. (ppc64_elf_layout_multitoc): Likewise. (got_and_plt_relr): Likewise. (ppc64_elf_size_dynamic_sections): Likewise for local got. (got_and_plt_relr_for_local_syms): Likewise. (ppc64_elf_size_stubs): Don't allocate space for relr either. (ppc64_elf_relocate_section): Don't write relocs against non-dynamic absolute symbols. Don't optimise got and toc code sequences loading absolute symbol entries. ld/ * testsuite/ld-powerpc/abs-reloc.s, * testsuite/ld-powerpc/abs-static.d, * testsuite/ld-powerpc/abs-static.r, * testsuite/ld-powerpc/abs-pie.d, * testsuite/ld-powerpc/abs-pie.r, * testsuite/ld-powerpc/abs-shared.d, * testsuite/ld-powerpc/abs-shared.r, * testsuite/ld-powerpc/abs-pie-relr.d, * testsuite/ld-powerpc/abs-pie-relr.r, * testsuite/ld-powerpc/abs-shared-relr.d, * testsuite/ld-powerpc/abs-shared-relr.r: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
2022-02-02Updated French translation for the ld/ and gold/ sub-directoriesNick Clifton2-1651/+1683
2022-01-31elf: Check symbol version without any symbolsH.J. Lu3-0/+24
VER_FLG_WEAK doesn't indicate that all symbol references of the symbol version have STB_WEAK. VER_FLG_WEAK indicates a weak symbol version definition with no symbols associated with it. It is used to verify the existence of a particular implementation without any symbol references to the weak symbol version. PR ld/24718 * testsuite/ld-elf/pr24718-1.d: New file. * testsuite/ld-elf/pr24718-1.s: Likewise. * testsuite/ld-elf/pr24718-1.t: Likewise.
2022-01-31Re: PR28827, assertion building LLVM 9 on powerpc64le-linux-gnuAlan Modra4-0/+73
In trying to find a testcase for PR28827, I managed to hit a linker error in bfd_set_section_contents with a .branch_lt input section being too large for the output .branch_lt. bfd/ PR 28827 * elf64-ppc.c (ppc64_elf_size_stubs): Set section size to maxsize past STUB_SHRINK_ITER before laying out. Remove now unnecessary conditional setting of maxsize at start of loop. ld/ * testsuite/ld-powerpc/pr28827-2.d, * testsuite/ld-powerpc/pr28827-2.lnk, * testsuite/ld-powerpc/pr28827-2.s: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2022-01-28Set __ehdr_start rel_from_abs earlierAlan Modra2-1/+1
This is just a tidy, making the __ehdr_start symbol flag tweaks all in one place. * ldelf.c (ldelf_before_allocation): Don't set rel_from_abs for __ehdr_start. * ldlang.c (lang_symbol_tweaks): Set it here instead.
2022-01-28Update PowerPC64 symtocbase testAlan Modra3-7/+15
Using a symbol other than .TOC. with @tocbase is an extension to the ABI. It is never valid to use a symbol without a definition in the binary, and symbols on these expressions cannot be overridden. Make this explicit by using ".hidden" in the testcase. * testsuite/ld-powerpc/symtocbase-1.s: Align data. Make function entry symbol hidden. * testsuite/ld-powerpc/symtocbase-2.s: Likewise. * testsuite/ld-powerpc/symtocbase.d: Adjust expected output.
2022-01-26ld: Rewrite lang_size_relro_segment_1H.J. Lu4-44/+118
1. Compute the desired PT_GNU_RELRO segment base and find the maximum section alignment of sections starting from the PT_GNU_RELRO segment. 2. Find the first preceding load section. 3. Don't add the 1-page gap between the first preceding load section and the relro segment if the maximum page size >= the maximum section alignment. Align the PT_GNU_RELRO segment first. Subtract the maximum page size if therer is still a 1-page gap. PR ld/28743 PR ld/28819 * ldlang.c (lang_size_relro_segment_1): Rewrite. * testsuite/ld-x86-64/pr28743-1.d: New file. * testsuite/ld-x86-64/pr28743-1.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run pr28743-1.
2022-01-24Update Bulgarian, French, Romaniam and Ukranian translation for some of the ↵Nick Clifton3-3587/+4055
sub-directories
2022-01-23Regenerate Makefile.in files with automake 1.15.1H.J. Lu1-1/+0
Regenerate Makefile.in files with the unmodified automake 1.15.1 to remove runstatedir = @runstatedir@ bfd/ * Makefile.in: Regenerate. binutils/ * Makefile.in: Regenerate. gas/ * Makefile.in: Regenerate. gold/ * Makefile.in: Regenerate. * testsuite/Makefile.in: Likewise. gprof/ * Makefile.in: Regenerate. ld/ * Makefile.in: Regenerate. opcodes/ * Makefile.in: Regenerate.
2022-01-23Regenerate configure files with autoconf 2.69H.J. Lu1-15/+3
Regenerate configure files with the unmodified autoconf 2.69 to remove --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] bfd/ * configure: Regenerate. binutils/ * configure: Regenerate. gas/ * configure: Regenerate. gold/ * configure: Regenerate. gprof/ * configure: Regenerate. ld/ * configure: Regenerate. opcodes/ * configure: Regenerate.
2022-01-22Adjust default page sizes for haiku arm.Alexander von Gluck IV3-3/+9
* configure.tgt (arm-haiku): Fix typo. * emulparams/armelf_haiku.su (MAXPAGESIZE): Use the default value. (COMMONPAGESIZE): Likewise.
2022-01-22Change version number to 2.38.50 and regenerate filesNick Clifton3-121/+140
2022-01-22Add markers for 2.38 branchNick Clifton2-0/+6
2022-01-21Updated Serbian translation for the ld sub-directoryNick Clifton2-1989/+2270
2022-01-21drop old unused stamp-h.in fileMike Frysinger1-1/+0
This was needed by ancient versions of automake, but that hasn't been the case since at least automake-1.5, so punt this from the tree.
2022-01-18lang_size_relro_segment tidyAlan Modra1-16/+4
This function has seen too many minimal change style edits. No functional changes in this patch. * ldlang.c (lang_size_relro_segment): Tidy.
2022-01-18PowerPC64 DT_RELRAlan Modra5-4/+5
PowerPC64 takes a more traditional approach to DT_RELR than x86. Count relative relocs in check_relocs, allocate space for them and output in the usual places but not doing so when enable_dt_relr. DT_RELR is sized in the existing ppc stub relaxation machinery, run via the linker's ldemul_after_allocation hook. DT_RELR is output in the same function that writes ppc stubs, run via ldemul_finish. This support should be considered experimental. bfd/ * elf64-ppc.c (struct ppc_local_dyn_relocs): Renamed from ppc_dyn_relocs. Add rel_count field. Update uses. (struct ppc_dyn_relocs): New. Replace all uses of elf_dyn_relocs. (struct ppc_link_hash_table): Add relr_alloc, relr_count and relr_addr. (ppc64_elf_copy_indirect_symbol): Merge rel_count. (ppc64_elf_check_relocs): Init rel_count for global and local syms. (dec_dynrel_count): Change r_info param to reloc pointer. Update all callers. Handle decrementing rel_count. (allocate_got): Don't allocate space for relative relocs when enable_dt_relr. (allocate_dynrelocs): Likewise. (ppc64_elf_size_dynamic_sections): Likewise. Handle srelrdyn. (ppc_build_one_stub): Don't emit relative relocs on .branch_lt. (compare_relr_address, append_relr_off): New functions. (got_and_plt_relr_for_local_syms, got_and_plt_relr): Likewise. (ppc64_elf_size_stubs): Size .relr.syn. (ppc64_elf_build_stubs): Emit .relr.dyn. (build_global_entry_stubs_and_plt): Don't output relative relocs when enable_dt_relr. (write_plt_relocs_for_local_syms): Likewise. (ppc64_elf_relocate_section): Likewise. binutils/ * testsuite/lib/binutils-common.exp (supports_dt_relr): Add powerpc64. ld/ * emulparams/elf64ppc.sh: Source dt-relr.sh. * testsuite/ld-elf/dt-relr-2b.d: Adjust for powerpc. * testsuite/ld-elf/dt-relr-2c.d: Likewise. * testsuite/ld-elf/dt-relr-2d.d: Likewise. * testsuite/ld-elf/dt-relr-2e.d: Likewise.
2022-01-18tweak __ehdr_start visibility and flags for check_relocsAlan Modra2-10/+38
bfd/ * elf-bfd.h (UNDEFWEAK_NO_DYNAMIC_RELOC): Test linker_def. ld/ * ldelf.c (ldelf_before_allocation): Don't force __ehdr_start local and hidden here.. * ldlang.c (lang_symbol_tweaks): ..do so here instead and set def_regular and linker_def for check_relocs. New function extracted from lang_process.
2022-01-17Update the config.guess and config.sub files from the master repository and ↵Nick Clifton3-1510/+1576
regenerate files.
2022-01-14PR28751 mbind2a / mbind2b regressions on powerpc*-linuxAlan Modra3-4/+12
include/ * bfdlink.h (struct bfd_link_info): Add commonpagesize_is_set. ld/ PR 28751 * emultempl/elf.em (handle_option): Set commonpagesize_is_set. * ldelf.c (ldelf_after_parse): Don't error when only one of -z max-page-size or -z common-page-size is given, correct the other value to make it sane. * testsuite/ld-elf/elf.exp (mbind2a, mbind2b): Do not pass -z max-page-size.
2022-01-13ld: Disable DT_RELR in some -z relro testsH.J. Lu10-10/+10
Disable DT_RELR in the following -z relro tests which don't expect DT_RELR in linker outputs. * testsuite/ld-i386/pr20830.d: Pass $NO_DT_RELR_LDFLAGS to ld. * testsuite/ld-x86-64/pr20830a-now.d: Likewise. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b-now.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a-now.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-01-13elf: Remove the 1-page gap before the RELRO segmentH.J. Lu14-57/+110
The existing RELRO scheme may leave a 1-page gap before the RELRO segment and align the end of the RELRO segment to the page size: [18] .eh_frame PROGBITS 408fa0 008fa0 005e80 00 A 0 0 8 [19] .init_array INIT_ARRAY 410de0 00fde0 000008 08 WA 0 0 8 [20] .fini_array FINI_ARRAY 410de8 00fde8 000008 08 WA 0 0 8 [21] .dynamic DYNAMIC 410df0 00fdf0 000200 10 WA 7 0 8 [22] .got PROGBITS 410ff0 00fff0 000010 08 WA 0 0 8 [23] .got.plt PROGBITS 411000 010000 000048 08 WA 0 0 8 Instead, we can remove the 1-page gap if the maximum page size >= the maximum section alignment: [18] .eh_frame PROGBITS 408fa0 008fa0 005e80 00 A 0 0 8 [19] .init_array INIT_ARRAY 40fde0 00fde0 000008 08 WA 0 0 8 [20] .fini_array FINI_ARRAY 40fde8 00fde8 000008 08 WA 0 0 8 [21] .dynamic DYNAMIC 40fdf0 00fdf0 000200 10 WA 7 0 8 [22] .got PROGBITS 40fff0 00fff0 000010 08 WA 0 0 8 [23] .got.plt PROGBITS 410000 010000 000048 08 WA 0 0 8 Because the end of the RELRO segment is always aligned to the page size and may not be moved, the RELRO segment size may be increased: [ 3] .dynstr STRTAB 000148 000148 000001 00 A 0 0 1 [ 4] .eh_frame PROGBITS 000150 000150 000000 00 A 0 0 8 [ 5] .init_array INIT_ARRAY 200150 000150 000010 08 WA 0 0 1 [ 6] .fini_array FINI_ARRAY 200160 000160 000010 08 WA 0 0 1 [ 7] .jcr PROGBITS 200170 000170 000008 00 WA 0 0 1 [ 8] .data.rel.ro PROGBITS 200180 000180 000020 00 WA 0 0 16 [ 9] .dynamic DYNAMIC 2001a0 0001a0 0001c0 10 WA 3 0 8 [10] .got PROGBITS 200360 000360 0002a8 00 WA 0 0 8 [11] .bss NOBITS 201000 000608 000840 00 WA 0 0 1 vs the old section layout: [ 3] .dynstr STRTAB 000148 000148 000001 00 A 0 0 1 [ 4] .eh_frame PROGBITS 000150 000150 000000 00 A 0 0 8 [ 5] .init_array INIT_ARRAY 200b48 000b48 000010 08 WA 0 0 1 [ 6] .fini_array FINI_ARRAY 200b58 000b58 000010 08 WA 0 0 1 [ 7] .jcr PROGBITS 200b68 000b68 000008 00 WA 0 0 1 [ 8] .data.rel.ro PROGBITS 200b70 000b70 000020 00 WA 0 0 16 [ 9] .dynamic DYNAMIC 200b90 000b90 0001c0 10 WA 3 0 8 [10] .got PROGBITS 200d50 000d50 0002a8 00 WA 0 0 8 [11] .bss NOBITS 201000 000ff8 000840 00 WA 0 0 1 But there is no 1-page gap. PR ld/28743 * ldlang.c (lang_size_relro_segment_1): Remove the 1-page gap before the RELRO segment if the maximum page size >= the maximum section alignment. * testsuite/ld-i386/pr20830.d: Adjusted. * testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise. * testsuite/ld-x86-64/pr14207.d: Likewise. * testsuite/ld-x86-64/pr18176.d: Likewise. * testsuite/ld-x86-64/pr20830a-now.d: Likewise. * testsuite/ld-x86-64/pr20830a.d: Likewise. * testsuite/ld-x86-64/pr20830b-now.d: Likewise. * testsuite/ld-x86-64/pr20830b.d: Likewise. * testsuite/ld-x86-64/pr21038a-now.d: Likewise. * testsuite/ld-x86-64/pr21038a.d: Likewise. * testsuite/ld-x86-64/pr21038b-now.d: Likewise. * testsuite/ld-x86-64/pr21038c-now.d: Likewise. * testsuite/ld-x86-64/pr21038c.d: Likewise.
2022-01-13dt-relr.exp --no-as-neededAlan Modra1-2/+2
Otherwise the very simple test may not be linked with libc.so at all, and thus correctly have no version reference added. Causing failure of the dt-relr-glibc-1b.so test. * testsuite/ld-elf/dt-relr.exp: Link with --no-as-needed.