summaryrefslogtreecommitdiff
path: root/ld
Commit message (Collapse)AuthorAgeFilesLines
* x86: Skip __[start|stop]_SECNAME for --gc-sections -z start-stop-gcH.J. Lu2021-12-0224-0/+348
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't convert memory load to immediate load on __start_SECNAME and __stop_SECNAME for --gc-sections -z start-stop-gc if all SECNAME sections been garbage collected. bfd/ PR ld/27491 * elf32-i386.c (elf_i386_convert_load_reloc): Skip __start_SECNAME and __stop_SECNAME for --gc-sections -z start-stop-gc if the input section been garbage collected. * elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise. * elfxx-x86.h (elf_x86_start_stop_gc_p): New function. ld/ PR ld/27491 * testsuite/ld-i386/i386.exp: Run PR ld/27491 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr27491-1.s: New file. * testsuite/ld-i386/pr27491-1a.d: Likewise. * testsuite/ld-i386/pr27491-1b.d: Likewise. * testsuite/ld-i386/pr27491-1c.d: Likewise. * testsuite/ld-i386/pr27491-2.d: Likewise. * testsuite/ld-i386/pr27491-2.s: Likewise. * testsuite/ld-i386/pr27491-3.d: Likewise. * testsuite/ld-i386/pr27491-3.s: Likewise. * testsuite/ld-i386/pr27491-4.d: Likewise. * testsuite/ld-i386/pr27491-4a.s: Likewise. * testsuite/ld-i386/pr27491-4b.s: Likewise. * testsuite/ld-x86-64/pr27491-1.s: Likewise. * testsuite/ld-x86-64/pr27491-1a.d: Likewise. * testsuite/ld-x86-64/pr27491-1b.d: Likewise. * testsuite/ld-x86-64/pr27491-1c.d: Likewise. * testsuite/ld-x86-64/pr27491-2.d: Likewise. * testsuite/ld-x86-64/pr27491-2.s: Likewise. * testsuite/ld-x86-64/pr27491-3.d: Likewise. * testsuite/ld-x86-64/pr27491-3.s: Likewise. * testsuite/ld-x86-64/pr27491-4.d: Likewise. * testsuite/ld-x86-64/pr27491-4a.s: Likewise. * testsuite/ld-x86-64/pr27491-4b.s: Likewise.
* elf: Discard input .note.gnu.build-id sectionsH.J. Lu2021-12-016-1/+117
| | | | | | | | | | | | | | | | | | | 1. Discard input .note.gnu.build-id sections. 2. Clear the build ID field before writing. 3. Use bfd_make_section_anyway_with_flags to create the output .note.gnu.build-id section. PR ld/28639 * ldelf.c (ldelf_after_open): Discard input .note.gnu.build-id sections, excluding the first one. (write_build_id): Clear the build ID field before writing. (ldelf_setup_build_id): Use bfd_make_section_anyway_with_flags to create the output .note.gnu.build-id section. * testsuite/ld-elf/build-id.exp: New file. * testsuite/ld-elf/pr28639a.rd: Likewise. * testsuite/ld-elf/pr28639b.rd: Likewise. * testsuite/ld-elf/pr28639c.rd: Likewise. * testsuite/ld-elf/pr28639d.rd: Likewise.
* ld: pru: Add pru_irq_map output sectionNick Clifton2021-11-305-0/+60
| | | | | | | * scripttempl/pru.sc (.pru_irq_map): Define output section. * testsuite/ld-pru/pru_irq_map-1.d: New test. * testsuite/ld-pru/pru_irq_map-2.d: New test. * testsuite/ld-pru/pru_irq_map.s: New test.
* ld: enable silent build rulesMike Frysinger2021-11-294-64/+104
| | | | Also add $(AM_V_xxx) to various manual rules in here.
* Fix ifunc test fails on hppa*-*-*John David Anglin2021-11-261-1/+2
| | | | | | | | | | | | 2021-11-26 John David Anglin <danglin@gcc.gnu.org> PR ld/27442 ld/ChangeLog: * ld/testsuite/ld-ifunc/ifunc.exp (contains_irelative_reloc): Adjust regexp. Skip static ifunc-using executable test on hppa*-*-*.
* ld: fix POSIX shell test usageMike Frysinger2021-11-252-2/+2
| | | | POSIX test uses = for compares, not == which is a bashism.
* ld: fix --disable-multiple-abs-defs alignment in helpMike Frysinger2021-11-2511-11/+12
|
* ld/testsuite/ld-elfvsb: correctly test "weak hidden symbol DSO last"Clément Chigot2021-11-251-1/+1
| | | | | | | | | The test must be done with the shared object and not with the object file which is already being tested above. ld/ * testsuite/ld-elfvsb/elfvsb.exp: use .so file in "weak hidden symbol DSO last"
* Update bug reporting addressAlan Modra2021-11-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | https://sourceware.org/bugzilla/ everywhere bfd/ * configure.ac (ACX_BUGURL): Set to https://sourceware.org/bugzilla/ * po/Make-in (msgid-bugs-address): Likewise. * README: Report bugs to the above. * configure: Regenerate. binutils/ * po/Make-in (msgid-bugs-address): Update. gas/ * README: Update bug address. Delete mention of gcc. * po/Make-in: Update bug address. gold/ * po/Make-in: Update bug address. gprof/ * po/Make-in: Update bug address. ld/ * po/Make-in: Update bug address. opcodes/ * po/Make-in: Update bug address.
* RISC-V: Support STO_RISCV_VARIANT_CC and DT_RISCV_VARIANT_CC.Nelson Chu2021-11-196-0/+347
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is the original discussion, https://github.com/riscv/riscv-elf-psabi-doc/pull/190 And here is the glibc part, https://sourceware.org/pipermail/libc-alpha/2021-August/129931.html For binutils part, we need to support a new direcitve: .variant_cc. The function symbol marked by .variant_cc means it need to be resolved directly without resolver for dynamic linker. We also add a new dynamic entry, STO_RISCV_VARIANT_CC, to indicate there are symbols with the special attribute in the dynamic symbol table of the object. I heard that llvm already have supported this in their mainline, so I think it's time to commit this. bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): Added variant_cc flag. It is used to check if relocations for variant CC symbols may be present. (allocate_dynrelocs): If the symbol has STO_RISCV_VARIANT_CC flag, then raise the variant_cc flag of riscv_elf_link_hash_table. (riscv_elf_size_dynamic_sections): Added dynamic entry for variant_cc. (riscv_elf_merge_symbol_attribute): New function, used to merge non-visibility st_other attributes, including STO_RISCV_VARIANT_CC. binutils/ * readelf.c (get_riscv_dynamic_type): New function. (get_dynamic_type): Called get_riscv_dynamic_type for riscv targets. (get_riscv_symbol_other): New function. (get_symbol_other): Called get_riscv_symbol_other for riscv targets. gas/ * config/tc-riscv.c (s_variant_cc): Marked symbol that it follows a variant CC convention. (riscv_elf_copy_symbol_attributes): Same as elf_copy_symbol_attributes, but without copying st_other. If a function symbol has special st_other value set via directives, then attaching an IFUNC resolver to that symbol should not override the st_other setting. (riscv_pseudo_table): Support variant_cc diretive. * config/tc-riscv.h (OBJ_COPY_SYMBOL_ATTRIBUTES): Defined. * testsuite/gas/riscv/variant_cc-set.d: New testcase. * testsuite/gas/riscv/variant_cc-set.s: Likewise. * testsuite/gas/riscv/variant_cc.d: Likewise. * testsuite/gas/riscv/variant_cc.s: Likewise. include/ * elf/riscv.h (DT_RISCV_VARIANT_CC): Defined to (DT_LOPROC + 1). (STO_RISCV_VARIANT_CC): Defined to 0x80. ld/ * testsuite/ld-riscv-elf/variant_cc-1.s: New testcase. * testsuite/ld-riscv-elf/variant_cc-2.s: Likewise. * testsuite/ld-riscv-elf/variant_cc-now.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-r.d: Likewise. * testsuite/ld-riscv-elf/variant_cc-shared.d: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
* elf/x86: Issue an error on discarded output .plt sectionH.J. Lu2021-11-183-0/+21
| | | | | | | | | | | | | | | | | | Issue an error, instead of crash, on discarded output .plt section. bfd/ PR ld/28597 * elf32-i386.c (elf_i386_finish_dynamic_sections): Issue an error on discarded output .plt section. * elf64-x86-64.c (elf_x86_64_finish_dynamic_sections): Likewise. ld/ PR ld/28597 * testsuite/ld-elf/pr28597.d: New file. * testsuite/ld-elf/pr28597.s: Likewise. * testsuite/ld-elf/pr28597.t: Likewise.
* Set the default DLL chracteristics to 0 for Cygwin based targets.Jeremy Drake2021-11-173-3/+23
| | | | | | * emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Set to 0 for Cygwin targets. * emultempl/pep.em (DEFAULT_DLL_CHARACTERISTICS): Likewise.
* Fix the linker script parser so that it will recognise the PT_GNU_RELRO ↵Nick Clifton2021-11-172-0/+10
| | | | | | | | | | | segment type, and the linker itself so that it will gracefully handle being unable to assign any sections to such a segment. PR 28452 bfd * elf.c (assign_file_positions_for_non_load_sections): Replace assertion with a warning message. ld * ldgram.y: Add support for PT_GNU_RELRO and PT_GNU_PROPERTY. * ldgram.c: Regenerate.
* ld: Fix testsuite failures under --enable-textrel-check=errorRoland McGrath2021-11-154-3/+10
| | | | | | | | ld/ * testsuite/ld-aarch64/dt_textrel.d: Pass explicit -z notext in case ld was configured with --enable-textrel-check=error. * testsuite/ld-aarch64/pr22764.d: Likewise. * testsuite/ld-aarch64/pr20402.d: Likewise.
* PowerPC64 @notoc in non-power10 codeAlan Modra2021-11-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | R_PPC64_REL24_P9NOTOC is a variant of R_PPC64_REL24_NOTOC for use on @notoc cals from non-power10 code in the rare case that using such a construct is useful. R_PPC64_REL24_P9NOTOC will be emitted by gas rather than R_PPC64_REL24_NOTOC when @notoc is used in a branch instruction if power10 instructions are not enabled at that point. The new relocation tells the linker to not use power10 instructions on any stub emitted for that branch, unless overridden by --power10-stubs=yes. The current linker heuristic of only generating power10 instructions for stubs if power10-only relocations are detected, continues to be used. include/ * elf/ppc64.h (R_PPC64_REL24_P9NOTOC): Define. bfd/ * reloc.c (BFD_RELOC_PPC64_REL24_P9NOTOC): Define. * elf64-ppc.c (ppc64_elf_howto_raw): Add entry for new reloc. (ppc64_elf_reloc_type_lookup): Handle it. (enum ppc_stub_type): Delete. (enum ppc_stub_main_type, ppc_stub_sub_type): New. (struct ppc_stub_type): New. (struct ppc_stub_hash_entry): Use the above new type. (struct ppc_link_hash_table): Update stub_count. (is_branch_reloc, ppc64_elf_check_relocs), (toc_adjusting_stub_needed): Handle new reloc. (stub_hash_newfunc, select_alt_stub, ppc_merge_stub), (ppc_type_of_stub, plt_stub_size, build_plt_stub), (build_tls_get_addr_head, build_tls_get_addr_tail), (ppc_build_one_stub, ppc_size_one_stub, ppc64_elf_size_stubs), (ppc64_elf_build_stubs, ppc64_elf_relocate_section): Handle new reloc. Modify stub handling to suit new scheme. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. gas/ * config/tc-ppc.c (ppc_elf_suffix): When power10 is not enabled return BFD_RELOC_PPC64_REL24_P9NOTOC for @notoc. (fixup_size, ppc_force_relocation, ppc_fix_adjustable): Handle BFD_RELOC_PPC64_REL24_P9NOTOC. ld/ * testsuite/ld-powerpc/callstub-2.s: Add .machine power10.
* Regenerate a couple of filesAlan Modra2021-11-152-4/+5
| | | | | | | | | | | | A couple of files changed on my latest --enable-maintainer-mode build. ld/Makefile.in had a missing dependency but better sorting of the loongson entries. intl/ * configure: Regenerate. ld/ * Makefile.am: Sort loongson entries. * Makefile.in: Regenerate.
* ld: set correct flags for AIX shared testsClément Chigot2021-11-101-1/+1
| | | | | | | | Previous flags were aimed to be run with XLC. Nowadays, only GCC is being tested with GNU toolchain. Moreover, recent XLC versions might also accept "-shared". * testsuite/ld-shared/shared.exp: Adjust shared flags.
* Correct ld script wildcard matching descriptionAlan Modra2021-11-081-7/+0
| | | | | | | Goes with commit 68bbb9f788d0 * ld.texi (Input Section Wildcards): Delete paragraph incorrectly saying '*' does not match '/'.
* Modernise yyerrorAlan Modra2021-11-061-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | Newer versions of bison emit a prototype for yyerror void yyerror (const char *); This clashes with some of our old code that declares yyerror to return an int. Fix that in most cases by modernizing yyerror. bfin-parse.y uses the return value all over the place, so for there disable generation of the prototype as specified by posix. binutils/ * arparse.y (yyerror): Return void. * dlltool.c (yyerror): Likewise. * dlltool.h (yyerror): Likewise. * sysinfo.y (yyerror): Likewise. * windmc.h (yyerror): Likewise. * mclex.c (mc_error): Extract from .. (yyerror): ..here, both now returning void. gas/ * config/bfin-parse.y (yyerror): Define. (yyerror): Make static. * itbl-parse.y (yyerror): Return void. ld/ * deffilep.y (def_error): Return void.
* asan: dlltool buffer overflow: embedded NUL in stringAlan Modra2021-11-031-12/+4
| | | | | | | | | | | | | | | | | yyleng gives the pattern length, xstrdup just copies up to the NUL. So it is quite possible writing at an index of yyleng-2 overflows the xstrdup allocated string buffer. xmemdup quite handily avoids this problem, even writing the terminating NUL over the trailing quote. Use it in ldlex.l too where we'd already had a report of this problem and fixed it by hand, and to implement xmemdup0 in gas. binutils/ * deflex.l (single and double quote strings): Use xmemdup. gas/ * as.h (xmemdup0): Use xmemdup. ld/ PR 20906 * ldlex.l (double quote string): Use xmemdup.
* ASSERT in empty output section with addressAlan Modra2021-10-285-8/+32
| | | | | | | | | * ldlang.c (lang_do_assignments_1): Correct "dot" inside ignored sections. * testsuite/ld-scripts/empty-address-4.d, * testsuite/ld-scripts/empty-address-4.s, * testsuite/ld-scripts/empty-address-4.t: New test. * testsuite/ld-scripts/empty-address.exp: Run it.
* libctf, ld: handle nonrepresentable types betterNick Alcock2021-10-253-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | ctf_type_visit (used, among other things, by the type dumping code) was aborting when it saw a nonrepresentable type anywhere: even a single structure member with a nonrepresentable type caused an abort with ECTF_NONREPRESENTABLE. This is not useful behaviour, given that the abort comes from a type-resolution we are only doing in order to determine whether the type is a structure or union. We know nonrepresentable types can't be either, so handle that case and pass the nonrepresentable type down. (The added test verifies that the dumper now handles this case and prints nonrepresentable structure members as it already does nonrepresentable top-level types, rather than skipping the whole structure -- or, without the previous commit, skipping the whole types section.) ld/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/nonrepresentable-member.*: New test. libctf/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * ctf-types.c (ctf_type_rvisit): Handle nonrepresentable types.
* binutils, ld: make objdump --ctf's parameter optionalNick Alcock2021-10-2532-31/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ld by default (and always, unless adjusted with a hand-rolled linker script) emits deduplicated CTF into the .ctf section. But viewing it needs you to explicitly tell objdump this: it doesn't default its argument, even though what you always end up typing is --ctf=.ctf. This is annoying, so make the argument optional. binutils/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * objdump.c (usage): --ctf now has an optional argument. (main): Adjust accordingly. (dump_ctf): Default it. * doc/ctf.options.texi: Adjust. ld/ChangeLog 2021-10-25 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/array.d: Change --ctf=.ctf to --ctf. * testsuite/ld-ctf/conflicting-cycle-1.B-1.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise. * testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise. * testsuite/ld-ctf/conflicting-enums.d: Likewise. * testsuite/ld-ctf/conflicting-typedefs.d: Likewise. * testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise. * testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d: Likewise. * testsuite/ld-ctf/cross-tu-into-cycle.d: Likewise. * testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise. * testsuite/ld-ctf/cycle-1.d: Likewise. * testsuite/ld-ctf/cycle-2.A.d: Likewise. * testsuite/ld-ctf/cycle-2.B.d: Likewise. * testsuite/ld-ctf/cycle-2.C.d: Likewise. * testsuite/ld-ctf/data-func-conflicted.d: Likewise. * testsuite/ld-ctf/diag-cttname-null.d: Likewise. * testsuite/ld-ctf/diag-cuname.d: Likewise. * testsuite/ld-ctf/diag-parlabel.d: Likewise. * testsuite/ld-ctf/enum-forward.d: Likewise. * testsuite/ld-ctf/enums.d: Likewise. * testsuite/ld-ctf/forward.d: Likewise. * testsuite/ld-ctf/function.d: Likewise. * testsuite/ld-ctf/nonrepresentable.d: Likewise. * testsuite/ld-ctf/slice.d: Likewise. * testsuite/ld-ctf/super-sub-cycles.d: Likewise.
* LoongArch ld supportliuzhensong2021-10-2422-1/+1146
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2021-10-22 Chenghua Xu <xuchenghua@loongson.cn> Zhensong Liu <liuzhensong@loongson.cn> Weinan Liu <liuweinan@loongson.cn> Xiaolin Tang <tangxiaolin@loongson.cn> ld/ * Makefile.am: Add LoongArch. * NEWS: Mention LoongArch support. * configure.tgt: Add LoongArch. * emulparams/elf32loongarch-defs.sh: New. * emulparams/elf32loongarch.sh: Likewise. * emulparams/elf64loongarch-defs.sh: Likewise. * emulparams/elf64loongarch.sh: Likewise. * emultempl/loongarchelf.em: Likewise. * Makefile.in: Regenerate. * po/BLD-POTFILES.in: Regenerate. ld/testsuite/ * ld-loongarch-elf/disas-jirl.d: New. * ld-loongarch-elf/disas-jirl.s: Likewise. * ld-loongarch-elf/jmp_op.d: Likewise. * ld-loongarch-elf/jmp_op.s: Likewise. * ld-loongarch-elf/ld-loongarch-elf.exp: Likewise. * ld-loongarch-elf/macro_op.d: Likewise. * ld-loongarch-elf/macro_op.s: Likewise. * ld-loongarch-elf/syscall-0.s: Likewise. * ld-loongarch-elf/syscall-1.s: Likewise. * ld-loongarch-elf/syscall.d: Likewise. * ld-srec/srec.exp: Add LoongArch. * ld-unique/pr21529.d: Likewise.
* RISC-V: Added ld testcase for pcgp relaxation.Lewis Revill2021-10-225-2/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider the the pcgp-relax-02 testcase, .text .globl _start _start: .L1: auipc a0, %pcrel_hi(data_a) .L2: auipc a1, %pcrel_hi(data_b) addi a0, a0, %pcrel_lo(.L1) addi a1, a1, %pcrel_lo(.L2) .data .word 0x0 .globl data_a data_a: .word 0x1 .section .rodata .globl data_b data_b: .word 0x2 If the first auipc is deleted, but we are still building the pcgp table (connect the high and low pcrel relocations), then there is an aliasing issue that we need some way to disambiguate which of the two symbols we are targeting. Therefore, Palmer thought of a way to use R_RISCV_DELETE to split this into two phases, so we could resolve the addresses before creating the ambiguities. This patch just add the ld testcase for the above case, in case we have changed something but break this. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Renamed pcgp-relax to pcgp-relax-01, and added pcgp-relax-02. * testsuite/ld-riscv-elf/pcgp-relax-01.d: Renmaed from pcgp-relax. * testsuite/ld-riscv-elf/pcgp-relax-01.s: Likewise. * testsuite/ld-riscv-elf/pcgp-relax-02.d: New testcase. * testsuite/ld-riscv-elf/pcgp-relax-02.s: Likewise.
* RISC-V: Don't separate pcgp relaxation to another relax pass.Lewis Revill2021-10-227-38/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit abd20cb637008da9d32018b4b03973e119388a0a and ebdcad3fddf6ec21f6d4dcc702379a12718cf0c4 introduced additional complexity into the paths run by the RISC-V relaxation pass in order to resolve the issue of accurately keeping track of pcrel_hi and pcrel_lo pairs. The first commit split up relaxation of these relocs into a pass which occurred after other relaxations in order to prevent the situation where bytes were deleted in between a pcrel_lo/pcrel_hi pair, inhibiting our ability to find the corresponding pcrel_hi relocation from the address attached to the pcrel_lo. Since the relaxation was split into two passes the 'again' parameter could not be used to perform the entire relaxation process again and so the second commit added a way to restart ldelf_map_segments, thus starting the whole process again. Unfortunately this process could not account for the fact that we were not finished with the relaxation process so in some cases - such as the case where code would not fit in a memory region before the R_RISCV_ALIGN relocation was relaxed - sanity checks in generic code would fail. This patch fixes all three of these concerns by reverting back to a system of having only one target relax pass but updating entries in the table of pcrel_hi/pcrel_lo relocs every time any bytes are deleted. Thus we can keep track of the pairs accurately, and we can use the 'again' parameter to restart the entire target relax pass, behaving in the way that generic code expects. Unfortunately we must still have an additional pass to delay deleting AUIPC bytes to avoid ambiguity between pcrel_hi relocs stored in the table after deletion. This pass can only be run once so we may potentially miss out on relaxation opportunities but this is likely to be rare. https://sourceware.org/bugzilla/show_bug.cgi?id=28410 bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): Removed restart_relax. (riscv_elf_link_hash_table_create): Updated. (riscv_relax_delete_bytes): Moved after the riscv_update_pcgp_relocs. Update the pcgp_relocs table whenever bytes are deleted. (riscv_update_pcgp_relocs): Add function to update the section offset of pcrel_hi and pcrel_lo, and also update the symbol value of pcrel_hi. (_bfd_riscv_relax_call): Need to update the pcgp_relocs table when deleting codes. (_bfd_riscv_relax_lui): Likewise. (_bfd_riscv_relax_tls_le): Likewise. (_bfd_riscv_relax_align): Once we've handled an R_RISCV_ALIGN, we can't relax anything else, so set the sec->sec_flg0 to true. Besides, we don't need to update the pcgp_relocs table at this stage, so just pass NULL pointer as the pcgp_relocs table for riscv_relax_delete_bytes. (_bfd_riscv_relax_section): Use only one pass for all target relaxations. (_bfd_riscv_relax_delete): Likewise, we don't need to update the pcgp_relocs table at this stage, and don't need to set the `again' since restart_relax mechanism is abandoned. (bfd_elfNN_riscv_restart_relax_sections): Removed. (_bfd_riscv_relax_section): Updated. * elfxx-riscv.h (bfd_elf32_riscv_restart_relax_sections): Removed. (bfd_elf64_riscv_restart_relax_sections): Likewise. ld/ * emultempl/riscvelf.em: Revert restart_relax changes and set relax_pass to 3. * testsuite/ld-riscv-elf/align-small-region.d: New testcase. * testsuite/ld-riscv-elf/align-small-region.ld: Likewise. * testsuite/ld-riscv-elf/align-small-region.s: Likewise. * testsuite/ld-riscv-elf/restart-relax.d: Removed sine the restart_relax mechanism is abandoned. * testsuite/ld-riscv-elf/restart-relax.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
* -Waddress warning in ldelf.cAlan Modra2021-10-211-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 */ * ldelf.c (ldelf_after_open): Remove useless elf_header test.
* ld: Adjust pr28158.rd for glibc 2.34H.J. Lu2021-10-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adjust pr28158.rd for glibc 2.34: $ readelf -W --dyn-syms tmpdir/pr28158 Symbol table '.dynsym' contains 4 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.34 (2) 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 3: 000000000040401c 4 OBJECT GLOBAL DEFAULT 23 foo@VERS_2.0 (3) $ vs older glibc: $ readelf -W --dyn-syms tmpdir/pr28158 Symbol table '.dynsym' contains 4 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (3) 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ 3: 000000000040401c 4 OBJECT GLOBAL DEFAULT 23 foo@VERS_2.0 (2) $ * testsuite/ld-elf/pr28158.rd: Adjusted for glibc 2.34.
* ld: pru: Fix resource_table output section alignmentDimitar Dimitrov2021-09-302-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>
* configure: regenerate in all projects that use libtool.m4Nick Alcock2021-09-272-45/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (including sim/, which has no changelog.) bfd/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. binutils/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. gas/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. gprof/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. ld/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. libctf/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. * Makefile.in: Regenerate. opcodes/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate. zlib/ChangeLog 2021-09-27 Nick Alcock <nick.alcock@oracle.com> * configure: Regenerate.
* Fix x86 "FAIL: TLS -fno-pic -shared"Alan Modra2021-09-221-1/+1
| | | | | | Fix a typo in commit 5d0869d9872a * testsuite/ld-i386/tlsnopic.rd: Typo fix.
* Change the linker's heuristic for computing the entry point for binaries so ↵Nick Clifton2021-09-2122-21/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | that shared libraries default to an entry point of 0. * ldlang.c (lang_end): When computing the entry point, only try the start address of the entry section when creating an executable. * ld.texi (Entry point): Update description of heuristic used to choose the entry point. testsuite/ld-alpha/tlspic.rd: Update expected entry point address. testsuite/ld-arm/tls-gdesc-got.d: Likewise. testsuite/ld-i386/tlsnopic.rd: Likewise. testsuite/ld-ia64/tlspic.rd: Likewise. testsuite/ld-sparc/gotop32.rd: Likewise. testsuite/ld-sparc/gotop64.rd: Likewise. testsuite/ld-sparc/tlssunnopic32.rd: Likewise. testsuite/ld-sparc/tlssunnopic64.rd: Likewise. testsuite/ld-sparc/tlssunpic32.rd: Likewise. testsuite/ld-sparc/tlssunpic64.rd: Likewise. testsuite/ld-tic6x/shlib-1.rd: Likewise. testsuite/ld-tic6x/shlib-1b.rd: Likewise. testsuite/ld-tic6x/shlib-1r.rd: Likewise. testsuite/ld-tic6x/shlib-1rb.rd: Likewise. testsuite/ld-tic6x/shlib-noindex.rd: Likewise. testsuite/ld-x86-64/pr14207.d: Likewise. testsuite/ld-x86-64/tlsdesc.rd: Likewise. testsuite/ld-x86-64/tlspic.rd: Likewise. testsuite/ld-x86-64/tlspic2.rd: Likewise.
* Move eelf_mipsel_haiki.c to ALL_64_EMULATION_SOURCESAlan Modra2021-09-202-118/+132
| | | | | | | | | | | | | | --enable-targets=all on a 32-bit host results in a link failure with undefined references due to elfxx-mips.c not being compiled. This patch fixes that by putting eelf_mipsel_haiki.c in the correct EMULATION_SOURCES Makefile variable. I've also added a bunch of missing file dependencies and sorted a few things so that it's easier to verify dependencies are present. * Makfile.am: Add missing haiku dependencies, sort. (ALL_EMULATION_SOURCES): Sort. Move eelf_mipsel_haiku.c to.. (ALL_64_EMULATION_SOURCES): ..here. Sort. * Makfile.in: Regenerate.
* elf: Don't set version info on unversioned symbolsH.J. Lu2021-09-196-0/+71
| | | | | | | | | | | | | | | | | | | | | | Don't set version info on unversioned symbols when seeing a hidden versioned symbol after an unversioned definition and the default versioned symbol. bfd/ PR ld/28348 * elflink.c (elf_link_add_object_symbols): Don't set version info on unversioned symbols. ld/ PR ld/28348 * testsuite/ld-elf/pr28348.rd: New file. * testsuite/ld-elf/pr28348.t: Likewise. * testsuite/ld-elf/pr28348a.c: Likewise. * testsuite/ld-elf/pr28348b.c: Likewise. * testsuite/ld-elf/pr28348c.c: Likewise. * testsuite/ld-elf/shared.exp: Run PR ld/28348 tests.
* arc: Fix got-weak linker testClaudiu Zissulescu2021-09-152-3/+7
| | | | | | | | | Use regular expressions to fix the got-weak linker test. ld/ * testsuite/got-weak.d: Update test. Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com>
* arc: Fix potential invalid pointer access when fixing got symbols.Claudiu Zissulescu2021-09-143-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When statically linking, it can arrive to an undefined weak symbol of which its value cannot be determined. However, we are having pieces of code which doesn't take this situation into account, leading to access a structure which may not be initialized. Fix this situation and add a test. bfd/ xxxx-xx-xx Cupertino Miranda <cmiranda@synopsys.com> Claudiu Zissulescu <claziss@synopsys.com> * arc-got.h (arc_static_sym_data): New structure. (get_static_sym_data): New function. (relocate_fix_got_relocs_for_got_info): Move the computation fo symbol value and section to above introduced function, and use this new function. ld/testsuite/ xxxx-xx-xx Claudiu Zissulescu <claziss@synopsys.com> * ld-arc/got-weak.d: New file. * ld-arc/got-weak.s: Likewise. Signed-off-by: Claudiu Zissulescu <claziss@synopsys.com> fix
* ld testsuite tidyAlan Modra2021-09-0318-115/+95
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes a few issues: 1) If you use "-fsanitize=address,undefined" in CFLAGS, the Makefile attempt to trim off -fsanitize options left us with ",undefined". 2) ld_compile adds CFLAGS_FOR_TARGET itself, no need to pass it. 3) CFLAGS might be needed linking bootstrap test. * Makefile.am (CFLAGS_FOR_TARGET, CXXFLAGS_FOR_TARGET): Trim off all -fsanitize=*. * Makefile.in: Regenerate. * testsuite/ld-bootstrap/bootstrap.exp: Use CFLAGS when linking. * testsuite/ld-cdtest/cdtest.exp: Use CFLAGS_FOR_TARGET when linking. * testsuite/ld-auto-import/auto-import.exp: Don't pass CFLAGS_FOR_TARGET to ld_compile. * testsuite/ld-cygwin/exe-export.exp: Likewise. * testsuite/ld-elfvers/vers.exp: Likewise. * testsuite/ld-elfvsb/elfvsb.exp: Likewise. * testsuite/ld-elfweak/elfweak.exp: Likewise. * testsuite/ld-gc/gc.exp: Likewise. * testsuite/ld-pe/pe-compile.exp: Likewise. * testsuite/ld-pe/pe-run.exp: Likewise. * testsuite/ld-pe/pe-run2.exp: Likewise. * testsuite/ld-plugin/plugin.exp: Likewise. * testsuite/ld-shared/shared.exp: Likewise. * testsuite/ld-elfcomm/elfcomm.exp: Likewise, and don't allow nios2 testing to trash CFLAGS_FOR_TARGET. * testsuite/ld-scripts/crossref.exp: Don't pass options in CC_FOR_TARGET, do so in CFLAGS_FOR_TARGET instead. * testsuite/ld-srec/srec.exp: Likewise, and for CXX.
* CC_FOR_TARGET et alAlan Modra2021-09-0331-321/+332
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The top level Makefile, the ld Makefile and others, define CC_FOR_TARGET to be a compiler for the binutils target machine. This is the compiler that should be used for almost all tests with C source. There are _FOR_TARGET versions of CFLAGS, CXX, and CXXFLAGS too. This was all supposed to work with the testsuite .exp files using CC for the target compiler, and CC_FOR_HOST for the host compiler, with the makefiles passing CC=$CC_FOR_TARGET and CC_FOR_HOST=$CC to the runtest invocation. One exception to the rule of using CC_FOR_TARGET is the native-only ld bootstrap test, which uses the newly built ld to link a copy of itself. Since the files being linked were created with the host compiler, the boostrap test should use CC and CFLAGS, in case some host compiler option provides needed libraries automatically. However, bootstrap.exp used CC where it should have used CC_FOR_HOST. I set about fixing that problem, then decided that playing games in the makefiles with CC was a bad idea. Not only is it confusing, but other dejagnu code knows about CC_FOR_TARGET. See dejagnu/target.exp. So this patch gets rid of the makefile variable renaming and changes all the .exp files to use the correct _FOR_TARGET variables. CC_FOR_HOST and CFLAGS_FOR_HOST disappear. A followup patch will correct bootstrap.exp to use CFLAGS, and a number of other things I noticed. binutils/ * testsuite/lib/binutils-common.exp (run_dump_test): Use CC_FOR_TARGET and CFLAGS_FOR_TARGET rather than CC and CFLAGS. ld/ * Makefile.am (check-DEJAGNU): Don't set CC to CC_FOR_TARGET and similar. Pass variables with unchanged names. Don't set CC_FOR_HOST or CFLAGS_FOR_HOST. * Makefile.in: Regenerate. * testsuite/config/default.exp: Update default CC and similar. (compiler_supports, plug_opt): Use CC_FOR_TARGET. * testsuite/ld-cdtest/cdtest.exp: Replace all uses of CC with CC_FOR_TARGET, and similarly for CFLAGS, CXX and CXXFLAGS. * testsuite/ld-auto-import/auto-import.exp: Likewise. * testsuite/ld-cygwin/exe-export.exp: Likewise. * testsuite/ld-elf/dwarf.exp: Likewise. * testsuite/ld-elf/indirect.exp: Likewise. * testsuite/ld-elf/shared.exp: Likewise. * testsuite/ld-elfcomm/elfcomm.exp: Likewise. * testsuite/ld-elfvers/vers.exp: Likewise. * testsuite/ld-elfvsb/elfvsb.exp: Likewise. * testsuite/ld-elfweak/elfweak.exp: Likewise. * testsuite/ld-gc/gc.exp: Likewise. * testsuite/ld-ifunc/ifunc.exp: Likewise. * testsuite/ld-mn10300/mn10300.exp: Likewise. * testsuite/ld-pe/pe-compile.exp: Likewise. * testsuite/ld-pe/pe-run.exp: Likewise. * testsuite/ld-pe/pe-run2.exp: Likewise. * testsuite/ld-pie/pie.exp: Likewise. * testsuite/ld-plugin/lto.exp: Likewise. * testsuite/ld-plugin/plugin.exp: Likewise. * testsuite/ld-scripts/crossref.exp: Likewise. * testsuite/ld-selective/selective.exp: Likewise. * testsuite/ld-sh/sh.exp: Likewise. * testsuite/ld-shared/shared.exp: Likewise. * testsuite/ld-srec/srec.exp: Likewise. * testsuite/ld-undefined/undefined.exp: Likewise. * testsuite/ld-unique/unique.exp: Likewise. * testsuite/ld-x86-64/tls.exp: Likewise. * testsuite/lib/ld-lib.exp: Likewise. libctf/ * Makefile.am (check-DEJAGNU): Don't set CC to CC_FOR_TARGET. Pass CC and CC_FOR_TARGET. Don't set CC_FOR_HOST. * Makefile.in: Regenerate. * testsuite/config/default.exp: Update default CC and similar. * testsuite/lib/ctf-lib.exp (run_native_host_cmd): Use CC rather than CC_FOR_HOST. (run_lookup_test): Use CC_FOR_TARGET and CFLAGS_FOR_TARGET.
* haiku tidyAlan Modra2021-09-033-6/+12
| | | | | | | | | | | | | | | --enable-maintainer-mode showed a number of files needing to be regenerated, and in the case of ld/Makefile.in that the file was regenerated by hand. Nothing to see here really. ld/ * Makefile.am (ALL_64_EMULATION_SOURCES): Sort haiku entry. * Makefile.in: Regenerate. * po/BLD-POTFILES.in: Regenerate. libctf/ * configure: Regenerate. zlib/ * configure: Regenerate.
* Add support for the haiku operating system. These are the os support ↵Alexander von Gluck IV2021-09-0211-2/+132
| | | | patches we have been grooming and maintaining for quite a few years over on git.haiku-os.org. All of these architectures are working and most have been stable for quite some time.
* ld: Change indirect symbol from IR to undefinedH.J. Lu2021-08-277-0/+46
| | | | | | | | | | | | | | | | | | | bfd/ PR ld/28264 * elflink.c (_bfd_elf_merge_symbol): Change indirect symbol from IR to undefined. ld/ PR ld/28264 * testsuite/ld-plugin/lto.exp: Run PR ld/28264 test. * testsuite/ld-plugin/pr28264-1.d: New file. * testsuite/ld-plugin/pr28264-2.d: Likewise. * testsuite/ld-plugin/pr28264-3.d: Likewise. * testsuite/ld-plugin/pr28264-4.d: Likewise. * testsuite/ld-plugin/pr28264.c: Likewise. * testsuite/ld-plugin/pr28264.ver: Likewise.
* Real programmers don't configure gcc using --with-ldAlan Modra2021-08-241-1/+5
| | | | | * testsuite/lib/ld-lib.exp (run_host_cmd): Give a clue as to why gcc -B doesn't pick up the ld under test.
* Another ld script backtrackAlan Modra2021-08-181-0/+5
| | | | * ldgram.y (length_spec): Throw away look-ahead NAME.
* ld script fill pattern expressionAlan Modra2021-08-142-3/+27
| | | | | | | | | | | | | It turns out we do need to backtrack when parsing after all. The fill_opt component in the section rule swiches to EXPRESSION and back to SCRIPT, and to find the end of an expression it is necessary to look ahead one token. * ldgram.y (section): Throw away lookahead NAME token. (overlay_section): Likewise. * testsuite/ld-elf/overlay.t: Add fill pattern on overlays. Test fill pattern before stupidly named normal sections too, and before /DISCARD/.
* ld lexer tidy, possibly break the worldAlan Modra2021-08-132-129/+140
| | | | | | | | | | | This tidies the states in which ld lexer rules are enabled. This change will quite likely trip over issues similar to those mentioned in the new ldlex.l comments, so please test it out. * ldgram.y (wildcard_name): Remove now unnecessary components. * ldlex.l: Restrict many rules' states. Remove -l expression state rule. Comment on lookahead state madness and need for /DISCARD/ in expression state.
* ld script lower-case absolute and sizeof_headersAlan Modra2021-08-133-5/+4
| | | | | | | | | | I think these happened by accident, so let's see what breaks if they are removed. * ldlex.l: Remove lower case "absolute" and "sizeof_headers" in non-mri mode. * ld.texi: Remove sizeof_headers index. * testsuite/ld-mmix/mmohdr1.ld: Use SIZEOF_HEADERS.
* tidy mri script externAlan Modra2021-08-131-10/+5
| | | | | | | | MRI mode generally doesn't flip lexer states, so let's make MRI mode "extern" not do so either. * ldgram.y (extern_name_list): Don't change lex state here. (ifile_p1): Change state here on EXTERN instead.
* Re: PR28217, Syntax error when memory region contains a hyphenAlan Modra2021-08-131-10/+3
| | | | | | | | | I discovered some more errors when tightening up the lexer rules. Just because we INCLUDE a file doesn't mean we've switched states. PR 28217 * ldgram.y (statement): Don't switch lexer state on INCLUDE. (mri_script_command, ifile_p1, memory_spec, section): Likewise.
* PR28217, Syntax error when memory region contains a hyphenAlan Modra2021-08-134-184/+171
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The saga of commit 40726f16a8d7 continues. This attacks the problem of switching between SCRIPT and EXPRESSION state lexing by removing the need to do so for phdrs like ":text". Instead {WILDCHAR}* matching, the reason why ":text" lexed as one token, is restricted to within the braces of a section or overlay statement. The new WILD lexer state is switched at the non-optional brace tokens, so ldlex_backup is no longer needed. I've also removed the BOTH state, which doesn't seem to be needed any more. Besides rules involving error reporting, there was just one place where SCRIPT appeared without BOTH, the {WILDCHAR}* rule, three where BOTH appears without SCRIPT for tokens that only need EXPRESSION state, and two where BOTH appears alongside INPUT_LIST. (Since I'm editing the wild and filename rules, removing BOTH and adding WILD can also be seen as renaming the old BOTH state to SCRIPT and renaming the old SCRIPT state to WILD with a reduced scope.) As a followup, I'll look at removing EXPRESSION state from some lexer rules that no longer need it due to this cleanup. PR 28217 * ldgram.y (exp <ORIGIN, LENGTH>): Use paren_script_name. (section): Parse within braces of section in wild mode, and after brace back in script mode. Remove ldlex_backup call. Similarly for OVERLAY. (overlay_section): Similarly. (script_file): Replace ldlex_both with ldlex_script. * ldlex.h (ldlex_wild): Declare. (ldlex_both): Delete. * ldlex.l (BOTH): Delete. Remove state from all rules. (WILD): New state. Enable many tokens in this state. Enable filename match in SCRIPT mode. Enable WILDCHAR match in WILD state, disable in SCRIPT mode. (ldlex_wild): New function. * ldfile.c (ldfile_try_open_bfd): Replace ldlex_both call with ldlex_script.
* ns32k configuryAlan Modra2021-08-131-1/+1
| | | | | | | | | | | | | Since ns32k-netbsd is as yet not removed, just marked obsolete, the target should still be accepted with --enable-obsolete. I also enabled ns32k-openbsd in ld since there doesn't seem to be a good reason why that target is not supported there but is elsewhere. bfd/ * config.bfd: Allow ns32k-netbsd. ld/ * configure.tgt: Allow ns32k-openbsd.