aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
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. (cherry picked from commit 30a954525f4e53a9cd50a1a8a6f201c7cf6595c7)
2021-12-31-Waddress warning in ldelf.cAlan Modra1-1/+0
ldelf.c: In function 'ldelf_after_open': ldelf.c:1049:43: warning: the comparison will always evaluate as 'true' for the address of 'elf_header' will never be NULL [-Waddress] 1049 | && elf_tdata (abfd)->elf_header != NULL | ^~ In file included from ldelf.c:37: ../bfd/elf-bfd.h:1957:21: note: 'elf_header' declared here 1957 | Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */ PR ld/28734 * ldelf.c (ldelf_after_open): Remove useless elf_header test. (cherry picked from commit ced10cb78d01652f9e1bb1d1e465327dfe1debaa)
2021-09-30ld: pru: Fix resource_table output section alignmentDimitar Dimitrov2-4/+8
My commit 261980de18b added alignment for the resource table symbol. But it is wrong. The Linux remoteproc driver loads and interprets the contents of the .resource_table ELF section, not of a table symbol. Without this patch, if the linker happens to output padding for symbol alignment, then the resource table contents as viewed by the kernel loader would "shift" and look corrupted. ld/ChangeLog: * scripttempl/pru.sc (.resource_table): Align the output section, not the first symbol. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu> (cherry picked from commit 5109a7bd9b87bdad530f2ebf97036e6087b4504d)
2021-08-11Revert "ld script expression parsing"Alan Modra4-30/+2
This reverts commit 40726f16a8d7105761e36398054860a923d4efc9.
2021-08-11Revert "ld --defsym"Alan Modra4-11/+24
This reverts commit fb6c220ebdae893d7d955827363010342fa1afa5.
2021-08-11Revert "Re: ld script expression parsing"Alan Modra3-32/+16
This reverts commit 6afc66a7772e69ac3888b496e12d3c8f257c693c.
2021-07-29bfd: Close the file descriptor if there is no archive fdH.J. Lu9-0/+96
Close the file descriptor if there is no archive plugin file descriptor to avoid running out of file descriptors on thin archives with many archive members. bfd/ PR ld/28138 * plugin.c (bfd_plugin_close_file_descriptor): Close the file descriptor there is no archive plugin file descriptor. ld/ PR ld/28138 * testsuite/ld-plugin/lto.exp: Run tmpdir/pr28138 only for native build. PR ld/28138 * testsuite/ld-plugin/lto.exp: Run ld/28138 tests. * testsuite/ld-plugin/pr28138.c: New file. * testsuite/ld-plugin/pr28138-1.c: Likewise. * testsuite/ld-plugin/pr28138-2.c: Likewise. * testsuite/ld-plugin/pr28138-3.c: Likewise. * testsuite/ld-plugin/pr28138-4.c: Likewise. * testsuite/ld-plugin/pr28138-5.c: Likewise. * testsuite/ld-plugin/pr28138-6.c: Likewise. * testsuite/ld-plugin/pr28138-7.c: Likewise. (cherry picked from commit 5a98fb7513b559e20dfebdbaa2a471afda3b4742) (cherry picked from commit 7dc37e1e1209c80e0bab784df6b6bac335e836f2)
2021-07-24Revert: PowerPC: Don't generate unused section symbolsAlan Modra15-23/+159
Blindly following x86 broke linux kernel builds. bfd/ * elf32-ppc.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): Define as true. * elf64-ppc.c (TARGET_KEEP_UNUSED_SECTION_SYMBOLS): Likewise. gas/ * testsuite/gas/ppc/power4.d: Adjust for section sym change. * testsuite/gas/ppc/test1elf32.d: Likewise. * testsuite/gas/ppc/test1elf64.d: Likewise. ld/ * testsuite/ld-powerpc/tlsexe.r: Adjust for section sym change. * testsuite/ld-powerpc/tlsexe32.r: Likewise. * testsuite/ld-powerpc/tlsexe32no.r: Likewise. * testsuite/ld-powerpc/tlsexeno.r: Likewise. * testsuite/ld-powerpc/tlsexenors.r: Likewise. * testsuite/ld-powerpc/tlsexers.r: Likewise. * testsuite/ld-powerpc/tlsexetoc.r: Likewise. * testsuite/ld-powerpc/tlsexetocrs.r: Likewise. * testsuite/ld-powerpc/tlsget.d: Likewise. * testsuite/ld-powerpc/tlsget.wf: Likewise. * testsuite/ld-powerpc/tlsget2.d: Likewise. * testsuite/ld-powerpc/tlsget2.wf: Likewise. * testsuite/ld-powerpc/tlsso.r: Likewise. * testsuite/ld-powerpc/tlsso32.r: Likewise. * testsuite/ld-powerpc/tlstocso.r: Likewise. (cherry picked from commit c09c8b42021180eee9495bd50d8b35e683d3901b)
2021-07-24Re: ld script expression parsingAlan Modra3-16/+32
Commit 40726f16a8d7 broke references to sections within ADDR(), and overlays with weird section names. * ldgram.y (paren_script_name): New rule. (exp): Use it for ALIGNOF, SIZEOF, ADDR, and LOADADDR. Similarly ensure script mode parsing for section name in SEGMENT_START. (overlay_section): Delete unnecessary ldlex_script call. Backup on a lookahead NAME parsed in expression mode. * testsuite/ld-elf/overlay.s: Add more sections. * testsuite/ld-elf/overlay.t: Test '-' in section names. (cherry picked from commit 553dd76c7e49e3e6afb528ff865589da8f6f3e1c)
2021-07-18This is the 2.37 releasebinutils-2_37Nick Clifton3-30/+34
2021-07-08x86-64: Disallow PC reloc against weak undefined symbols in PIEH.J. Lu2-10/+6
Disallow PC relocations against weak undefined symbols in PIE since they can lead to non-zero address at run-time. bfd/ PR ld/21782 * elf64-x86-64.c (elf_x86_64_relocate_section): Disallow PC relocations against weak undefined symbols in PIE. ld/ PR ld/21782 * testsuite/ld-x86-64/pie3.d: Expect linker error. (cherry picked from commit 661b504df9bfb8d7c5d669091720e1dc0079c05e)
2021-07-07elf/riscv: Fix relaxation with aliases [PR28021]Michael Matz5-0/+117
the fix for PR22756 only changed behaviour for hidden aliases, but the same situation exists for non-hidden aliases: sym_hashes[] can contain multiple entries pointing to the same symbol structure leading to relaxation adjustment to be applied twice. Fix this by testing for duplicates for everything that looks like it has a version. PR ld/28021 bfd/ * elfnn-riscv.c (riscv_relax_delete_bytes): Check for any versioning. ld/ * testsuite/ld-riscv-elf/relax-twice.ver: New. * testsuite/ld-riscv-elf/relax-twice-1.s: New. * testsuite/ld-riscv-elf/relax-twice-2.s: New. * testsuite/ld-riscv-elf/ld-riscv-elf.exp (run_relax_twice_test): New, and call it. (cherry picked from commit 235f5ef4a6b8fbdcfaea8b629f7c6a9792a789de)
2021-07-07ld: Check archive only for archive memberH.J. Lu2-1/+10
Since plugin_maybe_claim calls bfd_close on the original input BFD if it isn't an archive member, pass NULL to bfd_plugin_close_file_descriptor to indicate that the BFD isn't an archive member. bfd/ PR ld/18028 * plugin.c (bfd_plugin_close_file_descriptor): Check archive only of abfd != NULL. (try_claim): Pass NULL to bfd_plugin_close_file_descriptor if it isn't an archive member. ld/ PR ld/18028 * plugin.c (plugin_input_file): Add comments for abfd and ibfd. (plugin_object_p): Set input->ibfd to NULL if it isn't an archive member. (cherry picked from commit 7a30ac441a4e776e68399cb916c4731b5192e931)
2021-07-05ld: Cache and reuse the IR archive file descriptorH.J. Lu4-8/+42
Linker plugin_object_p opens the IR archive for each IR archive member. For GCC plugin, plugin_object_p closes the archive file descriptor. But for LLVM plugin, the archive file descriptor remains open. If there are 3000 IR archive members, there are 3000 file descriptors for them. We can run out of file descriptors petty easily. 1. Add archive_plugin_fd and archive_plugin_fd_open_count to bfd so that we can cache and reuse the IR archive file descriptor for all IR archive members in the archive. 2. Add bfd_plugin_close_file_descriptor to properly close the IR archive file descriptor. bfd/ PR ld/28040 * archive.c (_bfd_archive_close_and_cleanup): Close the archive plugin file descriptor if needed. * bfd.c (bfd): Add archive_plugin_fd and archive_plugin_fd_open_count. * opncls.c (_bfd_new_bfd): Initialize to -1. * plugin.c (bfd_plugin_open_input): Cache and reuse the archive plugin file descriptor. (bfd_plugin_close_file_descriptor): New function. (try_claim): Call bfd_plugin_close_file_descriptor. * plugin.h (bfd_plugin_close_file_descriptor): New. * bfd-in2.h: Regenerated. ld/ PR ld/28040 * plugin.c (plugin_input_file): Add ibfd. (release_plugin_file_descriptor): New function. (release_input_file): Call release_plugin_file_descriptor to close input->fd. (plugin_object_p): Call release_plugin_file_descriptor to close input->fd. Also call release_plugin_file_descriptor if not claimed. * testsuite/config/default.exp (RANLIB): New. * testsuite/ld-plugin/lto.exp: Run ranlib test. (cherry picked from commit 918172470430ea6fa082c941e6789add88331197)
2021-07-05Updated translationsNick Clifton4-4363/+4509
2021-07-03Update version number and regenerate filesNick Clifton3-1400/+1472
2021-07-03Add markers for 2.37 branchNick Clifton2-0/+6
2021-06-22RISC-V: Clarify the addends of pc-relative access.Nelson Chu9-0/+103
The original discussion was here, https://github.com/riscv/riscv-elf-psabi-doc/issues/184 After discussing with Kito Cheng, I think the addends of %pcrel_hi and %pcrel_lo are both allowed in GNU toolchain. However, both of the them mean the offset of symbols, rather than the pc address. But the addends of %got_pcrel_hi and it's %pcrel_lo do not look reasonable. I believe gcc won't generate the got patterns with addends, so linker should report dangerous relocation errors, in case the assembly code use them. Another issue was here, https://sourceware.org/pipermail/binutils/2021-June/116983.html At the beginnig, I suppose %pcrel_hi and %pcrel_lo are valid only when they are in the same input section. But Jim Wilson points out that gcc may generate %hi and %lo in the different input sections, when -freorder-blocks-and-partition option is used. So that a memory references for a loop may have the %hi outside the loop, but the %lo remain in the loop. However, it is hard to create the testcases, to see if %pcrel_hi and %pcrel_lo have the same behavior. Unfortunately, I notice that the current pcrel resolver cannot work for the above case. For now we build a hash table for pcrel at the start of riscv_elf_relocate_section, and then free the hash at the end. But riscv_elf_relocate_section only handles an input section at a time, so that means we can only resolve the %pcrel_hi and %pcrel_lo which are in the same input section. Otherwise, like the above case, we will report "%pcrel_lo missing matching %pcrel_hi" for them. I have no plan to improve this in the short-term, so maybe we can wait until someone meets the problem before we deal with it. bfd/ * elfnn-riscv.c (riscv_pcrel_hi_reloc): Added field to store the original relocation type, in case the type is converted to R_RISCV_HI20. (riscv_pcrel_lo_reloc): Removed unused name field. (riscv_pcrel_relocs): Added comments. (riscv_zero_pcrel_hi_reloc): Removed unused input_bfd. (riscv_record_pcrel_hi_reloc): Updated. (riscv_record_pcrel_lo_reloc): Likewise. (riscv_resolve_pcrel_lo_relocs): Likewise. Check the original type of auipc, to make sure the %pcrel_lo without any addends. Otherwise, report dangerous relocation error. (riscv_elf_relocate_section): Updated above functions are changed. For R_RISCV_GOT_HI20, report dangerous relocation error when addend isn't zero. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.d: New testcase. * testsuite/ld-riscv-elf/pcrel-lo-addend-3a.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.d: New testcase. Should report error since the %pcrel_lo with addend refers to %got_pcrel_hi. * testsuite/ld-riscv-elf/pcrel-lo-addend-3b.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.d: New testcase. Should report error since the %got_pcrel_hi with addend. * testsuite/ld-riscv-elf/pcrel-lo-addend-3c.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-3.ld: Likewise.
2021-06-19x86: Count PLT for GOTOFF relocation against IFUNC symbolH.J. Lu6-0/+67
Since GOTOFF relocations against IFUNC symbols must go through PLT, set PLT reference count to 1 for GOTOFF relocation. bfd/ PR ld/27998 * elfxx-x86.c (elf_x86_allocate_dynrelocs): Count PLT for GOTOFF relocation against IFUNC symbols. (_bfd_x86_elf_adjust_dynamic_symbol): Likewise. ld/ PR ld/27998 * testsuite/ld-i386/i386.exp: Run PR ld/27998 tests. * testsuite/ld-i386/pr27998a.d: New file. * testsuite/ld-i386/pr27998a.s: Likewise. * testsuite/ld-i386/pr27998b.d: Likewise. * testsuite/ld-i386/pr27998b.s: Likewise.
2021-06-19elf: Correct DT_TEXTREL warning in PDEH.J. Lu5-0/+40
Change ld: warning: creating DT_TEXTREL in a PIE to ld: warning: creating DT_TEXTREL in a PDE on PDE. bfd/ * elflink.c (bfd_elf_final_link): Correct DT_TEXTREL warning in PDE. ld/ * testsuite/ld-x86-64/textrel-1.err: New file. * testsuite/ld-x86-64/textrel-1a.s: Likewise. * testsuite/ld-x86-64/textrel-1b.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run textrel-1 tests.
2021-06-19elf: Update GNU_PROPERTY_UINT32_[AND|OR]_XXX testsH.J. Lu9-8/+79
1. Skip am33_2.0-*-* hppa*-*-hpux* mn10300-*-* since assembly source file for the HPPA assembler is renamed and modifed by sed. mn10300 has RELA relocations in .note.gnu.property section which elf_parse_notes doesn't support. 2. Pass --generate-missing-build-notes=no to assembler. 3. Allow other note sections for xtensa. * testsuite/ld-elf/property-and-1.d: Skip am33_2.0, hppa-hpux and mn10300. Pass --generate-missing-build-notes=no to assembler. Allow other note sections for xtensa. * testsuite/ld-elf/property-and-2.d: Likewise. * testsuite/ld-elf/property-and-3.d: Likewise. * testsuite/ld-elf/property-and-4.d: Likewise. * testsuite/ld-elf/property-or-1.d: Likewise. * testsuite/ld-elf/property-or-2.d: Likewise. * testsuite/ld-elf/property-or-3.d: Likewise. * testsuite/ld-elf/property-or-4.d: Likewise.
2021-06-18ld.texi: Move -z unique-symbol after -z undefs.H.J. Lu2-6/+10
* ld.texi: Move -z unique-symbol after -z undefs.
2021-06-18elf: Add GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXXH.J. Lu17-0/+218
Implement GNU_PROPERTY_UINT32_AND_XXX/GNU_PROPERTY_UINT32_OR_XXX: https://sourceware.org/pipermail/gnu-gabi/2021q1/000467.html 1. GNU_PROPERTY_UINT32_AND_LO..GNU_PROPERTY_UINT32_AND_HI #define GNU_PROPERTY_UINT32_AND_LO 0xb0000000 #define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff A bit in the output pr_data field is set only if it is set in all relocatable input pr_data fields. If all bits in the the output pr_data field are zero, this property should be removed from output. If the bit is 1, all input relocatables have the feature. If the bit is 0 or the property is missing, the info is unknown. 2. GNU_PROPERTY_UINT32_OR_LO..GNU_PROPERTY_UINT32_OR_HI #define GNU_PROPERTY_UINT32_OR_LO 0xb0008000 #define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff A bit in the output pr_data field is set if it is set in any relocatable input pr_data fields. If all bits in the the output pr_data field are zero, this property should be removed from output. If the bit is 1, some input relocatables have the feature. If the bit is 0 or the property is missing, the info is unknown. bfd/ * elf-properties.c (_bfd_elf_parse_gnu_properties): Handle GNU_PROPERTY_UINT32_AND_LO, GNU_PROPERTY_UINT32_AND_HI, GNU_PROPERTY_UINT32_OR_LO and GNU_PROPERTY_UINT32_OR_HI. (elf_merge_gnu_properties): Likewise. binutils/ * readelf.c (print_gnu_property_note): Handle GNU_PROPERTY_UINT32_AND_LO, GNU_PROPERTY_UINT32_AND_HI, GNU_PROPERTY_UINT32_OR_LO and GNU_PROPERTY_UINT32_OR_HI. include/ * elf/common.h (GNU_PROPERTY_UINT32_AND_LO): New. (GNU_PROPERTY_UINT32_AND_HI): Likewise. (GNU_PROPERTY_UINT32_OR_LO): Likewise. (GNU_PROPERTY_UINT32_OR_HI): Likewise. ld/ * testsuite/ld-elf/property-and-1.d: New file. * testsuite/ld-elf/property-and-1.s: Likewise. * testsuite/ld-elf/property-and-2.d: Likewise. * testsuite/ld-elf/property-and-2.s: Likewise. * testsuite/ld-elf/property-and-3.d: Likewise. * testsuite/ld-elf/property-and-3.s: Likewise. * testsuite/ld-elf/property-and-4.d: Likewise. * testsuite/ld-elf/property-and-empty.s: Likewise. * testsuite/ld-elf/property-or-1.d: Likewise. * testsuite/ld-elf/property-or-1.s: Likewise. * testsuite/ld-elf/property-or-2.d: Likewise. * testsuite/ld-elf/property-or-2.s: Likewise. * testsuite/ld-elf/property-or-3.d: Likewise. * testsuite/ld-elf/property-or-3.s: Likewise. * testsuite/ld-elf/property-or-4.d: Likewise. * testsuite/ld-elf/property-or-empty.s: Likewise.
2021-06-17x86-64: Use $NOPIE_LDFLAGS/$NOPIE_CFLAGS on protected-func-1H.J. Lu2-1/+8
PR ld/27973 * testsuite/ld-x86-64/x86-64.exp: Pass $NOPIE_LDFLAGS and $NOPIE_CFLAGS to protected-func-1 without PIE.
2021-06-17x86-64: Test protected function pointersH.J. Lu5-0/+122
On x86-64, function pointers in executable for external funtions may be resolved to their PLT entries in executable. If it happens, function pointers of protected funtions in shared libraries must be resolved to the PLT entries in executable, not addresses of protected funtions in shared libraries. PR ld/27973 * testsuite/ld-x86-64/x86-64.exp: Run protected function tests. * testsuite/ld-x86-64/protected-func-1.h: New file. * testsuite/ld-x86-64/protected-func-1a.s: Likewise. * testsuite/ld-x86-64/protected-func-1b.c: Likewise.
2021-06-17ld: Add ChangeLog entry for -no-pieFangrui Song1-0/+7
2021-06-17ld: Add -no-pieFangrui Song3-0/+11
gold has had this option for many years. Not having this option caused some confusion to users. The help message clarifies the default state. ld/ * ldlex.h (enum option_values): Add OPTION_NO_PIE. * lexsup.c (struct ld_options): Add -no-pie. (parse_args): Handle -no-pie. * ld.texi: Document -no-pie.
2021-06-15readelf: report DF_1_PIE as "Position-Independent Executable"Alan Modra2-1/+5
I finally found time to teach readelf to identify PIEs in the file header display and program header display. So in place of "DYN (Shared object file)" which isn't completely true, show "DYN (Position-Independent Executable file)". It requires a little bit of untangling code in readelf due to process_program_headers setting up dynamic_addr and dynamic_size, needed to scan .dynamic for the DT_FLAGS_1 entry, and process_program_headers itself wanting to display the file type in some cases. At first I modified process_program_header using a "probe" parameter similar to get_section_headers in order to inhibit output, but decided it was cleaner to separate out locate_dynamic_sections. binutils/ * readelf.c (locate_dynamic_section, is_pie): New functions. (get_file_type): Replace e_type parameter with filedata. Call is_pie for ET_DYN. Update all callers. (process_program_headers): Use local variables dynamic_addr and dynamic_size, updating filedata on exit from function. Set dynamic_size of 1 to indicate no dynamic section or segment. Update tests of dynamic_size throughout. * testsuite/binutils-all/x86-64/pr27708.dump: Update expected output. ld/ * testsuite/ld-pie/vaddr-0.d: Update expected output. gdb/ * testsuite/lib/gdb.exp (exec_is_pie): Match new PIE readelf output.
2021-06-11PR27952, Disallow ET_DYN DF_1_PIE linker inputAlan Modra2-1/+8
This patch adds a new elf_tdata flag, is_pie, set during the linker's open_input_bfds processing. The flag is then used to reject attempts to link a PIE as if it were a shared library. bfd/ PR 27952 * elf-bfd.h (struct elf_obj_tdata): Add is_pie. * elflink.c (elf_link_add_object_symbols): Set is_pie. ld/ PR 27952 * ldelf.c (ldelf_after_open): Error on input PIEs too.
2021-06-09Fix the creation of archives for Sparc Solaris2 targets by eliminating the ↵Nick Clifton2-7/+18
support for generic SPARC ELF files. PR 27666 bfd * config.bfd: Do not add the sparc_elf32_vec or sparc_elf64_vec vectors to Sparc Solaris2 targets. ld * testsuite/ld-sparc/sparc.exp: Do not run the sparctests or sparc64tests for Solaris2 targets.
2021-06-03PR2589, ld vs. ld.soAlan Modra2-4/+16
PR 2589 * ld.texi (link-time runtime library search path): Mention plugin library path. Correct order of search.
2021-05-31RISC-V: PR27566, Do not relax when data segment phase is exp_seg_relro_adjust.Nelson Chu7-0/+82
2021-05-31 Nelson Chu <nelson.chu@sifive.com> Lifang Xia <lifang_xia@c-sky.com> The data segment phase exp_seg_relro_adjust means we are still adjusting the relro segments, so we will get the symbol values which havn't consider the relro. It is dangerous and we shouldn't do the relaxations at this stage. Otherwise, we may get the truncated fails when the relax range crossing the data segment. One of the solution is that, we use a pointer to monitor the data segment phase while relaxing, to know whether the relro has been handled or not. Once we check the phase is exp_seg_relro_adjust, we should skip this round of relaxations, since the incorrect symbol values will affect the correctness of relaxations. I think we probably need to record more information about data segment or alignments in the future, to make sure it is safe to doing relaxations. For the two new testcases, relro-relax-lui and relro-relax-pcrel, we get the following truncated errors when using toolchains, which enable relro: (.text+0x0): relocation truncated to fit: R_RISCV_GPREL_I against symbol `SymbolRodata' defined in .rodata section in test1.o After applying this patch, the truncated errors should be resolved. However, only linux toolchains support -z relro, so we only test these two testcases when supporting shared library. bfd/ PR 27566 * elfnn-riscv.c (struct riscv_elf_link_hash_table): New integer pointer to monitor the data segment phase. (bfd_elfNN_riscv_set_data_segment_info): New function called by after_allocation, to set the data_segment_phase from expld.dataseg. (_bfd_riscv_relax_section): Don't relax when data_segment_phase is exp_seg_relro_adjust (0x4). * elfxx-riscv.h (bfd_elf32_riscv_set_data_segment_info): New extern. (bfd_elf64_riscv_set_data_segment_info): Likewise. ld/ PR 27566 * emultempl/riscvelf.em (after_allocation): Call riscv_set_data_segment_info to set data segment phase before relaxing. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/relro-relax-lui.d: New testcase. * testsuite/ld-riscv-elf/relro-relax-lui.s: Likewise. * testsuite/ld-riscv-elf/relro-relax-pcrel.d: Likewise. * testsuite/ld-riscv-elf/relro-relax-pcrel.s: Likewise.
2021-05-28x86: Restore PC16 relocation overflow checkH.J. Lu3-0/+8
The x86-64 psABI has --- A program or object file using R_X86_64_8, R_X86_64_16, R_X86_64_PC16 or R_X86_64_PC8 relocations is not conformant to this ABI, these relocations are only added for documentation purposes. --- Since x86 PC16 relocations have been used for 16-bit programs in an ELF32 or ELF64 container, PC16 relocation should wrap-around in 16-bit address space. Revert commit a7664973b24a242cd9ea17deb5eaf503065fc0bd Author: Jan Beulich <jbeulich@suse.com> Date: Mon Apr 26 10:41:35 2021 +0200 x86: correct overflow checking for 16-bit PC-relative relocs and xfail the related tests. Also revert commit 50c95a739c91ae70cf8481936611aa1f5397a384 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed May 26 12:13:13 2021 -0700 x86: Propery check PC16 reloc overflow in 16-bit mode instructions while keeping PR ld/27905 tests for PC16 relocation in 16-bit programs. bfd/ PR ld/27905 * elf32-i386.c: Don't include "libiberty.h". (elf_howto_table): Revert commits a7664973b24 and 50c95a739c9. (elf_i386_rtype_to_howto): Revert commit 50c95a739c9. (elf_i386_info_to_howto_rel): Likewise. (elf_i386_tls_transition): Likewise. (elf_i386_relocate_section): Likewise. * elf64-x86-64.c (x86_64_elf_howto_table): Revert commits a7664973b24 and 50c95a739c9. (elf_x86_64_rtype_to_howto): Revert commit 50c95a739c9. * elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Likewise. * elfxx-x86.h (elf_x86_obj_tdata): Likewise. (elf_x86_has_code16): Likewise. binutils/ PR ld/27905 * readelf.c (decode_x86_feature_2): Revert commit 50c95a739c9. gas/ PR ld/27905 * config/tc-i386.c (set_code_flag): Revert commit 50c95a739c9. (set_16bit_gcc_code_flag): Likewise. (x86_cleanup): Likewise. * testsuite/gas/i386/code16-2.d: Updated. * testsuite/gas/i386/x86-64-code16-2.d: Likewise. include/ PR ld/27905 * elf/common.h (GNU_PROPERTY_X86_FEATURE_2_CODE16): Removed. ld/ PR ld/27905 * testsuite/ld-i386/pcrel16-2.d: xfail. * testsuite/ld-x86-64/pcrel16-2.d: Likewise.
2021-05-26x86: Propery check PC16 reloc overflow in 16-bit mode instructionsH.J. Lu7-0/+64
commit a7664973b24a242cd9ea17deb5eaf503065fc0bd Author: Jan Beulich <jbeulich@suse.com> Date: Mon Apr 26 10:41:35 2021 +0200 x86: correct overflow checking for 16-bit PC-relative relocs caused linker failure when building 16-bit program in a 32-bit ELF container. Update GNU_PROPERTY_X86_FEATURE_2_USED with #define GNU_PROPERTY_X86_FEATURE_2_CODE16 (1U << 12) to indicate that 16-bit mode instructions are used in the input object: https://groups.google.com/g/x86-64-abi/c/UvvXWeHIGMA to indicate that 16-bit mode instructions are used in the object to allow linker to properly perform relocation overflow check for 16-bit PC-relative relocations in 16-bit mode instructions. 1. Update x86 assembler to always generate the GNU property note with GNU_PROPERTY_X86_FEATURE_2_CODE16 for .code16 in ELF object. 2. Update i386 and x86-64 linkers to use 16-bit PC16 relocations if input object is marked with GNU_PROPERTY_X86_FEATURE_2_CODE16. bfd/ PR ld/27905 * elf32-i386.c: Include "libiberty.h". (elf_howto_table): Add 16-bit R_386_PC16 entry. (elf_i386_rtype_to_howto): Add a BFD argument. Use 16-bit R_386_PC16 if input has 16-bit mode instructions. (elf_i386_info_to_howto_rel): Update elf_i386_rtype_to_howto call. (elf_i386_tls_transition): Likewise. (elf_i386_relocate_section): Likewise. * elf64-x86-64.c (x86_64_elf_howto_table): Add 16-bit R_X86_64_PC16 entry. (elf_x86_64_rtype_to_howto): Use 16-bit R_X86_64_PC16 if input has 16-bit mode instructions. * elfxx-x86.c (_bfd_x86_elf_parse_gnu_properties): Set elf_x86_has_code16 if relocatable input is marked with GNU_PROPERTY_X86_FEATURE_2_CODE16. * elfxx-x86.h (elf_x86_obj_tdata): Add has_code16. (elf_x86_has_code16): New. binutils/ PR ld/27905 * readelf.c (decode_x86_feature_2): Support GNU_PROPERTY_X86_FEATURE_2_CODE16. gas/ PR ld/27905 * config/tc-i386.c (set_code_flag): Update x86_feature_2_used with GNU_PROPERTY_X86_FEATURE_2_CODE16 for .code16 in ELF object. (set_16bit_gcc_code_flag): Likewise. (x86_cleanup): Always generate the GNU property note if x86_feature_2_used isn't 0. * testsuite/gas/i386/code16-2.d: New file. * testsuite/gas/i386/code16-2.s: Likewise. * testsuite/gas/i386/x86-64-code16-2.d: Likewise. * testsuite/gas/i386/i386.exp: Run code16-2 and x86-64-code16-2. include/ PR ld/27905 * elf/common.h (GNU_PROPERTY_X86_FEATURE_2_CODE16): New. ld/ PR ld/27905 * testsuite/ld-i386/code16.d: New file. * testsuite/ld-i386/code16.t: Likewise. * testsuite/ld-x86-64/code16.d: Likewise. * testsuite/ld-x86-64/code16.t: Likewise. * testsuite/ld-i386/i386.exp: Run code16. * testsuite/ld-x86-64/x86-64.exp: Likewise.
2021-05-26x86-64: Add ilp32-12 to check R_X86_64_32 for x32H.J. Lu4-0/+19
* testsuite/ld-x86-64/ilp32-12.d: New file. * testsuite/ld-x86-64/ilp32-12.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run ilp32-12.
2021-05-14RISC-V: Check the overflow for %pcrel_lo addend more strictly.Nelson Chu7-7/+38
The %pcrel_lo addend may causes the overflow, and need more than one %pcrel_hi values. But there may be only one auipc, shared by those %pcrel_lo with addends. However, the existing check method in the riscv_resolve_pcrel_lo_relocs, may not be able to work for some special/corner cases. Consider the testcases pcrel-lo-addend-2b. Before applying this patch, I can compile it successfully. But in fact the addend cause the value of %pcrel_hi to be different. This patch try to check the value of %pcrel_hi directly, to make sure it won't be changed. Otherwise, linker will report the following errors, (.text+0xa): dangerous relocation: %pcrel_lo overflow with an addend, the value of %pcrel_hi is 0x1000 without any addend, but may be 0x2000 after adding the %pcrel_lo addend The toolchain regressions, rv64gc-linux/rv64gc-elf/rv32gc-linux/rv32i-elf, pass expectedly and looks fine. bfd/ * elfnn-riscv.c (riscv_resolve_pcrel_lo_relocs): Check the values of %pcrel_hi, before and after adding the addend. Make sure the value won't be changed, otherwise, report dangerous error. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated. * testsuite/ld-riscv-elf/pcrel-lo-addend-2a.d: Renamed from pcrel-lo-addend-2. * testsuite/ld-riscv-elf/pcrel-lo-addend-2a.s: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-2b.d: New testcase. * testsuite/ld-riscv-elf/pcrel-lo-addend-2b.s: Likewise.
2021-05-13ld: Add -Bno-symbolicFangrui Song6-0/+30
PR 27834 * ldlex.h (enum option_values): Add OPTION_NO_SYMBOLIC. * lexsup.c (ld_options): Add -Bno-symbolic. (parse_args): Handle -Bno-symbolic. * ld.texi: Document -Bno-symbolic. * NEWS: Mention -Bno-symbolic. * testsuite/ld-elf/shared.exp: Add a test.
2021-05-12arm: fix fallout from recent thumb2 detection patchRichard Earnshaw2-1/+6
The recent change to correct the detection of thumb2 object files resulted in a ld test for veneering starting to fail. The problem was the test itself, which was incorrectly expecting thumb1 type far-call veneers instead of the thumb2 flavour. We already have a dump file of the expected form, so the fix is to change the expected output accordingly. ld/ * testsuite/ld-arm/arm-elf.exp (farcall test for v8-m.mainline): Correct expected output.
2021-05-11x86-64/ELF: Fix "clear src_mask for all reloc types" test caseRoland McGrath2-1/+6
ld/ * testsuite/ld-x86-64/rela.d: Fix regexp not to presume a specific address layout, so it works for e.g. --target=x86-64-elf.
2021-05-11Prevent libdel.dll.a from being installed on Windows based systems.Nick Clifton3-0/+9
PR 27113 * Makefile.am (install-data-local): Also delete libdep.dll.a if it is present. * Makefile.in: Regenerate.
2021-05-10Enable linker garbage collection for the PRU target.Dimitar Dimitrov8-7/+17
bfd * elf32-pru.c (elf_backend_can_gc_sections): Define as 1. ld * testsuite/ld-elf/group8a.d: Remove pru from XFAIL list. * testsuite/ld-elf/group8b.d: Ditto. * testsuite/ld-elf/group9a.d: Ditto. * testsuite/ld-elf/group9b.d: Ditto. * testsuite/ld-elf/pr12851.d: Ditto. * testsuite/ld-elf/pr22677.d: Ditto. * testsuite/lib/ld-lib.exp (check_gc_sections_available): Remove pru from list.
2021-05-10PRU: Add alignment for resource table, and allow sizes of memory regions to ↵Dimitar Dimitrov2-2/+14
be set from the command line. ld * scripttempl/pru.sc (.resource_table): Add ALIGN directive. Use symbols for memory sizes.
2021-05-08support generating multi-html pages in parallelMike Frysinger3-7/+24
Use the pattern from other projects where we generate the html pages in a dir named the same as the project. So now we have: gas/doc/gas.html - single html page gas/doc/gas/ - multiple html pages This works for projects that have a doc/ subdir already, but gprof & ld require a little tweaking since they generate their docs in their respective toplevels.
2021-05-08generate single html manual page by defaultMike Frysinger3-2/+7
This better matches other GNU projects like autoconf/automake where the html manual is the single page form. We'll support the multi-page form in a follow up change.
2021-05-07x86-64/ELF: clear src_mask for all reloc typesJan Beulich3-0/+16
x86-64 uses rela relocations. The comment next to the field's declaration says "Non-zero values for ELF USE_RELA targets should be viewed with suspicion ..." And indeed the fields being non-zero causes section contents to be accumulated into the final relocated values in addition to the relocations' addends, which is contrary to the ELF spec.
2021-05-07When computing section link order for a relocateable link, ignore section sizes.Nick Clifton2-6/+14
* ldelfgen.c (compare_link_order): Ignore section size when performing a relocateable link.
2021-05-07multiple definition warnings from script symbolsAlan Modra3-4/+14
In commit 89753bbf81 I enabled a warning for scripts redefining symbols. The idea was to not warn for symbols defined by shared libraries (the h->u.def.section->output_section != NULL test), but the test failed to take into account absolute symbols. Absolute symbols defined in shared libraries are currently indistinguishable from absolute symbols defined in relocatable objects, at least when only looking at struct bfd_link_hash_entry. So, don't warn for any absolute symbols. * ldexp.c (update_definedness): Don't return false for absolute symbols. * ldmain.c (multiple_definition): Print "warning: " in message when not a hard error.
2021-05-07Re: elf: Always append ".COUNT" to local symbolsAlan Modra3-4/+7
Fixes XPASSes on frv-linux. * testsuite/ld-elf/pr27825-1.d: Correct xfail. * testsuite/ld-elf/pr27825-2.d: Likewise.
2021-05-06or1k: Support large plt_relocs when generating plt entriesStafford Horne7-0/+122
The current PLT generation code will generate invalid code when the PLT relocation offset exceeds 64k. This fixes the issue by detecting large plt_reloc offsets and generare code sequences to create larger plt relocations. The "large" plt code needs 2 extra instructions to create 32-bit offsets. bfd/ChangeLog: PR 27746 * elf32-or1k.c (PLT_ENTRY_SIZE_LARGE, PLT_MAX_INSN_COUNT, OR1K_ADD, OR1K_ORI): New macros to help with plt creation. (elf_or1k_link_hash_table): New field plt_count. (elf_or1k_link_hash_entry): New field plt_index. (elf_or1k_plt_entry_size): New function. (or1k_write_plt_entry): Update to support variable size PLTs. (or1k_elf_finish_dynamic_sections): Use new or1k_write_plt_entry API. (or1k_elf_finish_dynamic_symbol): Update to write large PLTs when needed. (allocate_dynrelocs): Use elf_or1k_plt_entry_size to account for PLT size. ld/ChangeLog: PR 27746 testsuite/ld-or1k/or1k.exp (or1kplttests): Add tests for linking along with gotha() relocations. testsuite/ld-or1k/gotha1.dd: New file. testsuite/ld-or1k/gotha1.s: New file. testsuite/ld-or1k/gotha2.dd: New file. testsuite/ld-or1k/gotha2.s: New file testsuite/ld-or1k/pltlib.s (x): Define size to avoid link failure.
2021-05-06libctf, ld: fix test results for upstream GCCNick Alcock13-19/+81
The tests currently in binutils are aimed at the original GCC-based implementation of CTF, which emitted CTF directly from GCC's internal representation. The approach now under review emits CTF from DWARF, with an eye to eventually doing this for all non-DWARF debuginfo-like formats GCC supports. It also uses a different flag to enable CTF emission (-gctf rather than -gt). Adjust the testsuite accordingly. Given that the ld testsuite results are dependent on type ordering, which we do not guarantee at all, it's amazing how little changes. We see a few type ordering differences, slices change because the old GCC was buggy (slices were emitted "backwards", from the wrong end of the machine word) and its expected results were wrong, and GCC now emits the underlying integral type for enumerated types, though CTF has no way to record this yet (coming in v4). GCC also now emits even hidden symbols into the symtab (and thus symtypetab), so one symtypetab test changes its expected results slightly to compensate. Also add tests for the CTF_K_UNKNOWN nonrepresentable type: this couldn't be done before now since the only GCC that emits CTF_K_UNKNOWN for nonrepresentable types is the new one. ld/ChangeLog 2021-05-06 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/ctf.exp: Use -gctf, not -gt. * testsuite/lib/ld-lib.exp: Likewise. * testsuite/ld-ctf/nonrepresentable-1.c: New test for nonrepresentable types. * testsuite/ld-ctf/nonrepresentable-2.c: Likewise. * testsuite/ld-ctf/nonrepresentable.d: Likewise. * testsuite/ld-ctf/array.d: Larger type section. * testsuite/ld-ctf/data-func-conflicted.d: Likewise. * testsuite/ld-ctf/enums.d: Likewise. * testsuite/ld-ctf/conflicting-enums.d: Don't compare types. * testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Changed type order. * testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise. * testsuite/ld-ctf/slice.d: Adjust for improved slice emission. libctf/ChangeLog 2021-05-06 Nick Alcock <nick.alcock@oracle.com> * testsuite/lib/ctf-lib.exp: Use -gctf, not -gt. * testsuite/libctf-regression/nonstatic-var-section-ld-r.lk: Hidden symbols now get into the symtypetab anyway.