aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
AgeCommit message (Collapse)AuthorFilesLines
2018-01-3032-bit objcopy build failAlan Modra1-2/+2
* objcopy.c (merge_gnu_build_notes): Use (bfd_vma) -1 as "artificially large" end address.
2018-01-03Fix compile time warning introduced by previous delta.Nick Clifton1-2/+2
* objcopy.c (merge_gnu_build_notes): Add cast to maximum address constants.
2018-01-03Add support for v3 binary annotation notes.Nick Clifton1-175/+339
I am checking in the attached patch which updates the binutils support for version 3 binary annotation notes. (Version 3 adds an end address to the ranges covered by the notes, so that it is possible to detect gaps in the coverage). This patch also stops the note merging feature of objcopy from executing if the notes have relocations against them. This makes the code simpler, and prevents the problems with architectures which have unusual relocation management issues. * objcopy.c (objcopy_internal_note): New structure. (gap_exists): New function. (is_open_note): New function. (is_func_note): New function. (is_64bit): New function. (merge_gnu_build_notes): Handle v3 notes. Do not merge if there are relocations against the notes. * readelf.c (get_note_type): Use short names for build attribute notes. (print_symbol_for_build_attribute): Rename to get_symbol_for_build_attribute. Returns the found symbol rather than printing it. (print_gnu_build_attribute_description): Maintain address ranges for function notes as well as global notes. Handle v3 notes. (print_gnu_build_attribute_name): Use more space for printing the name in wide mode. * testsuite/binutils-all/note-2-32.s: Use .dc.l instead of .word. Eliminate symbol references in order to remove the need for relocations. * testsuite/binutils-all/note-2-64.s: Likewise. * testsuite/binutils-all/note-3-32.s: Add a size to the note_1 symbol. * testsuite/binutils-all/note-3-64.s: Likewise. * testsuite/binutils-all/mips/mips-note-2r-n32.d: Update expected output. * testsuite/binutils-all/mips/mips-note-2r-n64.d: Likewise. * testsuite/binutils-all/mips/mips-note-2r.d: Likewise. * testsuite/binutils-all/note-2-32.d: Likewise. * testsuite/binutils-all/note-2-64.d: Likewise. * testsuite/binutils-all/note-3-32.d: Likewise. * testsuite/binutils-all/note-3-64.d: Likewise. * testsuite/binutils-all/note-4-64.s: New test. Checks v3 notes. * testsuite/binutils-all/note-4-32.s: New test. * testsuite/binutils-all/note-4-64.d: New test result file. * testsuite/binutils-all/note-4-32.d: New test result file.
2018-01-03Update year range in copyright notice of binutils filesAlan Modra1-1/+1
2017-12-08Fix stripping relocs in a file with mergeable notes.Nick Clifton1-8/+19
A recent Fedora bug (1520805) exposed a problem with objcopy's reloc copying code, when a binary also contains mergeable notes. The note merging code would delete some relocs, but then the reloc copying code would try to put them back again, which did not work. So I am checking in the patch below to fix the problem. The patch also tweaks one of the binutils note merging tests so that it is skipped for the Sparc64 target, since this has funky relocs. binutils * objcopy.c (copy_relocations_in_section): Use the orelocations field of the input section, if it has been initialised. * testsuite/binutils-all/note-2-64.d: Skip test on Sparc64. bfd * elfcode.h (elf_write_relocs): Check for an empty howto field.
2017-12-06Objcopy interleave fails if section address not multiple of interleave.Jim Wilson1-0/+11
PR 22465 binutils/ * objcopy.c (copy_section): New local extra. If isection->lma not exactly divisible by interleave, then bias from. Also adjust osection->lma if necessary. ld/ * testsuite/ld-elf/interleave-0.d, testsuite/ld-elf/interleave-4.d, * testsuite/ld-elf/interleave.ld, testsuite/ld-elf/interleave.s: New.
2017-11-15objcopy memory leakAlan Modra1-0/+3
PR 22426 * objcopy.c (copy_main): Free tmpname.
2017-10-05Fix strip so that is accepts -M as an abbreviation for --merge-notes.Nick Clifton1-1/+1
PR 22260 * objcopy.c (strip_main): Add 'M' character to short options list when calling getopt_long.
2017-07-02Use bfd_malloc_and_get_sectionAlan Modra1-2/+3
It's nicer than xmalloc followed by bfd_get_section_contents, since xmalloc exits on failure and needs a check that its size_t arg doesn't lose high bits when converted from bfd_size_type. PR binutils/21665 * objdump.c (strtab): Make var a bfd_byte*. (disassemble_section): Don't limit malloc size. Instead, use bfd_malloc_and_get_section. (read_section_stabs): Use bfd_malloc_and_get_section. Return bfd_byte*. (find_stabs_section): Remove now unnecessary cast. * objcopy.c (copy_object): Use bfd_malloc_and_get_section. Free contents on error return. * nlmconv.c (copy_sections): Use bfd_malloc_and_get_section.
2017-06-28Add support for version 2 of the GNU Build Attribute note specification.Nick Clifton1-23/+45
* objcopy.c (merge_gnu_build_notes): Add support for version 2 notes. * readelf.c (print_gnu_build_attribute_name): Likewise.
2017-05-19binutils: remove sparc64/mips64 workaround in objcopy build notes merge codeJose E. Marchesi1-7/+0
This patch removes a workaround recently installed in objcopy that avoided removing duplicated notes in targets for which the number of internal relocations may be bigger than the number of external relocations. With the recent fixes in sparc64 and mips64, this workaround is no longer necessary. 2017-05-19 Jose E. Marchesi <jose.marchesi@oracle.com> * objcopy.c (merge_gnu_build_notes): Remove workaround that prevented deleting relocations in duplicated notes in mips64 and sparc.
2017-05-02Cast relcount to unsigned long when comparing with sec->reloc_countH.J. Lu1-1/+1
The type of relcount is long and the type of sec->reloc_count is unsigned int. On 32-bit hosts, GCC issues an error: objcopy.c:2144:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] if (relcount > sec->reloc_count) Cast relcount to unsigned long to silence GCC. * objcopy.c (merge_gnu_build_notes): Cast relcount to unsigned long when comparing with sec->reloc_count.
2017-05-02Don't merge notes when the relocs associated with them cannot be reliably ↵Nick Clifton1-0/+7
deleted. * objcopy.c (merge_gnu_build_notes): Disable merge if there are more internal relocs than external relocs.
2017-05-01merge_gnu_build_notes reloc deletionAlan Modra1-5/+8
If moving relocs, the next reloc to look at is at the same location. * objcopy.c (merge_gnu_build_notes): Correct code deleting relocs.
2017-04-13Add note merging to strip and add code to merge stack size notes.Nick Clifton1-5/+96
* objcopy.c: Add --no-merge-notes option to disable note merging. Add --[no-]merge-notes option to strip, and enable it by default. (num_bytes): New function. (merge_gnu_build_notes): Add code to merge stack size notes. * binutils.texi: Update strip and objcopy documentation. * readelf.c (print_gnu_build_attribute_name): Use defined constants for note types.
2017-04-06[objcopy] Fix quadratic-time when handling --redefine-symsJiong Wang1-33/+71
objcopy/ * objcopy.c (struct redefine_node): Delete the field "next". (redefine_sym_list): Deleted. (redefine_specific_htab): New hash table. (redefine_specific_reverse_htab): Likewise. (eq_string_redefnode): New function. (htab_hash_redefnode): Likewise. (create_symbol2redef_htab): Likewise. (add_specific_symbol_node): Likewise. (create_symbol_htabs): Create redefine_specific_htab and redefine_specific_reverse_htab. (lookup_sym_redefinition): Use hash table instead of list. (redefine_list_append): Likewise, and rename to add_redefine_and_check. (copy_main): Use redefine_specific_htab instead of redefine_sym_list. Update comments.
2017-03-21Update support for GNU BUILD notes so that version notes can contain extra ↵Nick Clifton1-1/+1
information, and stack protection notes can contain numeric values. * readelf.c (print_gnu_build_attribute_name): Allow stack protection notes to contain numeric values. Use a colon rather than a space to separate a string name from its values. Decode the numeric value of a stack protection note. * objcopy.c (merge_gnu_build_notes): Allow version notes to contain extra text after the protocol version number.
2017-03-02Support merging build notes in sections without the SHF_GNU_BUILD_NOTE flag set.Nick Clifton1-1/+5
* objcopy.c (is_merged_note_section): Support build note sections without the SHF_GNU_BUILD_NOTE section flag set.
2017-03-01Add support for displaying and merging GNU_BUILD_NOTEs.Nick Clifton1-26/+367
include * elf/common.h (SHF_GNU_BUILD_NOTE): Define. (NT_GNU_PROPERTY_TYPE_0): Define. (NT_GNU_BUILD_ATTRIBUTE_OPEN): Define. (NT_GNU_BUILD_ATTRIBUTE_FUN): Define. (GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC): Define. (GNU_BUILD_ATTRIBUTE_TYPE_STRING): Define. (GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE): Define. (GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE): Define. (GNU_BUILD_ATTRIBUTE_VERSION): Define. (GNU_BUILD_ATTRIBUTE_STACK_PROT): Define. (GNU_BUILD_ATTRIBUTE_RELRO): Define. (GNU_BUILD_ATTRIBUTE_STACK_SIZE): Define. (GNU_BUILD_ATTRIBUTE_TOOL): Define. (GNU_BUILD_ATTRIBUTE_ABI): Define. (GNU_BUILD_ATTRIBUTE_PIC): Define. (NOTE_GNU_PROPERTY_SECTION_NAME): Define. (GNU_BUILD_ATTRS_SECTION_NAME): Define. (GNU_PROPERTY_STACK_SIZE): Define. (GNU_PROPERTY_NO_COPY_ON_PROTECTED): Define. (GNU_PROPERTY_X86_ISA_1_USED): Define. (GNU_PROPERTY_X86_ISA_1_NEEDED): Define. (GNU_PROPERTY_X86_ISA_1_486): Define. (GNU_PROPERTY_X86_ISA_1_586): Define. (GNU_PROPERTY_X86_ISA_1_686): Define. (GNU_PROPERTY_X86_ISA_1_SSE): Define. (GNU_PROPERTY_X86_ISA_1_SSE2): Define. (GNU_PROPERTY_X86_ISA_1_SSE3): Define. (GNU_PROPERTY_X86_ISA_1_SSSE3): Define. (GNU_PROPERTY_X86_ISA_1_SSE4_1): Define. (GNU_PROPERTY_X86_ISA_1_SSE4_2): Define. (GNU_PROPERTY_X86_ISA_1_AVX): Define. (GNU_PROPERTY_X86_ISA_1_AVX2): Define. (GNU_PROPERTY_X86_ISA_1_AVX512F): Define. (GNU_PROPERTY_X86_ISA_1_AVX512CD): Define. (GNU_PROPERTY_X86_ISA_1_AVX512ER): Define. (GNU_PROPERTY_X86_ISA_1_AVX512PF): Define. (GNU_PROPERTY_X86_ISA_1_AVX512VL): Define. (GNU_PROPERTY_X86_ISA_1_AVX512DQ): Define. (GNU_PROPERTY_X86_ISA_1_AVX512BW): Define. binutils* readelf.c (get_note_type): Add support for GNU_BUILD_NOTEs. (get_gnu_elf_note_type): Add support for GNU_PROPERTY_NOTEs. (decode_x86_isa): New function. (print_gnu_property_note): New function. (print_gnu_note): Handle GNU_PROPERTY_NOTEs. (print_gnu_build_attribute_description): New function. (print_gnu_build_attribute_name): New function. (process_note): Add support for GNU_BUILD_NOTEs. * objcopy.c (--merge-notes): New command line option. (copy_options): Add merge-notes. (copy_usage): Likewise. (is_merge_note_section): New function. (merge_gnu_build_notes): New function. (copy_object): Merge note sections if asked to do so. (skip_section): Add skip_copy parameter. Add support for skipping merged note sections. (copy_relocations_in_section): Update call to skip_section. (copy_section): Likewise. (copy_main): Add support for merge-notes option. * doc/binutils.texi: Document the new option to objcopy. * NEWS: Mention the new feature. * testsuite/binutils-all/note-2-32.d: New test. Checks note merging on 32-bit targets. * testsuite/binutils-all/note-2-32.s: New test source file. * testsuite/binutils-all/note-2-64.d: New test. Like note-2-32.d but for 64-bit targets. * testsuite/binutils-all/note-2-64.s: New test source file. * testsuite/binutils-all/objcopy.exp: Run the new test.
2017-02-17bfd: Rename Chunk and S3ForcedPedro Alves1-6/+6
The direct references in objcopy kind of look like a hack to me, so I'm calling these symbols internal too. Certainly they aren't named and documented as a public BFD symbol today anyway. So ... give these bfd-internal symbols with external linkage a _bfd_ prefix to avoid collisions in the global symbol namespace. While at it, give them names that more closely match the corresponding option name that toggles them. Also while at it, fix a few related comment typos. gdb/ChangeLog: 2017-02-17 Pedro Alves <palves@redhat.com> * srec.c (Chunk): Rename to ... (_bfd_srec_len): ... this. (S3Forced): Rename to ... (_bfd_srec_forceS3): ... this. * objcopy.c: Adjust all references.
2017-01-02Update year range in copyright notice of all files.Alan Modra1-1/+1
2016-12-06Fix seg-fault running strip on a corrupt binary.Nick Clifton1-1/+2
PR binutils/20930 * objcopy.c (mark_symbols_used_in_relocations): Check for a null symbol pointer pointer before attempting to mark the symbol as kept.
2016-12-05Fix seg-fault running strip on a corrupt binary.Nick Clifton1-1/+3
PR ld/20923 * objcopy.c (mark_symbols_used_in_relocations): Check for a null symbol pointer before attempting to mark the symbol as kept.
2016-11-27Fix spelling in comments in C source files (binutils)Ambrogino Modigliani1-1/+1
* dwarf.c: Fix spelling in comments. * dwarf.h: Fix spelling in comments. * objcopy.c: Fix spelling in comments. * od-macho.c: Fix spelling in comments. * rclex.c: Fix spelling in comments. * readelf.c: Fix spelling in comments. * stabs.c: Fix spelling in comments.
2016-11-04objcopy: Close some memory leaks in error pathsAndrew Burgess1-0/+3
Closes some memory leaks within objcopy for error paths. binutils/ChangeLog: * objcopy.c (copy_section): Add extra calls to free for error paths.
2016-10-06-Wimplicit-fallthrough warning fixesAlan Modra1-1/+1
Comment changes. bfd/ * coff-h8300.c: Spell fall through comments consistently. * coffgen.c: Likewise. * elf32-hppa.c: Likewise. * elf32-ppc.c: Likewise. * elf32-score.c: Likewise. * elf32-score7.c: Likewise. * elf64-ppc.c: Likewise. * elfxx-aarch64.c: Likewise. * elfxx-mips.c: Likewise. * cpu-ns32k.c: Add missing fall through comments. * elf-m10300.c: Likewise. * elf32-arm.c: Likewise. * elf32-avr.c: Likewise. * elf32-bfin.c: Likewise. * elf32-frv.c: Likewise. * elf32-i386.c: Likewise. * elf32-microblaze.c: Likewise. * elf32-nds32.c: Likewise. * elf32-ppc.c: Likewise. * elf32-rl78.c: Likewise. * elf32-rx.c: Likewise. * elf32-s390.c: Likewise. * elf32-sh.c: Likewise. * elf32-tic6x.c: Likewise. * elf64-ia64-vms.c: Likewise. * elf64-ppc.c: Likewise. * elf64-s390.c: Likewise. * elf64-x86-64.c: Likewise. * elflink.c: Likewise. * elfnn-aarch64.c: Likewise. * elfnn-ia64.c: Likewise. * ieee.c: Likewise. * oasys.c: Likewise. * pdp11.c: Likewise. * srec.c: Likewise. * versados.c: Likewise. opcodes/ * aarch64-opc.c: Spell fall through comments consistently. * i386-dis.c: Likewise. * aarch64-dis.c: Add missing fall through comments. * aarch64-opc.c: Likewise. * arc-dis.c: Likewise. * arm-dis.c: Likewise. * i386-dis.c: Likewise. * m68k-dis.c: Likewise. * mep-asm.c: Likewise. * ns32k-dis.c: Likewise. * sh-dis.c: Likewise. * tic4x-dis.c: Likewise. * tic6x-dis.c: Likewise. * vax-dis.c: Likewise. binutils/ * dlltool.c: Spell fall through comments consistently. * objcopy.c: Likewise. * readelf.c: Likewise. * dwarf.c: Add missing fall through comments. * elfcomm.c: Likewise. * sysinfo.y: Likewise. * readelf.c: Likewise. Also remove extraneous comments. gas/ * app.c: Add missing fall through comments. * dw2gencfi.c: Likewise. * expr.c: Likewise. * config/tc-alpha.c: Likewise. * config/tc-arc.c: Likewise. * config/tc-arm.c: Likewise. * config/tc-cr16.c: Likewise. * config/tc-crx.c: Likewise. * config/tc-dlx.c: Likewise. * config/tc-h8300.c: Likewise. * config/tc-hppa.c: Likewise. * config/tc-i370.c: Likewise. * config/tc-i386.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68hc11.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-metag.c: Likewise. * config/tc-microblaze.c: Likewise. * config/tc-mips.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-rx.c: Likewise. * config/tc-score.c: Likewise. * config/tc-score7.c: Likewise. * config/tc-sh.c: Likewise. * config/tc-tic4x.c: Likewise. * config/tc-vax.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z80.c: Likewise. * config/tc-z8k.c: Likewise. * config/obj-elf.c: Likewise. * config/tc-i386.c: Likewise. * depend.c: Spell fall through comments consistently. * config/tc-arm.c: Likewise. * config/tc-d10v.c: Likewise. * config/tc-i960.c: Likewise. * config/tc-ia64.c: Likewise. * config/tc-m68k.c: Likewise. * config/tc-mcore.c: Likewise. * config/tc-mep.c: Likewise. * config/tc-ns32k.c: Likewise. * config/tc-visium.c: Likewise. * config/tc-xstormy16.c: Likewise. * config/tc-z8k.c: Likewise. gprof/ * gprof.c: Add missing fall through comments. ld/ * lexsup.c: Spell fall through comments consistently and add missing fall through comments.
2016-10-06-Wimplicit-fallthrough noreturn fixesAlan Modra1-2/+2
binutils/ * cxxfilt.c (usage): Add ATTRIBUTE_NORETURN. * elfedit.c (usage): Likewise. * nm.c (usage): Likewise. * objcopy.c (copy_usage, strip_usage): Likewise. * srconv.c (show_usage): Likewise. * strings.c (usage): Likewise. * sysdump.c (show_usage): Likewise. * srconv.c: Remove unneeded forward function declarations. * strings.c: Likewise. * sysdump.c: Likewise. gas/ * as.h (as_assert): Add ATTRIBUTE_NORETURN.
2016-07-16Don't include libbfd.h outside of bfd, part 1Alan Modra1-1/+0
Make BFD_ALIGN available to objcopy. Fix assertions. Don't use bfd_log2 in ppc32elf.em or bfd_malloc in xtensaelf.em and bucomm.c. bfd/ * libbfd-in.h (BFD_ALIGN): Move to.. * bfd-in.h: ..here. * elf32-ppc.h (struct ppc_elf_params): Add pagesize. * elf32-ppc.c (default_params): Adjust init. (ppc_elf_link_params): Set pagesize_p2. * libbfd.h: Regenerate. * bfd-in2.h: Regenerate. binutils/ * ar.c: Don't include libbfd.h. * objcopy.c: Likewise. * bucomm.c (bfd_get_archive_filename): Use xmalloc rather than bfd_malloc. gas/ * config/bfin-parse.y: Don't include libbfd.h. * config/tc-bfin.c: Likewise. * config/tc-rl78.c: Likewise. * config/tc-rx.c: Likewise. * config/tc-metag.c: Likewise. (create_dspreg_htabs, create_scond_htab): Use gas_assert not BFD_ASSERT. * Makefile.am: Update dependencies. * Makefile.in: Regenerate. ld/ * ldlang.c: Don't include libbfd.h. * emultempl/nds32elf.em: Likewise. * emultempl/ppc64elf.em: Likewise. * emultempl/ppc32elf.em: Likewise. (pagesize): Delete. (params): Update init. (ppc_after_open_output): Use params.pagesize. Don't call bfd_log2. (PARSE_AND_LIST_ARGS_CASES): Use params.pagesize. * emultempl/sh64elf.em: Don't include libbfd.h. (after_allocation): Use ASSERT, not BFD_ASSERT. * emultempl/xtensaelf.em: Don't include libbfd.h. (replace_insn_sec_with_prop_sec): Use xmalloc, not bfd_malloc. * Makefile.am: Update dependencies. * Makefile.in: Regenerate.
2016-07-14objcopy/strip: Add option --remove-relocations=SECTIONPATTERNAndrew Burgess1-5/+58
The objcopy and strip tools make use of the bfd library to manipulate the state of the input file (to produce an output file). Within the input file (for ELF at least), relocations are held within a section, and so, if the user wanted to remove the relocations, but keep the section to which the relocations would have been applied, it is tempting to think that specifying the name of a relocation section to objcopy's --remove-section option might do what you want, for example: objcopy --remove-section=.rela.text input.elf output.elf However, this does not work. The reason is that when the input file is loaded, relocations are not managed as sections, but are, instead, loaded as data associated with the section to which the relocations would be applied. In our example above the relocations in '.rela.text' are held as data on the section '.text' once 'input.elf' is loaded. One task that objcopy and strip do is copy the relocations from the input file to the output file if the section is also being copied from the input file to the output file. This commit adds a new command line option for objcopy and strip, --remove-relocations, which can be used to remove the relocations, while keeping the section that the relocations would have been applied to, for example: objcopy --remove-relocations=.text input.elf output.elf in this case the section '.text' will appear in both 'input.elf' and 'output.elf', but any relocations in 'input.elf' that apply to '.text' will not be present in 'output.elf'. I have also added a special case to the handling of --remove-section that spots if a user tries to remove a relocation section (currently this is done by spotting the '.rela.' or '.rel.' prefix) and forwards the request to --remove-relocations. As with --remove-section and --only-section the --remove-relocations option supports the '!' prefix on the section-patterns it takes to allow for sections to be specifically not matched. There are tests for all the new functionality. binutils/ChangeLog: * doc/binutils.texi (objcopy): Document 'remove-relocations'. (strip): Likewise. * objcopy.c (SECTION_CONTEXT_REMOVE_RELOCS): Define. (enum command_line_switch): Add 'OPTION_REMOVE_RELOCS'. (struct option strip_options): Add 'remove-relocations'. (struct option copy_options): Likewise. (copy_usage): Likewise. (strip_usage): Likewise. (handle_remove_relocations_option): New function. (discard_relocations): New function. (handle_remove_section_option): New function. (copy_relocations_in_section): Use discard_relocations. (strip_main): Use handle_remove_section_option for 'remove-section', and handle 'remove-relocations' option. (copy_main): Likewise. * testsuite/binutils-all/objcopy.exp: Run new tests. * testsuite/binutils-all/remove-relocs-01.d: New file. * testsuite/binutils-all/remove-relocs-01.s: New file. * testsuite/binutils-all/remove-relocs-02.d: New file. * testsuite/binutils-all/remove-relocs-03.d: New file. * testsuite/binutils-all/remove-relocs-04.d: New file. * testsuite/binutils-all/remove-relocs-05.d: New file. * testsuite/binutils-all/remove-relocs-06.d: New file.
2016-07-14objcopy/strip: Allow section patterns starting with '!'.Andrew Burgess1-11/+28
For symbol matching, prefixing a pattern with '!' will indicate a non-matching pattern, however, this is not the case for section patterns. As a result it is not possible to say "apply this action to all sections except ...". With this commit the objcopy and strip tools now support '!' prefix for section patterns, so we can say: objcopy --remove-section="*" --remove-section="!.text*" Which will remove all sections, except those matching the pattern '.text*'. binutils/ChangeLog: * objcopy.c (find_section_list): Handle section patterns starting with '!' being a non-matching pattern. * doc/binutils.texi (objcopy): Give example of using '!' with --remove-section and --only-section. (strip): Give example of using '!' with --remove-section. * testsuite/binutils-all/data-sections.s: New file. * testsuite/binutils-all/only-section-01.d: New file. * testsuite/binutils-all/remove-section-01.d: New file. * testsuite/binutils-all/objcopy.exp: Run new tests. * NEWS: Mention new feature.
2016-06-24MIPS objcopy --rename-section fixAlan Modra1-16/+17
Some MIPS targets use a named section symbol rather than a symbol with no name as is used with most ELF targets. When renaming sections, the named section symbol needs to be renamed too. Rather than fix this bug, I'd originally intended to just correct the xfail added recently for update-1.o vs update4.o in update-section.exp, using the same set of targets for the localize-hidden-1 mips xfail. I'd extracted that target test into a new function, is_bad_symtab. It turns out to be useful in readelf.exp too. bfd/ * config.bfd: Delete mips vxworks patterns matched earlier. Combine mips*-*-none with mips*-*-elf*. binutils/ * objcopy.c (find_section_rename): Forward declare. Remove ibfd and sec_ptr param. Add old_name param. Allow for NULL returned_flags. Move read of section name and flags to.. (setup_section): ..here. Update find_section_rename call. (filter_symbols): Rename section symbols for renamed sections. (copy_object): Call filter_symbols when renamed sections. * testsuite/lib/binutils-common.exp (is_bad_symtab): New. * testsuite/binutils-all/update-section.exp: Revert 96037eb0 mips xfail. * testsuite/binutils-all/objcopy.exp (copy_executable): Use is_bad_symtab. (localize-hidden-1): xfail if is_bad_symtab. * testsuite/binutils-all/readelf.exp: Use is_bad_symtab to select between mips/tmips.
2016-06-14Use correct enum type for do_elf_stt_common.John Baldwin1-1/+1
binutils/ChangeLog: * objcopy.c (do_elf_stt_common): Use correct type.
2016-06-02Also check that the group header's sh_info field is valid.Nick Clifton1-1/+2
PR 20089 * objcopy.c (group_signature): Fail if the input symbol table has not been loaded, or if the sh_info field of the group header is 0.
2016-06-02Fix a seg-fault when stripping a corrupt binary.Nick Clifton1-0/+4
PR 20089 * objcopy.c (group_signature): Fail if the input symbol table has not been loaded.
2016-05-31objcopy add-symbol uninitialised structAlan Modra1-110/+113
* objcopy.c: Formatting, whitespace throughout. (copy_main): Init newsym->othersym. (parse_symflags): Make len a size_t. Adjust uses.
2016-05-18Prevent a run time segmentation fault when stripping a corrupt binary.Nick Clifton1-1/+3
PR 20096 * objcopy.c (copy_relocations_in_section): Also check for the symbol pointed to by sym_ptr_ptr being NULL.
2016-02-26Properly implement STT_COMMONH.J. Lu1-6/+45
The BFD configure option, --enable-elf-stt-common, can't be to used to verify STT_COMMON implementation with the normal binutils build. Instead, this patch removes it from BFD. It adds --elf-stt-common=[no|yes] to ELF assembler/objcopy and adds -z common/-z nocommon to ld. A configure option, --enable-elf-stt-common, is added to gas to specify whether ELF assembler should generate common symbols with the STT_COMMON type by default. Since BSF_KEEP_G is never used, it is renamed to BSF_ELF_COMMON for ELF common symbols. bfd/ PR ld/19645 * bfd.c (bfd): Change flags to 20 bits. (BFD_CONVERT_ELF_COMMON): New. (BFD_USE_ELF_STT_COMMON): Likewise. (BFD_FLAGS_SAVED): Add BFD_CONVERT_ELF_COMMON and BFD_USE_ELF_STT_COMMON. (BFD_FLAGS_FOR_BFD_USE_MASK): Likewise. * configure.ac: Remove --enable-elf-stt-common. * elf.c (swap_out_syms): Choose STT_COMMON or STT_OBJECT for common symbol depending on BFD_CONVERT_ELF_COMMON and BFD_USE_ELF_STT_COMMON. * elfcode.h (elf_slurp_symbol_table): Set BSF_ELF_COMMON for STT_COMMON. * elflink.c (bfd_elf_link_mark_dynamic_symbol): Also check STT_COMMON. (elf_link_convert_common_type): New function. (elf_link_output_extsym): Choose STT_COMMON or STT_OBJECT for common symbol depending on BFD_CONVERT_ELF_COMMON and BFD_USE_ELF_STT_COMMON. Set sym.st_info after sym.st_shndx. * elfxx-target.h (TARGET_BIG_SYM): Add BFD_CONVERT_ELF_COMMON and BFD_USE_ELF_STT_COMMON to object_flags. (TARGET_LITTLE_SYM): Likewise. * syms.c (BSF_KEEP_G): Renamed to ... (BSF_ELF_COMMON): This. * bfd-in2.h: Regenerated. * config.in: Likewise. * configure: Likewise. binutils/ PR ld/19645 * NEWS: Mention --elf-stt-common= for objcopy. * doc/binutils.texi: Document --elf-stt-common= for objcopy. * objcopy.c (do_elf_stt_common): New. (command_line_switch): Add OPTION_ELF_STT_COMMON. (copy_options): Add --elf-stt-common=. (copy_usage): Add --elf-stt-common=. (copy_object): Also check do_elf_stt_common for ELF targets. (copy_file): Handle do_elf_stt_common. (copy_main): Handle OPTION_ELF_STT_COMMON. * readelf.c (apply_relocations): Support STT_COMMON. * testsuite/binutils-all/common-1.s: New file. * testsuite/binutils-all/common-1a.d: Likewise. * testsuite/binutils-all/common-1b.d: Likewise. * testsuite/binutils-all/common-1c.d: Likewise. * testsuite/binutils-all/common-1d.d: Likewise. * testsuite/binutils-all/common-1e.d: Likewise. * testsuite/binutils-all/common-1f.d: Likewise. * testsuite/binutils-all/common-2.s: Likewise. * testsuite/binutils-all/common-2a.d: Likewise. * testsuite/binutils-all/common-2b.d: Likewise. * testsuite/binutils-all/common-2c.d: Likewise. * testsuite/binutils-all/common-2d.d: Likewise. * testsuite/binutils-all/common-2e.d: Likewise. * testsuite/binutils-all/common-2f.d: Likewise. * testsuite/binutils-all/objcopy.exp (objcopy_test_elf_common_symbols): New proc. Run objcopy_test_elf_common_symbols for ELF targets gas/ PR ld/19645 * NEWS: Mention --enable-elf-stt-common and --elf-stt-common= for ELF assemblers. * as.c (flag_use_elf_stt_common): New. (show_usage): Add --elf-stt-common=. (option_values): Add OPTION_ELF_STT_COMMON. (std_longopts): Add --elf-stt-common=. (parse_args): Handle --elf-stt-common=. * as.h (flag_use_elf_stt_common): New. * config.in: Regenerated. * configure: Likewise. * configure.ac: Add --enable-elf-stt-common and define DEFAULT_GENERATE_ELF_STT_COMMON. * gas/write.c (write_object_file): Set BFD_CONVERT_ELF_COMMON and BFD_USE_ELF_STT_COMMON if flag_use_elf_stt_common is set. * doc/as.texinfo: Document --elf-stt-common=. * testsuite/gas/elf/common3.s: New file. * testsuite/gas/elf/common3a.d: Likewise. * testsuite/gas/elf/common3b.d: Likewise. * testsuite/gas/elf/common4.s: Likewise. * testsuite/gas/elf/common4a.d: Likewise. * testsuite/gas/elf/common4b.d: Likewise. * testsuite/gas/i386/dw2-compress-3b.d: Likewise. * testsuite/gas/i386/dw2-compressed-3b.d: Likewise. * testsuite/gas/elf/elf.exp: Run common3a, common3b, common4a and common4b. * testsuite/gas/i386/dw2-compress-3.d: Renamed to ... * testsuite/gas/i386/dw2-compress-3a.d: This. Pass --elf-stt-common=no to as. * testsuite/gas/i386/dw2-compressed-3.d: Renamed to ... * testsuite/gas/i386/dw2-compressed-3a.d: This. Pass --elf-stt-common=no to as. * testsuite/gas/i386/i386.exp: Run dw2-compress-3a, dw2-compress-3b, dw2-compressed-3a and dw2-compressed-3b instead of dw2-compress-3 and dw2-compressed-3. include/ PR ld/19645 * bfdlink.h (bfd_link_elf_stt_common): New enum. (bfd_link_info): Add elf_stt_common. ld/ PR ld/19645 * NEWS: Mention -z common/-z nocommon for ELF targets. * emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Handle -z common and -z nocommon. * ld.texinfo: Document -z common/-z nocommon. * lexsup.c (elf_shlib_list_options): Add -z common/-z nocommon. * testsuite/ld-elf/tls_common.exp: Test --elf-stt-common=no and --elf-stt-common=yes with assembler. * testsuite/ld-elfcomm/common-1.s: New file. * testsuite/ld-elfcomm/common-1a.d: Likewise. * testsuite/ld-elfcomm/common-1b.d: Likewise. * testsuite/ld-elfcomm/common-1c.d: Likewise. * testsuite/ld-elfcomm/common-1d.d: Likewise. * testsuite/ld-elfcomm/common-1e.d: Likewise. * testsuite/ld-elfcomm/common-1f.d: Likewise. * testsuite/ld-elfcomm/common-2.s: Likewise. * testsuite/ld-elfcomm/common-2a.d: Likewise. * testsuite/ld-elfcomm/common-2b.d: Likewise. * testsuite/ld-elfcomm/common-2c.d: Likewise. * testsuite/ld-elfcomm/common-2d.d: Likewise. * testsuite/ld-elfcomm/common-2e.d: Likewise. * testsuite/ld-elfcomm/common-2f.d: Likewise. * testsuite/ld-elfcomm/common-3a.rd: Likewise. * testsuite/ld-elfcomm/common-3b.rd: Likewise. * testsuite/ld-i386/pr19645.d: Likewise. * testsuite/ld-i386/pr19645.s: Likewise. * testsuite/ld-x86-64/largecomm-1.s: Likewise. * testsuite/ld-x86-64/largecomm-1a.d: Likewise. * testsuite/ld-x86-64/largecomm-1b.d: Likewise. * testsuite/ld-x86-64/largecomm-1c.d: Likewise. * testsuite/ld-x86-64/largecomm-1d.d: Likewise. * testsuite/ld-x86-64/largecomm-1e.d: Likewise. * testsuite/ld-x86-64/largecomm-1f.d: Likewise. * testsuite/ld-x86-64/pr19645.d: Likewise. * testsuite/ld-x86-64/pr19645.s: Likewise. * testsuite/ld-elfcomm/elfcomm.exp: Test --elf-stt-common=yes with assembler. (assembler_generates_commons): Removed. Run -z common/-z nocommon tests. Run *.d tests. * testsuite/ld-i386/i386.exp: Run pr19645. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-x86-64/dwarfreloc.exp: Test --elf-stt-common with assembler. Test STT_COMMON with readelf.
2016-01-01Copyright update for binutilsAlan Modra1-1/+1
2015-11-20Fix building objcopy under mingw64 by replacing uses of strndup with xstrndup.Ronald Hoogenboom1-3/+3
* objcopy.c (parse_symflags): Use xstrndup in place of strndup. (copy_main): Likewise.
2015-10-22binutils/objcopy.c (setup_section): missing extract_symbol partHans-Peter Nilsson1-5/+0
* objcopy.c (setup_section): Don't omit bfd_copy_private_bfd_data call when extract_symbol.
2015-10-21Add ability for objcopy to insert new symbols into a binary.Ronald Hoogenbllon1-100/+303
PR binutils/19104 binutils * objcopy.c (command_line_switch): Add OPTION_ADD_SYMBOL. (copy_options): Add add-symbol. (copy_usage): Likewise. (parse_symflags): New function. (need_sym_before): New function. (create_new_symbol): New function. (filter_symbols): Add code to insert new symbols. (copy_main): Process OPTION_ADD_SYMBOL. * doc/binutils.texi: Document new feature. * NEWS: Add note about the new feature. tests * binutils-all/add-symbol.d: New test. * binutils-all/objcopy.exp: Run the new test.
2015-10-15objcopy --extract-symbolAlan Modra1-5/+0
Calling bfd_copy_private_bfd_data is necessary to copy ELF file header info. binutils/ * objcopy.c (copy_object): Don't omit bfd_copy_private_bfd_data call when extract_symbol. bfd/ * elf32-v850.c (v850_elf_copy_private_bfd_data): Remove assertion that input and output .note.renesas sections are same size. Instead, only copy input to output if they are.
2015-09-29Don't use the output section size to copy input sectionH.J. Lu1-22/+5
We can't use the output section size to copy input section since --interleave will shrink the output section. Instead, we change bfd_convert_section_contents to return the updated input section size. When we do that, we don't need to adjust the output section size to skip gap fills. bfd/ PR binutils/19020 * bfd.c (bfd_convert_section_contents): Add ptr_size parameter. * bfd-in2.h: Regenerated. binutils/ PR binutils/19020 * objcopy.c (copy_object): Don't adjust the output section size when copying from input sections. (copy_section): Use input section size for the copy. Get the updated section size from bfd_convert_section_contents. binutils/testsuite/ PR binutils/19020 * binutils-all/objcopy.exp: Run pr19020a and pr19020b. * lib/utils-lib.exp (run_dump_test): Support binary input. * binutils-all/pr19020.in: New file. * binutils-all/pr19020a.d: Likewise. * binutils-all/pr19020b.d: Likewise.
2015-09-29Adjust the output section size to skip gap fillsH.J. Lu1-4/+20
In objcopy, copy_object calls copy_section to copy contents of input section to output section. When --gap-fill= is used, objcopy extends the size of output sectios to fill gaps between output sections with gap fills. In this case, we adjust the output section size to skip gap files to avoid reading beypond the input section buffer before calling copy_section and restore the output section size after input sections have been copied. binutils/ PR binutils/19005 * objcopy.c (copy_object): Adjust the output section size to skip gap fills between sections when copying from input sections to output sections. ld/testsuite/ PR binutils/19005 * ld-elf/pr19005.d: New file. * ld-elf/pr19005.s: Likewise. * ld-elf/pr19005.t: Likewise.
2015-08-12Remove trailing spaces in binutilsH.J. Lu1-5/+5
2015-08-07objcopy: Improve wildcard matching for symbols with '!' prefix.Andrew Burgess1-4/+4
When using options such as --localize-symbol, --globalize-symbol, etc, along with the --wildcard option, prefixing a symbol name with '!' should provide non-matching behaviour, as example the following example is given in the manual: --wildcard --weaken-symbol !foo --weaken-symbol fo* which should weaken all symbols matching the pattern 'fo*', but not the symbol 'foo'. However, this currently does not work, the current logic will waken all symbols matching the pattern 'fo*' AND all symbols that are not 'foo'. The symbol 'foo' is covered by the first condition, and so is weakened, while, other symbols, for example 'bar' will match the second condition, and so be weakened. This patch adjusts the logic so that a pattern prefixed with '!' specifically DOES NOT apply the relevant change to any matching symbols, instead of applying the change to all non-matching symbols. So this: --weaken-symbol !foo will ensure that the symbol 'foo' is not weakened, but says nothing about symbols that are not 'foo'. As a result, a pattern prefixed with '!' now only makes sense when used alongside a more wide ranging wildcard pattern. This change should make the wildcard matching feature more useful, with no overall loss of functionality. The example given in the manual, weaken all symbols matching 'fo*' except 'foo' can now be achieved, but so too can more complex examples, such as weaken all symbols matching 'fo*' except 'foo', 'foa', and 'fob', like this: --wildcard --weaken-symbol !foo \ --weaken-symbol !foa \ --weaken-symbol !fob \ --weaken-symbol fo* Under the previous scheme, something as symbols as, weaken all symbols except 'foo' could have been achieved with this: --weaken-symbol !foo however, this will no longer work. To achieve the same result under the new scheme this is now required: --weaken-symbol !foo --weaken-symbol * binutils/ChangeLog: * objcopy.c (is_specified_symbol_predicate): Don't stop at first match. Non-match rules set found to FALSE. binutils/testsuite/ChangeLog: * binutils-all/objcopy.exp: Run new symbol tests. (objcopy_test_symbol_manipulation): New function. * binutils-all/symbols-1.d: New file. * binutils-all/symbols-2.d: New file. * binutils-all/symbols-3.d: New file. * binutils-all/symbols-4.d: New file. * binutils-all/symbols.s: New file.
2015-07-14Make default compression gABI compliantH.J. Lu1-1/+1
All programs in binutils+gdb git repo now support gABI compression with the SHF_COMPRESSED bit. This patch makes the zlib-gabi option as compression default for gas, gold, ld and objcopy, instead of the zlib-gnu option whose outputs are incompatible with gABI. binutils/ * objcopy.c (copy_file): Set BFD_COMPRESS_GABI if not zlib-gnu. * doc/binutils.texi: Change --compress-debug-sections and --compress-debug-sections=zlib to zlib-gabi. binutils/testsuite/ * binutils-all/compress.exp: Update. gas/ * as.c (parse_args): Make --compress-debug-sections and --compress-debug-sections=zlib the same as --compress-debug-sections=zlib-gabi. * doc/as.texinfo: Change --compress-debug-sections and --compress-debug-sections=zlib to zlib-gabi. gold/ * compressed_output.cc (Output_compressed_section::set_final_data_size): Make --compress-debug-sections=zlib the same as --compress-debug-sections=zlib-gabi. * testsuite/Makefile.am (flagstest_compress_debug_sections.check): Expect ".debug_.*" with the SHF_COMPRESSED bit, instead of ".zdebug_". * testsuite/Makefile.in: Regenerated. ld/ * emultempl/elf32.em (gld${EMULATION_NAME}_handle_option): Make --compress-debug-sections=zlib the same as --compress-debug-sections=zlib-gabi. * ld.texinfo: Change --compress-debug-sections=zlib to zlib-gabi. ld/testsuite/ * ld-elf/zlibbegin.rS: Updated to .debug_.* with the SHF_COMPRESSED bit. * ld-elf/zlibnormal.rS: Likewise.
2015-07-10Properly convert objects between different ELF classesH.J. Lu1-2/+9
The output SHF_COMPRESSED section size is different from input if ELF classes of input and output aren't the same. We must adjust the section sizes as well as the compression headers in SHF_COMPRESSED sections when converting objects between different ELF classes. bfd/ PR binutils/18656 * bfd.c (bfd_convert_section_size): New function. (bfd_convert_section_contents): Likewise. * bfd-in2.h: Regenerated. binutils/ 2015-07-10 H.J. Lu <hongjiu.lu@intel.com> PR binutils/18656 * objcopy.c (setup_section): Call bfd_convert_section_size to get the output section size. (copy_section): Get the section size from the output section and call bfd_get_full_section_contents to convert section contents for output. binutils/testsuite/ PR binutils/18656 * binutils-all/compress.exp (convert_test): New proc. Run conversion tests between x86-64 and x32.
2015-04-23Don't change compressed input debug section namesH.J. Lu1-0/+3
Change compressed input debug section name for objdump is very confusing. But we need to change it for linker so that linker will consider the input section as a debug section. This patch delays section rename to elf_fake_sections for objcopy and avoids it for objdump. bfd/ PR binutils/18209 * bfd.c (bfd): Add is_linker_input. * elf.c (convert_debug_to_zdebug): New. (convert_zdebug_to_debug): Likewise. (_bfd_elf_make_section_from_shdr): Don't convert .debug_* to .zdebug_* here. Use convert_zdebug_to_debug. Set SEC_ELF_RENAME. (_bfd_elf_init_reloc_shdr): Pass a pointer to section name instead of a pointer to section. (elf_fake_sections): Rename the section name if SEC_ELF_RENAME is set. * section.c (SEC_ELF_RENAME): New. * bfd-in2.h: Regenerated. binutils/ PR binutils/18209 * objcopy.c (setup_section): Copy compress status. binutils/testsuite/ PR binutils/18209 * binutils-all/compress.exp: Replace dw2-3.W with dw2-3gabi.W on zlib-gabi output. * binutils-all/dw2-1.W: Convert section names to .zdebug_*. * binutils-all/dw2-3.W: Likewise. * binutils-all/objdump.W: Likewise. * binutils-all/dw2-3gabi.W: New file. ld/ PR binutils/18209 * ldfile.c (ldfile_try_open_bfd): Set is_linker_input to 1.
2015-04-09Properly check --compress-debug-sections=XXXH.J. Lu1-14/+19
We can't check if input is ELF in copy_file since some targets may only set xvec after bfd_check_format_matches is called. This patch moves this check to copy_object. bfd/ * elfxx-target.h (TARGET_BIG_SYM): Add BFD_COMPRESS_GABI to object_flags. (TARGET_LITTLE_SYM): Likewise. binutils/ * objcopy.c (do_debug_sections): Use bit patterns. (copy_object): Return FALSE for compress_zlib, compress_gnu_zlib and compress_gabi_zlib on non-ELF input. (copy_file): Don't check non-ELF input here.