aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2022-04-07Add support for COFF secidx relocationsMark Harmstone6-0/+171
bfd * coff-i386.c (in_reloc_p): Add R_SECTION. (howto_table): Add R_SECTION. (coff_pe_i386_relocation_section): Add support for R_SECTION. (coff_i386_reloc_type_lookup): Add support for BFD_RELOC_16_SECCIDX. * coff-x86_64.c (in_reloc_p): Add R_SECTION. (howto_table): Add R_SECTION. (coff_pe_amd64_relocation_section): Add support for R_SECTION. (coff_amd64_reloc_type_lookup): Add support for BFD_RELOC_16_SECCIDX. * reloc.c: Add BFD_RELOC_16_SECIDX. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas * config/tc-i386.c (pe_directive_secidx): New function. (md_pseudo_table): Add support for secidx. (x86_cons_fix_new): Likewise. (tc_gen_reloc): Likewise. * expr.c (op_rank): Add O_secidx. * expr.h (operatorT): Likewise. * symbols.c (resolve_symbol_value): Add support for O_secidx. * testsuite/gas/i386/secidx.s: New test source file. * testsuite/gas/i386/secidx.d: New test driver file. * testsuite/gas/i386/i386.exp: Run new test. include * coff/i386.h: Define R_SECTION. * coff/x86_64.h: Likewise. ld * testsuite/ld-pe/secidx1.s: New test source file. * testsuite/ld-pe/secidx2.s: New test source file. * testsuite/ld-pe/secidx.d: New test driver file. * testsuite/ld-pe/secidx_64.d: New test driver file. * testsuite/ld-pe/pe.exp: Add new tests.
2022-03-25libtool.m4: fix the NM="/nm/over/here -B/option/with/path" caseNick Alcock1-7/+13
My previous nm patch handled all cases but one -- if the user set NM in the environment to a path which contained an option, libtool's nm detection tries to run nm against a copy of nm with the options in it: e.g. if NM was set to "nm --blargle", and nm was found in /usr/bin, the test would try to run "/usr/bin/nm --blargle /usr/bin/nm --blargle". This is unlikely to be desirable: in this case we should run "/usr/bin/nm --blargle /usr/bin/nm". Furthermore, as part of this nm has to detect when the passed-in $NM contains a path, and in that case avoid doing a path search itself. This too was thrown off if an option contained something that looked like a path, e.g. NM="nm -B../prev-gcc"; libtool then tries to run "nm -B../prev-gcc nm" which rarely works well (and indeed it looks to see whether that nm exists, finds it doesn't, and wrongly concludes that nm -p or whatever does not work). Fix all of these by clipping all options (defined as everything including and after the first " -") before deciding whether nm contains a path (but not using the clipped value for anything else), and then removing all options from the path-modified nm before looking to see whether that nm existed. NM=my-nm now does a path search and runs e.g. /usr/bin/my-nm -B /usr/bin/my-nm NM=/usr/bin/my-nm now avoids a path search and runs e.g. /usr/bin/my-nm -B /usr/bin/my-nm NM="my-nm -p../wombat" now does a path search and runs e.g. /usr/bin/my-nm -p../wombat -B /usr/bin/my-nm NM="../prev-binutils/new-nm -B../prev-gcc" now avoids a path search: ../prev-binutils/my-nm -B../prev-gcc -B ../prev-binutils/my-nm This seems to be all combinations, including those used by GCC bootstrap (which, before this commit, fails to bootstrap when configured --with-build-config=bootstrap-lto, because the lto plugin is now using --export-symbols-regex, which requires libtool to find a working nm, while also using -B../prev-gcc to point at the lto plugin associated with the GCC just built.) Regenerate all affected configure scripts. * libtool.m4 (LT_PATH_NM): Handle user-specified NM with options, including options containing paths.
2022-03-24x86: mention dropped L1OM/K1OM support in ld/ as wellJan Beulich1-0/+3
This amends e961c696dcb2 ("x86: drop L1OM/K1OM support from ld"). Also remove the marker that I mistakenly added in c085ab00c7b2 ("x86: drop L1OM/K1OM support from gas").
2022-03-24x86: drop L1OM/K1OM support from ldJan Beulich8-120/+12
This was only rudimentary support anyway; none of the sub-architecture specific insns were ever supported.
2022-03-23libctf, ld: diagnose corrupted CTF header cth_strlenNick Alcock7-5/+54
The last section in a CTF dict is the string table, at an offset represented by the cth_stroff header field. Its length is recorded in the next field, cth_strlen, and the two added together are taken as the size of the CTF dict. Upon opening a dict, we check that none of the header offsets exceed this size, and we check when uncompressing a compressed dict that the result of the uncompression is the same length: but CTF dicts need not be compressed, and short ones are not. Uncompressed dicts just use the ctf_size without checking it. This field is thankfully almost unused: it is mostly used when reserializing a dict, which can't be done to dicts read off disk since they're read-only. However, when opening an uncompressed foreign-endian dict we have to copy it out of the mmaped region it is stored in so we can endian- swap it, and we use ctf_size when doing that. When the cth_strlen is corrupt, this can overrun. Fix this by checking the ctf_size in all uncompressed cases, just as we already do in the compressed case. Add a new test. This came to light because various corrupted-CTF raw-asm tests had an incorrect cth_strlen: fix all of them so they produce the expected error again. libctf/ PR libctf/28933 * ctf-open.c (ctf_bufopen_internal): Always check uncompressed CTF dict sizes against the section size in case the cth_strlen is corrupt. ld/ PR libctf/28933 * testsuite/ld-ctf/diag-strlen-invalid.*: New test, derived from diag-cttname-invalid.s. * testsuite/ld-ctf/diag-cttname-invalid.s: Fix incorrect cth_strlen. * testsuite/ld-ctf/diag-cttname-null.s: Likewise. * testsuite/ld-ctf/diag-cuname.s: Likewise. * testsuite/ld-ctf/diag-parlabel.s: Likewise. * testsuite/ld-ctf/diag-parname.s: Likewise.
2022-03-23include, libctf, ld: extend variable section to contain functions tooNick Alcock1-0/+69
The CTF variable section is an optional (usually-not-present) section in the CTF dict which contains name -> type mappings corresponding to data symbols that are present in the linker input but not in the output symbol table: the idea is that programs that use their own symbol- resolution mechanisms can use this section to look up the types of symbols they have found using their own mechanism. Because these removed symbols (mostly static variables, functions, etc) all have names that are unlikely to appear in the ELF symtab and because very few programs have their own symbol-resolution mechanisms, a special linker flag (--ctf-variables) is needed to emit this section. Historically, we emitted only removed data symbols into the variable section. This seemed to make sense at the time, but in hindsight it really doesn't: functions are symbols too, and a C program can look them up just like any other type. So extend the variable section so that it contains all static function symbols too (if it is emitted at all), with types of kind CTF_K_FUNCTION. This is a little fiddly. We relied on compiler assistance for data symbols: the compiler simply emits all data symbols twice, once into the symtypetab as an indexed symbol and once into the variable section. Rather than wait for a suitably adjusted compiler that does the same for function symbols, we can pluck unreported function symbols out of the symtab and add them to the variable section ourselves. While we're at it, we do the same with data symbols: this is redundant right now because the compiler does it, but it costs very little time and lets the compiler drop this kludge and save a little space in .o files. include/ * ctf.h: Mention the new things we can see in the variable section. ld/ * testsuite/ld-ctf/data-func-conflicted-vars.d: New test. libctf/ * ctf-link.c (ctf_link_deduplicating_variables): Duplicate symbols into the variable section too. * ctf-serialize.c (symtypetab_delete_nonstatic_vars): Rename to... (symtypetab_delete_nonstatics): ... this. Check the funchash when pruning redundant variables. (ctf_symtypetab_sect_sizes): Adjust accordingly. * NEWS: Describe this change.
2022-03-23ld, testsuite: improve CTF-availability testNick Alcock1-6/+18
The test for -gctf support in the compiler is used to determine when to run the ld-ctf tests and most of those in libctf. Unfortunately, because it uses check_compiler_available and compile_one_cc, it will fail whenever the compiler emits anything on stderr, even if it actually does support CTF perfectly well. So, instead, ask the compiler to emit assembler output and grep it for references to ".ctf": this is highly unlikely to be present if the compiler does not support CTF. (This will need adjusting when CTF grows support for non-ELF platforms that don't dot-prepend their section names, but right now the linker doesn't link CTF on any such platforms in any case.) With this in place we can do things like run all the libctf tests under leak sanitizers etc even if those spray warnings on simple CTF compilations, rather than being blocked from doing so just when we would most like to. ld/ * testsuite/lib/ld-lib.exp (check_ctf_available): detect CTF even if a CTF-capable compiler emits warnings.
2022-03-20ld:LoongArch: Add test cases to adapt to LoongArch32 and LoongArch64gdb-12-branchpointliuzhensong8-4/+791
ld/testsuite/ld-loongarch-elf * ld-loongarch-elf.exp: Test LoongArch32 and LoongArch64 testcases respectively. * jmp_op.d: Fix bug in test LoongArch32. * disas-jirl-32.d: New test case for LoongArch32. * disas-jirl-32.s: New test case for LoongArch32. * disas-jirl.d: Skip test case LoongArch32. * macro_op_32.d: New test case for LoongArch32. * macro_op_32.s: New test case for LoongArch32. * macro_op.d: Skip test case LoongArch32.
2022-03-20ld: loongarch: Skip unsupport test cases.liuzhensong3-3/+3
ld/testsuite/ld-elf/ * eh5.d Skip loongarch64 target. * pr21884.d Skip loongarch* targets. * pr26936.d Skip loongarch* targets.
2022-03-17x86: drop L1OM/K1OM support from gasJan Beulich7-100/+0
This was only rudimentary support anyway; none of the sub-architecture specific insns were ever supported.
2022-03-16PowerPC64 extended instructions in powerpc_macrosAlan Modra8-8/+8
The extended instructions implemented in powerpc_macros aren't used by the disassembler. That means instructions like "sldi r3,r3,2" appear in disassembly as "rldicr r3,r3,2,61", which is annoying since many other extended instructions are shown. Note that some of the instructions moved out of the macro table to the opcode table won't appear in disassembly, because they are aliases rather than a subset of the underlying raw instruction. If enabled, rotrdi, extrdi, extldi, clrlsldi, and insrdi would replace all occurrences of rotldi, rldicl, rldicr, rldic and rldimi. (Or many occurrences in the case of clrlsldi if n <= b was added to the extract functions.) The patch also fixes a small bug in opcode sanity checking. include/ * opcode/ppc.h (PPC_OPSHIFT_SH6): Define. opcodes/ * ppc-opc.c (insert_erdn, extract_erdn, insert_eldn, extract_eldn), (insert_crdn, extract_crdn, insert_rrdn, extract_rrdn), (insert_sldn, extract_sldn, insert_srdn, extract_srdn), (insert_erdb, extract_erdb, insert_csldn, extract_csldb), (insert_irdb, extract_irdn): New functions. (ELDn, ERDn, ERDn, RRDn, SRDn, ERDb, CSLDn, CSLDb, IRDn, IRDb): Define and add associated powerpc_operands entries. (powerpc_opcodes): Add "rotrdi", "srdi", "extrdi", "clrrdi", "sldi", "extldi", "clrlsldi", "insrdi" and corresponding record (ie. dot suffix) forms. (powerpc_macros): Delete same from here. gas/ * config/tc-ppc.c (insn_validate): Don't modify value passed to operand->insert for PPC_OPERAND_PLUS1 when calculating mask. Handle PPC_OPSHIFT_SH6. * testsuite/gas/ppc/prefix-reloc.d: Update. * testsuite/gas/ppc/simpshft.d: Update. ld/ * testsuite/ld-powerpc/elfv2so.d: Update. * testsuite/ld-powerpc/notoc.d: Update. * testsuite/ld-powerpc/notoc3.d: Update. * testsuite/ld-powerpc/tlsdesc2.d: Update. * testsuite/ld-powerpc/tlsget.d: Update. * testsuite/ld-powerpc/tlsget2.d: Update. * testsuite/ld-powerpc/tlsopt5.d: Update. * testsuite/ld-powerpc/tlsopt6.d: Update.
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