aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2023-02-15Automatic date update in version.inGDB Administrator1-1/+1
2023-02-14Automatic date update in version.inGDB Administrator1-1/+1
2023-02-13_bfd_ecoff_slurp_symbol_table buffer overflowAlan Modra1-12/+20
Add missing bounds check, and tidy the existing bounds checking. * ecoff.c (_bfd_ecoff_slurp_symbol_table): Break overlong lines. Set bfd_error. Bounds check internal_sym.iss.
2023-02-13Automatic date update in version.inGDB Administrator1-1/+1
2023-02-12Automatic date update in version.inGDB Administrator1-1/+1
2023-02-11.debug sections without contentsAlan Modra1-1/+2
* dwarf1.c (_bfd_dwarf1_find_nearest_line): Exclude .debug sections without contents.
2023-02-11Automatic date update in version.inGDB Administrator1-1/+1
2023-02-10RISC-V: Reduce effective linker relaxation passsesTsukasa OI1-3/+3
Commit 43025f01a0c9 ("RISC-V: Improve link time complexity.") reduced the time complexity of the linker relaxation but some code portions did not reflect this change. This commit fixes a comment describing each relaxation pass and reduces actual number of passes for the RISC-V linker relaxation from 3 to 2. Though it does not change the functionality, it marginally improves the performance while linking large programs (with many relocations). bfd/ChangeLog: * elfnn-riscv.c (_bfd_riscv_relax_section): Fix a comment to reflect current roles of each relaxation pass. ld/ChangeLog: * emultempl/riscvelf.em: Reduce the number of linker relaxation passes from 3 to 2.
2023-02-10Fix mmo memory leaksAlan Modra1-7/+6
The main one here is the section buffer, which can be quite large. By using alloc rather than malloc we can leave tidying memory to the generic bfd code when the bfd is closed. bfd_check_format also releases memory when object_p fails, so while it wouldn't be wrong to bfd_release at bad_format_free in mmo_object_p, it's a little extra code and work for no gain. * mmo.c (mmo_object_p): bfd_alloc rather than bfd_malloc lop_stab_symbol. Don't free/release on error. (mmo_get_spec_section): bfd_zalloc rather than bfd_zmalloc section buffer. (mmo_scan): Free fname on another error path.
2023-02-10objcopy of mach-o indirect symbolsAlan Modra1-0/+9
Anti-fuzzer measure. I'm not sure what the correct fix is for objcopy. Probably the BFD_MACH_O_S_NON_LAZY_SYMBOL_POINTERS, BFD_MACH_O_S_LAZY_SYMBOL_POINTERS and BFD_MACH_O_S_SYMBOL_STUBS contents should be read. * mach-o.c (bfd_mach_o_section_get_nbr_indirect): Omit sections with NULL sec->indirect_syms.
2023-02-10Automatic date update in version.inGDB Administrator1-1/+1
2023-02-09coff keep_relocs and keep_contentsAlan Modra3-43/+28
keep_relocs is set by pe_ILF_save_relocs but not used anywhere in the coff/pe code. It is tested by the xcoff backend but not set. keep_contents is only used by the xcoff backend when dealing with the .loader section, and it's easy enough to dispense with it there. keep_contents is set in various places but that's fairly useless when the contents aren't freed anyway until later linker support functions, add_dynamic_symbols and check_dynamic_ar_symbols. There the contents were freed if keep_contents wasn't set. I reckon we can free them unconditionally. * coff-bfd.h (struct coff_section_tdata): Delete keep_relocs and keep_contents. * peicode.h (pe_ILF_save_relocs): Don't set keep_relocs. * xcofflink.c (xcoff_get_section_contents): Cache contents. Return the contents. Update callers. (_bfd_xcoff_canonicalize_dynamic_symtab): Don't set keep_contents for .loader. (xcoff_link_add_dynamic_symbols): Free .loader contents unconditionally. (xcoff_link_check_dynamic_ar_symbols): Likewise.
2023-02-09Automatic date update in version.inGDB Administrator1-1/+1
2023-02-09coff-sh.c keep_relocs, keep_contents and keep_symsAlan Modra1-12/+0
keep_relocs and keep_contents are unused nowadays except by xcofflink.c, and I can't see a reason why keep_syms needs to be set. The external syms are read and used by sh_relax_section and used by sh_relax_delete_bytes. There doesn't appear to be any way that freeing them will cause trouble. * coff-sh.c (sh_relax_section): Don't set keep_relocs, keep_contents or keep_syms. (sh_relax_delete_bytes): Don't set keep_contents.
2023-02-09Memory leak in bfd_init_section_compress_statusAlan Modra1-1/+4
* compress.c (bfd_init_section_compress_status): Free uncompressed_buffer on error return.
2023-02-09Clear cached file size when bfd changed to BFD_IN_MEMORYAlan Modra3-0/+3
If file size is calculated by bfd_get_file_size, as it is by _bfd_alloc_and_read calls in coff_object_p, then it is cached and when pe_ILF_build_a_bfd converts an archive entry over to BFD_IN_MEMORY, the file size is no longer valid. Found when attempting objdump -t on a very small (27 bytes) ILF file and hitting the pr24707 fix (commit 781152ec18f5). So, clear file size when setting BFD_IN_MEMORY on bfds that may have been read. (It's not necessary in writable bfds, because caching is ignored by bfd_get_size when bfd_write_p.) I also think the PR 24707 fix is no longer neeeded. All of the testcases in that PR and in PR24712 are caught earlier by file size checks when reading the symbols from file. So I'm reverting that fix, which just compared the size of an array of symbol pointers against file size. That's only valid if on-disk symbols are larger than a host pointer, so the test is better done in format-specific code. bfd/ * coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Clear cached file size when making a BFD_IN_MEMORY bfd. * opncls.c (bfd_make_readable): Likewise. * peicode.h (pe_ILF_build_a_bfd): Likewise. binutils/ PR 24707 * objdump.c (slurp_symtab): Revert PR24707 fix. Tidy. (slurp_dynamic_symtab): Tidy.
2023-02-08Re: Resetting section vma after _bfd_dwarf2_find_nearest_lineAlan Modra1-1/+1
f.bfd_ptr is set too early to be a reliable indicator of good debug info. * dwarf2.c (_bfd_dwarf2_slurp_debug_info): Correct test for debug info being previously found.
2023-02-08Automatic date update in version.inGDB Administrator1-1/+1
2023-02-07Automatic date update in version.inGDB Administrator1-1/+1
2023-02-06ppc32 and "LOAD segment with RWX permissions"Alan Modra1-5/+12
When using a bss-plt we'll always trigger the RWX warning, which disturbs gcc test results. On the other hand, there may be reason to want the warning when gcc is configured with --enable-secureplt. So turning off the warning entirely for powerpc might not be the best solution. Instead, we'll turn off the warning whenever a bss-plt is generated, unless the user explicitly asked for the warning. bfd/ * elf32-ppc.c (ppc_elf_select_plt_layout): Set no_warn_rwx_segments on generating a bss plt, unless explicity enabled by the user. Also show the bss-plt warning when --warn-rwx-segments is given without --bss-plt. include/ * bfdlink.h (struct bfd_link_info): Add user_warn_rwx_segments. ld/ * lexsup.c (parse_args): Set user_warn_rwx_segments. * testsuite/ld-elf/elf.exp: Pass --secure-plt for powerpc to the rwx tests.
2023-02-06Resetting section vma after _bfd_dwarf2_find_nearest_lineAlan Modra1-42/+33
There are failure paths in _bfd_dwarf2_slurp_debug_info that can result in altered section vmas. Also, when setting ET_REL section vmas it's not too difficult to handle cases where the original vma was non-zero, so do that too. This patch was really in response to an addr2line buffer overflow processing a fuzzed mips relocatable object file. The file had a number of .debug_info sections with relocations that included lo16 and hi16 relocs, and in that order. At least one section VMA was non-zero. This resulted in processing of DWARF info twice, once via the call to _bfd_dwarf2_find_nearest_line in _bfd_mips_elf_find_nearest_line, and because that failed leaving VMAs altered, the second via the call in _bfd_elf_find_nearest_line. The first call left entries on mips_hi16_list pointing at buffers allocated during the first call, the second call processed the mips_hi16_list after the buffers had been freed. (At least when running with asan and under valgrind. Under gdb with a non-asan addr2line the second call allocated exactly the same buffer and the bug didn't show.) Now I don't really care too much what happens with fuzzed files, but the logic in _bfd_dwarf2_find_nearest_line is meant to result in only one read of .debug_info, not multiple reads of the same info when there are errors. This patch fixes that problem. * dwarf2.c (struct adjusted_section): Add orig_vma. (unset_sections): Reset vma to it. (place_sections): Handle non-zero vma too. Save orig_vma. (_bfd_dwarf2_slurp_debug_info): Tidy. Correct outdated comment. On error returns after calling place_sections, call unset_sections. (_bfd_dwarf2_find_nearest_line_with_alt): Simplify call to unset_sections.
2023-02-06Automatic date update in version.inGDB Administrator1-1/+1
2023-02-05Automatic date update in version.inGDB Administrator1-1/+1
2023-02-04Automatic date update in version.inGDB Administrator1-1/+1
2023-02-03Add ECOFF Symbolic Header sanity checksAlan Modra1-4/+17
Anti-fuzzer measures. The checks don't ensure the various elements in the header are distinct, but that isn't important as far as making sure we don't overrun the buffer containing all the elements. Also, we now don't care about offsets where the corresponding count is zero. * ecoff.c (_bfd_ecoff_slurp_symbolic_info): Sanity check offsets in debug->symbolic_header.
2023-02-03Automatic date update in version.inGDB Administrator1-1/+1
2023-02-02bfd: use "stack trace" instead of "unwind" for SFrameIndu Bhagat4-11/+12
SFrame format is meant for generating stack traces only. bfd/ * elf-bfd.h: Replace the use of "unwind" with "stack trace". * elf-sframe.c: Likewise. * elf64-x86-64.c: Likewise. * elfxx-x86.c: Likewise. include/ * elf/common.h: Likewise.
2023-02-02Automatic date update in version.inGDB Administrator1-1/+1
2023-02-01Automatic date update in version.inGDB Administrator1-1/+1
2023-01-31Silence ubsan warning about 1<<31Alan Modra1-1/+1
* merge.c (hash_blob): Write 1u << 31.
2023-01-31Automatic date update in version.inGDB Administrator1-1/+1
2023-01-30Automatic date update in version.inGDB Administrator1-1/+1
2023-01-29Automatic date update in version.inGDB Administrator1-1/+1
2023-01-28Automatic date update in version.inGDB Administrator1-1/+1
2023-01-27Perform cleanup in bfd_close after errorsAlan Modra1-13/+10
It seems reasonable to continue after errors in bfd_close_all_done, particularly since bfd_close_all_done is typically called on an output file after we've hit some sort of error elsewhere. The iovec test is necessary if bfd_close_all_done is to work on odd bfd's opened by bfd_create. * opncls.c (bfd_close): Call bfd_close_all_done after errors from _bfd_write_contents. (bfd_close_all_done): Call _bfd_delete_bfd after errors. Don't call iovec->bclose when iovec is NULL.
2023-01-27Automatic date update in version.inGDB Administrator1-1/+1
2023-01-27segv in coff_aarch64_addr32nb_relocAlan Modra1-3/+4
* coff-aarch64.c (coff_aarch64_addr32nb_reloc): When output_bfd is NULL (which it is for objdump -W) get the output bfd via the input section.
2023-01-26Automatic date update in version.inGDB Administrator1-1/+1
2023-01-25Automatic date update in version.inGDB Administrator1-1/+1
2023-01-24Fix seg-fault when generating an empty DLL with LTO enabled.Nick Clifton2-2/+10
ld PR 29998 * pe-dll.c (generate_reloc): Handle sections with no assigned output section. Terminate early of there are no relocs to put in the .reloc section. (pe_exe_fill_sections): Do not emit an empty .reloc section. bfd * cofflink.c (_bfd_coff_generic_relocate_section): Add an assertion that the output section is set for defined, global symbols.
2023-01-24Automatic date update in version.inGDB Administrator1-1/+1
2023-01-23Add support for secidx relocations to aarch64-w64-mingw32Mark Harmstone1-1/+35
This patch adds support for the .secidx directive and its corresponding relocation to aarch64-w64-mingw32. As with x86, this is a two-byte LE integer which gets filled in with the 1-based index of the output section that a symbol ends up in. This is needed for PDBs, which represent addresses as a .secrel32, .secidx pair. The test is substantially the same as for amd64, but with changes made for padding and alignment.
2023-01-23Automatic date update in version.inGDB Administrator1-1/+1
2023-01-22Automatic date update in version.inGDB Administrator1-1/+1
2023-01-21Automatic date update in version.inGDB Administrator1-1/+1
2023-01-20Faster string mergingMichael Matz5-304/+739
* use power-of-two hash table * use better hash function (hashing 32bits at once and with better mixing characteristics) * use input-offset-to-entry maps instead of retaining full input contents for lookup time * don't reread SEC_MERGE section multiple times * care for cache behaviour for the hot lookup routine The overall effect is less usage in libz and much faster string merging itself. On a debug-info-enabled cc1 the effect at the time of this writing on the machine I used was going from 14400 perf samples to 9300 perf samples or from 3.7 seconds to 2.4 seconds, i.e. about 33% .
2023-01-20Automatic date update in version.inGDB Administrator1-1/+1
2023-01-19i386: Don't emit unsupported TLS relocs on SolarisRainer Orth1-8/+32
Emit R_386_TLS_LE and R_386_TLS_IE, instead of R_386_TLS_LE_32 and R_386_TLS_IE_32, on Solaris. PR ld/13671 * elf32-i386.c (elf_i386_tls_transition): Only emit R_386_TLS_LE, R_386_TLS_IE on Solaris. (elf_i386_relocate_section): Only use R_386_TLS_GD->R_386_TLS_LE transition on Solaris. Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
2023-01-19PR 30022, concurrent builds can failAlan Modra2-78/+23
So let's not copy .libs/libbfd.a to libbfd.a now that nothing in the binutils-gdb source tries to link against it. PR 30022 * Makefile.am (noinst_LIBRARIES, libbfd_a_SOURCES, stamp-lib), (libbfd.a): Delete rules. (CLEANFILES): Adjust to suit.
2023-01-19The fuzzers have found the reloc special functions in coff-aarch64.cAlan Modra1-42/+157
All of them need a bfd_reloc_offset_in_range check before accessing data + reloc_entry->address. This patch adds the missing checks and sanity checks reloc offsets in coff_pe_aarch64_relocate_section too. All of them also need changing to support objdump -W calls to bfd_simple_get_relocated_section_contents. At least, secrel_reloc needs the support, the others might not be present in dwarf debug sections. * coff-aarch64.c (coff_aarch64_rel21_reloc): Range check reloc offset. Support final-linking. (coff_aarch64_po12l_reloc): Likewise. (coff_aarch64_addr32nb_reloc): Likewise. (coff_aarch64_secrel_reloc): Likewise. (coff_pe_aarch64_relocate_section): Range check reloc offset.