aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
AgeCommit message (Collapse)AuthorFilesLines
2024-07-20PR31999 strip [.gnu.build.attributes]: failedAlan Modra1-0/+1
PR 31999 * objcopy.c (merge_gnu_build_notes): Always set *new_size.
2024-07-06objcopy bfd_map_over_sections and global statusAlan Modra1-142/+139
This patch started life as a relatively simple change to fix some unimportant objcopy memory leaks, but expanded into a larger patch when I was annoyed by the awkwardness of passing data when using bfd_map_over_sections. A simple loop over sections is much more convenient, and we really don't need the abstraction layer. Sections in a list isn't going to disappear any time soon. The patch also removes use of the global "status" variable by all but the top-level functions called from main. * objcopy.c (filter_symbols): Return success as a bool. Pass symcount as a pointer, updated on return. (merge_gnu_build_notes): Similarly return a bool and add newsize param with updated smaller section size. (setup_bfd_headers): Return bool success rather than setting "status" on failure. (setup_section): Likewise. (copy_relocations_in_section, copy_section): Likewise, and adjust params. (mark_symbols_used_in_relocations): Likewise, and free memory on failure path. Don't call bfd_fatal. (get_sections): Delete function. (copy_object): Don't use bfd_map_over_sections, instead use a loop allowing easy detection of failure status. Free memory on error paths. (copy_archive): Return bool success rather than setting "status" on failure. (copy_file): Set "status" here. * testsuite/binutils-all/strip-13.d: Adjust to suit.
2024-07-01PR31941 objcopy --globalize-symbolAlan Modra1-0/+1
I think FILE symbols are special, and I can't see why anyone would want them to be made global. The fact that no one has reported this bug since commit 7b4a0685e80a in 2005 supports that claim. PR 31941 * objcopy.c (filter_symbols): Don't allow BSF_FILE symbols to be made global.
2024-07-01objcopy: Allow making symbol global and weak on same invocationMarcus Nilsson1-15/+16
Previously objcopy had to be run twice in order to make a local symbol weak, first once to globalize it, and once again to mark it as weak. * objcopy.c (filter_symbols): Weaken symbols after making local/global changes. * testsuite/binutils-all/symbols-5.d, * testsuite/binutils-all/symbols-5.s: New test.
2024-04-26objcopy: check input flavor before setting PE/COFF section alignmentJan Beulich1-0/+1
coff_section_data() and elf_section_data() use the same underlying field. The pointer being non-NULL therefore isn't sufficient to know that pei_section_data() can validly be used on the incoming object. Apparently in 64-bit-host builds the resulting memory corruption is benign, whereas in 32-bit-host builds a segmentation fault occurs upon de-referencing pei_section_data()'s return value.
2024-04-23objcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hostsH.J. Lu1-2/+2
Use long with bfd_copy_private_symbol_data to fix .../binutils/objcopy.c: In function ‘copy_object’: .../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare] 3383 | for (i = 0; i < symcount; i++) | ^ on 32-bit hosts. PR binutils/14493 * objcopy.c (copy_object): Use long with bfd_copy_private_symbol_data.
2024-04-23use copy_private_symbol_data in objcopyAlan Modra1-0/+7
osympp appearing twice here is not a bug. PR 14493 * objcopy.c (copy_object): Run the symbols through bfd_copy_private_symbol_data.
2024-04-11Re: Update objcopy's --section-alignment optionAlan Modra1-2/+6
ubsan: shift exponent 255 is too large for 64-bit type I should have known oss-fuzz wouldn't be satisfied so easily. The pef format allows quite silly section alignments in object files. * objcopy.c (setup_section): Limit shift exponent when checking vma and lma for alignment.
2024-04-04Re: Update objcopy's --section-alignment optionAlan Modra1-2/+2
ubsan: left shift of 1 by 31 places cannot be represented in type 'int' * objcopy.c (setup_section): Avoid undefined behaviour when checking vma and lma for alignment.
2024-04-02Update objcopy's --section-alignment option so that it sets the alignment ↵Nick Clifton1-9/+101
flag on PE sections. Add a check for aligned sections not matching their VMAs.
2024-01-26Fix: Stripping Rust static libraries fails because of overly zealous illegal ↵Nick Clifton1-12/+14
path check PR 31250 * objcopy.c (copy_archive): Improve the handling of archives that contain elements with invalid pathnames.
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-27PR31191, objcopy leaves temporary filesAlan Modra1-23/+24
Fix the ENOTDIR rmdir too. PR 31191 * objcopy.c (copy_archive): Localise uses of "l". Remove const from name_list.name. Unlink output element on bfd_close error, and NULL list->name to indicate file is removed. Adjust cleanup to prevent rmdir on non-existent file.
2023-12-05Handle "efi-app-riscv64" and similar targets in objcopy.Peter Jones1-0/+5
This adds the efi target name handling for riscv64 to objcopy. binutils: * binutils/objcopy.c: add riscv64 handling to convert_efi_target() Signed-off-by: Peter Jones <pjones@redhat.com> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-10-23objcopy: fix typo in --heap and --stack parserClément Chigot1-2/+2
The help says that <reserve> and <commit> should be separated by a "," but the implementation is checking for ".". Having two numbers being separated by a "." could be confusing, thus adjust the implementation to match the help syntax. binutils/ChangeLog: * objcopy.c (copy_main): Set separator to "," between <reserve> and <commit> for --heap and --stack. * doc/binutils.texi: Add <commit> for --heap and --stack.
2023-10-16objcopy: Fix name of the field modified by pe_stack_reserve.Clément Chigot1-1/+1
2023-08-09Rename bfd_bread and bfd_bwriteAlan Modra1-3/+3
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-38/+70
This reverts commit 675b9d612cc59446e84e2c6d89b45500cb603a8d. See https://sourceware.org/pipermail/binutils/2023-August/128761.html.
2023-08-022.41 Release sourcesbinutils-2_41-releaseNick Clifton1-70/+38
2023-07-28coff/pe/xcoff and --extract-symbolsAlan Modra1-7/+19
This fixes failure of the "extract symbols" test for rs6000, where --extract-symbols generates a non-zero sized .text. By the look of coffcode.h the same problem might occur for coff/pe too, but doesn't happen to trigger a test failure. bfd/ * coffcode.h (coff_compute_section_file_positions): Don't adjust size of !SEC_LOAD sections. binutils/ * objcopy.c (setup_section): Clear SEC_LOAD for --extract-symbol.
2023-07-14More tidies to objcopy archive handlingAlan Modra1-28/+32
This makes sure copy_archive exits with ibfd and obfd closed. Error paths didn't do that, leading to memory leaks. None of this matters very much. * objcopy.c (copy_archive): bfd_close ibfd and obfd on error return paths. Remove braces around "list" free. (copy_file): Don't close invalid file descriptor.
2023-07-09PR30592 objcopy: allow --set-section-flags to add or remove SHF_X86_64_LARGEFangrui Song1-3/+19
For example, objcopy --set-section-flags .data=alloc,large will add SHF_X86_64_LARGE to the .data section. Omitting "large" will drop the SHF_X86_64_LARGE flag. The bfd_section flag is named generically, SEC_ELF_LARGE, in case other processors want to follow SHF_X86_64_LARGE. SEC_ELF_LARGE has the same value as SEC_TIC54X_BLOCK used by coff. bfd/ * section.c: Define SEC_ELF_LARGE. * bfd-in2.h: Regenerate. * elf64-x86-64.c (elf_x86_64_section_flags, elf_x86_64_fake_sections, elf_x86_64_copy_private_section_data): New. binutils/ * NEWS: Mention the new feature for objcopy. * doc/binutils.texi: Mention "large". * objcopy.c (parse_flags): Parse "large". (check_new_section_flags): Error if "large" is used with a non-x86-64 ELF target. * testsuite/binutils-all/x86-64/large-sections.d: New. * testsuite/binutils-all/x86-64/large-sections.s: New. * testsuite/binutils-all/x86-64/large-sections-i386.d: New. * testsuite/binutils-all/x86-64/large-sections-2.d: New. * testsuite/binutils-all/x86-64/large-sections-2-x32.d: New.
2023-06-29ELF: Discard non-alloc sections without section headerH.J. Lu1-1/+6
Discard non-alloc sections when section headers are stripped. bfd/ PR ld/25617 * elf.c (_bfd_elf_assign_file_positions_for_non_load): Skip non-load sections without section header. (_bfd_elf_write_object_contents): Don't set the sh_name field without section header. Write out the .shstrtab section only if its sh_offset field isn't -1. binutils/ PR ld/25617 * objcopy.c (is_strip_section_1): Remove non-alloc sections for --strip-section-headers. ld/ PR ld/25617 * ldlang.c (lang_discard_section_p): Discard non-alloc sections if we are stripping section headers.
2023-06-29ELF: Strip section header in ELF objectsKaylee Blake1-2/+31
Section header isn't mandatory on ELF executable nor shared library. This patch adds a new linker option, -z nosectionheader, to omit ELF section header, a new objcopy and strip option, --strip-section-headers, to remove ELF section headers. bfd/ 2023-06-06 H.J. Lu <hongjiu.lu@intel.com> Kaylee Blake <klkblake@gmail.com> PR ld/25617 * bfd.c (BFD_NO_SECTION_HEADER): New. (BFD_FLAGS_SAVED): Add BFD_NO_SECTION_HEADER. (BFD_FLAGS_FOR_BFD_USE_MASK): Likewise. * elfcode.h (elf_swap_ehdr_out): Omit section header with BFD_NO_SECTION_HEADER. (elf_write_shdrs_and_ehdr): Likewise. * elfxx-target.h (TARGET_BIG_SYM): Add BFD_NO_SECTION_HEADER to object_flags. (TARGET_LITTLE_SYM): Likewise. * bfd-in2.h: Regenerated. binutils/ 2023-06-06 H.J. Lu <hongjiu.lu@intel.com> PR ld/25617 * NEWS: Mention --strip-section-headers for objcopy and strip. * objcopy.c (strip_section_headers): New. (command_line_switch): Add OPTION_STRIP_SECTION_HEADERS. (strip_options): Add --strip-section-headers. (copy_options): Likewise. (copy_usage): Add --strip-section-headers. (strip_usage): Likewise. (copy_object): Handle --strip-section-headers for ELF files. (strip_main): Handle OPTION_STRIP_SECTION_HEADERS. (copy_main): Likewise. * doc/binutils.texi: Document --strip-section-headers for objcopy and strip. ld/ 2023-06-06 H.J. Lu <hongjiu.lu@intel.com> Kaylee Blake <klkblake@gmail.com> PR ld/25617 * NEWS: Mention -z nosectionheader. * emultempl/elf.em: Support -z sectionheader and -z nosectionheader. * ld.h (ld_config_type): Add no_section_header. * ld.texi: Document -z sectionheader and -z nosectionheader. * ldlang.c (ldlang_open_output): Handle config.no_section_header. * lexsup.c (parse_args): Enable --strip-all with -z nosectionheader. Disallow -r with -z nosectionheader. (elf_static_list_options): Add -z sectionheader and -z nosectionheader.
2023-06-07objcopy memory leaks after errorsAlan Modra1-0/+5
These aren't important at all, but tidy them in case they obscure other more important leaks. * objcopy (copy_file): Close input bfd after errors.
2023-06-02Minor objcopy optimisation for copy_relocations_in_sectionAlan Modra1-0/+2
* objcopy (copy_relocations_in_section): Don't read the relocs for STRIP_ALL if keep_specific_htab is empty.
2023-04-24objcopy of archives tidyAlan Modra1-16/+19
This makes sure the input element bfd is closed before exiting the loop copying elements. * objcopy.c (copy_archive): Rename output_bfd to output_element. Localise last_element. Close this_element in more error cases.
2023-04-06objcopy write_debugging_info memory leaksAlan Modra1-6/+6
The old stabs code didn't bother too much about freeing memory. This patch corrects that and avoids some dubious copying of strings. * objcopy.c (write_debugging_info): Free both strings and syms on failure to create sections. * wrstabs.c: Delete unnecessary forward declarations and casts throughout file. (stab_write_symbol_and_free): New function. Use it throughout, simplifying return paths. (stab_push_string): Don't strdup string. Use it thoughout for malloced strings. (stab_push_string_dup): New function. Use it throughout for strings in auto buffers. (write_stabs_in_sections_debugging_info): Free malloced memory. (stab_enum_type): Increase buffer sizing for worst case. (stab_range_type, stab_array_type): Reduce buffer size. (stab_set_type): Likewise. (stab_method_type): Free args on error return. Correct buffer size. (stab_struct_field): Fix memory leaks. (stab_class_static_member, stab_class_baseclass): Likewise. (stab_start_class_type): Likewise. Correct buffer size. (stab_class_start_method): Correct buffer size. (stab_class_method_var): Free memory on error return. (stab_start_function): Fix "rettype" memory leak.
2023-04-04Use bfd_alloc memory for read_debugging_info storageAlan Modra1-4/+1
Trying to free malloc'd memory used by the stabs and coff debug info parsers is complicated, and traversing the trees generated requires a lot of code. It's better to bfd_alloc the memory which allows it all to be freed without fuss when the bfd is closed. In the process of doing this I reverted most of commit a6336913332. Some of the stabs handling code grows arrays of pointers with realloc, to deal with arbitrary numbers of fields, function args, etc. The code still does that but copies over to bfd_alloc memory when finished. The alternative is to parse twice, once to size, then again to populate the arrays. I think that complication is unwarranted. Note that there is a greater than zero chance this patch breaks something, eg. that I missed an attempt to free obj_alloc memory. Also it seems there are no tests in the binutils testsuite aimed at exercising objdump --debugging. * budbg.h (finish_stab, parse_stab): Update prototypes * debug.c: Include bucomm.h. (struct debug_handle): Add "abfd" field. (debug_init): Add "abfd" param. bfd_alloc handle. (debug_xalloc, debug_xzalloc): New functions. Use throughout in place of xmalloc and memset. (debug_start_source): Remove "name_used" param. * debug.h (debug_init, debug_start_source): Update prototypes. (debug_xalloc, debug_xzalloc): Declare. * objcopy.c (copy_object): Don't free dhandle. * objdump.c (dump_bfd): Likewise. * rdcoff.c (coff_get_slot): Add dhandle arg. debug_xzalloc memory in place of xcalloc. Update callers. (parse_coff_struct_type): Don't leak on error return. Copy fields over to debug_xalloc memory. (parse_coff_enum_type): Copy names and vals over the debug_xalloc memory. * rddbg.c (read_debugging_info): Adjust debug_init call. Don't free dhandle. (read_section_stabs_debugging_info): Don't free shandle. Adjust parse_stab call. Call finish_stab on error return. (read_symbol_stabs_debugging_info): Similarly. * stabs.c (savestring): Delete unnecessary forward declaration. Add dhandle param. debug_xalloc memory. Update callers. (start_stab): Delete unnecessary casts. (finish_stab): Add "emit" param. Free file_types, so_string, and stabs handle. (parse_stab): Delete string_used param. Revert code dealing with string_used. Copy so_string passed to debug_set_filename and stored as main_filename to debug_xalloc memory. Similarly for string passed to debug_start_source and push_bincl. Copy args to debug_xalloc memory. Don't leak args. (parse_stab_enum_type): Copy names and values to debug_xalloc memory. Don't free name. (parse_stab_struct_type): Don't free fields. (parse_stab_baseclasses): Delete unnecessary cast. (parse_stab_struct_fields): Return debug_xalloc fields. (parse_stab_cpp_abbrev): Use debug_xalloc for _vb$ type name. (parse_stab_one_struct_field): Don't free name. (parse_stab_members): Copy variants and methods to debug_xalloc memory. Don't free name or argtypes. (parse_stab_argtypes): Use debug_xalloc memory for physname and args. (push_bincl): Add dhandle param. Use debug_xalloc memory. (stab_record_variable): Use debug_xalloc memory. (stab_emit_pending_vars): Don't free var list. (stab_find_slot): Add dhandle param. Use debug_xzalloc memory. Update all callers. (stab_find_tagged_type): Don't free name. Use debug_xzalloc. (stab_demangle_qualified): Don't free name. (stab_demangle_template): Don't free s1. (stab_demangle_args): Tidy pvarargs refs. Copy *pargs on success to debug_xalloc memory, free on failure. (stab_demangle_fund_type): Don't free name. (stab_demangle_v3_arglist): Copy args to debug_xalloc memory. Don't free dt.
2023-03-30Tidy leaked objcopy memoryAlan Modra1-3/+10
* objcopy.c (delete_symbol_htabs): Also free symbols. (write_debugging_info): Free strings and syms once written. * wrstabs.c (write_stabs_in_sections_debugging_info): memset entire info struct. Free hash tables before returning. Free syms on error return.
2023-02-16Delete PROGRESS macrosAlan Modra1-5/+0
I don't see much point in cluttering the source with the PROGRESS macros, which of course do nothing at all with the definitions in progress.h. progress.h is unchanged apart from the copyright comment since commit d4d4c53c68f0 in 1994. binutils/ * ar.c: Don't include progress.h, or invoke PROGRESS macros. * nm.c: Likewise. * objcopy.c: Likewise. * objdump.c: Likewise. gas/ * as.h: Don't include progress.h. * as.c: Don't invoke PROGRESS macros. * write.c: Likewise. include/ * progress.h: Delete. ld/ * ldmain.c: Don't include progress.h, or invoke PROGRESS macros.
2023-02-13objcopy memory leaksAlan Modra1-2/+1
This fixes some objcopy memory leaks. commit 450da4bd38ae used xatexit to tidy most of the hash table memory, but of course that's ineffective without a call to xexit. The other major memory leak happens if there is an error of some sort writing the output file, due to not closing the input file and thus not freeing memory attached to the bfd. * objcopy.c (copy_file): Don't return when bfd_close of output gives an error, always bfd_close input too. (main): Call xexit.
2023-01-18Speed up objcopy's note merging.Nick Clifton1-7/+17
PR 29993 * objcopy.c (merge_gnu_build_notes): Remember the last non-deleted note in order to speed up the scan for matching notes.
2023-01-06Make coff backend data read-onlyAlan Modra1-19/+16
The bfd_coff_backend_data struct should be read-only, the only thing preventing this is that objcopy writes to one of the fields, _bfd_coff_long_section_names. This patch creates a copy of the field in bfd coff_obj_tdata, which makes more sense anyway. When enabling long section names the intent is to do so for a particular bfd, not for all bfds that might happen to be using the target xvec. bfd/ * coffcode.h: Update coff long section name comment. (bfd_coff_set_long_section_names_allowed): Use macro accessor to set flag. (bfd_coff_set_long_section_names_disallowed): Tidy. (coff_backend_info): Return a const pointer. (bfd_coff_std_swap_table, ticoff0_swap_table, ticoff1_swap_table), (bigobj_swap_table): Make const. (bfd_coff_long_section_names): Use tdata copy. (coff_mkobject): Set long_section_names from coff_backend_info. * coff-go32.c (_bfd_go32_mkobject): Likewise. * peicode.h (pe_mkobject): Likewise. * coff-sh.c (bfd_coff_small_swap_table): Make const. * libcoff-in.h (struct coff_tdata): Add long_section_names, reorder fields. * libcoff.h: Regenerate. binutils/ * objcopy.c (set_long_section_mode): Move earlier in file. (copy_object): Call set_long_section_mode here, after setting output format. (copy_file): Don't call set_long_section_mode.
2023-01-04objcopy fuzzed pe out of memoryAlan Modra1-0/+4
This occurs when attempting to read back a section from the output file in _bfd_XX_bfd_copy_private_bfd_data_common. The copy of the section failed size sanity checking, thus it won't be written. * objcopy.c (copy_object): Return false if copy_section or copy_relocations_in_section fails.
2023-01-04fuzzed file timeoutAlan Modra1-1/+2
objcopy of archive, element containing an object with a fuzzed section size far exceeding the element size. copy_section detects this, but the temp file is laid out for the large section. It can take a long time to write terabytes of sparse file, a waste of time when it will be deleted. * objcopy.c (copy_archive): Don't write element contents after bad status result from copy_object.
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-12-14Don't access freed memory printing objcopy warningAlan Modra1-3/+5
abfd->filename will be freed if bfd_close gets far enough to delete the bfd. It's possible to have an error from fclose at this point. * objcopy.c (copy_archive): Dup filename before closing bfd for potential use in bfd_nonfatal_message.
2022-12-07Compression tidy and fixesAlan Modra1-6/+8
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-06Get rid of SEC_ELF_RENAMEAlan Modra1-2/+7
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-01Fix verilog output when the width is > 1.Nick Clifton1-2/+23
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-11-14objcopy renaming section with explicit flagsAlan Modra1-6/+1
This tidies SEC_RELOC handling in bfd, in the process fixing a bug with objcopy when renaming sections. bfd/ * reloc.c (_bfd_generic_set_reloc): Set/clear SEC_RELOC depending on reloc count. * elf64-sparc.c (elf64_sparc_set_reloc): Likewise. binutils/ * objcopy.c (copy_relocations_in_section): Remove now unnecessary clearing of SEC_RELOC. * testsuite/binutils-all/rename-section-01.d: New test. * testsuite/binutils-all/objcopy.exp: Run it. gas/ * write.c (size_seg): Remove unneccesary twiddle of SEC_RELOC. (write_relocs): Likewise. Always call bfd_set_reloc.
2022-11-09Re: Fuzzed files in archivesAlan Modra1-14/+7
Like commit ffbe89531c2e this avoids more silliness writing output that is going to be deleted. bfd_close and bfd_close_all_done differ in that only the former calls _bfd_write_contents. * objcopy.c (copy_archive): Don't call bfd_close for elements that are going to be deleted, call bfd_close_all_done instead. Do the same for the archive itself.
2022-10-29Fix small objcopy memory leakAlan Modra1-0/+1
* objcopy.c (copy_archive): Free l->name.
2022-10-27Fuzzed files in archivesAlan Modra1-0/+1
Given a fuzzed object file in an archive with section size exceeding file size, objcopy will report an error like "section size (0xfeffffff bytes) is larger than file size (0x17a bytes)" but will create a copy of the object laid out for the large section. That means a large temporary file on disk that is read back and written to the output archive, which can take a while. The output archive is then deleted due to the error. Avoid some of this silliness. * objcopy.c (copy_section): If section contents cannot be read set output section size to zero.
2022-10-12Fix objcopy's error message when it cannot add a .gnu_debuglink section ↵Nick Clifton1-1/+1
because the section already exists. PR 29665 * objcopy.c (copy_object): Use the input filename when reporting that a .gnu_debuglink section already exists.
2022-09-30objcopy: avoid "shadowing" of remove() function nameJan Beulich1-4/+4
remove() is a standard library function (declared in stdio.h), which triggers a "shadows a global declaration" warning with some gcc versions.
2022-09-26binutils, gdb: support zstd compressed debug sectionsFangrui Song1-4/+15
PR29397 PR29563: Add new configure option --with-zstd which defaults to auto. If pkgconfig/libzstd.pc is found, define HAVE_ZSTD and support zstd compressed debug sections for most tools. * bfd: for addr2line, objdump --dwarf, gdb, etc * gas: support --compress-debug-sections=zstd * ld: support ELFCOMPRESS_ZSTD input and --compress-debug-sections=zstd * objcopy: support ELFCOMPRESS_ZSTD input for --decompress-debug-sections and --compress-debug-sections=zstd * gdb: support ELFCOMPRESS_ZSTD input. The bfd change references zstd symbols, so gdb has to link against -lzstd in this patch. If zstd is not supported, ELFCOMPRESS_ZSTD input triggers an error. We can avoid HAVE_ZSTD if binutils-gdb imports zstd/ like zlib/, but this is too heavyweight, so don't do it for now. ``` % ld/ld-new a.o ld/ld-new: a.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support ... % ld/ld-new a.o --compress-debug-sections=zstd ld/ld-new: --compress-debug-sections=zstd: ld is not built with zstd support % binutils/objcopy --compress-debug-sections=zstd a.o b.o binutils/objcopy: --compress-debug-sections=zstd: binutils is not built with zstd support % binutils/objcopy b.o --decompress-debug-sections binutils/objcopy: zstd.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support ... ```
2022-09-20Stop strip from complaining about empty note sections when stripping a ↵Nick Clifton1-5/+3
binary for a second time. * objcopy.c (copy_object): Do not issue a warning message when encountering empty .gnu.build.attribute sections.
2022-09-09Support debuginfo files with empty group sections.Nick Clifton1-3/+12
PR 29532 bfd * elf.c (setup_group): Do not return false if there is no group information available. bionutils* objcopy.c (setup_section): Leave group sections intact when creating separate debuginfo files.