aboutsummaryrefslogtreecommitdiff
path: root/bfd
AgeCommit message (Collapse)AuthorFilesLines
2022-12-12PR29892, Field file_table of struct module is uninitializedAlan Modra1-3/+6
PR 29892 * vms-alphs.c (new_module): Use bfd_zmalloc to alloc file_table. (parse_module): Rewrite file_table reallocation code and clear.
2022-12-12Lack of bounds checking in vms-alpha.c parse_moduleAlan Modra1-45/+168
PR 29873 PR 29874 PR 29875 PR 29876 PR 29877 PR 29878 PR 29879 PR 29880 PR 29881 PR 29882 PR 29883 PR 29884 PR 29885 PR 29886 PR 29887 PR 29888 PR 29889 PR 29890 PR 29891 * vms-alpha.c (parse_module): Make length param bfd_size_type. Delete length == -1 checks. Sanity check record_length. Sanity check DST__K_MODBEG, DST__K_RTNBEG, DST__K_RTNEND lengths. Sanity check DST__K_SOURCE and DST__K_LINE_NUM elements before accessing. (build_module_list): Pass dst_section size to parse_module.
2022-12-12Automatic date update in version.inGDB Administrator1-1/+1
2022-12-11Automatic date update in version.inGDB Administrator1-1/+1
2022-12-10Automatic date update in version.inGDB Administrator1-1/+1
2022-12-09libsframe: rename API sframe_fde_func_info to sframe_fde_create_func_infoIndu Bhagat1-3/+3
The new name better reflects the purpose of the function. ChangeLog: * bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Use new name. * libsframe/sframe.c (sframe_fde_create_func_info): Rename sframe_fde_func_info to this. * libsframe/testsuite/libsframe.encode/encode-1.c: Use new name. include/ChangeLog: * sframe-api.h (sframe_fde_create_func_info): Rename sframe_fde_func_info to this.
2022-12-09PR28306, segfault in _bfd_mips_elf_reloc_unshuffleAlan Modra5-22/+96
Access to section data during relocation processing should be bounds checked, as it is in bfd_perform_relocation. bfd_perform_relocation does these checks after any special_function is called. So a reloc special_function needs to do its own bounds checking before accessing section data. This patch adds many such checks to the mips backend. Checking mips relocs is not without some difficulty. See the comment in _bfd_mips_reloc_offset_in_range. In a multitple reloc sequence applied to the same location, relocs that may appear somewhere other than the last one of the sequence need to be treated specially since they apply to the addend for the next relocation rather than the section contents. If the addend is in the section then it needs to be checked but not when the addend is in the reloc. check_inplace handles this situation. _bfd_mips_reloc_offset_in_range with check_shuffle handles the case where contents are shuffled before applying the relocation. PR 28306 * elf32-mips.c (_bfd_mips_elf32_gprel16_reloc): Check reloc address using _bfd_mips_reloc_offset_in_range. (gprel32_with_gp, mips16_gprel_reloc): Likewise. * elf64-mips.c (mips_elf64_gprel32_reloc): Likewise. (mips16_gprel_reloc): Likewise. * elfn32-mips.c (mips16_gprel_reloc): Likewise. (gprel32_with_gp): Check reloc address using bfd_reloc_offset_in_range. * elfxx-mips.h (enum reloc_check): Define. (_bfd_mips_reloc_offset_in_range): Declare. * elfxx-mips.c (needs_shuffle): New function. (_bfd_mips_elf_reloc_unshuffle, _bfd_mips_elf_reloc_shuffle): Use it. (_bfd_mips_reloc_offset_in_range): New function. (_bfd_mips_elf_gprel16_with_gp): Move reloc address checks to partial_inplace handling. Use bfd_reloc_offset_in_range. (_bfd_mips_elf_lo16_reloc): Check reloc address using bfd_reloc_offset_in_range. (_bfd_mips_elf_generic_reloc): Check reloc address using _bfd_mips_reloc_offset_in_range. (mips_elf_calculate_relocation): Check reloc address before calling mips_elf_nullify_got_load. (_bfd_mips_elf_check_relocs): Likewise. (mips_elf_read_rel_addend): Add sec param, check reloc address before reading. Adjust callers. (mips_elf_add_lo16_rel_addend): Add sec param, adjust callers.
2022-12-09Automatic date update in version.inGDB Administrator1-1/+1
2022-12-08x86-64: Remove BND from 64-bit IBT PLTH.J. Lu1-11/+33
Since MPX support has been removed from x86-64 psABI, remove BND from 64-bit IBT PLT by using x32 IBT PLT. bfd/ PR ld/29851 * elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Also check x32 IBT PLT for 64-bit. (elf_x86_64_link_setup_gnu_properties): Always use x32 IBT PLT. ld/ PR ld/29851 * testsuite/ld-x86-64/ibt-plt-1.d: Updated. * testsuite/ld-x86-64/ibt-plt-2a.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2b.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-2d.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3a.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3b.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3c.d: Likewise. * testsuite/ld-x86-64/ibt-plt-3d.d: Likewise. * testsuite/ld-x86-64/plt-main-ibt-x32.dd: Moved to ... * testsuite/ld-x86-64/plt-main-ibt.dd: This. * testsuite/ld-x86-64/x86-64.exp: Don't use plt-main-ibt-x32.dd.
2022-12-08Automatic date update in version.inGDB Administrator1-1/+1
2022-12-07coff make_a_section_from_file tidyAlan Modra1-53/+41
Also support compressing a few more sections. * coffgen.c (make_a_section_from_file): Rename return_section to newsect. Don't try to be clever matching section name. Compress .gnu.debuglto_.debug_ and .gnu.linkonce.wi. too. Only rename debug sections when decompressing for linker.
2022-12-07_bfd_elf_slurp_secondary_reloc_section sanity checkAlan Modra1-3/+14
* elf.c (_bfd_elf_slurp_secondary_reloc_section): Sanity check section header against file size. Avoid overflow in reloc_count.
2022-12-07bfd_compress_section_contents access to elf_section_dataAlan Modra1-1/+2
* compress.c (bfd_compress_section_contents): Don't access elf_section_data for non-ELF.
2022-12-07Compression tidy and fixesAlan Modra5-89/+92
Tidies: - Move stuff from bfd-in.h and libbfd.c to compress.c - Delete COMPRESS_DEBUG from enum compressed_debug_section_type - Move compress_debug field out of link_info to ld_config. Fixes: - Correct test in bfd_convert_section_setup to use obfd flags, not ibfd. - Apply bfd_applicable_file_flags to compression bfd flags added by gas and ld to the output bfd. bfd/ * bfd-in.h (enum compressed_debug_section_type), (struct compressed_type_tuple), (bfd_get_compression_algorithm), (bfd_get_compression_algorithm_name), * libbfd.c (compressed_debug_section_names), (bfd_get_compression_algorithm), (bfd_get_compression_algorithm_name): Move.. * compress.c: ..to here, deleting COMPRESS_DEBUG from enum compressed_debug_section_type. (bfd_convert_section_setup): Test obfd flags not ibfd for compression flags. * elf.c (elf_fake_sections): Replace link_info->compress_debug test with abfd->flags test. * bfd-in2.h: Regenerate. binutils/ * objcopy.c (copy_file): Tidy setting of bfd compress flags. Expand comment. gas/ * write.c (compress_debug): Test bfd compress flags rather than flag_compress_debug. (write_object_file): Apply bfd_applicable_file_flags to compress debug flags added to output bfd. include/ * bfdlink.h (struct bfd_link_info): Delete compress_debug. ld/ * ld.h (ld_config_type): Add compress_debug. * emultempl/elf.em: Replace references to link_info.compress_debug with config.compress_debug. * lexsup.c (elf_static_list_options): Likewise. * ldmain.c (main): Likewise. Apply bfd_applicable_file_flags to compress debug flags added to output bfd.
2022-12-07Automatic date update in version.inGDB Administrator1-1/+1
2022-12-06bfd: Avoid signed overflow for new_size adjustmentH.J. Lu1-1/+1
When bfd_size_type is unsigned 64-bit integer and sizeof is unsigned 32-bit integer, subtraction in *new_size += sizeof (Elf32_External_Chdr) - sizeof (Elf64_External_Chdr); will overflow. Use *new_size -= sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr); to avoid overflow. PR binutils/29860 * compress.c (bfd_convert_section_setup): Avoid signed overflow for new_size adjustment.
2022-12-06Fix a dereference of NULL when scanning the symbol hashes array in the ARM ↵Nick Clifton2-0/+12
linker. PR 29852 * elf32-arm.c (cmse_scan): Check for NULL entries in the sym_hashes array. (elf32_arm_gc_mark_extra_sections): Likewise.
2022-12-06Get rid of SEC_ELF_COMPRESSAlan Modra5-91/+61
This flag also isn't needed, except for some sanity checks which we can omit. * elf.c (elf_fake_sections): Don't set SEC_ELF_COMPRESS for compressed debug sections, just leave sh_name as -1. (assign_file_positions_for_non_load_sections), (assign_file_positions_except_relocs): Decide whether a section needs compressing and thus should not have its file offset set by looking at sh_name. (_bfd_elf_assign_file_positions_for_non_load): Similarly decide which sections need compressing. * elflink.c (bfd_elf_final_link): Don't test SEC_ELF_COMPRESS. * merge.c (_bfd_write_merged_section): Likewise. * section.c (SEC_ELF_COMPRESS): Don't define. (SEC_ELF_PURECODE): Renumber. * bfd-in2.h: Regenerate.
2022-12-06Get rid of SEC_ELF_RENAMEAlan Modra4-100/+78
SEC_ELF_RENAME is a flag used to effect section name changes when compressing/decompressing zlib-gnu debug sections. This can be accomplished more directly in one of the objcopy specific bfd functions. Renaming for ld input is simplified too. Ld input object files always have BFD_DECOMPRESS set. bfd/ * compress.c (bfd_convert_section_size): Rename to.. (bfd_convert_section_setup): ..this. Handle objcopy renaming of compressed/decompressed debug sections. * elf.c (_bfd_elf_make_section_from_shdr): Only rename zdebug input for linker. (elf_fake_sections): Don't handle renaming of debug sections for objcopy here. * section.c (SEC_ELF_RENAME): Delete. * bfd-in2.h: Regenerate. binutils/ * objcopy.c (setup_section): Call bfd_convert_section_setup. Don't call bfd_convert_section_size.
2022-12-06Compression header enumAlan Modra4-384/+376
Define an enum instead of using ELFCOMPRESS_ZLIB and ELFCOMPRESS_ZSTD in bfd and binutils, and move some functions from bfd.c to compress.c. When looking at the COFF/PE debug compression support, I wondered about extending it to support zstd. I likely won't do that, but the compression header ch_type field isn't just ELF specific if these headers are to be used in COFF/PE too. bfd/ * bfd.c (bfd_update_compression_header), (bfd_check_compression_header, bfd_get_compression_header_size), (bfd_convert_section_size, bfd_convert_section_contents): Move to.. * compress.c: ..here. (enum compression_type): New. Use it throughout file. * elf.c (_bfd_elf_make_section_from_shdr): Replace uses of ELFCOMPRESS_ZLIB and ELFCOMPRESS_ZSTD with ch_compress_zlib and ch_compress_zstd. * bfd-in2.h: Regenerate. binutils/ * readelf.c (process_section_headers, dump_section_as_strings), (dump_section_as_bytes, load_specific_debug_section): Replace uses of ELFCOMPRESS_ZLIB and ELFCOMPRESS_ZSTD with ch_compress_zlib and ch_compress_zstd.
2022-12-06LoongArch: Fix dynamic reloc not generated bug in some cases.mengqinggang1-1/+1
bfd/ChangeLog: * elfnn-loongarch.c (loongarch_elf_relocate_section): Likewise.
2022-12-06PR29855, ch_type in bfd_init_section_decompress_status can be uninitializedAlan Modra1-0/+1
PR 29855 * compress.c (bfd_init_section_decompress_status): Set ch_type to zero for zlib-gnu case.
2022-12-06Automatic date update in version.inGDB Administrator1-1/+1
2022-12-05Fix an illegal memory access when parsing a corrupt VMS Alpha file.Nick Clifton2-1/+7
PR 29848 * vms-alpha.c (parse_module): Fix potential out of bounds memory access.
2022-12-05Re: Renaming .debug to .zdebug and vice versaAlan Modra2-4/+4
* compress.c (bfd_debug_name_to_zdebug): Fix C++ compile error. (bfd_zdebug_name_to_debug): Likewise. * bfd-in2.h: Regenerate.
2022-12-05Automatic date update in version.inGDB Administrator1-1/+1
2022-12-04COFF compressed debug supportAlan Modra1-8/+8
Since commit 4bea06d73c04 COFF support for compressed debug sections has been broken due to the "flags" variable not getting SEC_HAS_CONTENTS. * coffgen.c (make_a_section_from_file): Correct section flags handling. Delete extraneous condition. Update error messages to be the same as in elf.c.
2022-12-04Renaming .debug to .zdebug and vice versaAlan Modra4-47/+64
Move a couple of elf.c functions to compress.c. * compress.c (bfd_debug_name_to_zdebug): New inline function. (bfd_zdebug_name_to_debug): Likewise. * elf.c (convert_debug_to_zdebug, convert_zdebug_to_debug): Delete. (_bfd_elf_make_section_from_shdr, elf_fake_sections), (_bfd_elf_assign_file_positions_for_non_load): Adjust to suit. * coffgen.c (make_a_section_from_file): Use new inlines here.
2022-12-04Automatic date update in version.inGDB Administrator1-1/+1
2022-12-03Automatic date update in version.inGDB Administrator1-1/+1
2022-12-02Automatic date update in version.inGDB Administrator1-1/+1
2022-12-01Fix verilog output when the width is > 1.Nick Clifton2-4/+27
PR 25202 bfd * bfd.c (VerilogDataEndianness): New variable. (verilog_write_record): Use VerilogDataEndianness, if set, to choose the endianness of the output. (verilog_write_section): Adjust the address by the data width. binutils* objcopy.c (copy_object): Set VerilogDataEndianness to the endianness of the input file. (copy_main): Verifiy the value set by the --verilog-data-width option. * testsuite/binutils-all/objcopy.exp: Add tests of the new behaviour. * testsuite/binutils-all/verilog-I4.hex: New file.
2022-12-01Automatic date update in version.inGDB Administrator1-1/+1
2022-11-30regen SRC-POTFILES.inAlan Modra1-0/+1
2022-11-30Automatic date update in version.inGDB Administrator1-1/+1
2022-11-28xtensa: allow dynamic configurationMax Filippov7-18/+170
Import include/xtensa-dynconfig.h that defines XCHAL_* macros as fields of a structure returned from the xtensa_get_config_v<x> function call. Define that structure and fill it with default parameter values specified in the include/xtensa-config.h. Define reusable function xtensa_load_config that tries to load configuration and return an address of an exported object from it. Define functions xtensa_get_config_v{1,2} that use xtensa_load_config to get structures xtensa_config_v{1,2}, either dynamically configured or the default. bfd/ * Makefile.am (BFD32_BACKENDS, BFD32_BACKENDS_CFILES): Append xtensa-dynconfig.c. * Makefile.in: Regenerate. * configure: Regenerate. * configure.ac (xtensa_elf32_be_vec, xtensa_elf32_le_vec): Add xtensa-dynconfig.lo to the tb. * elf32-xtensa.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove definitions. * xtensa-dynconfig.c: New file. * xtensa-isa.c (xtensa-dynconfig.h): New #include. (xtensa_get_modules): New function. (xtensa_isa_init): Call xtensa_get_modules instead of taking address of global xtensa_modules. gas/ * config/tc-xtensa.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0, XTENSA_MARCH_EARLIEST): Remove definitions. * config/tc-xtensa.h (xtensa-config.h): Replace #include with xtensa-dynconfig.h. * config/xtensa-relax.c (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XCHAL_HAVE_WIDE_BRANCHES): Remove definition. include/ * xtensa-dynconfig.h: New file. ld/ * emultempl/xtensaelf.em (xtensa-config.h): Replace #include with xtensa-dynconfig.h. (XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove definitions.
2022-11-29Automatic date update in version.inGDB Administrator1-1/+1
2022-11-28asan: pef: buffer overflowAlan Modra1-1/+1
* pef.c (bfd_pef_parse_traceback_table): Correct size moved when stripping leading dot.
2022-11-28RISC-V: Allow merging 'H' extensionTsukasa OI1-1/+1
Because riscv_merge_std_ext function did not merge the 'H' extension, linked executables lacked 'H' extension when multiple objects are merged. This issue is found while building OpenSBI with 'H' extension (resulting ELF files did not contain "h1p0" in "Tag_RISCV_arch" even if *all* linked object files contained it). This commit adds 'h' to standard_exts variable to merge 'H' extension. bfd/ChangeLog: * elfnn-riscv.c (riscv_merge_std_ext): Add 'H' extension merging.
2022-11-28Automatic date update in version.inGDB Administrator1-1/+1
2022-11-27Automatic date update in version.inGDB Administrator1-1/+1
2022-11-26Automatic date update in version.inGDB Administrator1-1/+1
2022-11-25riscv: Add AIA extension support (Smaia, Ssaia)Christoph Müllner1-0/+4
This commit adds the AIA extensions (Smaia and Ssaia) CSRs. bfd/ChangeLog: * elfxx-riscv.c: Add 'smaia' and 'ssaia' to the list of known standard extensions. gas/ChangeLog: * config/tc-riscv.c (enum riscv_csr_class): (riscv_csr_address): Add CSR classes for Smaia/Ssaia. * testsuite/gas/riscv/csr-dw-regnums.d: Add new CSRs. * testsuite/gas/riscv/csr-dw-regnums.s: Likewise. * testsuite/gas/riscv/csr-version-1p10.d: Likewise. * testsuite/gas/riscv/csr-version-1p10.l: Likewise. * testsuite/gas/riscv/csr-version-1p11.d: Likewise. * testsuite/gas/riscv/csr-version-1p11.l: Likewise. * testsuite/gas/riscv/csr-version-1p12.d: Likewise. * testsuite/gas/riscv/csr-version-1p12.l: Likewise. * testsuite/gas/riscv/csr-version-1p9p1.d: Likewise. * testsuite/gas/riscv/csr-version-1p9p1.l: Likewise. * testsuite/gas/riscv/csr.s: Likewise. include/ChangeLog: * opcode/riscv-opc.h (CSR_MISELECT): New CSR macro. (CSR_MIREG): Likewise. (CSR_MTOPEI): Likewise. (CSR_MTOPI): Likewise. (CSR_MVIEN): Likewise. (CSR_MVIP): Likewise. (CSR_MIDELEGH): Likewise. (CSR_MIEH): Likewise. (CSR_MVIENH): Likewise. (CSR_MVIPH): Likewise. (CSR_MIPH): Likewise. (CSR_SISELECT): Likewise. (CSR_SIREG): Likewise. (CSR_STOPEI): Likewise. (CSR_STOPI): Likewise. (CSR_SIEH): Likewise. (CSR_SIPH): Likewise. (CSR_HVIEN): Likewise. (CSR_HVICTL): Likewise. (CSR_HVIPRIO1): Likewise. (CSR_HVIPRIO2): Likewise. (CSR_VSISELECT): Likewise. (CSR_VSIREG): Likewise. (CSR_VSTOPEI): Likewise. (CSR_VSTOPI): Likewise. (CSR_HIDELEGH): Likewise. (CSR_HVIENH): Likewise. (CSR_HVIPH): Likewise. (CSR_HVIPRIO1H): Likewise. (CSR_HVIPRIO2H): Likewise. (CSR_VSIEH): Likewise. (CSR_VSIPH): Likewise. (DECLARE_CSR): Add CSRs for Smaia and Ssaia. Changes for v3: - Imply ssaia for smaia - Imply zicsr for ssaia (and transitively smaia) - Move hypervisor CSRs to Ssaia+H - Rebase on upstream/master Changes for v2: - Add hypervisor and VS CSRs - Fix whitespace issue Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
2022-11-25Automatic date update in version.inGDB Administrator1-1/+1
2022-11-24Automatic date update in version.inGDB Administrator1-1/+1
2022-11-23PR22509 - Null pointer dereference on coff_slurp_reloc_tableAlan Modra10-10/+17
This extends the commit 4581a1c7d304 fix to more targets, which hardens BFD a little. I think the real underlying problem was the bfd_canonicalize_reloc call in load_specific_debug_section which passed a NULL for "symbols". Fix that too. PR 22509 bfd/ * aoutx.h (swap_ext_reloc_out): Gracefully handle NULL symbols. * i386lynx.c (swap_ext_reloc_out): Likewise. * pdp11.c (pdp11_aout_swap_reloc_out): Likewise. * coff-tic30.c (reloc_processing): Likewise. * coff-tic4x.c (tic4x_reloc_processing): Likewise. * coff-tic54x.c (tic54x_reloc_processing): Likewise. * coff-z80.c (reloc_processing): Likewise. * coff-z8k.c (reloc_processing): Likewise. * ecoff.c (ecoff_slurp_reloc_table): Likewise. * som.c (som_set_reloc_info): Likewise. binutils/ * objdump.c (load_specific_debug_section): Pass syms to bfd_canonicalize_reloc.
2022-11-23asan: NULL deref in filter_symbolsAlan Modra1-0/+1
If tdata->symbols is NULL, make tdata->symcount zero too. This makes wasm_get_symtab_upper_bound return the proper result and stops cascading errors. * wasm-module.c (wasm_scan_name_function_section): Clear tdata->symcount on error.
2022-11-23RISC-V: Make R_RISCV_SUB6 conforms to riscv ABI standardXiao Zeng2-0/+13
According to the riscv psabi, R_RISCV_SUB6 only allows 6 least significant bits are valid, but since binutils implementation, we usually get 8 bits field for it. That means, the high 2 bits could be other field and have different purpose. Therefore, we should filter the 8 bits to 6 bits before calculate, and then only encode the valid 6 bits back. By the way, we also need the out-of-range check for R_RISCV_SUB6, and the overflow checks for all R_RISCV_ADD/SUB/SET relocations, but we can add them in the future patches. Passing riscv-gnu-toolchain regressions. bfd/ChangeLog: * elfnn-riscv.c (riscv_elf_relocate_section): Take the R_RISCV_SUB6 lower 6 bits as the significant bit. * elfxx-riscv.c (riscv_elf_add_sub_reloc): Likewise.
2022-11-23Automatic date update in version.inGDB Administrator1-1/+1
2022-11-22x86: Don't define _TLS_MODULE_BASE_ for ld -rH.J. Lu1-1/+1
bfd/ PR ld/29820 * elfxx-x86.c (_bfd_x86_elf_always_size_sections): Don't define _TLS_MODULE_BASE_ for ld -r. ld/ PR ld/29820 * testsuite/ld-x86-64/pr29820.d: New file. * testsuite/ld-x86-64/pr29820.s: Likewise. * testsuite/ld-x86-64/x86-64.ex: Run pr29820.