aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2021-04-20Rework the R_NEG support on both gas and ld for the PowerPC AIX targets, in ↵Cl?ment Chigot6-0/+92
order to manage C++ exceptions built with GCC. bfd PR binutils/21700 * reloc.c (BFD_RELOC_PPC_NEG): New relocation. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * coff-rs6000.c (_bfd_xcoff_reloc_type_lookup): Add BFD_RELOC_PPC_NEG handler. (xcoff_reloc_type_neg): Correctly substract addend. * coff64-rs6000.c (xcoff64_howto_table): Add R_NEG_32 howto. (xcoff64_rtype2howto): Add handler for R_NEG_32. (xcoff64_reloc_type_lookup): Add BFD_RELOC_PPC_NEG handler. * xcofflink.c (xcoff_need_ldrel_p): Check output section for R_POS-like relocations. New argument added. (xcoff_mark): Adapt to new xcoff_need_ldrel_p argument. (xcoff_link_input_bfd): Likewise. gas * config/tc-ppc.c (ppc_get_csect_to_adjust): New function. (ppc_fix_adjustable): Manage fx_subsy part. (tc_gen_reloc): Create second relocation when both fx_addsy and fx_subsy are provided. * config/tc-ppc.h (RELOC_EXPANSION_POSSIBLE): New define. (MAX_RELOC_EXPANSION): Likewise. (TC_FORCE_RELOCATION_SUB_SAME): Likewise (UNDEFINED_DIFFERENCE_OK): Likewise * testsuite/gas/all/gas.exp: Skip difference between two undefined symbols test. ld * testsuite/ld-powerpc/aix52.exp: Add new test. * testsuite/ld-powerpc/aix-neg-reloc-32.d: New test. * testsuite/ld-powerpc/aix-neg-reloc-64.d: New test. * testsuite/ld-powerpc/aix-neg-reloc.ex: New test. * testsuite/ld-powerpc/aix-neg-reloc.s: New test.
2021-04-13Document the effect of --as-needed on --rpath on Linux based systems.Nick Clifton2-0/+21
* ld.texi (Options): Add note about the effect of --as-needed on the --rpath and --rpath-link options on Linux based systems.
2021-04-13PR27722, error: array subscript has type charAlan Modra2-3/+9
PR 27722 * libdep_plugin.c (str2vec): Don't pass a potentially signed char to isspace.
2021-04-13ENABLE_CHECKING in bfd, opcodes, binutils, ldAlan Modra4-2/+42
gas already has this. Here it enables checking hash table type passed to elf_link_hash_lookup and elf_link_hash_traverse. bfd/ * elf-bfd.h (ENABLE_CHECKING): Define. (elf_link_hash_lookup): Abort if wrong type of hash table. (elf_link_hash_traverse): Likewise. * configure.ac (--enable-checking): Add support. * config.in: Regenerate. * configure: Regenerate. binutils/ * configure.ac (--enable-checking): Add support. * config.in: Regenerate. * configure: Regenerate. ld/ * configure.ac (--enable-checking): Add support. * config.in: Regenerate. * configure: Regenerate. opcodes/ * configure.ac (--enable-checking): Add support. * config.in: Regenerate. * configure: Regenerate.
2021-04-12convert elf_link_hash macros to inline functionsAlan Modra3-2/+8
Involves a bit of editing as we now need to be more precise in pointer types. bfd/ * elf-bfd.h (is_elf_hash_table): Convert macro to inline function. (elf_link_hash_lookup, elf_link_hash_traverse): Likewise. (elf_hash_table, elf_hash_table_id): Likewise. * elf32-arm.c (elf32_arm_setup_section_lists): Delete redundant is_elf_hash_table check. * elf32-csky.c (elf32_csky_setup_section_lists): Likewise. * elf32-hppa.c (clobber_millicode_symbols): Correct param types. * elf64-alpha.c (elf64_alpha_output_extsym): Likewise. * elfnn-ia64.c (elfNN_ia64_global_dyn_info_free: Likewise. (elfNN_ia64_global_dyn_sym_thunk: Likewise. * elf64-ia64-vms.c (elf64_ia64_global_dyn_info_free): Likewise. (elf64_ia64_global_dyn_sym_thunk): Likewise. (elf64_vms_link_add_object_symbols): Pass base type of hash table to is_elf_hash_table. * elflink.c (_bfd_elf_dynamic_symbol_p): Likewise. (_bfd_elf_symbol_refs_local_p, _bfd_elf_add_dynamic_entry): Likewise. (_bfd_elf_strip_zero_sized_dynamic_sections): Likewise. (_bfd_elf_link_check_relocs, elf_link_add_object_symbols): Likewise. (bfd_elf_final_link): Likewise. * elfnn-aarch64.c (elfNN_aarch64_setup_section_lists): Likewise. * elf64-ppc.c (ppc64_elf_set_toc): Likewise. Use bfd_link_hash_lookup. ld/ * emultempl/mipself.em (mips_create_output_section_statements): Pass base type of hash table to is_elf_hash_table. * ldelf.c (ldelf_after_open): Likewise.
2021-04-12PR27719, lang_mark_undefineds trashes memoryAlan Modra5-5/+16
It's not enough to test that the output is ELF before casting bfd_link_hash_entry to elf_link_hash_entry. Some ELF targets (d30v, dlx, pj, s12z, xgate) use the generic linker support in bfd/linker.c and thus their symbols are of type generic_link_hash_entry. Not all of the places this patch touches can result in wrong accesses, but I thought it worth ensuring that all occurrences of elf_link_hash_entry in ld/ were obviously correct. PR 27719 * ldlang.c (lang_mark_undefineds, undef_start_stop): Test that the symbol hash table is the correct type before accessing elf_link_hash_entry symbols. * plugin.c (is_visible_from_outside): Likewise. * emultempl/armelf.em (ld${EMULATION_NAME}_finish): Likewise. * emultempl/solaris2.em (elf_solaris2_before_allocation): Likewise.
2021-04-09PowerPC disassembly of pcrel referencesAlan Modra12-56/+70
This adds some annotation to Power10 pcrel instructions, displaying the target address (ie. pc + D34 field) plus a symbol if there is one at exactly that target address. pld from the .got or .plt will also look up the entry and display it, symbolically if there is a dynamic relocation on the entry. include/ * dis-asm.h (struct disassemble_info): Add dynrelbuf and dynrelcount. binutils/ * objdump.c (struct objdump_disasm_info): Delete dynrelbuf and dynrelcount. (find_symbol_for_address): Adjust for dynrelbuf and dynrelcount move. (disassemble_section, disassemble_data): Likewise. opcodes/ * ppc-dis.c (struct dis_private): Add "special". (POWERPC_DIALECT): Delete. Replace uses with.. (private_data): ..this. New inline function. (disassemble_init_powerpc): Init "special" names. (skip_optional_operands): Add is_pcrel arg, set when detecting R field of prefix instructions. (bsearch_reloc, print_got_plt): New functions. (print_insn_powerpc): For pcrel instructions, print target address and symbol if known, and decode plt and got loads too. gas/ * testsuite/gas/ppc/prefix-pcrel.d: Update expected output. * testsuite/gas/ppc/prefix-reloc.d: Likewise. * gas/testsuite/gas/ppc/vsx_32byte.d: Likewise. ld/ * testsuite/ld-powerpc/inlinepcrel-1.d: Update expected output. * testsuite/ld-powerpc/inlinepcrel-2.d: Likewise. * testsuite/ld-powerpc/notoc2.d: Likewise. * testsuite/ld-powerpc/notoc3.d: Likewise. * testsuite/ld-powerpc/pcrelopt.d: Likewise. * testsuite/ld-powerpc/startstop.d: Likewise. * testsuite/ld-powerpc/tlsget.d: Likewise. * testsuite/ld-powerpc/tlsget2.d: Likewise. * testsuite/ld-powerpc/tlsld.d: Likewise. * testsuite/ld-powerpc/weak1.d: Likewise. * testsuite/ld-powerpc/weak1so.d: Likewise.
2021-04-06ld: warn about PE base relocations to sections above .relocJan Beulich2-1/+15
Due to a bogus linker script, or perhaps because a section doesn't get placed by a linker script while default placement puts it too high up, sections can end up above .reloc. Since the process of determining its contents (and hence its size) happens before final section placement, relocations needed for such sections would no longer point at the correct address in the final binary. Warn about this (down the road this may want to become an error, unless size determination and content creation for .reloc would get decoupled). To avoid triggering the warning when .reloc gets discarded, suppress populating the section in the first place in this case.
2021-04-05C99 ld configuryAlan Modra7-1573/+633
* configure.ac: Move initfini-array arg handling earlier. Don't check for string.h, strings.h, stdlib.h, or locale.h. Do check for inttypes.h, stdint.h, sys/types.h. Don't check for setlocale, free, getev or strstr. (AC_ISC_POSIX): Don't invoke. * sysdep.h: Include string.h and stdlib.h unconditionally. Test HAVE_SYS_TYPE_H and HAVE_SYS_STAT_H. Remove strstr, free and getenv fallback declarations. * ld.h: Don't test HAVE_LOCALE_H. * ldmain.c: Don't test HAVE_SETLOCALE. * config.in: Regenerate. * configure: Regenerate.
2021-04-01PE/Windows x86_64: Fix weak undef symbols after image base changeTamar Christina4-0/+78
The change in PR19011 changed the image load address from being in the lower 32-bit address space to the higher 64-bit address space. However when you have a weak undef symbol which stays undef at the end of linking the linker has to resolve this (Windows loader does not support undef symbols). As such typically these would resolve to 0. The relocation used for these weak symbols are the normal 32-bit PC_REL call relocs. So when doing the overflow check LD checks if the distance between the symbol and the call is within range. However now that the load address is > 32-bits and the symbol val is 0 this overflow check will always fail. As such the linker gives a bogus error. This patch makes the linker not emit the overflow failure but chooses to still let the check be performed (as it's mid-end code). One down side of this is that it does break the common convention that the call be to sym at 0x0. i.e. before you'd get 401015: 74 05 je 40101c 401017: e8 e4 ef bf ff callq 0 and now you get 140001015: 74 05 je 14000101c 140001017: e8 e4 ef ff bf call 100000000 since the call is PC_REL there's no way to get the range large enough to resolve to 0. As such I have chosen to leave it as the furthest simple range that we can still represent. By only ignoring the error we leave the symbol value itself to still be 0 such that the if(<symbol>) checks still work correctly. bfd/ChangeLog: 2021-04-01 Tamar Christina <tamar.christina@arm.com> PR ld/26659 * cofflink.c (_bfd_coff_generic_relocate_section): Ignore overflow. ld/ChangeLog: 2021-04-01 Tamar Christina <tamar.christina@arm.com> PR ld/26659 * testsuite/ld-pe/pe.exp: Add test. * testsuite/ld-pe/pr26659-weak-undef-sym.d: New test. * testsuite/ld-pe/pr26659-weak-undef-sym.s: New test.
2021-04-01Remove strneq macro and use startswith.Martin Liska2-4/+9
bfd/ChangeLog: * ecoff.c (strneq): Remove strneq and use startswith. (_bfd_ecoff_slurp_armap): Likewise. binutils/ChangeLog: * elfcomm.h (strneq): Remove strneq and use startswith. * readelf.c (ia64_process_unwind): Likewise. (process_note): Likewise. gas/ChangeLog: * config/obj-coff.c (strneq): Remove strneq and use startswith. (weak_is_altname): Likewise. (obj_coff_section): Likewise. * config/tc-cr16.c (process_label_constant): Likewise. * config/tc-crx.c (strneq): Likewise. include/ChangeLog: * opcode/cr16.h (strneq): Remove strneq and use startswith. ld/ChangeLog: * ldbuildid.c (strneq): Remove strneq and use startswith. (validate_build_id_style): Likewise. (compute_build_id_size): Likewise. opcodes/ChangeLog: * arm-dis.c (strneq): Remove strneq and use startswith. * cr16-dis.c (print_insn_cr16): Likewise. * score-dis.c (streq): Likewise. (strneq): Likewise. * score7-dis.c (strneq): Likewise.
2021-03-31Use bool in ldAlan Modra91-1532/+1571
* sysdep.h (POISON_BFD_BOOLEAN): Define. * configure.ac (elf_list_options, elf_shlib_list_options=false), (elf_plt_unwind_list_options=false): Replace FALSE with false, and TRUE with true. * emulparams/call_nop.sh, * emulparams/cet.sh, * emulparams/dynamic_undefined_weak.sh, * emulparams/elf32b4300.sh, * emulparams/elf32lm32.sh, * emulparams/elf32lr5900.sh, * emulparams/elf32lr5900n32.sh, * emulparams/elf32visium.sh, * emulparams/elf_x86_64.sh, * emulparams/extern_protected_data.sh, * emulparams/plt_unwind.sh, * emulparams/reloc_overflow.sh, * emulparams/static.sh, * emulparams/x86-64-lam.sh, * emultempl/aarch64elf.em, * emultempl/aix.em, * emultempl/alphaelf.em, * emultempl/armcoff.em, * emultempl/armelf.em, * emultempl/avrelf.em, * emultempl/beos.em, * emultempl/bfin.em, * emultempl/cr16elf.em, * emultempl/crxelf.em, * emultempl/cskyelf.em, * emultempl/elf.em, * emultempl/genelf.em, * emultempl/hppaelf.em, * emultempl/linux.em, * emultempl/m68hc1xelf.em, * emultempl/metagelf.em, * emultempl/mipself.em, * emultempl/mmix-elfnmmo.em, * emultempl/mmixelf.em, * emultempl/mmo.em, * emultempl/msp430.em, * emultempl/nios2elf.em, * emultempl/pdp11.em, * emultempl/pe.em, * emultempl/pep.em, * emultempl/ppc32elf.em, * emultempl/ppc64elf.em, * emultempl/rxelf.em, * emultempl/rxlinux.em, * emultempl/scoreelf.em, * emultempl/solaris2.em, * emultempl/spuelf.em, * emultempl/ticoff.em, * emultempl/v850elf.em, * emultempl/vms.em, * emultempl/xtensaelf.em, * emultempl/z80.em, * ld.h, * ldbuildid.c, * ldbuildid.h, * ldcref.c, * ldctor.c, * ldctor.h, * ldelf.c, * ldelf.h, * ldelfgen.c, * ldelfgen.h, * ldemul.c, * ldemul.h, * ldexp.c, * ldexp.h, * ldfile.c, * ldfile.h, * ldgram.y, * ldlang.c, * ldlang.h, * ldmain.c, * ldmain.h, * ldmisc.c, * ldmisc.h, * ldwrite.c, * lexsup.c, * mri.c, * pe-dll.c, * pe-dll.h, * pep-dll.h, * plugin.c, * plugin.h, * testplug.c, * testplug2.c, * testplug3.c, * testplug4.c: Replace bfd_boolean with bool, FALSE with false, and TRUE with true. * configure: Regenerate.
2021-03-31Remove bfd_stdint.hAlan Modra18-19/+39
If we require C99 for binutils then stdint.h is available. bfd/ * .gitignore: Delete bfd_stdint.h entry. * Makefile.am (bfdinclude_HEADERS): Delete bfd_stdint.h. (BUILD_HFILES, LOCAL_H_DEPS): Likewise. * bfd-in.h: Include stdint.h in place of bfd_stdint.h. * configure.ac: Don't invoke GCC_HEADER_STDINT. * configure.com: Don't create bfd_stdint.h. * Makefile.in: Regenerate. * aclocal.m4: Regenerate. * bfd-in2.h: Regenerate. * config.in: Regenerate. * configure: Regenerate. * doc/Makefile.in: Regenerate. * po/BLD-POTFILES.in: Regenerate. binutils/ * coffdump.c: Include stdint.h in place of bfd_stdint.h. * dwarf.c: Likewise. gas/ * config/tc-aarch64.c: Include stdint.h in place of bfd_stdint.h. * config/tc-crx.c: Likewise. * config/tc-nds32.h: Likewise. include/ * cgen/basic-modes.h: Include stdint.h in place of bfd_stdint.h. * elf/nfp.h: Likewise. * opcode/aarch64.h: Likewise. * opcode/cgen.h: Likewise. * opcode/nfp.h: Likewise. * opcode/ppc.h: Likewise. ld/ * elf-hints-local.h: Include stdint.h in place of bfd_stdint.h. * emultempl/nds32elf.em: Likewise. * testsuite/ld-elf/mbind2b.c: Likewise. * testsuite/ld-elf/pr18718.c: Likewise. * testsuite/ld-elf/pr18720a.c: Likewise. * testsuite/ld-elf/pr25749-1.c: Likewise. * testsuite/ld-elf/pr25749-1a.c: Likewise. * testsuite/ld-elf/pr25749-1b.c: Likewise. * testsuite/ld-elf/pr25749-1c.c: Likewise. * testsuite/ld-elf/pr25749-1d.c: Likewise. * testsuite/ld-elf/pr25749-2.c: Likewise. * testsuite/ld-elf/pr25754-1a.c: Likewise. * testsuite/ld-elf/pr25754-2a.c: Likewise. * testsuite/ld-elf/pr25754-3a.c: Likewise. * testsuite/ld-elf/pr25754-4a.c: Likewise. * testsuite/ld-elf/pr25754-5a.c: Likewise. * testsuite/ld-elf/pr25754-6a.c: Likewise. opcodes/ * aarch64-dis.c: Include stdint.h in place of bfd_stdint.h. * aarch64-dis.h: Likewise. * aarch64-opc.c: Likewise. * avr-dis.c: Likewise. * csky-dis.c: Likewise. * nds32-asm.c: Likewise. * nds32-dis.c: Likewise. * nfp-dis.c: Likewise. * riscv-dis.c: Likewise. * s12z-dis.c: Likewise. * wasm32-dis.c: Likewise.
2021-03-29TRUE/FALSE simplificationAlan Modra4-5/+11
There is really no need to write code like "foo != 0 ? TRUE : FALSE" unless we had stupidly defined FALSE as something other than 0 or TRUE as something other than 1. The simpler "foo != 0" does just as well. Similarly "(condition == TRUE)" or "(condition == FALSE) can be simplified to "(condition)" and "(!condition)" respectively. I'll note that there is reason to use "integer_expression != 0" when assigning a bfd_boolean rather than the simpler "integer_expression", if you expect the variable to have 0 or 1 value. It's probably even a good idea to not rely on implicit conversion if bfd_boolean were _Bool. bfd/ * aoutx.h (aout_link_write_symbols): Don't cast boolean expression to bfd_boolean. * elf32-or1k.c (or1k_set_got_and_rela_sizes): Dont compare booleans against FALSE. * elf32-arc.c (name_for_global_symbol): Don't compare boolean to TRUE. (is_reloc_PC_relative): Don't use "boolean_condition ? TRUE : FALSE". (is_reloc_SDA_relative, is_reloc_for_GOT): Likewise. (is_reloc_for_PLT, is_reloc_for_TLS): Likewise. * elf32-arm.c (stm32l4xx_need_create_replacing_stub): Likewise. * elf32-nds32.c (insert_nds32_elf_blank): Likewise. * elf32-rx.c (rx_set_section_contents): Likewise. * elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise. * elfxx-mips.c (_bfd_mips_elf_ignore_undef_symbol): Likewise. * mach-o.c (bfd_mach_o_read_command): Likewise. * targets.c (bfd_get_target_info): Likewise. binutils/ * dlltool.c (main): Don't use "boolean_condition ? TRUE : FALSE". * dwarf.c (read_and_display_attr_value): Likewise. (display_debug_str_offsets): Likewise. * objdump.c (dump_bfd): Likewise. * readelf.c (dump_section_as_strings): Likewise. (dump_section_as_bytes): Likewise. gas/ * atof-generic.c (FALSE, TRUE): Don't define. * config/obj-elf.h (FALSE, TRUE): Don't define. * config/obj-som.h (FALSE, TRUE): Don't define. * config/tc-hppa.h (FALSE, TRUE): Don't define. * config/tc-pdp11.c (FALSE, TRUE): Don't define. * config/tc-iq2000.h (obj_fix_adjustable): Delete. * config/tc-m32r.h (TC_FIX_ADJUSTABLE): Delete. * config/tc-mt.h (obj_fix_adjustable): Delete. * config/tc-nds32.h (TC_FIX_ADJUSTABLE): Delete. * config/tc-arc.c (parse_opcode_flags): Simplify boolean expression. (relaxable_flag, relaxable_operand, assemble_insn): Likewise. (tokenize_extregister): Likewise. * config/tc-csky.c (parse_opcode, get_operand_value): Likewise. (parse_operands_op, parse_operands, md_assemble): Likewise. * config/tc-d10v.c (build_insn): Likewise. * config/tc-score.c (s3_gen_insn_frag): Likewise. * config/tc-score7.c (s7_gen_insn_frag, s7_relax_frag): Likewise. * config/tc-tic6x.c (tic6x_update_features, md_assemble): Likewise. * config/tc-z80.c (emit_byte): Likewise. include/ * opcode/aarch64.h (alias_opcode_p): Simplify boolean expression. (opcode_has_alias, pseudo_opcode_p, optional_operand_p): Likewise. (opcode_has_special_coder): Likewise. ld/ * emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Simplify boolean expression. * lexsup.c (parse_args): Likewise. * pe-dll.c (pe_dll_id_target): Likewise. opcodes/ * aarch64-opc.c (vector_qualifier_p): Simplify boolean expression. (fp_qualifier_p, get_data_pattern): Likewise. (aarch64_get_operand_modifier_from_value): Likewise. (aarch64_extend_operator_p, aarch64_shift_operator_p): Likewise. (operand_variant_qualifier_p): Likewise. (qualifier_value_in_range_constraint_p): Likewise. (aarch64_get_qualifier_esize): Likewise. (aarch64_get_qualifier_nelem): Likewise. (aarch64_get_qualifier_standard_value): Likewise. (get_lower_bound, get_upper_bound): Likewise. (aarch64_find_best_match, match_operands_qualifier): Likewise. (aarch64_print_operand): Likewise. * aarch64-opc.h (operand_has_inserter, operand_has_extractor): Likewise. (operand_need_sign_extension, operand_need_shift_by_two): Likewise. (operand_need_shift_by_four, operand_maybe_stack_pointer): Likewise. * arm-dis.c (print_insn_mve, print_insn_thumb32): Likewise. * tic6x-dis.c (tic6x_check_fetch_packet_header): Likewise. (print_insn_tic6x): Likewise.
2021-03-25ld: do not rely on the exact size of the CTF symtypetabs in test resultsNick Alcock6-8/+18
The data object and function info sections (collectively "symtypetabs") usually (i.e. if non-indexed) have sizes defined by the size of the ELF dynamic symbol table in the object they are linked to. This means test results should not depend on the exact sizes of these sections, because adding entirely irrelevant symbols to the dynsym can cause spurious test failures. (This also means we should not match the offset of sections that follow them, since those too depend on the exact size of the symtypetab sections.) Spotted by turning the sanitizer on, which introduced new dynsym entries and expanded the symtypetab sizes to match. ld/ChangeLog 2021-03-25 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/array.d: Only check that the data object section is nonempty: do not check its exact size. * testsuite/ld-ctf/diag-parlabel.d: Likewise. * testsuite/ld-ctf/slice.d: Likewise. * testsuite/ld-ctf/data-func-conflicted.d: Likewise, and for the func info section too. * testsuite/ld-ctf/function.d: Likewise, for the func info section.
2021-03-22Add startswith function and use it instead of CONST_STRNEQ.Martin Liska15-33/+58
bfd/ChangeLog: * bfd-in.h (startswith): Add startswith function. (CONST_STRNEQ): Remove. * bfd-in2.h (startswith): Regenerate with make headers. * archive.c (bfd_slurp_armap): Replace usage of CONST_STRNEQ with startswith. (_bfd_slurp_extended_name_table): Likewise. * archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise. * bfd.c (bfd_get_sign_extend_vma): Likewise. (bfd_convert_section_size): Likewise. (bfd_convert_section_contents): Likewise. * coff-stgo32.c (go32exe_create_stub): Likewise. (go32exe_check_format): Likewise. * coffcode.h (styp_to_sec_flags): Likewise. (GNU_DEBUGALTLINK): Likewise. * coffgen.c (_bfd_coff_section_already_linked): Likewise. (coff_gc_sweep): Likewise. (bfd_coff_gc_sections): Likewise. * cofflink.c (coff_link_add_symbols): Likewise. (process_embedded_commands): Likewise. * compress.c (bfd_is_section_compressed_with_header): Likewise. (bfd_init_section_decompress_status): Likewise. * dwarf2.c (find_debug_info): Likewise. (place_sections): Likewise. * ecoff.c (_bfd_ecoff_slurp_armap): Likewise. * elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Likewise. * elf.c (_bfd_elf_make_section_from_shdr): Likewise. (assign_section_numbers): Likewise. (elfcore_grok_win32pstatus): Likewise. * elf32-arm.c (cmse_scan): Likewise. (elf32_arm_gc_mark_extra_sections): Likewise. (elf32_arm_size_dynamic_sections): Likewise. (is_arm_elf_unwind_section_name): Likewise. * elf32-bfin.c (bfin_size_dynamic_sections): Likewise. * elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise. * elf32-cris.c (elf_cris_size_dynamic_sections): Likewise. * elf32-csky.c (csky_elf_size_dynamic_sections): Likewise. * elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise. * elf32-iq2000.c (iq2000_elf_check_relocs): Likewise. * elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise. * elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise. * elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise. * elf32-metag.c (elf_metag_size_dynamic_sections): Likewise. * elf32-msp430.c (msp430_elf_relax_delete_bytes): Likewise. * elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise. * elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise. * elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise. * elf32-s390.c (elf_s390_size_dynamic_sections): Likewise. * elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise. * elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise. * elf32-sh.c (sh_elf_size_dynamic_sections): Likewise. * elf32-tic6x.c (is_tic6x_elf_unwind_section_name): Likewise. (elf32_tic6x_size_dynamic_sections): Likewise. * elf32-vax.c (elf_vax_size_dynamic_sections): Likewise. * elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise. (xtensa_is_insntable_section): Likewise. (xtensa_is_littable_section): Likewise. (xtensa_is_proptable_section): Likewise. (xtensa_property_section_name): Likewise. (xtensa_callback_required_dependence): Likewise. * elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise. * elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise. * elf64-ia64-vms.c (is_unwind_section_name): Likewise. (get_reloc_section): Likewise. (elf64_ia64_size_dynamic_sections): Likewise. (elf64_ia64_object_p): Likewise. * elf64-mmix.c (mmix_elf_add_symbol_hook): Likewise. * elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise. * elf64-s390.c (elf_s390_size_dynamic_sections): Likewise. * elflink.c (elf_link_add_object_symbols): Likewise. (_bfd_elf_gc_mark_extra_sections): Likewise. (bfd_elf_parse_eh_frame_entries): Likewise. (_bfd_elf_section_already_linked): Likewise. * elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise. * elfnn-ia64.c (is_unwind_section_name): Likewise. (elfNN_ia64_size_dynamic_sections): Likewise. (elfNN_ia64_object_p): Likewise. * elfxx-mips.c (FN_STUB_P): Likewise. (CALL_STUB_P): Likewise. (CALL_FP_STUB_P): Likewise. (_bfd_mips_elf_section_from_shdr): Likewise. (_bfd_mips_elf_fake_sections): Likewise. (_bfd_mips_elf_size_dynamic_sections): Likewise. (_bfd_mips_final_write_processing): Likewise. (_bfd_mips_elf_final_link): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise. * elfxx-x86.c (elf_i386_is_reloc_section): Likewise. (elf_x86_64_is_reloc_section): Likewise. * hpux-core.c (thread_section_p): Likewise. * libcoff.h (bfd_pei_p): Likewise. * linker.c (REAL): Likewise. (unwrap_hash_lookup): Likewise. (_bfd_generic_link_add_one_symbol): Likewise. * mmo.c (mmo_internal_write_section): Likewise. * osf-core.c (osf_core_core_file_p): Likewise. * pef.c (bfd_pef_print_symbol): Likewise. * pei-x86_64.c (pex64_print_all_pdata_sections): Likewise. * som.c (som_slurp_symbol_table): Likewise. (som_slurp_armap): Likewise. * wasm-module.c (wasm_compute_custom_section_file_position): Likewise. binutils/ChangeLog: * dlltool.c (scan_drectve_symbols): Replace usage of CONST_STRNEQ with startswith. * emul_aix.c (ar_emul_aix_parse_arg): Likewise. * objcopy.c (is_mergeable_note_section): Likewise. * objdump.c (dump_dwarf_section): Likewise. * prdbg.c (pr_method_type): Likewise. (pr_class_baseclass): Likewise. (tg_class_baseclass): Likewise. * readelf.c (process_lto_symbol_tables): Likewise. * stabs.c (ULLHIGH): Likewise. (parse_stab_argtypes): Likewise. (stab_demangle_function_name): Likewise. gas/ChangeLog: * config/tc-i386.c (md_parse_option): Replace usage of CONST_STRNEQ with startswith. (x86_64_section_word): Likewise. * config/tc-sparc.c (md_parse_option): Likewise. gdb/ChangeLog: * arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith. (_initialize_arm_tdep): Likewise. ld/ChangeLog: * emultempl/aix.em: Replace usage of CONST_STRNEQ with startswith. * emultempl/beos.em: Likewise. * emultempl/elf.em: Likewise. * emultempl/pe.em: Likewise. * emultempl/pep.em: Likewise. * emultempl/xtensaelf.em: Likewise. * ldctor.c (ctor_prio): Likewise. * ldelf.c (ldelf_try_needed): Likewise. (ldelf_parse_ld_so_conf): Likewise. (ldelf_after_open): Likewise. (output_rel_find): Likewise. (ldelf_place_orphan): Likewise. * ldfile.c (ldfile_add_library_path): Likewise. * ldlang.c (lang_add_input_file): Likewise. * ldmain.c (get_sysroot): Likewise. (get_emulation): Likewise. (add_archive_element): Likewise. * ldwrite.c (unsplittable_name): Likewise. (clone_section): Likewise. * lexsup.c (parse_args): Likewise. * pe-dll.c (is_import): Likewise. (pe_implied_import_dll): Likewise. opcodes/ChangeLog: * aarch64-dis.c (parse_aarch64_dis_option): Replace usage of CONST_STRNEQ with startswith. * arc-dis.c (parse_option): Likewise. * arm-dis.c (parse_arm_disassembler_options): Likewise. * cris-dis.c (print_with_operands): Likewise. * h8300-dis.c (bfd_h8_disassemble): Likewise. * i386-dis.c (print_insn): Likewise. * ia64-gen.c (fetch_insn_class): Likewise. (parse_resource_users): Likewise. (in_iclass): Likewise. (lookup_specifier): Likewise. (insert_opcode_dependencies): Likewise. * mips-dis.c (parse_mips_ase_option): Likewise. (parse_mips_dis_option): Likewise. * s390-dis.c (disassemble_init_s390): Likewise. * wasm32-dis.c (parse_wasm32_disassembler_options): Likewise.
2021-03-19x86-64: Add a testcase for PR ld/27590H.J. Lu5-0/+24
PR ld/27590 * testsuite/ld-x86-64/pr27590.rd: New file. * testsuite/ld-x86-64/pr27590a.obj.bz2: Likewise. * testsuite/ld-x86-64/pr27590b.obj.bz2: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run ld/27590 test.
2021-03-20DWARF LTO debug sections vs. .stabstrAlan Modra2-2/+9
The exception for debug sections in clearing SEC_EXCLUDE when relocatable was really for one specific debug section, so let's make it do just that. bfd/ PR 27590 * elf.c (_bfd_elf_make_section_from_shdr): Remove SHF_EXCLUDE test for .gnu.debuglto*. ld/ PR 27590 * ldlang.c (lang_gc_sections): Clear SEC_EXCLUDE when relocatable for all sections except .stabstr.
2021-03-19pr27590 testcase fixesAlan Modra3-4/+15
PR 27590 * testsuite/ld-elf/pr27590a.d: Match relocs using label, and R_MIPS_NONE. * testsuite/ld-elf/pr27590b.d: Likewise.
2021-03-18elf: Handle .gnu.debuglto_.debug_* sectionsH.J. Lu5-2/+42
commit 994b25132814f4c2be93ce53a616a74139c4cf3c Author: H.J. Lu <hjl.tools@gmail.com> Date: Sun Jan 17 20:01:16 2021 -0800 ld/elf: Ignore section symbols when matching linkonce with comdat ignored section symbols when comparing symbols in 2 sections. Since all references to debugging sections are done with section symbols, symbols in debugging sections are ignored and we fail to match symbols in comdat debugging sections. Also .gnu.debuglto_.debug_* sections aren't treated as debugging sections. 1. Treate .gnu.debuglto_.debug_ section as debugging section unless it is marked with SHF_EXCLUDE. 2. Revert commit 994b2513281 in elf_create_symbuf. 3. Ignore section symbols only when matching non-debugging sections or linkonce section with comdat section. bfd/ PR ld/27590 * elf.c (_bfd_elf_make_section_from_shdr): Treate .gnu.debuglto_.debug_ section as debugging section unless it is marked with SHF_EXCLUDE. * elflink.c (elf_create_symbuf): Revert commit 994b2513281. (bfd_elf_match_symbols_in_sections): Ignore section symbols when matching non-debugging sections or linkonce section with comdat section. ld/ PR ld/27590 * testsuite/ld-elf/pr27590.s: New file. * testsuite/ld-elf/pr27590a.d: Likewise. * testsuite/ld-elf/pr27590b.d: Likewise. * testsuite/ld-i386/i386.exp: Also run ld/27193 test with --reduce-memory-overheads.
2021-03-18DWARF: Check version >= 3 for DW_FORM_ref_addrH.J. Lu5-0/+16
Check version >= 3, instead of version == 3 || version == 4, for DW_FORM_ref_addr. bfd/ PR ld/27587 * dwarf2.c (read_attribute_value): Check version >= 3 for DW_FORM_ref_addr. ld/ PR ld/27587 * testsuite/ld-x86-64/pr27587.err: New file. * testsuite/ld-x86-64/pr27587a.obj.bz2: Likewise. * testsuite/ld-x86-64/pr27587b.obj.bz2: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run PR ld/27587 test.
2021-03-18libctf: support encodings for enumsNick Alcock3-2/+10
The previous commit started to error-check the lookup of ctf_type_encoding for the underlying type that is internally done when carrying out a ctf_type_encoding on a slice. Unfortunately, enums have no encoding, so this has historically been returning an error (which is ignored) and then populating the cte_format with uninitialized data. Now the error is not ignored, this is returning an error, which breaks linking of CTF containing bitfields of enumerated type. CTF format v3 does not record the actual underlying type of a enum, but we can mock up something that is not *too* wrong, and that is at any rate better than uninitialized data. ld/ChangeLog 2021-03-18 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/slice.c: Check slices of enums too. * testsuite/ld-ctf/slice.d: Results adjusted. libctf/ChangeLog 2021-03-18 Nick Alcock <nick.alcock@oracle.com> * ctf-types.c (ctf_type_encoding): Support, after a fashion, for enums. * ctf-dump.c (ctf_dump_format_type): Do not report enums' degenerate encoding.
2021-03-16Fix potentially undefined behaviour use of strcpcy.Nick Clifton2-1/+8
* pe-dll.c (pe_find_cdecl_alias_match): Use memmove to overwrite lname string.
2021-03-15ld: don't chance overrunning PE .reloc section contentJan Beulich2-3/+4
The allocation of reloc_d doesn't take reloc_s->size into account. There is already padding being emitted up to the allocated size. While reloc_s->size ought to still be zero at this point anyway (and hence the code being deleted would have been just dead), don't risk writing past the actual allocation.
2021-03-12riscv --enable-targets=all on 32-bit hostAlan Modra3-12/+18
Attempting to build --enable-targets=all on a 32-bit host results in a number of errors like the following. eelf32lriscv.o: in function `gldelf32lriscv_after_allocation': eelf32lriscv.c:98: undefined reference to `bfd_elf32_riscv_restart_relax_sections' That's due to needing --enable-64-bit-bfd to get the riscv BFD support built. * Makefile.am (ALL_EMULATION_SOURCES): Move riscv files to.. (ALL_64_EMULATION_SOURCES): ..here. * Makefile.in: Regenerate.
2021-03-12aix: implement TLS relocation for gas and ldClément Chigot12-1/+264
Add support for TLS in XCOFF. Amongst the things done by this commit: - Update XCOFF auxialiary header to match new version and allow TLS sections. - Add TLS sections (.tdata and .tbss) support in gas and ld. - Add support for the TLS relocations in gas and ld. Two different types BFD_RELOC are created for PPC and PPC64 as the size is a pointer, thus distinct in 32 or 64bit. The addresses given by ld to .tdata and .tbss is a bit special. In XCOFF, these addresses are actually offsets from the TLS pointer computed at runtime. AIX assembly and linker does the same. In top of that, the .tdata must be before .data (this is mandatory for AIX loader). Thus, the aix ld script is recomputing "." before .data to restore its original value. There might be a simpler way, but this one is working. Optimisation linked to TLS relocations aren't yet implemented. bfd/ * reloc.c (BFD_RELOC_PPC_TLS_LE, BFD_RELOC_PPC_TLS_IE, BFD_RELOC_PPC_TLS_M, BFD_RELOC_PPC_TLS_ML, BFD_RELOC_PPC64_TLS_GD, BFD_RELOC_PPC64_TLS_LD, BFD_RELOC_PPC64_TLS_LE, BFD_RELOC_PPC64_TLS_IE, BFD_RELOC_PPC64_TLS_M, BFD_RELOC_PPC64_TLS_ML): New relocations. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * coff-rs6000.c (xcoff_calculate_relocation): Call xcoff_reloc_type_tls for TLS relocations. (xcoff_howto_table): Implement TLS relocations. (_bfd_xcoff_reloc_type_lookup): Add cases TLS relocations. (xcoff_reloc_type_tls): New function. * coff64-rs6000.c (xcoff_calculate_relocation): Likewise. (xcoff_howto_table): Likewise. (_bfd_xcoff_reloc_type_lookup): Likewise. * coffcode.h (sec_to_styp_flags): Handle TLS sections. (styp_to_sec_flags): Likewise. (coff_compute_section_file_positions): Avoid file offset optimisation for .data when the previous section is .tdata. (coff_write_object_contents): Handle TLS sections. * coffswap.h (coff_swap_aouthdr_out): Add support for new fields in aouthdr. * libxcoff.h (xcoff_reloc_type_tls): Add prototype. * xcofflink.c (xcoff_link_add_symbols): Handle XMC_UL. (xcoff_need_ldrel_p): Add cases for TLS relocations. (xcoff_create_ldrel): Add l_symndx for TLS sections. gas/ * config/tc-ppc.c (ppc_xcoff_text_section, ppc_xcoff_data_section, (ppc_xcoff_bss_section, ppc_xcoff_tdata_section, (ppc_xcoff_tbss_section): New variables. (ppc_text_subsegment, ppc_text_csects, ppc_data_subgments, (ppc_data_csects): Removed. (ppc_xcoff_section_is_initialized, ppc_init_xcoff_section, ppc_xcoff_parse_cons): New functions. (md_being): Initialize XCOFF sections. (ppc_xcoff_suffix): Add support for TLS relocations (fixup_size, md_apply_fix): Add support for new BFD_RELOC. (ppc_change_csect): Handle XMC_TL, XMC_UL. Correctly, add XMC_BS to .bss section. Handle new XCOFF section variables. (ppc_comm): Likewise. (ppc_toc): Likewise. (ppc_symbol_new_hook): Likewise. (ppc_frob_symbol): Likewise. (ppc_fix_adjustable): Add tbss support. * config/tc-ppc.h (TC_PARSE_CONS_EXPRESSION): New define. (ppc_xcoff_parse_cons): Add prototype. (struct ppc_xcoff_section): New structure. ld/ * emultempl/aix.em: Ensure .tdata section is removed if empty, even with -r flag. * scripttempl/aix.sc: Handle TLS sections. * testsuite/ld-powerpc/aix52.exp: Add new tests. * testsuite/ld-powerpc/aix-tls-reloc-32.d: New test. * testsuite/ld-powerpc/aix-tls-reloc-64.d: New test. * testsuite/ld-powerpc/aix-tls-reloc.ex: New test. * testsuite/ld-powerpc/aix-tls-reloc.s: New test. * testsuite/ld-powerpc/aix-tls-section-32.d: New test. * testsuite/ld-powerpc/aix-tls-section-64.d: New test. * testsuite/ld-powerpc/aix-tls-section.ex: New test. * testsuite/ld-powerpc/aix-tls-section.s: New test. include/ * coff/internal.h (struct internal_aouthdr): Add new fields. * coff/rs6000.h (AOUTHDRÃ): Add new fields. * coff/rs6k64.h (struct external_filehdr): Likewise. * coff/xcoff.h (_TDATA), _TBSS): New defines (RS6K_AOUTHDR_TLS_LE, RS6K_AOUTHDR_RAS, RS6K_AOUTHDR_ALGNTDATA, RS6K_AOUTHDR_SHR_SYMTAB, RS6K_AOUTHDR_FORK_POLICY, RS6K_AOUTHDR_FORK_COR): New defines. (XMC_TU): Removed. (XMC_UL): New define.
2021-03-12aix: implement R_TOCU and R_TOCL relocationsClément Chigot7-0/+94
Implement support for largetoc on XCOFF. R_TOCU and R_TOCL are referenced by the new BFD defines: BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO. A new toc storage class is added XMC_TE. In order to correctly handle R_TOCU, the logic behind xcoff_reloc_type_toc is changed to compute the whole TOC offset instead of just the difference between the "link" offset and the "assembly" offset. In gas, add a function to transform addis format used by AIX "addis RT, D(RA)" into the ELF format "addis RT, RA, SI". bfd/ * reloc.c (BFD_RELOC_PPC_TOC16_HI, BFD_RELOC_PPC_TOC16_LO): New relocations. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * coff-rs6000.c (xcoff_calculate_relocation): Call xcoff_reloc_type_toc for R_TOCU and R_TOCL. (xcoff_howto_table): Remove src_mask for TOC relocations. Add R_TOCU and R_TOCL howtos. (_bfd_xcoff_reloc_type_lookup): Add cases for BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO. (xcoff_reloc_type_toc): Compute the whole offset. Implement R_TOCU and R_TOCL. * coff64-rs6000.c (xcoff64_calculate_relocation): Likewise. (xcoff64_howto_table): Likewise. (xcoff64_reloc_type_lookup): Likewise. gas/ * config/tc-ppc.c (ppc_xcoff_suffix): New function. (MAP, MAP32, MAP64): New macros for XCOFF. (ppc_xcoff_fixup_addis): New function. (ppc_is_toc_sym): Handle XMC_TE. (fixup_size): Add cases for BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO. (md_assemble): Call ppc_xcoff_fixup_addis for XCOFF. (ppc_change_csect): Handle XMC_TE. (ppc_tc): Enable .tc symbols to have only a XMC_TC or XMC_TE storage class. (ppc_symbol_new_hook): Handle XMC_TE. (ppc_frob_symbol): Likewise. (ppc_fix_adjustable): Likewise. (md_apply_fix): Handle BFD_RELOC_PPC_TOC16_HI and BFD_RELOC_PPC_TOC16_LO. ld/ * scripttempl/aix.sc: Add .te to .data section. * testsuite/ld-powerpc/aix52.exp: Add test structure for AIX7+. Add aix-largetoc-1 test. * testsuite/ld-powerpc/aix-largetoc-1-32.d: New test. * testsuite/ld-powerpc/aix-largetoc-1-64.d: New test. * testsuite/ld-powerpc/aix-largetoc-1.ex: New test. * testsuite/ld-powerpc/aix-largetoc-1.s: New test.
2021-03-12PE image base falloutAlan Modra7-21/+53
Fixes x86_64-w64-mingw32 tests that failed with the recent diagnosis for out of range RVA, and a couple of other gc-sections tests that failed for other reasons. * testsuite/ld-gc/gc.exp: Pass "-image-base 0" to ld for PE, and arrange to define __main for some run_dump_test tests. * testsuite/ld-gc/pr13683.d: Accept more symbols. * testsuite/ld-gc/pr14265.d: Likewise, and ordering. * testsuite/ld-scripts/crossref.exp: Pass "-image-base 0" to ld for PE. * testsuite/ld-srec/srec.exp: Likewise. * testsuite/lib/ld-lib.exp (ld_link_defsyms): Use is_pecoff_format.
2021-03-11RISC-V: Improve multiple relax passes problem.Nelson Chu5-1/+47
According to the commit abd20cb637008da9d32018b4b03973e119388a0a, an intersting thing is that - the more relax passes, the more chances of relaxations are reduced [1]. Originally, we set the boolean `again` to TRUE once the code is actually deleted, and then we run the relaxations repeatedly if `again` is still TRUE. But `again` only works for the relax pass itself, and won't affect others. That is - we can not use `again` to re-run the relax pass when we already enter into the following passes (can not run the relax passes backwards). Besides, we must seperate the PCREL relaxations into two relax passes for some reasons [2], it make us lose some relax opportunities. This patch try to fix the problem, and the basic idea was come from Jim Wilson - we use a new boolean, restart_relax, to determine if we need to run the whole relax passes again from 0 to 2. Once we have deleted the code between relax pass 0 to 2, the restart_relax will be set to TRUE, we should run the whole relaxations again to give them more chances to shorten the code. We will only enter into the relax pass 3 when the restart_relax is FALSE, since we can't relax anything else once we start to handle the alignments. I have passed the gcc/binutils regressions by riscv-gnu-toolchain, and looks fine for now. [1] https://sourceware.org/pipermail/binutils/2020-November/114223.html [2] https://sourceware.org/pipermail/binutils/2020-November/114235.html bfd/ * elfnn-riscv.c (riscv_elf_link_hash_table): New boolean restart_relax, used to check if we need to run the whole relaxations from relax pass 0 to 2 again. (riscv_elf_link_hash_table_create): Init restart_relax to FALSE. (_bfd_riscv_relax_align): Remove obsolete sec_flg0 set. (_bfd_riscv_relax_delete): Set again to TRUE if we do delete the code. (bfd_elfNN_riscv_restart_relax_sections): New function. Called by after_allocation to check if we need to run the whole relaxations again. (_bfd_riscv_relax_section): We will only enter into the relax pass 3 when the restart_relax is FALSE; At last set restart_relax to TRUE if again is TRUE, too. * elfxx-riscv.h (bfd_elf32_riscv_restart_relax_sections): Declaration. (bfd_elf64_riscv_restart_relax_sections): Likewise. ld/ * emultempl/riscvelf.em (after_allocation): Run ldelf_map_segments many times if riscv_restart_relax_sections returns TRUE. * testsuite/ld-riscv-elf/restart-relax.d: New testcase. Before applying this patch, the call won't be relaxed to jal; But now we have more chances to do relaxations. * testsuite/ld-riscv-elf/restart-relax.s: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2021-03-10bfd: strip symbols not representable in COFF/PE symbol tableJan Beulich4-4/+11
The offset-within-section field in the symbol table entry is only 32 bits wide, so rather than emitting bogus entries omit them, and issue a diagnostic identifying the issue. This requires adjusting the PR/22267 test to no longer produce symbols with out of range values on 64-bit BFD. This also depends on adjustments to testsuite/ld-scripts/map-address.* made by an earlier patch. The purpose of the test can very well be achieved nevertheless.
2021-03-09ld: adjust PE base relocations testcaseJan Beulich3-1/+15
mcore-pe and sh-pe pointed out that the testcase added by 6fa7408d72b3 ("ld: don't generate base relocations in PE output for absolute symbols") wasn't quite generic enough yet. Copy entry point stuff from another test and increase alignment to also cover targets with a page size lower than 4k. Despite all of this the test needs to be xfail-ed for mcore, as this target isn't included in the set getting DLL_SUPPORT enabled in emultempl/pe.em, and hence no base relocations get generated there (yet).
2021-03-09bfd: don't silently wrap or truncate PE image section RVAsJan Beulich12-14/+58
In PE images section addresses get expressed as addresses relative to the image base. Therefore the VA of a section must be no less than the image base, and after subtraction of the image base the resulting value should fit in 32 bits. (The issue is particularly obvious to notice when sections, perhaps because of ELF assumptions, get placed at VA 0 by default. Debugging info sections as well as .comment, when input files are ELF, are a good example. All such sections need proper mentioning in the linker script to avoid this warning.) There are a number of test cases which previously produced bogus images, yet still declared the test a success. Like done for other tests already, force a zero image base for these. This then also allows (and requires) dropping again xfail-s which 39a7b38fac0e ("Fix linker tests to work with 16-bit targets") had added to ld-scripts/default-script*.d (originally as skip-s). This also depends on similar adjustments to testsuite/ld-scripts/map-address.* made by an earlier patch. For ld-scripts/print-memory-usage.* I suppose xcoff could be dropped from the exclusion list by suppressing garbage collection, just like already done in e.g. (as seen in the diff here) ld-scripts/data.*, but I didn't want to make unrelated adjustments.
2021-03-05elf/x86-64: Subtract __ImageBase for R_AMD64_IMAGEBASEH.J. Lu13-2/+135
When linking Windows x86-64 relocatable object files to generate x86-64 ELF executable, we need to subtract __ImageBase, aka __executable_start, for R_AMD64_IMAGEBASE relocation: 1. Add link_info to struct output_elf_obj_tdata to store linker info and _bfd_get_link_info() to retrieve it. 2. Add ldelf_set_output_arch to set up link_info. 3. Add pex64_link_add_symbols to create an indirect reference to __executable_start for __ImageBase to support R_AMD64_IMAGEBASE relocation when adding symbols from Windows x86-64 relocatable object files to generate x86-64 ELF executable. 4. Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. bfd/ PR ld/27425 PR ld/27432 * bfd.c (_bfd_get_link_info): New function. * elf-bfd.h (output_elf_obj_tdata): Add link_info. (elf_link_info): New. * libbfd-in.h (_bfd_get_link_info): New prototype. * coff-x86_64.c (coff_amd64_reloc): Also subtract __ImageBase for R_AMD64_IMAGEBASE when generating x86-64 ELF executable. * pe-x86_64.c: Include "coff/internal.h" and "libcoff.h". (pex64_link_add_symbols): New function. (coff_bfd_link_add_symbols): New macro. * libbfd.h: Regenerated. ld/ PR ld/27425 PR ld/27432 * ldelf.c (ldelf_set_output_arch): New function. * ldelf.h (ldelf_set_output_arch): New prototype. * emultempl/elf.em (LDEMUL_SET_OUTPUT_ARCH): Default to ldelf_set_output_arch. * ld-x86-64/pe-x86-64-1.od: Expect __executable_start. * testsuite/ld-x86-64/pe-x86-64-2.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-3.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-4.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.od: Likewise. * testsuite/ld-x86-64/pe-x86-64-5.rd: Likewise. * testsuite/ld-x86-64/pe-x86-64-6.obj.bz2: New file. * testsuite/ld-x86-64/pe-x86-64-6.od: Likewise. * testsuite/ld-x86-64/pe-x86-64.exp: Run ld/27425 test.
2021-03-04ld: adjust ld-scripts/map-address.*Jan Beulich3-4/+19
Without setting an image base address and without naming at least .text, this test produces entirely bogus PE output. To be honest, even the ELF output looks odd: .text gets placed at 0x10204, and both foo and bar get associated with .text despite living below its start address. Since neither image base nor .text placement are the subject of this test, specify .text placement explicitly and in the PE case force the image base to zero.
2021-03-04ld: don't generate base relocations in PE output for absolute symbolsJan Beulich7-3/+69
It is the very nature of absolute symbols that they don't change even if the loader decides to put the image at other than its link-time base address. Of the linker-defined (and PE-specific) symbols __image_base__ (and its alias) needs special casing, as it'll still appear to be absolute at this point. A new inquiry function in ldexp.c is needed because PE base relocations get generated before ldexp_finalize_syms() runs, yet whether a relocation is needed depends on the ultimate property of a symbol.
2021-03-03--gc-sections with groups and start/stop symsAlan Modra7-2/+99
The testcases added here show situations where synthesized start/stop symbols don't cause their associated input sections to be marked. Fixed with the elflink.c and ldlang.c changes. bfd/ PR 27500 * elflink.c (_bfd_elf_gc_mark_rsec): Do special start/stop processing not when start/stop symbol section is unmarked but on first time a start/stop symbol is processed. ld/ * ldlang.c (insert_undefined): Don't mark symbols here. (lang_mark_undefineds): Do so here instead, new function. (lang_process): Call lang_mark_undefineds. * testsuite/ld-gc/start3.d, * testsuite/ld-gc/start3.s: New test. * testsuite/ld-gc/start4.d, * testsuite/ld-gc/start4.s: New test. * testsuite/ld-gc/gc.exp: Run them.
2021-03-03ld-gc tests on underscore targetsAlan Modra10-18/+48
Adjust tests to reference __start and __stop syms with an extra leading underscore when appropriate, and run tests on more targets. * testsuite/ld-gc/gc.exp: Define UNDERSCORE in ASFLAGS. Move tests with ELF section directives to is_elf_format block. * testsuite/ld-gc/abi-note.d: Run on more targets. * testsuite/ld-gc/pr19167.d: Likewise and adjust xfails. * testsuite/ld-gc/start.d: Likewise. * testsuite/ld-gc/start2.d: Likewise. * testsuite/ld-gc/stop.d: Likewise. * testsuite/ld-gc/pr19167a.s: Add support for underscore targets. * testsuite/ld-gc/start.s: Likewise. * testsuite/ld-gc/start2.s: Likewise.
2021-03-02bfd, ld, libctf: skip zero-refcount strings in CTF string reportingNick Alcock2-4/+15
This is a tricky one. BFD, on the linker's behalf, reports symbols to libctf via the ctf_new_symbol and ctf_new_dynsym callbacks, which ultimately call ctf_link_add_linker_symbol. But while this happens after strtab offsets are finalized, it happens before the .dynstr is actually laid out, so we can't iterate over it at this stage and it is not clear what the reported symbols are actually called. So a second callback, examine_strtab, is called after the .dynstr is finalized, which calls ctf_link_add_strtab and ultimately leads to ldelf_ctf_strtab_iter_cb being called back repeatedly until the offsets of every string in the .dynstr is passed to libctf. libctf can then use this to get symbol names out of the input (which usually stores symbol types in the form of a name -> type mapping at this stage) and extract the types of those symbols, feeding them back into their final form as a 1:1 association with the real symtab's STT_OBJ and STT_FUNC symbols (with a few skipped, see ctf_symtab_skippable). This representation is compact, but has one problem: if libctf somehow gets confused about the st_type of a symbol, it'll stick an entry into the function symtypetab when it should put it into the object symtypetab, or vice versa, and *every symbol from that one on* will have the wrong CTF type because it's actually looking up the type for a different symbol. And we have just such a bug. ctf_link_add_strtab was not taking the refcounts of strings into consideration, so even strings that had been eliminated from the strtab by virtue of being in objects eliminated via --as-needed etc were being reported. This is harmful because it can lead to multiple strings with the same apparent offset, and if the last duplicate to be reported relates to an eliminated symbol, we look up the wrong symbol from the input and gets its type wrong: if it's unlucky and the eliminated symbol is also of the wrong st_type, we will end up with a corrupted symtypetab. Thankfully the wrong-st_type case is already diagnosed by a this-can-never-happen paranoid warning: CTF warning: Symbol 61a added to CTF as a function but is of type 1 or the converse * CTF warning: Symbol a3 added to CTF as a data object but is of type 2 so at least we can tell when the corruption has spread to more than one symbol's type. Skipping zero-refcounted strings is easy: teach _bfd_elf_strtab_str to skip them, and ldelf_ctf_strtab_iter_cb to loop over skipped strings until it falls off the end or finds one that isn't skipped. bfd/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * elf-strtab.c (_bfd_elf_strtab_str): Skip strings with zero refcount. ld/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * ldelfgen.c (ldelf_ctf_strtab_iter_cb): Skip zero-refcount strings. libctf/ChangeLog 2021-03-02 Nick Alcock <nick.alcock@oracle.com> * ctf-create.c (symtypetab_density): Report the symbol name as well as index in the name != object error; note the likely consequences. * ctf-link.c (ctf_link_shuffle_syms): Report the symbol index as well as name.
2021-03-02PR27451, -z start_stop_gc for powerpc64Alan Modra5-0/+38
PowerPC64 has its own gc_mark_dynamic_ref. bfd/ PR 27451 * elf64-ppc.c (ppc64_elf_gc_mark_dynamic_ref): Ignore synthesized linker defined start/stop symbols when start_stop_gc. ld/ * testsuite/ld-powerpc/startstop.d, * testsuite/ld-powerpc/startstop.r, * testsuite/ld-powerpc/startstop.s: New test. * testsuite/ld-powerpc/powerpc.exp: Run it.
2021-03-02PowerPC64 undefined weak visibility vs GOT optimisationAlan Modra7-0/+101
Undefined weak symbols with non-default visibility are seen as local by SYMBOL_REFERENCES_LOCAL. This stops a got indirect to relative optimisation for them, so that pies and dlls don't get non-zero values when loading somewhere other than the address they are linked at (which always happens). The optimisation could be allowed for pdes, but I thought it best not to allow it there too. bfd/ * elf64-ppc.c (ppc64_elf_relocate_section): Don't optimise got indirect to pc-relative or toc-relative for undefined symbols. ld/ * testsuite/ld-powerpc/weak1.d, * testsuite/ld-powerpc/weak1.r, * testsuite/ld-powerpc/weak1.s, * testsuite/ld-powerpc/weak1so.d, * testsuite/ld-powerpc/weak1so.r: New tests. * testsuite/ld-powerpc/powerpc.exp: Run them.
2021-03-01Add DWARF-5 section names to PE and PEP linker scripts.Nick Clifton3-31/+144
PR 27268 * scripttempl/pe.sc: Add DWARF-5 section names. * scripttempl/pep.sc: Likewise.
2021-03-01PR27451, -z start_stop_gcAlan Modra9-2/+67
When --gc-sections is in effect, a reference from a retained section to __start_SECNAME or __stop_SECNAME causes all input sections named SECNAME to also be retained, if SECNAME is representable as a C identifier and either __start_SECNAME or __stop_SECNAME is synthesized by the linker. Add an option to disable that feature, effectively ignoring any relocation that references a synthesized linker defined __start_ or __stop_ symbol. PR 27451 include/ * bfdlink.h (struct bfd_link_info): Add start_stop_gc. bfd/ * elflink.c (_bfd_elf_gc_mark_rsec): Ignore synthesized linker defined start/stop symbols when start_stop_gc. (bfd_elf_gc_mark_dynamic_ref_symbol): Likewise. (bfd_elf_define_start_stop): Don't modify ldscript_def syms. * linker.c (bfd_generic_define_start_stop): Likewise. ld/ * emultempl/elf.em: Handle -z start-stop-gc and -z nostart-stop-gc. * lexsup.c (elf_static_list_options): Display help for them. Move help for -z stack-size to here from elf_shlib_list_options. Add help for -z start-stop-visibility and -z undefs. * ld.texi: Document -z start-stop-gc and -z nostart-stop-gc. * NEWS: Mention -z start-stop-gc. * testsuite/ld-gc/start2.s, * testsuite/ld-gc/start2.d: New test. * testsuite/ld-gc/gc.exp: Run it.
2021-03-01Weak references to __start_/__stop_ symbolsAlan Modra2-0/+19
If a weak reference to a __start_foo or __stop_foo symbol ends up having no definition due to all the foo sections being removed for some reason, undef_start_stop currently makes the symbol strong undefined. That risks a linker undefined symbol error. Fix that by making the symbol undefweak and also undo some dynamic symbol state. Note that saving the state of the symbol type at the time lang_init_start_stop runs is not sufficient. The linker may have merged in a shared library reference by that point and made what was an undefweak in regular objects, a strong undefined. So it is necessary to look at the ELF symbol flags to decide whether an undefweak is the proper resolution. Something probably should be done for COFF/PE too, but I'm unsure how to do go about that. * ldlang.c (undef_start_stop): For ELF make undefined start/stop symbols undefweak if that was how they were referenced. Undo dynamic state too.
2021-03-01PR27128, nm -P portable output format regressionAlan Modra7-6/+15
Add nm --without-symbol-versions. binutils/ PR 27128 * doc/binutils.texi: Add nm --with-symbol-versions and --without-symbol-versions documentation. * nm.c (with_symbol_versions): New variable. (enum long_option_values): Delete OPTION_WITH_SYMBOL_VERSIONS. (long_options): Make --with-symbol-versions entry twiddle the flag. Add --without-symbol-versions. (print_symname): Strip version when !with_symbol_versions. Add dynamic version info under control of with_symbol_versions. (main): Remove OPTION_WITH_SYMBOL_VERSIONS case. ld/ * testsuite/ld-elf/pr25708.d: Add --with-symbol-versions to nm. * testsuite/ld-elf/pr27128a.d: Likewise. * testsuite/ld-elf/pr27128b.d: Likewise. * testsuite/ld-elf/pr27128c.d: Likewise. * testsuite/ld-elf/pr27128d.d: Likewise. * testsuite/ld-elf/pr27128e.d: Likewise.
2021-02-26Add PR27441 testcaseAlan Modra6-0/+36
PR 27441 * testsuite/ld-plugin/pr27441a.c, * testsuite/ld-plugin/pr27441b.c, * testsuite/ld-plugin/pr27441c.c, * testsuite/ld-plugin/pr27441c.d: New test. * testsuite/ld-plugin/lto.exp: Run it.
2021-02-25ld: correct description of behavior for symbols redefined by scriptJan Beulich2-2/+6
Prior to 89753bbf8102 ("Warn when a script redefines a symbol") there was no diagnostic at all. As of that commit, it's a warning, not an error.
2021-02-21Warn when a script redefines a symbolAlan Modra4-9/+22
Note that we don't even warn if scripts adjust a symbol as in ld-elf/var1 and ld-scripts/pr14962. include/ * bfdlink.h (struct bfd_link_info): Add warn_multiple_definition. ld/ * ldexp.c (exp_fold_tree_1): Warn on script defining a symbol defined in an object file. * ldmain.c (multiple_definition): Heed info->warn_multiple_definition. * testsuite/ld-scripts/defined5.d: Expect a warning.
2021-02-20readelf: Replace procesor with processorH.J. Lu3-3/+3
binutils/ PR binutils/27445 * readelf.c (print_gnu_property_note): Replace procesor with processor. ld/ PR binutils/27445 * testsuite/ld-i386/property-x86-isa1.d: Replace procesor with processor. * testsuite/ld-x86-64/property-x86-isa1-x32.d: Likewise. * testsuite/ld-x86-64/property-x86-isa1.d: Likewise.
2021-02-19Wrong ELF class plugin vs. gcc ld versionAlan Modra2-72/+79
When building 32-bit binutils with CC="gcc -m32" CXX="g++ -m32" we can fail the gcc ld version test due to an error attempting to load a 64-bit plugin into 32-bit ld-new. This results in bogus errors about "Your compiler driver ignores -B when choosing ld." * testsuite/lib/ld-lib.exp: Whitespace. (load_common_lib): Expand single use and delete this proc. (run_host_cmd): Use -fno-lto when getting gcc's ld version. Use -B for clang too.
2021-02-18ld: remove stray debug fprintfAndrew Burgess2-4/+5
In this commit: commit ace667e59aede65c400381f1cff704b61e8ccb0b Date: Mon Jul 18 21:00:00 2016 +0100 ld: Restore file offset after a plugin fails to claim a file I inadvertently left in a stray fprintf call. Removed in this commit. ld/ChangeLog: * testplugin.c (record_read_length): Remove debug fprintf.