Commit Graph

192 Commits

Author SHA1 Message Date
H.J. Lu cbd44e247e Don't use the output section size to copy input section
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-29 13:31:57 -07:00
H.J. Lu c68c163716 Adjust the output section size to skip gap fills
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-09-29 06:33:24 -07:00
H.J. Lu 3aade68889 Remove trailing spaces in binutils 2015-08-12 04:42:37 -07:00
Andrew Burgess 0b45135ec1 objcopy: Improve wildcard matching for symbols with '!' prefix.
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-08-07 11:41:40 +02:00
H.J. Lu 19a7fe52ae Make default compression gABI compliant
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-14 10:26:23 -07:00
H.J. Lu 889884731e Properly convert objects between different ELF classes
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-07-10 14:27:39 -07:00
H.J. Lu f6fe1ccd62 Don't change compressed input debug section names
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-23 07:59:59 -07:00
H.J. Lu cd6faa73f8 Properly check --compress-debug-sections=XXX
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.
2015-04-09 10:56:28 -07:00
H.J. Lu 151411f8af Add SHF_COMPRESSED support to gas and objcopy
This patch adds --compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}
options to gas and objcopy for ELF files. They control how DWARF debug
sections are compressed.  --compress-debug-sections=none is equivalent to
--nocompress-debug-sections.  --compress-debug-sections=zlib and
--compress-debug-sections=zlib-gnu are equivalent to
--compress-debug-sections.  --compress-debug-sections=zlib-gabi compresses
DWARF debug sections with SHF_COMPRESSED from the ELF ABI.  No linker
changes are required to support SHF_COMPRESSED.

bfd/

	* archive.c (_bfd_get_elt_at_filepos): Also copy BFD_COMPRESS_GABI
	bit.
	* bfd.c (bfd::flags): Increase size to 18 bits.
	(BFD_COMPRESS_GABI): New.
	(BFD_FLAGS_SAVED): Add BFD_COMPRESS_GABI.
	(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
	(bfd_update_compression_header): New fuction.
	(bfd_check_compression_header): Likewise.
	(bfd_get_compression_header_size): Likewise.
	(bfd_is_section_compressed_with_header): Likewise.
	* compress.c (MAX_COMPRESSION_HEADER_SIZE): New.
	(bfd_compress_section_contents): Return the uncompressed size if
	the full section contents is compressed successfully.  Support
	converting from/to .zdebug* sections.
	(bfd_get_full_section_contents): Call
	bfd_get_compression_header_size to get compression header size.
	(bfd_is_section_compressed): Renamed to ...
	(bfd_is_section_compressed_with_header): This.  Add a pointer
	argument to return compression header size.
	(bfd_is_section_compressed): Use it.
	(bfd_init_section_decompress_status): Call
	bfd_get_compression_header_size to get compression header size.
	Return FALSE if uncompressed section size is 0.
	* elf.c (_bfd_elf_make_section_from_shdr): Support converting
	from/to .zdebug* sections.
	* bfd-in2.h: Regenerated.

binutils/

	* objcopy.c (do_debug_sections): Add compress_zlib,
	compress_gnu_zlib and compress_gabi_zlib.
	(copy_options): Use optional_argument on compress-debug-sections.
	(copy_usage): Update --compress-debug-sections.
	(copy_file): Handle compress_zlib, compress_gnu_zlib and
	compress_gabi_zlib.
	(copy_main): Handle
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.
	* doc/binutils.texi: Document
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.

binutils/testsuite/

	* compress.exp: Add tests for
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.
	* binutils-all/dw2-3.rS: New file.
	* binutils-all/dw2-3.rt: Likewise.
	* binutils-all/libdw2-compressedgabi.out: Likewise.

gas/

	* as.c (show_usage): Update --compress-debug-sections.
	(std_longopts): Use optional_argument on compress-debug-sections.
	(parse_args): Handle
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.
	* as.h (compressed_debug_section_type): New.
	(flag_compress_debug): Change type to compressed_debug_section_type.
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.
	* write.c (compress_debug): Set BFD_COMPRESS_GABI for
	--compress-debug-sections=zlib-gabi.  Call
	bfd_get_compression_header_size to get compression header size.
	Don't rename section name for --compress-debug-sections=zlib-gabi.
	* config/tc-i386.c (compressed_debug_section_type): Set to
	COMPRESS_DEBUG_ZLIB.
	* doc/as.texinfo: Document
	--compress-debug-sections={none|zlib|zlib-gnu|zlib-gabi}.

gas/testsuite/

	* gas/i386/dw2-compressed-1.d: New file.
	* gas/i386/dw2-compressed-2.d: Likewise.
	* gas/i386/dw2-compressed-3.d: Likewise.
	* gas/i386/x86-64-dw2-compressed-2.d: Likewise.
	* gas/i386/i386.exp: Run dw2-compressed-2, dw2-compressed-1,
	dw2-compressed-3 and x86-64-dw2-compressed-2.

ld/testsuite/

	* ld-elf/compress.exp: Add a test for
	--compress-debug-sections=zlib-gabi.
	(build_tests): Add 2 tests for --compress-debug-sections=zlib-gabi.
	(run_tests): Likewise.
	Verify linker output with zlib-gabi compressed debug input.
	* ld-elf/compressed1a.d: New file.
	* ld-elf/compressed1b.d: Likewise.
	* ld-elf/compressed1c.d: Likewise.
2015-04-08 07:54:09 -07:00
H.J. Lu bfcf0ccd01 Display --interleave[=<number>]
Optional argument of a command line option must start with "=".

	* objcopy.c (copy_usage): Replace "--interleave [<number>]" with
	--interleave[=<number>].
2015-04-08 05:04:13 -07:00
Nick Clifton cfad873011 Fixes a problem with objcopy leaving temporary files and directories around if it encounters a problem during a copy.
PR binutils/17636
	* objcopy.c (copy_object): Avoid calling fatal as that does not
	allow the parent to clean up temporary files.
2015-03-10 13:38:24 +00:00
Andrew Burgess acf1419f9c objcopy: Add --update-section option.
New option for objcopy --update-section allows the contents of a section
to be updated while maintaining the section flags, and, for ELF files,
the section to segment mapping.

New test uses --dump-section and --update-section to check that a
section can be made larger and smaller with an update.

binutils/ChangeLog:

	* objcopy.c (update_sections): New list.
	(command_line_switch): Add OPTION_UPDATE_SECTION.
	(copy_options): Add update-section.
	(copy_usage): Document new option.
	(is_update_section): New function.
	(is_strip_section_1): Add check for attempt to update and remove
	the same section.
	(copy_object): Update size and content of requested sections.
	(skip_section): Don't copy for updated sections.
	(copy_main): Handle --update-section.
	* doc/binutils.texi (objcopy): Add description of --update-section
	option.
	* NEWS: Mention --update-section option.

binutils/testsuite/ChangeLog:

	* binutils-all/update-1.s: New file.
	* binutils-all/update-2.s: New file.
	* binutils-all/update-3.s: New file.
	* binutils-all/update-4.s: New file.
	* binutils-all/update-section.exp: New file.
2015-02-28 21:25:51 +00:00
Andrew Burgess 06b73f4199 objcopy: Avoid shadowing optarg.
In commit 7173b38a44 I used optarg as the
name for a function parameter, shadowing the global of that name.  This
commit changes the function parameter to be called arg.

binutils/ChangeLog:

	* objcopy.c (init_section_add): Rename optarg to arg in order to
	avoid shadowing a global variable.
2015-02-26 18:05:10 +00:00
Andrew Burgess 7173b38a44 objcopy: Factor out some of the option parsing code.
This patch splits out some of the option parsing code, increasing code
reuse.

binutils/ChangeLog:

	* objcopy.c (init_section_add): New function.
	(section_add_load_file): New function.
	(copy_main): Make use of new functions.
2015-02-25 23:57:30 +00:00
Nick Clifton 86eafac0aa Fix memory access violations triggered by running strip on fuzzed binaries.
PR binutils/17512
	* coffcode.h (coff_set_arch_mach_hook): Check return value from
	bfd_malloc.
	(coff_slurp_line_table): Return FALSE if the line number
	information was corrupt.
	(coff_slurp_symbol_table): Return FALSE if the symbol information
	was corrupt.
	* mach-o.c (bfd_mach_o_bfd_copy_private_header_data): Always
	initialise the fields of the dyld_info structure.
	(bfd_mach_o_build_exec_seg_command): Replace assertion with an
	error message and a return value.
	(bfd_mach_o_layout_commands): Change the function to boolean.
	Return FALSE if the function fails.
	(bfd_mach_o_build_commands): Fail if bfd_mach_o_layout_commands
	fails.
	(bfd_mach_o_read_command): Fail if an unrecognised command is
	encountered.
	* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Set bfd_error if the
	read fails.
	(slurp_symtab): Check the return from bfd_malloc.
	(_bfd_XX_bfd_copy_private_bfd_data_common): Fail if the copy
	encountered an error.
	(_bfd_XXi_final_link_postscript): Fail if a section could not be
	copied.
	* peicode.h (pe_bfd_object_p): Fail if the header could not be
	swapped in.
	* tekhex.c (first_phase): Fail if the section is too big.
	* versados.c (struct esdid): Add content_size field.
	(process_otr): Use and check the new field.
	(versados_get_section_contents): Check that the section exists and
	that the requested data is available.

	PR binutils/17512
	* addr2line.c (main): Call bfd_set_error_program_name.
	* ar.c (main): Likewise.
	* coffdump.c (main): Likewise.
	* cxxfilt.c (main): Likewise.
	* dlltool.c (main): Likewise.
	* nlmconv.c (main): Likewise.
	* nm.c (main): Likewise.
	* objdump.c (main): Likewise.
	* size.c (main): Likewise.
	* srconv.c (main): Likewise.
	* strings.c (main): Likewise.
	* sysdump.c (main): Likewise.
	* windmc.c (main): Likewise.
	* windres.c (main): Likewise.
	* objcopy.c (main): Likewise.
	(copy_relocations_in_section): Check for relocs without associated
	symbol pointers.
2015-01-21 17:37:23 +00:00
Nick Clifton 063bb0250d Fix memory access violations exposed by running strip on fuzzed binaries.
PR binutils/17512
	* coffcode.h (coff_slurp_symbol_table): Return false if we failed
	to load the line table.
	* elf.c (_bfd_elf_map_sections_to_segments): Enforce a minimum
	maxpagesize of 1.
	* peXXigen.c (_bfd_XX_bfd_copy_private_bfd_data_common): Fail if
	the Data Directory Size is too large.

	* objcopy.c (copy_object): Free the symbol table if no symbols
	could be loaded.
	(copy_file): Use bfd_close_all_done to close files that could not
	be copied.
2015-01-08 15:39:49 +00:00
Alan Modra b90efa5b79 ChangeLog rotatation and copyright year update 2015-01-02 00:53:45 +10:30
Alexander Cherepanov 7a093a7820 This patch fixes a snafu where the -D and -U short versions of the
--enable-deterministic-archives and --disable-deteministic-archive
options were not being accepted.

	PR binutils/17671
	* objcopy.c (copy_main, strip_main): Add D and U to the list of
	accepted short versions of long options.
2014-12-24 14:50:53 +00:00
Andrew Stubbs 805b1c8bc6 Clarify strip docs.
binutils/
	* objcopy.c (strip_usage): Reword --remove-section description.
	* doc/binutils.texi (strip): Likewise.
2014-12-23 20:28:16 +00:00
Nick Clifton 5e186ece2f Fix objcopy and strip so that they remove their temporary files even if an error occurs.
PR binutils/17552
	* (copy_archive): Clean up temporary files even if an error
	occurs.
2014-11-10 14:28:43 +00:00
Nick Clifton dd9b91de21 Prevent archive memebers with illegal pathnames from being extracted from an archive.
PR binutils/17552, binutils/17533
	* bucomm.c (is_valid_archive_path): New function.  Returns false
	for absolute pathnames and pathnames that include /../.
	* bucomm.h (is_valid_archive_path): Add prototype.
	* ar.c (extract_file): Use new function to check for valid
	pathnames when extracting files from an archive.
	* objcopy.c (copy_archive): Likewise.
	* doc/binutils.texi: Update documentation to mention the
	limitation on pathname of archive members.
2014-11-06 14:49:10 +00:00
Jon TURNEY 74fffc3982 Change pe/coff build-id section name to '.buildid'
The section name used to store the build-id on pe/coff is arbitrary, as it's
contents should be located using the pe/coff header's DataDirectory debug data
entry, not by using the section name.

But '.build-id' is not a good choice for that section name, as it is 9
characters long, and hence truncated to 8 characters when
--disable-long-section-names is used (which is the default, when producing an
executable with no dwarf debug sections, e.g. using ld --strip-all --build-id)

This truncation then breaks 'objcopy --only-keep-debug', which does use the
section name, due to concerns that keeping an arbitrary section which contains
the debug directory is not sensible.

binutils/ChangeLog

2014-09-01  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* objcopy.c (is_nondebug_keep_contents_section): Change pe/coff
	build-id section name from '.build-id' to '.buildid'.

ld/ChangeLog

2014-09-01  Jon TURNEY  <jon.turney@dronecode.org.uk>

	* emultempl/pe.em (write_build_id, setup_build_id): Change pe/coff
	build-id section name from '.build-id' to '.buildid'.
	* emultempl/pep.em (write_build_id, setup_build_id): Ditto.

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2014-09-08 17:54:20 +01:00
Jon Turney 6e6e7cfc78 This fixes a few issues with pe/coff build-ids that were discovered since the
original patches were posted:

  pe/coff: Display GUID build-id in the conventional way
  pe/coff: Don't interpret debug directory in section with no contents
  pe/coff: Keep .build-id with --only-keep-debug
  pe/coff: Don't break .build-id with objcopy/strip

	* peXXigen.c (pe_print_debugdata): Don't interpret debug directory
	in a section with no contents.
	(is_vma_in_section, find_section_by_vma): New functions.
	(_bfd_XX_bfd_copy_private_bfd_data_common): Recalculate file
	offsets in the debug directory.
	(_bfd_XXi_slurp_codeview_record, _bfd_XXi_write_codeview_record):
	Byte-swap GUID from little-endian to big-endian order for
	consistent and conventional display.

	* objcopy.c (is_nondebug_keep_contents_section): New function.
	(setup_section): Use it.
2014-05-16 15:34:13 +01:00
Alan Modra 5063a42103 Report an error on objcopy/strip of sectionless binaries
All strip operations require section headers to be present, as do most
objcopy operations.  BFD is seriously confused by objects without
section info.  The error message added here is similar to the error
on attempting to strip/objcopy a zero length object.

	PR binutils/16811
	* objcopy.c (copy_object): Error if no sections.
2014-04-07 13:59:31 +09:30
Anthony Green 182a105a38 Check fwrite return code 2014-03-14 12:56:12 -04:00
Alan Modra 4b95cf5c0c Update copyright years 2014-03-05 22:16:15 +10:30
Nick Clifton bbad633bb8 * objcopy.c (dump_sections): New list.
(command_line_switch): Add OPTION_DUMP_SECTION.
	(copy_options): Add dump-section.
	(copy_usage): Document new option.
	(copy_object): Dump requested sections.
	(copy_main): Handle --dump-section.
	* doc/binutils.texi: Document --dump-section option.
	* NEWS: Mention new feature.
2013-12-31 09:52:24 +00:00
Kai Tietz 76d8cf45bb * objcopy.c (copy_main): Initialize context variable. 2013-02-15 14:25:34 +00:00
Nick Clifton 2e62b7218b PR binutils/15033
* objcopy.c (enum change_action): Delete.
	(struct section_list): Delete remove, copy, change_vma, change_lma
	and set_flags fields.  Add context field.
	(find_section_list): Add a context parameter.  Add support for
	wildcard characters in section names.
	(is_strip_section): Check for sections being both  copied and
	removed.
	(copy_object): Pass context to find_section_list.
	(setup_section): Likewise.
	(copy_section): Likewise.
	(copy_main): Likewise.
	* doc/binutils: Document the new behaviour.
	* NEWS: Mention the new feature
2013-02-15 09:32:31 +00:00
Nick Clifton d99b05a32e PR binutils/15125
* objcopy.c (copy_object): Provide a helpful warning message when
	adding a gnu_debuglink section to an object which already contains
	one.
2013-02-14 11:52:25 +00:00
Alan Modra 5dddde8e64 * objcopy.c (parse_flags): Add merge and strings section flags. 2013-01-28 09:31:01 +00:00
Nick Clifton 9b8bf3211b * objcopy.c : Enable long section names for OPTION_ADD_GNU_DEBUGLINK. 2013-01-25 11:32:44 +00:00
Roland McGrath 955d0b3bd7 binutils/
* objcopy.c (deterministic): Make int rather than bfd_boolean,
	initialize to -1.
	(strip_options, copy_options): Add -U/--disable-deterministic-archives.
	(default_deterministic): New function.
	(strip_main, copy_main): Handle -U.  Call default_deterministic.
	(copy_usage, strip_usage): Describe -U.  Cite whether -D or -U is
	the default based on DEFAULT_AR_DETERMINISTIC.
	* doc/binutils.texi (objcopy, strip): Describe -U and effect of
	configure options on -D.

	* ar.c (default_deterministic): Comment fix.
2013-01-07 17:40:59 +00:00
H.J. Lu ee7da987c9 Don't read beyond section end
* objcopy.c (copy_section): Don't read beyond section end.
2012-11-07 06:16:26 +00:00
Kai Tietz 4fc8b8950a * objcopy.c (is_strip_section_1): Don't strip
.reloc section by default.
2012-10-18 17:29:54 +00:00
Cary Coutant 96109726a4 binutils/
* doc/binutils.texi (objcopy): Add --strip-dwo, --extract-dwo options.
	(strip): Add --strip-dwo option.
	* objcopy.c (enum strip_action): Add STRIP_DWO, STRIP_NONDWO.
	(enum command_line_switch): Add OPTION_EXTRACT_DWO, OPTION_STRIP_DWO.
	(strip_options): Add --strip-dwo option.
	(copy_options): Add --extract-dwo, --strip-dwo options.
	(copy_usage): Likewise.
	(strip_usage): Add --strip-dwo option.
	(is_dwo_section): New function.
	(is_strip_section_1): Check for DWO sections.
	(copy_object): Check for --strip-dwo, --extract-dwo options.
	(copy_relocations_in_section): Discard relocations for DWO sections.
	Discard entire relocation section when no relocations.
	(strip_main): Add --strip-dwo option.
	(copy_main): Add --strip-dwo, --extract-dwo options.
2012-05-08 17:49:36 +00:00
Cary Coutant 2e30cb575a * doc/binutils.texi: Add -D/--enable-deterministic-archives option
to strip and objcopy.
	* objcopy.c (deterministic): New global variable.
	(strip_options): Add --enable-deterministic-archives.
	(copy_options): Likewise.
	(copy_usage): Likewise.
	(strip_usage): Likewise.
	(copy_archive): When stripping all, don't add archive map; set
	deterministic output when requested.
	(strip_main): Add -D/--enable-deterministic-archives option.
	(copy_main): Likewise.
2012-04-25 17:50:14 +00:00
H.J. Lu c398915025 Don't generate empty reloc sections
binutils/

	PR binutils/13947
	* objcopy.c (copy_object): Call copy_relocations_in_section
	before copy_section.
	(skip_section): New.
	(copy_relocations_in_section): Likewise.
	(copy_section): Use skip_section.  Don't copy relocations here.

binutils/testsuite/

	PR binutils/13947
	* binutils-all/i386/compressed-1b.d: Remove empty REL section.
	* binutils-all/i386/compressed-1c.d: Likewise.

	* binutils-all/x86-64/compressed-1b.d: Remove empty RELA
	section.
	* binutils-all/x86-64/compressed-1c.d: Likewise.
2012-04-13 02:52:34 +00:00
Alan Modra dbb7c4414b * sysdep.h: Include sys/stat.h here.
* ar.c: Don't include headers already included by sysdep.h.
	* bucomm.c: Likewise.
	* budbg.h: Likewise.
	* dlltool.h: Likewise.
	* elfedit.c: Likewise.
	* nlmconv.c: Likewise.
	* objcopy.c: Likewise.
	* objdump.c: Likewise.
	* objdump.h: Likewise.
	* readelf.c: Likewise.
	* rename.c: Likewise.
	* resrc.c: Likewise.
	* strings.c: Likewise.
	* windres.c: Likewise.
	* od-macho.c: Ensure #include sysdep.h is first.
	* od-xcoff.c: Likewise.
	* dllwrap.c: Remove alloca pragma handled by sysdep.h, and
	remove duplicate headers.
	* dlltool.c: Likewise and ensure #include sysdep.h is first.
2012-02-09 04:51:44 +00:00
H.J. Lu 4c8e8a7ee0 Remove the group section if all members are removed.
binutils/

2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/13180
	* objcopy.c (is_strip_section_1): New.
	(is_strip_section): Use it.  Remove the group section if all
	members are removed.

binutils/testsuite/

2011-09-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/13180
	* binutils-all/group-6.d: New.
	* binutils-all/group-6.s: Likewise.

	* binutils-all/objcopy.exp: Run group-6 for ELF targrts.
2011-09-16 04:23:19 +00:00
Alan Modra 19094d10cd * objcopy.c (copy_archive): Check bfd_openw result in unknown object
case.  Rewrite without goto.
2011-05-06 14:41:56 +00:00
H.J. Lu 1e99536ae5 Make the unknown archive element readable.
2011-04-03  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/12632
	* objcopy.c (copy_unknown_object): Make the archive element
	readable.
2011-04-04 01:35:59 +00:00
Michael Snyder 0cbf353135 2011-03-14 Michael Snyder <msnyder@vmware.com>
* objcopy.c (set_pe_subsystem): Free subsystem.
2011-03-14 20:51:59 +00:00
Kai Tietz 8b6efd89a4 ChangeLog binutils/
2011-02-28  Kai Tietz  <kai.tietz@onevision.com>

	* debug.c (debug_start_source): Use filename_(n)cmp.
	* ieee.c (ieee_finish_compilation_unit): Likewise.
	(ieee_lineno): Likewise.
	* nlmconv.c (main): Likewise.
	* objcopy.c (strip_main): Likewise.
	(copy_main): Likewise.
	* objdump.c (show_line): Likewise.
	(dump_reloc_set): Likewise.
	* srconv.c (main): Likewise.
	* wrstabs.c (stab_lineno): Likewise.

ChangeLog gas/
2011-02-28  Kai Tietz  <kai.tietz@onevision.com>

	* depend.c (register_dependency): Use filename_(n)cmp.
	* dwarf2dbg.c (get_filenum): Likewise.
	* ecoff.c (add_file): Likewise.
	(ecoff_generate_asm_lineno): Likewise.
	* input-scrub.c (new_logical_line_flags): Likewise.
	* listing.c (file_info): Likewise.
	(listing_newline): Likewise.
	* remap.c (remap_debug_filename): Likewise.
	* stabs.c (generate_asm_file): Likewise.
	(stabs_generate_asm_lineno): Likewise.
2011-02-28 18:32:52 +00:00
Alan Modra 4e011fb578 bfd/
* hash.c (bfd_hash_hash): Extract from..
	(bfd_hash_lookup): ..here.
	(bfd_hash_rename): New function.
	* section.c (bfd_rename_section): New function.
	* bfd-in.h (bfd_hash_rename): Declare.
	* bfd-in2.h: Regenerate.
	* elf.c (_bfd_elf_make_section_from_shdr): Rename input sections
	when compressing or decompressing.  Don't assert name match.
	* elf64-hppa.c (get_reloc_section): Don't assert name match.
	* elfxx-ia64.c (get_reloc_section): Likewise.
binutils/
	* objcopy.c (copy_main): No need to rename sections when compressing
	or decompressing.
binutils/testsuite/
	* binutils-all/objdump.W: Adjust expected result for debug section
	rename.
2010-11-08 02:48:57 +00:00
H.J. Lu 4a114e3e0c Add compressed debug section support to binutils and ld.
bfd/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>
	    Cary Coutant  <ccoutant@google.com>

	* archive.c (bfd_openr_next_archived_file): Copy BFD_COMPRESS
	and BFD_DECOMPRESS.

	* bfd.c (BFD_COMPRESS): New.
	(BFD_DECOMPRESS): Likewise.
	(BFD_FLAGS_SAVED): Likewise.
	(bfd_preserve_save): Replace BFD_IN_MEMORY with BFD_FLAGS_SAVED.

	* compress.c (bfd_uncompress_section_contents): Removed.
	(get_uncompressed_size): New.
	(decompress_contents): Likewise.
	(bfd_compress_section_contents): Likewise.
	(bfd_get_full_section_contents): Likewise.
	(bfd_is_section_compressed): Likewise.
	(bfd_init_section_decompress_status): Likewise.
	(bfd_init_section_compress_status): Likewise.

	* dwarf2.c (dwarf_debug_sections): New.
	(dwarf_debug_section_enum): Likewise.
	(read_section): Remove section_name and compressed_section_name.
	Add dwarf_debug_section_enum.  Try compressed debug section.
	(read_indirect_string): Updated.
	(read_abbrevs): Likewise.
	(decode_line_info): Likewise.
	(read_debug_ranges): Likewise.
	(find_line): Updated.

	* ecoff.c (bfd_debug_section): Add compress_status and
	compressed_size.

	* elf.c (_bfd_elf_make_section_from_shdr): Call
	bfd_is_section_compressed to check if a DWARF debug section is
	compressed.  Call bfd_init_section_compress_status or
	bfd_init_section_decompress_status if needed.

	* elflink.c (elf_link_input_bfd): Replace bfd_get_section_contents
	with bfd_get_full_section_contents.
	* merge.c (_bfd_add_merge_section): Likewise.
	* reloc.c (bfd_generic_get_relocated_section_contents): Likewise.
	* simple.c (bfd_simple_get_relocated_section_contents): Likewise.

	* elfxx-target.h (TARGET_BIG_SYM): Allow BFD_COMPRESS and
	BFD_DECOMPRESS.
	(TARGET_LITTLE_SYM): Likewise.

	* libbfd-in.h (dwarf_debug_section): New.
	(dwarf_debug_sections): Likewise.

	* libbfd.c (_bfd_generic_get_section_contents): Issue an error
	when getting contents on compressed/decompressed section.

	* section.c (COMPRESS_SECTION_NONE): New.
	(COMPRESS_SECTION_DONE): Likewise.
	(DECOMPRESS_SECTION_SIZED): Likewise.
	(BFD_FAKE_SECTION): Add compress_status and compressed_size.
	(bfd_malloc_and_get_section): Replace bfd_get_section_contents
	with bfd_get_full_section_contents.

	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

binutils/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* addr2line.c (process_file): Set BFD_DECOMPRESS.

	* objcopy.c (do_debug_sections): New.
	(OPTION_COMPRESS_DEBUG_SECTIONS): New.
	(OPTION_DECOMPRESS_DEBUG_SECTIONS): Likewise.
	(copy_options): Add OPTION_COMPRESS_DEBUG_SECTIONS and
	OPTION_DECOMPRESS_DEBUG_SECTIONS.
	(copy_usage): Add --compress-debug-sections and
	--decompress-debug-sections.
	(copy_file): Set BFD_COMPRESS or BFD_DECOMPRESS.
	(copy_section): Replace bfd_get_section_contents with
	bfd_get_full_section_contents.
	(copy_main): Handle OPTION_COMPRESS_DEBUG_SECTIONS and
	OPTION_DECOMPRESS_DEBUG_SECTIONS.  Check do_debug_sections to
	rename DWARF debug sections.

	* objdump.c (load_specific_debug_section): Replace
	bfd_get_section_contents with bfd_get_full_section_contents.
	Remove bfd_uncompress_section_contents.
	(dump_section): Replace bfd_get_section_contents with
	bfd_get_full_section_contents.
	(display_file): Set BFD_DECOMPRESS if needed.

	* readelf.c (uncompress_section_contents): Set buffer to NULL
	to indiate decompression failure.
	(load_specific_debug_section): Always call
	uncompress_section_contents.

	* doc/binutils.texi: Document --compress-debug-sections and
	--decompress-debug-sections.

binutils/testsuite/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* binutils-all/compress.exp: New.
	* binutils-all/dw2-1.S: Likewise.
	* binutils-all/dw2-2.S: Likewise.
	* binutils-all/libdw2-compressed.out: Likewise.
	* binutils-all/libdw2.out: Likewise.

gas/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* write.c (compress_debug): Optimize section flags check.

gas/testsuite/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* elf/dwarf2-1.s: Replace .zdebug_abbrev section with
	.debug_abbrev section.
	* elf/dwarf2-2.3: Likewise.

	* elf/dwarf2-1.d: Pass --compress-debug-sections to assembler.
	Updated.
	* elf/dwarf2-2.d: Likewise.

	* gas/i386/i386.exp: Remove xfail on dw2-compress-2 and
	x86-64-dw2-compress-2.

ld/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* ldfile.c (ldfile_try_open_bfd): Set BFD_DECOMPRESS after
	bfd_openr returns.
	* emultempl/elf32.em (gld${EMULATION_NAME}_try_needed): Likewise.

	* scripttempl/elf.sc: Include compressed DWARF debug sections.

ld/testsuite/

2010-10-29  H.J. Lu  <hongjiu.lu@intel.com>

	* ld-elf/compress.exp: New.
	* ld-elf/compress1.s: Likewise.
	* ld-elf/compress1a.d: Likewise.
	* ld-elf/compress1b.d: Likewise.
	* ld-elf/compress1c.d: Likewise.
2010-10-29 12:10:39 +00:00
Nick Clifton b7dd81f7c5 * objcopy.c: Add --interleave-width option to allow interleaving
of more than one byte at a time.
        (copy_width): New variable.
        (copy_options): Add --interleave-width.
        (copy_section): When interleaving copy in units of copy_width
        bytes.
        (copy_main): Parse the new option.
        * doc/binutils: Document the new option.
        * NEWS: Mention the new feature.

        * binutils-all/objcopy.exp: Add test of new --interleave-width
        option.
2010-09-10 12:11:28 +00:00
Dave Korn 447049af48 * objcopy.c (copy_usage): Tweak previous typofix. 2010-07-17 19:33:11 +00:00
H.J. Lu 235f6e5342 Fix a typo in "objcopy --help".
2010-07-17  H.J. Lu  <hongjiu.lu@intel.com>

	* objcopy.c (copy_usage): Fix a typo.
2010-07-17 14:41:28 +00:00
Alan Modra 6c67a030ce PR binutils/3166
* objcopy.c (is_strip_section): Revert 2006-09-05.
	(setup_section): Make SHT_GROUP section nobits.
2010-06-29 08:47:40 +00:00