aboutsummaryrefslogtreecommitdiff
path: root/bfd/peXXigen.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-04Update year range in copyright notice of binutils filesAlan Modra1-1/+1
Adds two new external authors to etc/update-copyright.py to cover bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then updates copyright messages as follows: 1) Update cgen/utils.scm emitted copyrights. 2) Run "etc/update-copyright.py --this-year" with an extra external author I haven't committed, 'Kalray SA.', to cover gas testsuite files (which should have their copyright message removed). 3) Build with --enable-maintainer-mode --enable-cgen-maint=yes. 4) Check out */po/*.pot which we don't update frequently.
2023-12-05Add basic support for RISC-V 64-bit EFI objectsAndreas Schwab1-21/+23
This adds a new PEI target pei-riscv64-little. Only objdump and objcopy are supported. bfd: * .gitignore: Add pe-riscv64igen.c. * Makefile.am (BFD64_BACKENDS): Add pei-riscv64.lo, pe-riscv64igen.lo. (BFD64_BACKENDS_CFILES): Add pei-riscv64.c. (BUILD_CFILES): Add pe-riscv64igen.c. (pe-riscv64igen.c): New rule. * Makefile.in: Regenerate. * bfd.c (bfd_get_sign_extend_vma): Add pei-riscv64-little. * coff-riscv64.c: New file. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags) (coff_write_object_contents): Add riscv64 (riscv64_pei_vec) support. * config.bfd (targ_selvecs): Add riscv64_pei_vec to all riscv* targets. * configure.ac: Handle riscv64_pei_vec. * configure: Regenerate. * libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE) (GET_OPTHDR_SIZE_OF_STACK_RESERVE) (PUT_OPTHDR_SIZE_OF_STACK_RESERVE) (GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT) (GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE) (GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT) (GET_PDATA_ENTRY, _bfd_XX_bfd_copy_private_bfd_data_common) (_bfd_XX_bfd_copy_private_section_data) (_bfd_XX_get_symbol_info, _bfd_XX_only_swap_filehdr_out) (_bfd_XX_print_private_bfd_data_common) (_bfd_XXi_final_link_postscript, _bfd_XXi_only_swap_filehdr_out) (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out) (_bfd_XXi_swap_aux_in, _bfd_XXi_swap_aux_out) (_bfd_XXi_swap_lineno_in, _bfd_XXi_swap_lineno_out) (_bfd_XXi_swap_scnhdr_out, _bfd_XXi_swap_sym_in) (_bfd_XXi_swap_sym_out, _bfd_XXi_swap_debugdir_in) (_bfd_XXi_swap_debugdir_out, _bfd_XXi_write_codeview_record) (_bfd_XXi_slurp_codeview_record) [COFF_WITH_peRiscV64]: Define. (_bfd_peRiscV64_print_ce_compressed_pdata): Declare. * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out) (_bfd_XXi_swap_scnhdr_out, pe_print_pdata) (_bfd_XX_print_private_bfd_data_common) (_bfd_XX_bfd_copy_private_section_data) (_bfd_XXi_final_link_postscript): Support COFF_WITH_peRiscV64. * pei-riscv64.c: New file. * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd) (pe_ILF_object_p): Support COFF_WITH_peRiscV64. (jtab): Add dummy entry that traps. * targets.c (_bfd_target_vector): Add riscv64_pei_vec. binutils: * testsuite/binutils-all/riscv/pei-riscv64.d: New. * testsuite/binutils-all/riscv/pei-riscv64.s: New. include: * coff/riscv64.h: New file. * coff/pe.h (IMAGE_FILE_MACHINE_RISCV32) (IMAGE_FILE_MACHINE_RISCV64): Define.
2023-10-02Use bfd_get_current_time in places where it is suitableNick Clifton1-11/+1
2023-08-27PE dos_messageAlan Modra1-3/+2
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-09Rename bfd_bread and bfd_bwriteAlan Modra1-2/+2
These were renamed from bfd_read and bfd_write back in 2001 when they lost an unnecessary parameter. Rename them back, and get rid of a few casts that are only needed without prototyped functions (K&R C).
2023-08-02Revert "2.41 Release sources"Sam James1-1/+14
This reverts commit 675b9d612cc59446e84e2c6d89b45500cb603a8d. See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-022.41 Release sourcesbinutils-2_41-releaseNick Clifton1-14/+1
2023-07-24objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the ↵Johannes Schauer Marin Rodrigues1-1/+14
output unreproducible. bfd * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined. binutils * doc/binutils.texi (objcopy): Document change in behaviour of objcopy's --preserve-dates command line option. ld * pe-dll.c (fill_edata): If inserting a timestamp, use the value held in the SOURCE_DATE_EPOCH environment variable, if it is defined. * ld.texi (--insert-timestamp): Document change in behaviour.
2023-04-17Make the .rsrc section read only.Nick Clifton1-1/+1
PR 30142 * peXXigen.c (_bfd_XXi_swap_scnhdr_out): Do not force the .rsrc section to be writeable. * rescoff.c (write_coff_file): Add the SEC_READONLY flag to the .rsrc section.
2023-03-27Use stdint types in coff internal_auxentAlan Modra1-4/+4
long is a poor choice of type to store 32-bit values read from objects files by H_GET_32. H_GET_32 doesn't sign extend so tests like that in gdb/coffread.c for "negative" values won't work if long is larger than 32 bits. If long is 32-bit then code needs to be careful to not accidentally index negative array elements. (I'd rather see a segfault on an unmapped 4G array index than silently reading bogus data.) long is also a poor choice for x_sect.s_scnlen, which might have 64-bit values. It's better to use unsigned exact width types to avoid surprises. I decided to change the field names too, which makes most of this patch simply renaming. Besides that there are a few places where casts are no longer needed, and where printf format strings or tests need adjusting. include/ * coff/internal.h (union internal_auxent): Use unsigned stdint types. Rename l fields to u32 and u64 as appropriate. bfd/ * coff-bfd.c, * coff-rs6000.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * coffswap.h, * peXXigen.c, * xcofflink.c: Adjust to suit internal_auxent changes. binutils/ * rdcoff.c: Adjust to suit internal_auxent changes. gas/ * config/obj-coff.h, * config/tc-ppc.c: Adjust to suit internal_auxent changes. gdb/ * coffread.c, * xcoffread.c: Adjust to suit internal_auxent changes. ld/ * pe-dll.c: Adjust to suit internal_auxent changes.
2023-03-22PE fake section for C_SECTION symsAlan Modra1-12/+2
It's an odd thing to have objdump -x show a different section table to objdump -h, but that can happen if swapping in symbols leads to creating sections. Setting SEC_LINKER_CREATED stops the display of these sections, so that you get shown what is in the object file. * peXXigen.c (_bfd_XXi_swap_sym_in): Set SEC_LINKER_CREATED on fake section created for C_SECTION syms. Don't zero asection fields that are already zero.
2023-02-28Another PE SEC_HAS_CONTENTS testAlan Modra1-1/+2
I'd skipped this one before, thinking "obfd, that's the linker output bfd so no need to test". Wrong, this is objcopy output. * peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Test SEC_HAS_CONTENTS before reading section.
2023-02-23Test SEC_HAS_CONTENTS before reading section contentsAlan Modra1-2/+6
bfd_malloc_and_get_section does size sanity checking before allocating memory and reading contents. These size checks are not done for bss style sections, because they typically don't occupy file space and thus can't be compared against file size. However, if you are expecting to look at something other than a whole lot of zeros, don't allow fuzzers to avoid the size checking. * cofflink.c (process_embedded_commands): Don't look at sections without SEC_HAS_CONTENTS set. * cpu-arm.c (bfd_arm_update_notes): Likewise. (bfd_arm_get_mach_from_notes): Likewise. * elf-eh-frame.c (_bfd_elf_parse_eh_frame): Likewise. * elf-hppa.h (elf_hppa_sort_unwind): Likewise. * elf-m10300.c (mn10300_elf_relax_section): Likewise. * elf-sframe.c (_bfd_elf_parse_sframe): Likewise. * elf.c (_bfd_elf_print_private_bfd_data): Likewise. * elf32-arm.c (bfd_elf32_arm_process_before_allocation): Likewise. * elf32-avr.c (avr_elf32_load_property_records): Likewise. * elf32-ppc.c (_bfd_elf_ppc_set_arch): Likewise. (ppc_elf_get_synthetic_symtab, ppc_elf_relax_section): Likewise. * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Likewise. (opd_entry_value, ppc64_elf_edit_opd, ppc64_elf_edit_toc): Likewise. * elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise. * elflink.c (elf_link_add_object_symbols): Likewise. (bfd_elf_get_bfd_needed_list): Likewise. * elfnn-aarch64.c (get_plt_type): Likewise. * elfxx-mips.c (_bfd_mips_elf_get_synthetic_symtab): Likewise. * linker.c (_bfd_handle_already_linked): Likewise. * opncls.c (bfd_get_debug_link_info_1): Likewise. (bfd_get_alt_debug_link_info, get_build_id): Likewise. * peXXigen.c (pe_print_idata, pe_print_pdata): Likewise. (_bfd_XX_print_ce_compressed_pdata, pe_print_reloc): Likewise. * pei-x86_64.c (pex64_bfd_print_pdata_section): Likewise. * stabs.c (_bfd_link_section_stabs): Likewise. (_bfd_discard_section_stabs): Likewise. * xcofflink.c (_bfd_xcoff_get_dynamic_symtab_upper_bound): Likewise. (_bfd_xcoff_canonicalize_dynamic_symtab): Likewise. (_bfd_xcoff_get_dynamic_reloc_upper_bound): Likewise. (_bfd_xcoff_canonicalize_dynamic_reloc): Likewise. (xcoff_link_add_dynamic_symbols): Likewise. (xcoff_link_check_dynamic_ar_symbols): Likewise. (bfd_xcoff_build_dynamic_sections): Likewise.
2023-01-10peXXigen.c sanity checksAlan Modra1-44/+52
Also fix a memory leak, and make some style changes. I tend to read (sizeof * x) as a multiplication of two variables, which I would not do if binutils followed the gcc coding conventions consistently (see https://gcc.gnu.org/codingconventions.html#Expressions). (sizeof *x) looks a lot better to me, or even (sizeof (*x)) which I've used here. * peXXigen.c (get_contents_sanity_check): New function. (pe_print_idata): Use it here.. (pe_print_edata): ..and here. Free data on error return. (rsrc_parse_entry): Check entry size read from file. (rsrc_parse_entries): Style fixes. (rsrc_process_section): Use bfd_malloc_and_get_section. (_bfd_XXi_final_link_postscript): Likewise.
2023-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The newer update-copyright.py fixes file encoding too, removing cr/lf on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2022-10-26buffer overflow in _bfd_XX_print_ce_compressed_pdataAlan Modra1-0/+2
More fuzzed fun. * peXXigen.c (_bfd_XX_print_ce_compressed_pdata): Use smaller of virt_size and bfd section size as limit of function table.
2022-10-20ld: Add --pdb optionMark Harmstone1-7/+23
Second patch incorporates fixes for endian and UB issues in calc_hash, as per https://sourceware.org/pipermail/binutils/2022-October/123514.html.
2022-10-07PR29653, objcopy/strip: fuzzed small input file induces large output fileAlan Modra1-37/+18
_bfd_check_format functions should not print errors or warnings if they return NULL. A NULL return means the particular target under test does not match, so there isn't any reason to make a complaint about the target. In fact there isn't a good reason to warn even if the target matches, except via the _bfd_per_xvec_warn mechanism; Some other target might be a better match. This patch tidies pe_bfd_object_p with the above in mind, and restricts the PE optional header SectionAlignment and FileAlignment fields somewhat. I chose to warn on nonsense values rather than refusing to match. Refusing to match would be OK too. PR 29653 * peXXigen.c (_bfd_XXi_swap_aouthdr_in): Don't emit error about invalid NumberOfRvaAndSizes here. Limit loop copying data directory to IMAGE_NUMBEROF_DIRECTORY_ENTRIES. * peicode.h (pe_bfd_object_p): Don't clear and test bfd_error around bfd_coff_swap_aouthdr_in. Warn on invalid SectionAlignment, FileAlignment and NumberOfRvaAndSizes. Don't return NULL on invalid NumberOfRvaAndSizes.
2022-08-10bfd: Add support for LoongArch64 EFI (efi-*-loongarch64).Youling Tang1-21/+28
This adds support for efi-loongarch64 by virtue of adding a new PEI target pei-loongarch64. This is not a full target and only exists to support EFI at this time. This means that this target does not support relocation processing and is mostly a container format. This format has been added to elf based loongarch64 targets such that efi images can be made natively on Linux. However this target is not valid for use with gas but only with objcopy. We should't limit addresses to 32-bits for 64-bit vma, otherwise there will be "RVA truncated" error when using objcopy on loongarch64. With these changes the resulting file is recognized as an efi image. Any magic number is based on the Microsoft PE specification [1]. The test results are as follows: $ make check-binutils RUNTESTFLAGS='loongarch64.exp' PASS: Check if efi app format is recognized $ objdump -h -f tmpdir/loongarch64copy.o tmpdir/loongarch64copy.o: file format pei-loongarch64 architecture: Loongarch64, flags 0x00000132: EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED start address 0x0000000000000000 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000003c 00000000200000b0 00000000200000b0 00000200 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd: * .gitignore (pe-loongarch64igen.c): New. * Makefile.am (pei-loongarch64.lo, pe-loongarch64igen.lo, pei-loongarch64.c, pe-loongarch64igen.c): Add support. * Makefile.in: Likewise. * bfd.c (bfd_get_sign_extend_vma): Add pei-loongarch64. * coff-loongarch64.c: New file. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags, coff_write_object_contents) Add loongarch64 (loongarch64_pei_vec) support. * config.bfd: Likewise. * configure: Likewise. * configure.ac: Likewise. * libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE, GET_OPTHDR_SIZE_OF_STACK_RESERVE, PUT_OPTHDR_SIZE_OF_STACK_RESERVE, GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT, GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE, GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT, GET_PDATA_ENTRY, _bfd_peLoongArch64_bfd_copy_private_bfd_data_common, _bfd_peLoongArch64_bfd_copy_private_section_data, _bfd_peLoongArch64_get_symbol_info, _bfd_peLoongArch64_only_swap_filehdr_out, _bfd_peLoongArch64_print_private_bfd_data_common, _bfd_peLoongArch64i_final_link_postscript, _bfd_peLoongArch64i_only_swap_filehdr_out, _bfd_peLoongArch64i_swap_aouthdr_in, _bfd_peLoongArch64i_swap_aouthdr_out, _bfd_peLoongArch64i_swap_aux_in, _bfd_peLoongArch64i_swap_aux_out, _bfd_peLoongArch64i_swap_lineno_in, _bfd_peLoongArch64i_swap_lineno_out, _bfd_peLoongArch64i_swap_scnhdr_out, _bfd_peLoongArch64i_swap_sym_in, _bfd_peLoongArch64i_swap_sym_out, _bfd_peLoongArch64i_swap_debugdir_in, _bfd_peLoongArch64i_swap_debugdir_out, _bfd_peLoongArch64i_write_codeview_record, _bfd_peLoongArch64i_slurp_codeview_record, _bfd_peLoongArch64_print_ce_compressed_pdata): New. * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out, _bfd_XXi_swap_scnhdr_out, pe_print_pdata, _bfd_XX_print_private_bfd_data_common, _bfd_XX_bfd_copy_private_section_data, _bfd_XXi_final_link_postscript): Support COFF_WITH_peLoongArch64, * pei-loongarch64.c: New file. * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p): Support COFF_WITH_peLoongArch64. (jtab): Add dummy entry that traps. * targets.c (loongarch64_pei_vec): New. binutils * testsuite/binutils-all/loongarch64/loongarch64.exp: New file. * testsuite/binutils-all/loongarch64/pei-loongarch64.d: New test. * testsuite/binutils-all/loongarch64/pei-loongarch64.s: New test. include * coff/loongarch64.h: New file. * coff/pe.h (IMAGE_FILE_MACHINE_LOONGARCH64): New. Signed-off-by: Youling Tang <tangyouling@loongson.cn>
2022-05-19COFF/PE: keep linker version during objcopy / stripJan Beulich1-4/+14
Neither of the tools is really a linker, so whatever was originally recorded should be retained rather than being overwritten by these tools' versions.
2022-03-17Re: asan: buffer overflow in peXXigen.cAlan Modra1-44/+52
In the process of fixing a buffer overflow in commit fe69d4fcf0194a, I managed to introduce a fairly obvious NULL pointer dereference.. * peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Don't segfault on not finding section. Wrap overlong lines.
2022-02-16asan: buffer overflow in peXXigen.cAlan Modra1-4/+10
* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Properly sanity check DataDirectory[PE_DEBUG_DATA].Size.
2022-01-02Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The result of running etc/update-copyright.py --this-year, fixing all the files whose mode is changed by the script, plus a build with --enable-maintainer-mode --enable-cgen-maint=yes, then checking out */po/*.pot which we don't update frequently. The copy of cgen was with commit d1dd5fcc38ead reverted as that commit breaks building of bfp opcodes files.
2021-12-31ld: fix coff PE SEHTamar Christina1-2/+2
COFF_WITH_pex64 and COFF_WITH_peAArch64 can't be true at the same time. That means that two conditionals that control the sorting of the .pdata section became a falsum. The testsuite doesn't catch this because the linker does the sorting and to link you require library support from the unwinder so we can't test from binutils in isolation. bfd/ChangeLog: 2021-12-31 Tamar Christina <tamar.christina@arm.com> PR ld/28682 * peXXigen.c: Fix conditional.
2021-11-23AArch64: Add support for AArch64 EFI (efi-*-aarch64).Tamar Christina1-20/+23
This adds support for efi-*-aarch64 by virtue of adding a new PEI target pei-aarch64-little. This is not a full target and only exists to support EFI at this time. This means that this target does not support relocation processing and is mostly a container format. This format has been added to elf based aarch64 targets such that efi images can be made natively on Linux. However this target is not valid for use with gas but only with objcopy. With these changes the resulting file is recognized as an efi image by third party tools: > pecli info hello.efi Metadata ================================================================================ MD5: 598c32a778b0f0deebe977fef8578c4e SHA1: 4580121edd5cb4dc40f51b28f171fd15250df84c SHA256: 3154bd7cf42433d1c957f6bf55a17ad8c57ed41b29df2d485703349fd6ff1d5c Imphash: Size: 47561 bytes Type: PE32+ executable (EFI application) (stripped to external PDB), for MS Windows Compile Time: 1970-01-01 00:00:00 (UTC - 0x0 ) Entry point: 0x2000 (section .text) Sections ================================================================================ Name RWX VirtSize VirtAddr RawAddr RawSize Entropy md5 .text R-X 0x5bb0 0x2000 0x400 0x5c00 6.39 551fbc264256a3f387de8a891500ae0d .reloc R-- 0xc 0x8000 0x6000 0x200 0.02 0c45f6d812d079821c1d54c09ab89e1d .data RW- 0x1d88 0x9000 0x6200 0x1e00 4.18 5d1137c09f01289dc62bf754f7290db3 .dynamic RW- 0xf0 0xb000 0x8000 0x200 0.34 5c94ed3206f05a277e6f04fbf131f131 .rela R-- 0xe58 0xc000 0x8200 0x1000 1.87 8b5c6bc30f3acb7ca7bf2e6789d68519 .dynsym R-- 0x138 0xd000 0x9200 0x200 0.96 bdcf5101da51aadc663ca8859f88138c Imports ================================================================================ Any magic number is based on the Microsoft PE specification [1]. [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * .gitignore (pe-aarch64igen.c): New. * Makefile.am (pei-aarch64.lo, pe-aarch64igen.lo, pei-aarch64.c, pe-aarch64igen.c): Add support. * Makefile.in: Likewise. * bfd.c (bfd_get_sign_extend_vma): Add pei-aarch64-little. * coff-aarch64.c: New file. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags, coff_write_object_contents) Add aarch64 (aarch64_pei_vec) support. * config.bfd: Likewise. * configure: Likewise. * configure.ac: Likewise. * libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE, GET_OPTHDR_SIZE_OF_STACK_RESERVE, PUT_OPTHDR_SIZE_OF_STACK_RESERVE, GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT, GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE, GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT, GET_PDATA_ENTRY, _bfd_peAArch64_bfd_copy_private_bfd_data_common, _bfd_peAArch64_bfd_copy_private_section_data, _bfd_peAArch64_get_symbol_info, _bfd_peAArch64_only_swap_filehdr_out, _bfd_peAArch64_print_private_bfd_data_common, _bfd_peAArch64i_final_link_postscript, _bfd_peAArch64i_only_swap_filehdr_out, _bfd_peAArch64i_swap_aouthdr_in, _bfd_peAArch64i_swap_aouthdr_out, _bfd_peAArch64i_swap_aux_in, _bfd_peAArch64i_swap_aux_out, _bfd_peAArch64i_swap_lineno_in, _bfd_peAArch64i_swap_lineno_out, _bfd_peAArch64i_swap_scnhdr_out, _bfd_peAArch64i_swap_sym_in, _bfd_peAArch64i_swap_sym_out, _bfd_peAArch64i_swap_debugdir_in, _bfd_peAArch64i_swap_debugdir_out, _bfd_peAArch64i_write_codeview_record, _bfd_peAArch64i_slurp_codeview_record, _bfd_peAArch64_print_ce_compressed_pdata): New. * peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out, pe_print_pdata, _bfd_XX_print_private_bfd_data_common, _bfd_XX_bfd_copy_private_section_data, _bfd_XXi_final_link_postscript): Support COFF_WITH_peAArch64, * pei-aarch64.c: New file. * peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p): Support COFF_WITH_peAArch64. (jtab): Add dummy entry that traps. * targets.c (aarch64_pei_vec): New. binutils/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * NEWS: Add new support. * objcopy.c (convert_efi_target): Add efi-*-aarch64 support. * testsuite/binutils-all/aarch64/pei-aarch64-little.d: New test. * testsuite/binutils-all/aarch64/pei-aarch64-little.s: New test. include/ChangeLog: 2021-10-21 Tamar Christina <tamar.christina@arm.com> PR binutils/26206 * coff/aarch64.h: New file. * coff/pe.h (IMAGE_FILE_MACHINE_ARM64): New.
2021-11-10PR 28447: implement multiple parameters for .file on XCOFFClément Chigot1-6/+6
On XCOFF, ".file" pseudo-op allows 3 extras parameters to provide additional information to AIX linker, or its debugger. These are stored in auxiliary entries of the C_FILE symbol. bfd/ PR 28447 * coffcode.h (combined_entry_type): Add extrap field. (coff_bigobj_swap_aux_in): Adjust names of x_file fields. (coff_bigobj_swap_aux_out): Likewise. * coffgen.c (coff_write_auxent_fname): New function. (coff_fix_symbol_name): Write x_file using coff_write_auxent_fname. (coff_write_symbol): Likewise. (coff_write_symbols): Add C_FILE auxiliary entries to string table if needed. (coff_get_normalized_symtab): Adjust names of x_file fields. Normalize C_FILE auxiliary entries. (coff_print_symbol): Print C_FILE auxiliary entries. * coff-rs6000.c (_bfd_xcoff_swap_aux_in): Adjust names of x_file fields. (_bfd_xcoff_swap_aux_out): Likewise. * coff64-rs6000.c (_bfd_xcoff64_swap_aux_in): Likewise. (_bfd_xcoff64_swap_aux_out): Likewise. * cofflink.c (_bfd_coff_final_link): Likewise. (_bfd_coff_link_input_bfd): Likewise. * coffswap.h (coff_swap_aux_in): Likewise. * peXXigen.c (_bfd_XXi_swap_aux_in): Likewise. (_bfd_XXi_swap_aux_out): Likewise. * xcofflink.c (xcoff_link_input_bfd): Likewise. * libcoff.h: Regenerate. gas/ * config/tc-ppc.c (ppc_file): New function. * config/tc-ppc.h (OBJ_COFF_MAX_AUXENTRIES): Change to 4. * testsuite/gas/ppc/aix.exp: Add tests. * testsuite/gas/ppc/xcoff-file-32.d: New test. * testsuite/gas/ppc/xcoff-file-64.d: New test. * testsuite/gas/ppc/xcoff-file.s: New test. include/ * coff/internal.h (union internal_auxent): Change x_file to be a struct instead of a union. Add x_ftype field. * coff/rs6000.h (union external_auxent): Add x_resv field. * coff/xcoff.h (XFT_FN): New define. (XFT_CT): Likewise. (XFT_CV): Likewise. (XFT_CD): Likewise.
2021-04-21Extend the description of PE header flags.Eli Zaretskii1-0/+31
PR 27760 include * coff/pe.h (IMAGE_DLLCHARACTERISTICS_APPCONTAINER): Define. (IMAGE_DLLCHARACTERISTICS_GUARD_CF): Define. bfd * peXXigen.c (_bfd_XX_print_private_bfd_data_common): Add display of IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP, IMAGE_FILE_NET_RUN_FROM_SWAP and IMAGE_FILE_UP_SYSTEM_ONLY flags. Decode the contents of the DllCharacteristics field.
2021-04-05C99 bfd configuryAlan Modra1-23/+3
Certain library headers and functions are required by C99. This removes configure tests for them. The patch also removes AC_ISC_POSIX and AC_HEADER_DIRENT, which the autoconf manual states are obsolescent. sys/time.h is no longer tangled up with time.h so it can be handled by the gprof configure. * configure.ac: Don't check for long long or long double type. Don't check for alloca.h, limits.h, stddef.h, stdlib.h, string.h, strings.h, time.h, wchar.h, wctype.h or sys/time.h. Don't check for strtoull, free, malloc, realloc, getenv, strstr, snprintf, vsnprintf, strlen or setitimer. Sort AC_CHECK_DECLS. (AC_ISC_POSIX): Don't invoke. (AC_HEADER_TIME, AC_HEADER_DIRENT, ACX_HEADER_STRING): Likewise. * sysdep.h: Remove many HAVE_*_H checks and fallback declarations. Do test HAVE_SYS_TYPES_H. Don't include sys/time.h. Reorder header order as per automake AC_INCLUDES_DEFAULT. * bfd-in.h: Include inttypes.h unconditionally. * bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Assume long long and long double are available. (bfd_scan_vma): Assume long long and strtoull are available. * elflink.c: Include limits.h unconditionally. * elfnn-riscv.c: Likewise. * wasm-module.c: Likewise. * hpux-core.c: Include dirent.h unconditionally. * trad-core.c: Likewise. * hosts/x86-64linux.h: Include stdlib.h unconditionally. * peXXigen.c: Remove HAVE_WCHAR_H and HAVE_WCTYPE_H checks. * elf32-m68hc1x.c: Don't include alloca-conf.h. * elf64-hppa.c: Likewise. * som.c: Likewise. * wasm-module.c: Likewise. * xsym.c: Likewise. * bfd-in2.h: Regenerate. * config.in: Regenerate. * configure: Regenerate.
2021-03-31Use bool in bfdAlan Modra1-142/+142
* sysdep.h: POISON_BFD_BOOLEAN: Define. * aix5ppc-core.c, * aout-cris.c, * aout-ns32k.c, * aout-target.h, * aoutx.h, * arc-got.h, * archive.c, * archive64.c, * archures.c, * bfd-in.h, * bfd.c, * bfdwin.c, * binary.c, * cache.c, * coff-alpha.c, * coff-arm.c, * coff-arm.h, * coff-bfd.c, * coff-bfd.h, * coff-go32.c, * coff-i386.c, * coff-ia64.c, * coff-mcore.c, * coff-mips.c, * coff-rs6000.c, * coff-sh.c, * coff-stgo32.c, * coff-tic30.c, * coff-tic4x.c, * coff-tic54x.c, * coff-x86_64.c, * coff-z80.c, * coff-z8k.c, * coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c, * compress.c, * corefile.c, * cpu-aarch64.c, * cpu-aarch64.h, * cpu-alpha.c, * cpu-arc.c, * cpu-arm.c, * cpu-arm.h, * cpu-avr.c, * cpu-bfin.c, * cpu-bpf.c, * cpu-cr16.c, * cpu-cris.c, * cpu-crx.c, * cpu-csky.c, * cpu-d10v.c, * cpu-d30v.c, * cpu-dlx.c, * cpu-epiphany.c, * cpu-fr30.c, * cpu-frv.c, * cpu-ft32.c, * cpu-h8300.c, * cpu-hppa.c, * cpu-i386.c, * cpu-ia64.c, * cpu-iamcu.c, * cpu-ip2k.c, * cpu-iq2000.c, * cpu-k1om.c, * cpu-l1om.c, * cpu-lm32.c, * cpu-m10200.c, * cpu-m10300.c, * cpu-m32c.c, * cpu-m32r.c, * cpu-m68hc11.c, * cpu-m68hc12.c, * cpu-m68k.c, * cpu-m9s12x.c, * cpu-m9s12xg.c, * cpu-mcore.c, * cpu-mep.c, * cpu-metag.c, * cpu-microblaze.c, * cpu-mips.c, * cpu-mmix.c, * cpu-moxie.c, * cpu-msp430.c, * cpu-mt.c, * cpu-nds32.c, * cpu-nfp.c, * cpu-nios2.c, * cpu-ns32k.c, * cpu-or1k.c, * cpu-pdp11.c, * cpu-pj.c, * cpu-powerpc.c, * cpu-pru.c, * cpu-riscv.c, * cpu-rl78.c, * cpu-rs6000.c, * cpu-rx.c, * cpu-s12z.c, * cpu-s390.c, * cpu-score.c, * cpu-sh.c, * cpu-sparc.c, * cpu-spu.c, * cpu-tic30.c, * cpu-tic4x.c, * cpu-tic54x.c, * cpu-tic6x.c, * cpu-tilegx.c, * cpu-tilepro.c, * cpu-v850.c, * cpu-v850_rh850.c, * cpu-vax.c, * cpu-visium.c, * cpu-wasm32.c, * cpu-xc16x.c, * cpu-xgate.c, * cpu-xstormy16.c, * cpu-xtensa.c, * cpu-z80.c, * cpu-z8k.c, * dwarf1.c, * dwarf2.c, * ecoff-bfd.h, * ecoff.c, * ecofflink.c, * elf-attrs.c, * elf-bfd.h, * elf-eh-frame.c, * elf-hppa.h, * elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-nacl.c, * elf-nacl.h, * elf-properties.c, * elf-s390-common.c, * elf-s390.h, * elf-strtab.c, * elf-vxworks.c, * elf-vxworks.h, * elf.c, * elf32-am33lin.c, * elf32-arc.c, * elf32-arm.c, * elf32-arm.h, * elf32-avr.c, * elf32-avr.h, * elf32-bfin.c, * elf32-bfin.h, * elf32-cr16.c, * elf32-cr16.h, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c, * elf32-csky.h, * elf32-d10v.c, * elf32-d30v.c, * elf32-dlx.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c, * elf32-ft32.c, * elf32-gen.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-hppa.h, * elf32-i386.c, * elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c, * elf32-m32r.c, * elf32-m68hc11.c, * elf32-m68hc12.c, * elf32-m68hc1x.c, * elf32-m68hc1x.h, * elf32-m68k.c, * elf32-m68k.h, * elf32-mcore.c, * elf32-mep.c, * elf32-metag.c, * elf32-metag.h, * elf32-microblaze.c, * elf32-mips.c, * elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-nios2.h, * elf32-or1k.c, * elf32-pj.c, * elf32-ppc.c, * elf32-ppc.h, * elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-s12z.c, * elf32-s390.c, * elf32-score.c, * elf32-score.h, * elf32-score7.c, * elf32-sh-relocs.h, * elf32-sh.c, * elf32-sparc.c, * elf32-spu.c, * elf32-spu.h, * elf32-tic6x.c, * elf32-tic6x.h, * elf32-tilegx.c, * elf32-tilepro.c, * elf32-v850.c, * elf32-v850.h, * elf32-vax.c, * elf32-visium.c, * elf32-wasm32.c, * elf32-xc16x.c, * elf32-xgate.c, * elf32-xstormy16.c, * elf32-xtensa.c, * elf32-z80.c, * elf64-alpha.c, * elf64-bpf.c, * elf64-gen.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c, * elf64-mmix.c, * elf64-nfp.c, * elf64-ppc.c, * elf64-ppc.h, * elf64-s390.c, * elf64-sparc.c, * elf64-tilegx.c, * elf64-x86-64.c, * elfcode.h, * elfcore.h, * elflink.c, * elfn32-mips.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c, * elfxx-aarch64.c, * elfxx-aarch64.h, * elfxx-ia64.c, * elfxx-ia64.h, * elfxx-mips.c, * elfxx-mips.h, * elfxx-riscv.c, * elfxx-riscv.h, * elfxx-sparc.c, * elfxx-sparc.h, * elfxx-target.h, * elfxx-tilegx.c, * elfxx-tilegx.h, * elfxx-x86.c, * elfxx-x86.h, * format.c, * genlink.h, * hash.c, * i386aout.c, * i386lynx.c, * i386msdos.c, * ihex.c, * libaout.h, * libbfd-in.h, * libbfd.c, * libcoff-in.h, * libecoff.h, * libpei.h, * libxcoff.h, * linker.c, * mach-o-aarch64.c, * mach-o-arm.c, * mach-o-i386.c, * mach-o-x86-64.c, * mach-o.c, * mach-o.h, * merge.c, * mmo.c, * netbsd.h, * opncls.c, * pc532-mach.c, * pdp11.c, * pe-arm.c, * pe-i386.c, * pe-mcore.c, * pe-sh.c, * pe-x86_64.c, * peXXigen.c, * pef.c, * pei-arm.c, * pei-i386.c, * pei-ia64.c, * pei-mcore.c, * pei-sh.c, * pei-x86_64.c, * peicode.h, * plugin.c, * plugin.h, * ppcboot.c, * reloc.c, * reloc16.c, * rs6000-core.c, * section.c, * simple.c, * som.c, * som.h, * srec.c, * stabs.c, * syms.c, * targets.c, * tekhex.c, * verilog.c, * vms-alpha.c, * vms-lib.c, * vms-misc.c, * vms.h, * wasm-module.c, * xcofflink.c, * xcofflink.h, * xsym.c, * xsym.h: Replace bfd_boolean with bool, FALSE with false, and TRUE with true throughout. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate.
2021-03-22bfd: add translation wrappers to PE image section RVA diagnosticsJan Beulich1-2/+2
In commit 87fa7d568ddd ("bfd: don't silently wrap or truncate PE image section RVAs") I forgot about the need to wrap string literals for translation.
2021-03-16Fix a potential buffer overrun qwhen writing out PE aux entries.Nick Clifton1-1/+1
* peXXigen.c (_bfd_XXi_swap_aux_out): Avoid potential buffer overrun by using sizeof of the destination x_fname field as the limit for a memcpy. * coff/internal.h (struct internal_auxent): Fix a couple of typos in comment describing the x_fname field.
2021-03-09bfd: don't silently wrap or truncate PE image section RVAsJan Beulich1-5/+7
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-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2020-12-18Remove some static buffersAlan Modra1-4/+7
Fixes possible overflow of a static buffer for powerpc with translated messages, and on v850 when symbol names are large. * archive.c (_bfd_ar_spacepad, _bfd_ar_sizepad): Use auto buf. * coff-mcore.c (coff_mcore_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_unhandled_reloc): Use asprintf in place of fixed size and possibly too small buf for translated message. * elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise. * elf32-v850.c (v850_elf_check_relocs): Likewise. * ecoff.c (ecoff_type_to_string): Pass in return string buff rather than using static buffer2. Delete dead code. Remove unnecessary parentheses. (_bfd_ecoff_print_symbol): Pass auto buff to ecoff_type_to_string. * elf32-rx.c (describe_flags): Pass in return string buf rather than using static buf. (rx_elf_merge_private_bfd_data): Pass buf to describe_flags. (rx_elf_print_private_bfd_data): Likewise. * mach-o.c (cpusubtype): Pass in return string buffer rather than using static buffer. (bfd_mach_o_bfd_print_private_bfd_data): Pass buff to cpusubtype. * opncls.c (separate_debug_file_exists): Make buffer an auto var. (bfd_fill_in_gnu_debuglink_section): Likewise. * peXXigen.c (rsrc_resource_name): Pass in return string buffer rather than using static buffer. (rsrc_sort_entries): Pass buff to rsrc_resource_name. * vms-alpha.c (_bfd_vms_write_emh): Pass tbuf to get_vms_time_string. * vms-misc.c (get_vms_time_string): Pass in return string tbuf rather than using static tbuf. * vms.h (get_vms_time_string): Update prototype.
2020-08-21fix objcopy of PE images with .buildid sectionJan Beulich1-15/+19
Xen Project embeds a build ID in its hypervisor binary (including its EFI variant), living in a standalone section. This usually gets placed right after .rodata, and due to the rounding done on the (file) size of .rodata the two sections appear to overlap (as far as e.g. find_section_by_vma() is concerned). With the first byte "found" in .rodata, nothing guarantees that the entire debug dir fits in that section, leading to apparently random failure of objcopy on such an image. Possible alternatives to the solution chosen: - make find_section_by_vma() honor virt_size, - correct the recording of sizes elsewhere (ibfd has size == virt_size, while obfd doesn't), - fix the linker to avoid producing apparently overlapping sections. While touching the condition around and the contents of the disgnostic, pull it up ahead of the bfd_malloc_and_get_section() call: There's no point first obtaining the section contents, in order to then fail.
2020-07-09Remove powerpc PE supportAlan Modra1-112/+1
Plus some leftover powerpc lynxos support. bfd/ * coff-ppc.c: Delete. * pe-ppc.c: Delete. * pei-ppc.c: Delete. * Makefile.am (BFD32_BACKENDS, BFD32_BACKENDS_CFILES): Remove PE PPC. * coffcode.h (coff_set_arch_mach_hook, coff_set_flags): Remove PPCMAGIC code. (coff_write_object_contents): Remove PPC_PE code. * config.bfd: Move powerpcle-pe to removed targets. * configure.ac: Remove powerpc PE entries. * libcoff-in.h (ppc_allocate_toc_section): Delete. (ppc_process_before_allocation): Delete. * peXXigen.c: Remove POWERPC_LE_PE code and comments. * targets.c: Remove powerpc PE vectors. * po/SRC-POTFILES.in: Regenerate. * libcoff.h: Regenerate. * Makefile.in: Regenerate. * configure: Regenerate. binutils/ * dlltool.c: Remove powerpc PE support and comments. * configure.ac: Remove powerpc PE dlltool config. * configure: Regenerate. gas/ * config/obj-coff.h: Remove TE_PE support. * config/tc-ppc.c: Likewise. * config/tc-ppc.h: Likewise. * configure.tgt: Remove powerpc PE and powerpc lynxos. * testsuite/gas/cfi/cfi.exp (cfi-common-6): Remove powerpc PE condition. * testsuite/gas/macros/macros.exp: Don't xfail powerpc PE. include/ * coff/powerpc.h: Delete. ld/ * emulparams/ppcpe.sh: Delete. * scripttempl/ppcpe.sc: Delete. * emulparams/ppclynx.sh: Delete. * Makefile.am (ALL_EMULATION_SOURCES): Remove ppc PE and lynxos. * configure.tgt: Likewise. * emultempl/beos.em: Remove powerpc PE support. * emultempl/pe.em: Likewise. * po/BLD-POTFILES.in: Regenerate. * Makefile.in: Regenerate.
2020-06-29asan: _bfd_pei_slurp_codeview_record use of uninit valueAlan Modra1-2/+8
Fixes some seriously careless code. bfd_bread return value is (bfd_size_type)-1 on error. "if (bfd_bread (...) < 4)" does not check for an error since bfd_size_type is unsigned. In any case, I think we should be reading and checking the requested length. * peXXigen.c (_bfd_XXi_slurp_codeview_record): Properly check return value of bfd_bread. Don't read more than requested length. Sanity check length. Properly terminate file name.
2020-06-29C++ commentsAlan Modra1-5/+5
binutils isn't c99 (yet). This replaces or removes some C++ style comments. bfd/ * arc-got.h: Use C style comments. * coff-z80.c: Likewise. * elf32-csky.c: Likewise. * peXXigen.c: Likewise. * elf32-m32c.c (m32c_elf_relax_delete_bytes): Remove commented out code. binutils/ * dwarf.c: Use C style comments. * resrc.c: Likewise. gas/ * config/tc-s12z.c: Use C style comments. * config/tc-z80.c: Likewise. * config/tc-xtensa.c (emit_ld_r_n): Remove commented out code. include/ * coff/internal.h: Use C style comments. * coff/pe.h: Likewise. * elf/ppc64.h: Likewise. opcodes/ * arm-dis.c: Use C style comments. * cr16-opc.c: Likewise. * ft32-dis.c: Likewise. * moxie-opc.c: Likewise. * tic54x-dis.c: Likewise. * s12z-opc.c: Remove useless comment. * xgate-dis.c: Likewise.
2020-05-21Replace "if (x) free (x)" with "free (x)", bfdAlan Modra1-20/+10
* aoutx.h: Replace "if (x) free (x)" with "free (x)" throughout. * archive.c, * bfd.c, * bfdio.c, * coff-alpha.c, * coff-ppc.c, * coff-sh.c, * coff-stgo32.c, * coffcode.h, * coffgen.c, * cofflink.c, * cpu-arm.c, * doc/chew.c, * dwarf2.c, * ecoff.c, * ecofflink.c, * elf-eh-frame.c, * elf-m10200.c, * elf-m10300.c, * elf-strtab.c, * elf.c, * elf32-arc.c, * elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c, * elf32-crx.c, * elf32-epiphany.c, * elf32-ft32.c, * elf32-h8300.c, * elf32-ip2k.c, * elf32-m32c.c, * elf32-m68hc11.c, * elf32-m68k.c, * elf32-microblaze.c, * elf32-msp430.c, * elf32-nds32.c, * elf32-nios2.c, * elf32-ppc.c, * elf32-pru.c, * elf32-rl78.c, * elf32-rx.c, * elf32-sh.c, * elf32-spu.c, * elf32-v850.c, * elf32-xtensa.c, * elf64-alpha.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mips.c * elf64-mmix.c, * elf64-ppc.c, * elf64-sparc.c, * elfcode.h, * elflink.c, * elfnn-ia64.c, * elfnn-riscv.c, * elfxx-mips.c, * elfxx-x86.c, * format.c, * ihex.c, * libbfd.c, * linker.c, * mmo.c, * opncls.c, * pdp11.c, * peXXigen.c, * pef.c, * peicode.h, * simple.c, * som.c, * srec.c, * stabs.c, * syms.c, * targets.c, * vms-lib.c, * xcofflink.c, * xtensa-isa.c: Likewise.
2020-04-15PR25823, Use after free in bfd_hash_lookupAlan Modra1-10/+10
PR 25823 * peXXigen.c (_bfd_XXi_swap_sym_in <C_SECTION>): Don't use a pointer into strings that may be freed for section name, always allocate a new string.
2020-03-30Fix objcopy's --preserve-dates command line option so that it will work with ↵Nick Clifton1-2/+2
PE format files. PR binutils/pr25662 bfd * libcoff-in.h (struct pe_tdata): Rename the insert_timestamp field to timestamp and make it an integer. * libcoff.h: Regenerate. * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Test the timestamp field in the pe_data structure rather than the insert_timestamp field. binutils* objcopy.c (copy_object): When copying PE format files set the timestamp field in the pe_data structure if the preserve_dates flag is set. * testsuite/binutils-all/objcopy.exp (objcopy_test) Use --preserve-dates in place of the -p option, in order to make its effect more obvious. ld * emultempl/pe.em (after_open): Replace initialisation of the insert_timestamp field in the pe_data structure with an initialisation of the timestamp field. * emultemp/pep.em: Likewise. * pe-dll.c (fill_edata): Use the timestamp field in the pe_data structure instead of the insert_timestamp field.
2020-02-19bfd_size_type to size_tAlan Modra1-2/+2
bfd_size_type was invented a long time ago in the K&R days. Many places in binutils ought to be using size_t instead (and there are lots of places that use long or unsigned long that really ought to use size_t too). Note that you can't change everything over to size_t: A 32-bit host needs a larger type than size_t to support reading and processing of 64-bit ELF object files. This patch just tidies some of the more obvious uses of bfd_size_type that could be size_t. There no doubt are more lurking in the source. Incidentally, practically all functions used for output of object files can use size_t and don't need to worry about overflow of size expressions. If you have something like symcount * sizeof (void *) when symcount is counting symbols already in memory then you know that this expression can't overflow since the size of a symbol in memory is larger by far than that of a pointer. * aix386-core.c (aix386_core_file_p): Use size_t for "amt". * aout-target.h (object_p): Likewise. * aout-tic30.c (tic30_aout_object_p): Likewise. * aoutx.h (some_aout_object_p, mkobject, make_empty_symbol), (emit_stringtab, write_syms, link_hash_table_create), (aout_link_write_other_symbol): Likewise. * archive.c (_bfd_generic_mkarchive, bfd_generic_archive_p), (bfd_ar_hdr_from_filesystem, _bfd_write_archive_contents), (_bfd_compute_and_write_armap): Likewise. * archures.c (bfd_arch_list): Likewise. * bfd.c (bfd_record_phdr): Likewise. * binary.c (binary_canonicalize_symtab): Likewise. * cisco-core.c (cisco_core_file_validate): Likewise. * coff-arm.c (coff_arm_link_hash_table_create, find_thumb_glue), (find_arm_glue, record_arm_to_thumb_glue), (record_thumb_to_arm_glue): Likewise. * coff-ppc.c (ppc_coff_link_hash_table_create, record_toc), (ppc_allocate_toc_section): Likewise. * coff-rs6000.c (_bfd_xcoff_mkobject, _bfd_xcoff_archive_p): Likewise. * coff-sh.c (sh_relax_section): Likewise. * coff64-rs6000.c (xcoff64_archive_p): Likewise. * coffcode.h (handle_COMDAT, coff_new_section_hook), (coff_set_alignment_hook, coff_mkobject), (coff_compute_section_file_positions): Likewise. * coffgen.c (coff_make_empty_symbol, coff_bfd_make_debug_symbol), (coff_find_nearest_line_with_names), ( bfd_coff_set_symbol_class): Likewise. * cofflink.c (_bfd_coff_link_hash_table_create), (_bfd_coff_link_input_bfd): Likewise. * dwarf1.c (alloc_dwarf1_unit, alloc_dwarf1_func): Likewise. * dwarf2.c (read_abbrevs, read_attribute_value, add_line_info), (build_line_info_table, sort_line_sequences), (line_info_add_include_dir, line_info_add_file_name), (decode_line_info, scan_unit_for_symbols, parse_comp_unit), (place_sections, _bfd_dwarf2_slurp_debug_info): Likewise. * ecoff.c (_bfd_ecoff_mkobject, _bfd_ecoff_make_empty_symbol), (_bfd_ecoff_find_nearest_line), (_bfd_ecoff_bfd_link_hash_table_create): Likewise. * ecofflink.c (bfd_ecoff_debug_init): Likewise. * elf-hppa.h (_bfd_elf_hppa_gen_reloc_type): Likewise. * elf-m10300.c (mn10300_elf_relax_section), (elf32_mn10300_link_hash_table_create): Likewise. * elf-strtab.c (_bfd_elf_strtab_init): Likewise. * elf.c (make_mapping, copy_elf_program_header): Likewise. * elf32-arm.c (elf32_arm_link_hash_table_create), (elf32_arm_setup_section_lists, elf32_arm_check_relocs), (elf32_arm_new_section_hook): Likewise. * elf32-avr.c (elf_avr_new_section_hook), (elf32_avr_link_hash_table_create, get_local_syms), (elf32_avr_setup_section_lists): Likewise. * elf32-bfin.c (bfinfdpic_elf_link_hash_table_create), (bfin_link_hash_table_create): Likewise. * elf32-cr16.c (elf32_cr16_link_hash_table_create): Likewise. * elf32-cris.c (elf_cris_link_hash_table_create): Likewise. * elf32-csky.c (csky_elf_link_hash_table_create), (csky_elf_check_relocs, elf32_csky_setup_section_lists): Likewise. * elf32-frv.c (frvfdpic_elf_link_hash_table_create): Likewise. * elf32-hppa.c (elf32_hppa_link_hash_table_create), (elf32_hppa_setup_section_lists, get_local_syms): Likewise. * elf32-i386.c (elf_i386_check_relocs): Likewise. * elf32-lm32.c (lm32_elf_link_hash_table_create): Likewise. * elf32-m32r.c (m32r_elf_link_hash_table_create), (m32r_elf_check_relocs): Likewise. * elf32-m68hc1x.c (m68hc11_elf_hash_table_create), (elf32_m68hc11_setup_section_lists), (elf32_m68hc11_size_stubs): Likewise. * elf32-m68k.c (elf_m68k_link_hash_table_create): Likewise. * elf32-metag.c (elf_metag_link_hash_table_create), (elf_metag_setup_section_lists): Likewise. * elf32-microblaze.c (microblaze_elf_link_hash_table_create), (microblaze_elf_check_relocs): Likewise. * elf32-nds32.c (nds32_elf_link_hash_table_create), (nds32_elf_check_relocs): Likewise. * elf32-nios2.c (nios2_elf32_setup_section_lists), (get_local_syms, nios2_elf32_check_relocs), (nios2_elf32_link_hash_table_create): Likewise. * elf32-or1k.c (or1k_elf_link_hash_table_create), (or1k_elf_check_relocs): Likewise. * elf32-ppc.c (ppc_elf_modify_segment_map, update_plt_info): Likewise. * elf32-pru.c (pru_elf32_link_hash_table_create): Likewise. * elf32-s390.c (elf_s390_link_hash_table_create), (elf_s390_check_relocs): Likewise. * elf32-score.c (score_elf_create_got_section), (s3_elf32_score_new_section_hook), (elf32_score_link_hash_table_create): Likewise. * elf32-score7.c (score_elf_create_got_section), (s7_elf32_score_new_section_hook): Likewise. * elf32-sh.c (sh_elf_link_hash_table_create), (sh_elf_check_relocs): Likewise. * elf32-tic6x.c (elf32_tic6x_link_hash_table_create), (elf32_tic6x_new_section_hook, elf32_tic6x_check_relocs): Likewise. * elf32-tilepro.c (tilepro_elf_link_hash_table_create), (tilepro_elf_check_relocs): Likewise. * elf32-v850.c (remember_hi16s_reloc): Likewise. * elf32-vax.c (elf_vax_link_hash_table_create): Likewise. * elf32-xtensa.c (elf_xtensa_link_hash_table_create), (elf_xtensa_new_section_hook): Likewise. * elf64-alpha.c (elf64_alpha_bfd_link_hash_table_create), (get_got_entry, elf64_alpha_check_relocs): Likewise. * elf64-hppa.c (elf64_hppa_hash_table_create): Likewise. * elf64-ia64-vms.c (elf64_ia64_object_p): Likewise. * elf64-mmix.c (mmix_elf_new_section_hook): Likewise. * elf64-ppc.c (ppc64_elf_new_section_hook), (ppc64_elf_link_hash_table_create, update_local_sym_info), (update_plt_info, ppc64_elf_check_relocs): Likewise. * elf64-s390.c (elf_s390_link_hash_table_create), (elf_s390_check_relocs): Likewise. * elf64-x86-64.c (elf_x86_64_check_relocs): Likewise. * elflink.c (bfd_elf_link_record_local_dynamic_symbol), (_bfd_elf_link_find_version_dependencies, elf_link_add_object_symbols), (elf_link_add_archive_symbols, compute_bucket_count), (bfd_elf_size_dynsym_hash_dynstr, _bfd_elf_link_hash_table_create), (bfd_elf_get_bfd_needed_list, elf_link_swap_symbols_out), (bfd_elf_final_link): Likewise. * elfnn-aarch64.c (elfNN_aarch64_link_hash_table_create), (elfNN_aarch64_setup_section_lists, elfNN_aarch64_check_relocs), (elfNN_aarch64_new_section_hook): Likewise. * elfnn-ia64.c (elfNN_ia64_object_p): Likewise. * elfnn-riscv.c (riscv_elf_link_hash_table_create), (riscv_elf_check_relocs): Likewise. * elfxx-mips.c (_bfd_mips_elf_new_section_hook), (_bfd_mips_elf_add_symbol_hook, _bfd_mips_elf_check_relocs), (_bfd_mips_elf_modify_segment_map, _bfd_mips_elf_set_section_contents), (_bfd_mips_elf_link_hash_table_create): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_link_hash_table_create), (_bfd_sparc_elf_check_relocs), (_bfd_sparc_elf_new_section_hook): Likewise. * elfxx-tilegx.c (tilegx_elf_link_hash_table_create), (tilegx_elf_check_relocs): Likewise. * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Likewise. * format.c (bfd_check_format_matches): Likewise. * hash.c (_bfd_stringtab_init): Likewise. * ihex.c (ihex_scan): Likewise. * irix-core.c (irix_core_core_file_p): Likewise. * linker.c (bfd_wrapped_link_hash_lookup), (_bfd_generic_link_hash_table_create), (_bfd_generic_reloc_link_order): Likewise. * lynx-core.c (lynx_core_file_p): Likewise. * netbsd-core.c (netbsd_core_file_p): Likewise. * osf-core.c (osf_core_core_file_p): Likewise. * pdp11.c (some_aout_object_p, mkobject, make_empty_symbol), (link_hash_table_create, aout_link_write_other_symbol): Likewise. * peXXigen.c (_bfd_XX_bfd_copy_private_section_data): Likewise. * peicode.h (pe_mkobject): Likewise. * ppcboot.c (ppcboot_mkobject, ppcboot_canonicalize_symtab): Likewise. * ptrace-core.c (ptrace_unix_core_file_p): Likewise. * sco5-core.c (read_uarea): Likewise. * som.c (hppa_som_gen_reloc_type, som_object_p, som_prep_headers), (som_write_fixups, som_write_space_strings, som_write_symbol_strings), (som_finish_writing, som_canonicalize_symtab, som_new_section_hook), (som_bfd_copy_private_section_data, bfd_som_set_section_attributes), (bfd_som_attach_aux_hdr, som_write_armap): Likewise. * srec.c (srec_scan): Likewise. * syms.c (_bfd_generic_make_empty_symbol): Likewise. * targets.c (bfd_target_list): Likewise. * tekhex.c (first_phase, tekhex_sizeof_headers): Likewise. * trad-core.c (trad_unix_core_file_p): Likewise. * vms-alpha.c (vms_initialize, alpha_vms_bfd_link_hash_table_create), (vms_new_section_hook): Likewise. * wasm-module.c (wasm_make_empty_symbol): Likewise. * xcofflink.c (xcoff_get_section_contents), (_bfd_xcoff_bfd_link_hash_table_create, xcoff_set_import_path), (xcoff_find_function, bfd_xcoff_link_record_set, xcoff_build_ldsym), (bfd_xcoff_size_dynamic_sections, xcoff_link_input_bfd): Likewise.
2020-01-30Identify reproducible builds in 'objdump -p' output for PE filesJon Turney1-5/+80
These are produced by MSVC when the '/Brepro' flag is used. To quote from the PE specification [1]: "The presence of an entry of type IMAGE_DEBUG_TYPE_REPRO indicates the PE file is built in a way to achieve determinism or reproducibility. If the input does not change, the output PE file is guaranteed to be bit-for-bit identical no matter when or where the PE is produced. Various date/time stamp fields in the PE file are filled with part or all the bits from a calculated hash value that uses PE file content as input, and therefore no longer represent the actual date and time when a PE file or related specific data within the PE is produced. The raw data of this debug entry may be empty, or may contain a calculated hash value preceded by a four-byte value that represents the hash value length." [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd/ChangeLog: 2020-01-16 Jon Turney <jon.turney@dronecode.org.uk> * peXXigen.c (pe_is_repro): New function. (_bfd_XX_print_private_bfd_data_common): Note timestamp is actually a build hash if PE_IMAGE_DEBUG_TYPE_REPRO is present.
2020-01-30Add some new PE_IMAGE_DEBUG_TYPE valuesJon Turney1-1/+6
IMAGE_DEBUG_TYPE_REPRO is defined in the latest version of the PE specification [1]. The others are defined in Windows SDK headers and/or reported by DUMPBIN. [1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format bfd/ChangeLog: 2020-01-16 Jon Turney <jon.turney@dronecode.org.uk> * peXXigen.c (debug_type_names): Add names for new debug data type values. include/ChangeLog: 2020-01-16 Jon Turney <jon.turney@dronecode.org.uk> * coff/internal.h (PE_IMAGE_DEBUG_TYPE_VC_FEATURE) (PE_IMAGE_DEBUG_TYPE_POGO, PE_IMAGE_DEBUG_TYPE_ILTCG) (PE_IMAGE_DEBUG_TYPE_MPX, PE_IMAGE_DEBUG_TYPE_REPRO): Add.
2020-01-30Bugfixes for pe_print_debugdata()Jon Turney1-3/+5
Use a separate iteration variable for inner loop (:blush:). This generally prevented any debug directory entries after a IMAGE_DEBUG_TYPE_CODEVIEW entry from being reported. Don't leak the memory allocated for the section containing the debug directory. bfd/ChangeLog: 2020-01-16 Jon Turney <jon.turney@dronecode.org.uk> * peXXigen.c (pe_print_debugdata): Fix the iteration variable for inner loop. Fix a memory leak.
2020-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2019-12-05Fix a problem computing the size fields in the PE format header.Nick Clifton1-0/+3
PR 25029 * peXXigen.c (_bfd_XXi_swap_aouthdr_out): Ignore empty sections when computing the sizes stored in the headers.
2019-10-29When copying pe format files, copy the dos_message array, rather than ↵Andrew Eikum1-16/+5
re-initiialising it. * libcoff-in.h (struct pe_tdata): Add dos_message field. * libcoff.h: Regenerate. * peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Copy the dos_message field rather than initialising it. (_bfd_XX_bfd_copy_private_bfd_data_common): Copy the dos_message field. * peicode.h (pe_mkobject): Initialise the dos_message field. (pe_mkobject_hook): Copy the dos_message field. (pe_bfd_object_p): Copy the dos_message field.
2019-10-14PR24955, libbfd terminating program on out of memory (part2)Alan Modra1-1/+4
PR 24955 * elflink.c (elf_output_implib): Don't use xmalloc. Don't ignore return value of bfd_alloc2. * peXXigen.c (_bfd_XXi_write_codeview_record): Don't use xmalloc. * pef.c (bfd_pef_print_symbol): Likewise. Don't ignore return value of bfd_get_section_contents. * som.c (som_write_space_strings): Don't use xmalloc. (som_write_symbol_strings): Likewise.
2019-07-23Allow objdump to recognise the System.Runtime.dll files that get shipped ↵Omar Majid1-0/+7
with .NET Core 2.1. include * coff/i386.h (IMAGE_FILE_MACHINE_NATIVE_APPLE_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_FREEBSD_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_LINUX_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_NETBSD_OVERRIDE): Define. (I386_APPLE_MAGIC): Define. (I386_FREEBSD_MAGIC): Define. (I386_LINUX_MAGIC): Define. (I386_NETBSD_MAGIC): Define. (I386BADMAG): Extend macro to allow new magic numbers. * coff/x86_64.h (IMAGE_FILE_MACHINE_NATIVE_APPLE_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_FREEBSD_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_LINUX_OVERRIDE): Define. (IMAGE_FILE_MACHINE_NATIVE_NETBSD_OVERRIDE): Define. (AMD64_APPLE_MAGIC): Define. (AMD64_FREEBSD_MAGIC): Define. (AMD64_LINUX_MAGIC): Define. (AMD64_NETBSD_MAGIC): Define. (AMD64BADMAG): Extend macro to allow new magic numbers. bfd * coffcode.h (coff_set_arch_mach_hook): Handle I386_APPLE_MAGIC, I386_FREEBSD_MAGIC, I386_LINUX_MAGIC, I386_NETBSD_MAGIC, AMD64_APPLE_MAGIC, AMD64_FREEBSD_MAGIC, AMD64_LINUX_MAGIC, AMD64_NETBSD_MAGIC. * peXXigen.c: Add comment about source of .NET magic numbers. binutils* Makefile.am (AUTOMAKE_OPTIONS): Add subdir-objects (GENTESTDLLSPROG): Define. (TEST_PROGS): Add GENTESTDLLSPROG. * Makefile.in: Regenerate. * testsuite/binutils-all/objdump.exp (test_objdump_dotnet_assemblies): New proc. Run the new proc. * testsuite/gentestdlls.c: New source file.