aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2023-08-28Re: comdat_hash memory leaksAlan Modra1-1/+2
I missed another field that needs freeing. Also, oss-fuzz found a case with a C_FILE sym using multiple auxents for a long file name which overflowed the single auxent buffer. I'm going to fix that problem in swap_aux_in too, but we may as well avoid it here too, saving unnecessary work. * coffcode.h (comdat_delf): Free comdat_name. (fill_comdat_hash): Only look at symbols with one auxent.
2023-08-27MIPS: Use 64-bit a ABI by default for `mipsisa64*-*-linux*' targetsYunQiang Su1-4/+4
Following the arrangement in GCC select a 64-bit ABI by default, either n32 or n64, rather than o32 for `mipsisa64*-*-linux*' targets, just as with the corresponding `mips64*-*-linux*' targets.
2023-08-28Automatic date update in version.inGDB Administrator1-1/+1
2023-08-27PE dos_messageAlan Modra4-32/+19
I was looking at dos_message and wondering why we have H_PUT_32 in _bfd_XXi_only_swap_filehdr_out but no H_GET_32 in pe_bfd_object_p. On a big-endian machine this would result in scrambling the code and strings constained in dos_message. Rather than fix the lack of H_GET_32 in pe_bfd_object_p, I decided it doesn't make sense to store dos_message internally as an array of ints. include/ * coff/internal.h (struct internal_extra_pe_filehdr): Make dos_message a char array. * coff/msdos.h (struct external_DOS_hdr): Flatten dos_message. * coff/pe.h (struct external_PEI_filehdr): Likewise. bfd/ * libcoff-in.h (struct pe_tdata): Make dos_message a char array. * libcoff.h: Regenerate. * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): memcpy dos_message to output. * peicode.h (pe_mkobject): Don't memset already zeroed pe_opthdr. Tidy allocation of tdata.pe_obj_data. Set up dos_message from.. (default_dos_message): ..this. New static array.
2023-08-27comdat_hash memory leaksAlan Modra2-17/+31
Entries added to the hash table with bfd_malloc ought to be freed when the hash table is deleted. This patch adds the necessary del_f to the htab_create call, and delays creating the table until an IMAGE_SCN_LNK_COMDAT symbol is read. * peicode.h (pe_mkobject): Move comdat_hash creation.. (htab_hash_flags, htab_eq_flags): ..and these support functions.. * coffcode.h (handle_COMDAT): ..to here, renaming support to (comdat_hashf, comdat_eqf): ..this and adding.. (comdat_delf): ..this new function.
2023-08-27Confusion in coff_object_cleanupAlan Modra2-11/+10
A bfd_cleanup function needs to run when only tdata is correct for the bfd. The xvec may have changed during bfd_check_format and thus the flavour may be incorrect. The format won't have changed but checking is superfluous. (In contrast to _bfd_free_cached_info or _close_and_cleanup where we do need to check things.) Not getting this correct leaked comdat_hash. Also, pe_ILF_cleanup ought to call coff_object_cleanup as do all PE files. * coffgen.c (coff_object_cleanup): Don't check bfd flavour or format. * peicode.h (pe_ILF_cleanup): Call coff_object_cleanup.
2023-08-27sanity check n_numauxAlan Modra1-90/+70
Sanity check aux entries used by PE to extend a C_FILE name. See coffswap.h:coff_swap_aux_in. The existing check only catered for n_numaux == 1. * coffcode.h (fill_comdat_hash): Properly sanity check n_numaux. Formatting. (handle_COMDAT): Formatting.
2023-08-27Automatic date update in version.inGDB Administrator1-1/+1
2023-08-26Automatic date update in version.inGDB Administrator1-1/+1
2023-08-25bfd: correct relocation handling for objcopy COFF -> ELFJan Beulich4-4/+14
While documented to not be reliable, it is still odd for objcopy to silently produce bad output when converting COFF/PE object files to ELF ones. The issue there is that relocation addends all are screwed up by subtracting the symbol's section offset. In the COFF/PE world, to my knowledge, section contents stores the addends alone, not the result of symbol value plus addend. Hence the compensation talked about in a comment ahead of the sole use site of CALC_ADDEND() may need to account for the VMA (which is always zero for object files anyway), but not for the symbol value. The coff-sh.c adjustment is based upon guessing that behavior there is the same. Note also how coff-aarch64.c short-circuits CALC_ADDEND() altogether, which may suggest that a much simpler macro might do for the COFF_WITH_PE case in the three arch-specific files touched here. For (at least) Arm/WinCE this actually results in more appropriate objdump output as well, as can be seen in the one testcase which has its expectations adjusted (the generated binary doesn't change).
2023-08-25som: buffer overflow writing stringsAlan Modra2-182/+99
Code in som_write_symbol_strings neglected to allow for padding, which can result in a buffer overflow. It also used xrealloc, which we're not supposed to use in libbfd because libbfd isn't supposed to call exit. Also a realloc is perhaps not a good idea when none of the buffer contents are needed, so replace with free, bfd_malloc. There were three copies of the string handling code, so rather than fix them all I've extracted them to a function. This necessitated making one of the fields in struct som_symbol unsigned. * som.c (add_string): New function. (som_write_space_strings, som_write_symbol_strings): Use it. * som.h (som_symbol_type <stringtab_offset>): Make unsigned.
2023-08-25Automatic date update in version.inGDB Administrator1-1/+1
2023-08-24optimize handle_COMDATOleg Tolmatcev5-193/+283
Signed-off-by: Oleg Tolmatcev <oleg.tolmatcev@gmail.com>
2023-08-24nds32, sh, kvx: DT_JMPREL/DT_PLTRELSZAlan Modra3-11/+10
As commit fa4f2d46f9 did for x86, there a few other targets that wrongly use the output section rather than the dynamic section for DT_JMPREL and others. * elfnn-kvx.c (elfNN_kvx_finish_dynamic_sections): Use input section for DT_JMPREL. * elf32-sh.c (sh_elf_finish_dynamic_sections): Use input section for DT_JMPREL and DT_PLTRELSZ. * elf32-nds32.c (nds32_elf_finish_dynamic_sections): Likewise, and for DT_PLTGOT and when adjusting DT_RELA.
2023-08-24kvx: bfd/config.bfd & ld/configure.tgtPaul Iannetta1-1/+1
bfd/ * config.bfd: Remove kvx_elf64_vec from targ_selvecs as it is already in targ_defvec. ld/ * configure.tgt: Split long line.
2023-08-24kvx: remove kvx_elf64_linux_vecPaul Iannetta2-2/+0
* configure.ac: Remove kvx_elf64_linux_vec. * configure: Regenerate.
2023-08-24Automatic date update in version.inGDB Administrator1-1/+1
2023-08-23x86: Fix DT_JMPREL/DT_PLTRELSZ when relocs share a sectionPeter Edwards1-2/+3
If a linker script does not place the PLT relocations and "normal" relocations in separate ELF sections, `ld` will currently output incorrect values for DT_JMPREL and DT_PLTRELSZ - they cover the entire ELF section, rather than just the PLT relocations Don't ignore the extent of the BFD section - use the size of the srelplt BFD section and its offset from the output_secttion bfd/ PR ld/30787 * elfxx-x86.c (_bfd_x86_elf_finish_dynamic_sections): Use input section for DT_JMPREL and DT_PLTRELSZ. ld/ PR ld/30787 * testsuite/ld-i386/i386.exp: Run pr30787. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr30787.d: New file. * testsuite/ld-i386/pr30787.s: Likewise. * testsuite/ld-i386/pr30787.t: Likewise. * testsuite/ld-x86-64/pr30787.d: Likewise. * testsuite/ld-x86-64/pr30787.s: Likewise. * testsuite/ld-x86-64/pr30787.t: Likewise.
2023-08-23kvx: fix 32-bit buildPaul Iannetta7-22/+16
bfd/ * Makefile.am: Move elf32-kvx.lo from BFD32_BACKENDS to BFD64_BACKENDS. Remove elfxx-kvx.lo from BFD32_BACKENDS. Remove elfxx-kvx.c from BFD32_BACKENDS_CFILES. * Makefile.in: Regenerate. * config.bfd: Adjust targ_defvec and targ_selvecs and gate them behind BFD64. * configure.ac: Add target_size=64 to kvx_elf64_*vec. * configure: Regenerate. * elfnn-kvx.c (elfNN_kvx_stub_name): Cast rel->r_addend to uint64_t to match format string. (elfNN_kvx_relocate_section): Similarly for r_offset, and use PRIx64 in format string. * targets.c (_bfd_target_vector <kvx_elf32_vec>): Move inside #ifdef BFD64. ld/ * Makefile.am: Move eelf32kvx.c from ALL_EMULATION_SOURCES to ALL_64_EMULATION_SOURCES. * Makefile.in: Regenerate.
2023-08-23kvx bfd signed calculations and _bfd_kvx_elf_resolve_relocationAlan Modra3-46/+20
It is generally a good idea to avoid signed arithmetic on values extracted from object files, to avoid ubsan warnings on overflow. This patch replaces some uses of bfd_signed_vma in the kvx backend with bfd_vma, and removes _bfd_kvx_elf_resolve_relocation, a do-nothing function. In the process of making this patch I noticed some dead code in the GOT entry handling, setting value to got_entry_addr but using "off" in the _bfd_final_link_relocate call. Since kvx_calculate_got_entry_vma also returns the GOT offset, I presume the code is correct, but I've left the dead code and comment there. * elfxx-kvx.h (_bfd_kvx_elf_resolve_relocation): Delete. * elfxx-kvx.c (kvx_signed_overflow): Rewrite using unsigned arithmetic. (_bfd_kvx_elf_resolve_relocation): Delete. * elfnn-kvx.c (kvx_relocate): Update for _bfd_kvx_elf_resolve_relocation removal. (elfNN_kvx_final_link_relocate): Likewise. Don't use a signed addend.
2023-08-23bfd kvx formatting fixesAlan Modra2-403/+390
Indentation, whitespace and comment fixes. * elfnn-kvx.c: Formatting. * elfxx-kvx.c: Formatting. (elfNN_kvx_final_link_relocate): Correct GOT entry comment.
2023-08-23bfd_get_symbol_leading_char vs. ""Alan Modra2-4/+8
Some places matching the first char of a string against bfd_get_symbol_leading_char, which may be zero, didn't check for the string being "". This patch adds the check to stop accesses past the end of the string and potential buffer overruns. The dlltool one was found by oss-fuzz quite a while ago. bfd/ * cofflink.c (_bfd_coff_link_input_bfd): Ensure a zero bfd_get_symbol_leading_char doesn't lead to accessing past the zero string terminator. * linker.c (bfd_wrapped_link_hash_lookup): Likewise. (unwrap_hash_lookup): Likewise. binutils/ * dlltool.c (scan_filtered_symbols): Ensure a zero bfd_get_symbol_leading_char doesn't lead to accessing past the zero string terminator.
2023-08-23Automatic date update in version.inGDB Administrator1-1/+1
2023-08-22kvx-linux configAlan Modra1-1/+1
A misplaced line, resulting in testsuite errors when attempting to use as -m32. * config.bfd (kvx-*-linux*): Add targ_selvecs. (kvx-*-*): Remove targ_selvecs.
2023-08-22Automatic date update in version.inGDB Administrator1-1/+1
2023-08-21aarch64/sme2: Teach binutils/BFD about the NT_ARM_ZT register setLuis Machado2-0/+39
The Scalable Matrix Extension v2 (SME2) defines a new register, ZT0, that the Linux Kernel handles through a new NT_ARM_ZT register set. Teach binutils/BFD about it so that gdb can make use of it for reading and writing core files. This also enables readelf/objdump to show the correct identification for the NT_ARM_ZT register set. Validated under Fast Models.
2023-08-21aarch64/sme: Core file supportEzra Sitorus2-0/+62
Add required code to support core file dumps with NT_ARM_ZA and NT_ARM_SSVE register sets in them. These new register sets are dumped when SME is supported.
2023-08-21bfd_close_all_done bug and bfd_last_cacheAlan Modra2-7/+6
bfd_close ought to always call iovec->bclose so that cache_bclose is called. If not, bfd_last_cache will be left pointing at freed memory. This bug was found by oss-fuzz with the trigger being an old bug in the ia64-vms support. Given a file of the "wrong" size, elf64_vms_close_and_cleanup attempted to extend it, leading to an error since the file was opened read-only by nm. nm bad_file bad_file then hit the use-after-free when opening the second file. commit 8219cab3f8 fixed multiple bugs of this type in bfd_close and bfd_close_all_done, but didn't go quite far enough. * elf64-ia64-vms.c (elf64_vms_close_and_cleanup): Don't attempt to extend read-only files. * opncls.c (bfd_close_all_done): Always call _close_and_cleanup. An old bug in the ia64-vms support can be used to tickle another bug in bfd_close_all_done. If _close_and_cleanup returns an error,
2023-08-21Automatic date update in version.inGDB Administrator1-1/+1
2023-08-20Automatic date update in version.inGDB Administrator1-1/+1
2023-08-19Automatic date update in version.inGDB Administrator1-1/+1
2023-08-18RISC-V: Report "c or zca" for INSN_CLASS_C when error reporting.Nelson Chu1-1/+1
bfd/ * elfxx-riscv.c (riscv_multi_subset_supports_ext): Return "c or zca" rather than "c".
2023-08-18Automatic date update in version.inGDB Administrator1-1/+1
2023-08-17generated bfd files, and kvx regenAlan Modra4-130/+120
The elf32-kvx.c and elf64-kvx.c rules in the bfd makefile are different to the other similar generated files, and that reminded me that we need to have $srcdir in the generated #line reference back to the source for debugging, but don't want it for comments in bfd.pot (because then bfd.pot will likely reference Nick's source tree). This patch fixes that by making all the #line use $srcdir by virtue of using $<, and edits bfd.pot. I also uniq list of files to remove duplicated elfxx-x86.c, sort lists of files and regen with our standard automake/autoconf. * configure: Regenerate. bfd/ * Makefile.am: Sort various lists of files. Use $< in #line directive of generated C files. (po/SRC-POTFILES.in): uniq SRC_POTFILES. (po/BLD-POTFILES.in): uniq BFD_POTFILES. * Makefile.in: Regenerate. * po/Make-in (bfd.pot): Edit out source dir from comments. * po/SRC-POTFILES.in: Regenerate. gas/ * Makefile.in: Regenerate. * configure: Regenerate. * po/POTFILES.in: Regenerate. ld/ * Makefile.am (ALL_64_EMULATION_SOURCES): Sort. * Makefile.in: Regenerate.
2023-08-17Automatic date update in version.inGDB Administrator1-1/+1
2023-08-16kvx: New port.Paul Iannetta18-1/+6799
2023-08-16aarch64: Enable Cortex-A720 CPURichard Ball1-1/+2
This patch adds support for the Cortex-A720 CPU to binutils. bfd/ChangeLog: * cpu-aarch64.c: Add Cortex-A720. gas/ChangeLog: * NEWS: Update docs. * config/tc-aarch64.c: Add Cortex-A720. * doc/c-aarch64.texi: Update docs. * testsuite/gas/aarch64/cpu-cortex-a720.d: New test.
2023-08-16Automatic date update in version.inGDB Administrator1-1/+1
2023-08-15Updated Russian translation for the bfd directoryNick Clifton1-1518/+1645
2023-08-15RISC-V: Make "fli.h" available to 'Zvfh' + 'Zfa'Tsukasa OI1-0/+15
The documentation of the 'Zfa' extension states that "fli.h" is available "if the Zfh or Zvfh extension is implemented" (both the latest and the oldest editions are checked). This fact was not reflected in Binutils ('Zvfh' implies 'Zfhmin', not full 'Zfh' extension and "fli.h" required 'Zfh' and 'Zfa' extensions). This commit makes "fli.h" also available when both 'Zfa' and 'Zvfh' extensions are implemented. bfd/ChangeLog: * elfxx-riscv.c (riscv_multi_subset_supports): Add new instruction class handling. (riscv_multi_subset_supports_ext): Likewise. gas/ChangeLog: * testsuite/gas/riscv/zfa-zvfh.s: New test. * testsuite/gas/riscv/zfa-zvfh.d: Ditto. include/ChangeLog: * opcode/riscv.h (enum riscv_insn_class): Add new instruction class. opcodes/ChangeLog: * riscv-opc.c (riscv_opcodes): Change instruction class of "fli.h" from INSN_CLASS_ZFH_AND_ZFA to new INSN_CLASS_ZFH_OR_ZVFH_AND_ZFA.
2023-08-15RISC-V: Add support for the 'Zihintntl' extensionTsukasa OI1-0/+20
This commit adds 'Zihintntl' extension and its hint instructions. This is based on: <https://github.com/riscv/riscv-isa-manual/commit/0dc91f505e6da7791d5a733c553e6e2506ddcab5>, the first ISA Manual noting that the 'Zihintntl' extension is ratified. Note that compressed 'Zihintntl' hints require either 'C' or 'Zca' extension. Co-authored-by: Nelson Chu <nelson@rivosinc.com> bfd/ChangeLog: * elfxx-riscv.c (riscv_supported_std_z_ext): Add 'Zihintntl' standard hint 'Z' extension. (riscv_multi_subset_supports): Support new instruction classes. (riscv_multi_subset_supports_ext): Likewise. gas/ChangeLog: * testsuite/gas/riscv/zihintntl.s: New test for 'Zihintntl' including auto-compression without C prefix and explicit C prefix. * testsuite/gas/riscv/zihintntl.d: Likewise. * testsuite/gas/riscv/zihintntl-na.d: Likewise. * testsuite/gas/riscv/zihintntl-base.s: New test for correspondence between 'Zihintntl' and base 'I' or 'C' instructions. * testsuite/gas/riscv/zihintntl-base.d: Likewise. include/ChangeLog: * opcode/riscv.h (enum riscv_insn_class): Add new instruction classes: INSN_CLASS_ZIHINTNTL and INSN_CLASS_ZIHINTNTL_AND_C. (MASK_NTL_P1, MATCH_NTL_P1, MASK_NTL_PALL, MATCH_NTL_PALL, MASK_NTL_S1, MATCH_NTL_S1, MASK_NTL_ALL, MATCH_NTL_ALL, MASK_C_NTL_P1, MATCH_C_NTL_P1, MASK_C_NTL_PALL, MATCH_C_NTL_PALL, MASK_C_NTL_S1, MATCH_C_NTL_S1, MASK_C_NTL_ALL, MATCH_C_NTL_ALL): New. opcodes/ChangeLog: * riscv-opc.c (riscv_opcodes): Add instructions from the 'Zihintntl' extension.
2023-08-15Automatic date update in version.inGDB Administrator1-1/+1
2023-08-14Automatic date update in version.inGDB Administrator1-1/+1
2023-08-13Automatic date update in version.inGDB Administrator1-1/+1
2023-08-12regen configAlan Modra1-21/+52
This regenerates config files changed by the previous 44 commits. Note that subject lines in these commits mostly match the gcc git originating commit.
2023-08-12Automatic date update in version.inGDB Administrator1-1/+1
2023-08-11warn unused result for bfd IO functionsAlan Modra13-127/+192
This patch fixes all the warnings I found in bfd, binutils and ld, plus some bitrotted COFF_GO32 code that tried to allocate -168ul bytes. When the malloc fail was reported these testsuite fails resulted: i386-go32 +FAIL: go32 stub i386-go32 +ERROR: tcl error sourcing /home/alan/src/binutils-gdb/ld/testsuite/ld-i386/i386.exp. i386-go32 +ERROR: couldn't open "tmpdir/go32stub": no such file or directory i386-go32 +FAIL: ld-scripts/sane1 i386-go32 +FAIL: ld-scripts/assign-loc i386-go32 +FAIL: ld-scripts/pr18963 This does result in some warnings in gdb which are fixed in a followup patch. bfd/ * bfdio.c (bfd_read, bfd_write): Add ATTRIBUTE_WARN_UNUSED_RESULT. (bfd_tell, bfd_stat, bfd_seek, bfd_mmap): Likewise. * bfd-in2.h: Regenerate. * coff-rs6000.c (xcoff_write_armap_big) Don't ignore bfd_write return value. (xcoff_generate_rtinit): Likewise. Also free data_buffer and string_table before returning. * coff64-rs6000.c (xcoff64_generate_rtinit): Likewise. * coff-stgo32.c (go32exe_check_format): Don't ignore bfd_seek return value. * coffcode.h (coff_apply_checksum): Don't ignore bfd_write return. (coff_write_object_contents <COFF_GO32>): Likewise, and bfd_malloc. Fix bitrotted code to look for first section with non-zero filepos. * elf64-ia64-vms.c (elf64_vms_write_shdrs_and_ehdr): Don't ignore bfd_seek or bfd_write return values. * pef.c (bfd_pef_scan_section): Likewise. (bfd_pef_read_header, bfd_pef_xlib_read_header): Likewise. * vms-misc.c (_bfd_vms_output_end): Likewise. Return status. * vms.h (_bfd_vms_output_end): Update prototype. * vms-alpha.c: Pass _bfd_vms_output_end status up call chains. * wasm-module.c (wasm_compute_custom_section_file_position): Don't ignore bfd_seek or bfd_write return values. (wasm_compute_section_file_positions): Likewise. * xsym.c (bfd_sym_scan): Don't ignore bfd_seek return value. (bfd_sym_read_name_table): Likewise. binutils/ * ar.c (print_contents, extract_file): Don't ignore bfd_seek return value. ld/ * pdb.c (create_section_contrib_substream): Don't ignore bfd_seek return value. (create_section_header_stream): Likewise. * pe-dll.c (pe_get16, pe_get32): Add fail param to return results from bfd_seek and bfd_read. (pe_implied_import_dll): Handle these fails, and other bfd_seek and bfd_read return values.
2023-08-11RISC-V: Remove support for non-existing 'Zve32d'Tsukasa OI1-1/+0
Since this "extension" does not exist (on the other hand, 'Zve64d' exists) and it's not useful if we keep it (as other code portions just ignore "zve32d"), this commit just removes it. bfd/ChangeLog: * elfxx-riscv.c (riscv_supported_std_z_ext): Remove 'Zve32d' extension from the list.
2023-08-11Automatic date update in version.inGDB Administrator1-1/+1
2023-08-10Automatic date update in version.inGDB Administrator1-1/+1