summaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2010-10-29 12:10:39 +0000
committerH.J. Lu <hjl.tools@gmail.com>2010-10-29 12:10:39 +0000
commit4a114e3e0c1c3337981179b774f1d6d1b06d201f (patch)
tree98b0b1e45b3ae0e7845215136253fa56e487a9b8 /binutils/objcopy.c
parente58bcb8f099ec42b3c905480629d1a49dd38b03f (diff)
downloadbinutils-gdb-4a114e3e0c1c3337981179b774f1d6d1b06d201f.tar.gz
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.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 84b9febbf3b..2077fca481b 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -194,6 +194,14 @@ static const char * gnu_debuglink_filename = NULL;
/* Whether to convert debugging information. */
static bfd_boolean convert_debugging = FALSE;
+/* Whether to compress/decompress DWARF debug sections. */
+static enum
+{
+ nothing,
+ compress,
+ decompress
+} do_debug_sections = nothing;
+
/* Whether to change the leading character in symbol names. */
static bfd_boolean change_leading_char = FALSE;
@@ -259,7 +267,9 @@ enum command_line_switch
OPTION_CHANGE_SECTION_LMA,
OPTION_CHANGE_SECTION_VMA,
OPTION_CHANGE_WARNINGS,
+ OPTION_COMPRESS_DEBUG_SECTIONS,
OPTION_DEBUGGING,
+ OPTION_DECOMPRESS_DEBUG_SECTIONS,
OPTION_GAP_FILL,
OPTION_NO_CHANGE_WARNINGS,
OPTION_PAD_TO,
@@ -357,7 +367,9 @@ static struct option copy_options[] =
{"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA},
{"change-start", required_argument, 0, OPTION_CHANGE_START},
{"change-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
+ {"compress-debug-sections", no_argument, 0, OPTION_COMPRESS_DEBUG_SECTIONS},
{"debugging", no_argument, 0, OPTION_DEBUGGING},
+ {"decompress-debug-sections", no_argument, 0, OPTION_DECOMPRESS_DEBUG_SECTIONS},
{"discard-all", no_argument, 0, 'x'},
{"discard-locals", no_argument, 0, 'X'},
{"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL},
@@ -551,6 +563,8 @@ copy_usage (FILE *stream, int exit_status)
<commit>\n\
--subsystem <name>[:<version>]\n\
Set PE subsystem to <name> [& <version>]\n\
+ --compress-debug-sections Compress DWARF debug sections using zlib\n\
+ --decompress-debug-sections Decompress DWARF debug sections using zlib\n\
-v --verbose List all object files modified\n\
@<file> Read options from <file>\n\
-V --version Display this program's version number\n\
@@ -2193,6 +2207,18 @@ copy_file (const char *input_filename, const char *output_filename,
return;
}
+ switch (do_debug_sections)
+ {
+ case compress:
+ ibfd->flags |= BFD_COMPRESS;
+ break;
+ case decompress:
+ ibfd->flags |= BFD_DECOMPRESS;
+ break;
+ default:
+ break;
+ }
+
if (bfd_check_format (ibfd, bfd_archive))
{
bfd_boolean force_output_target;
@@ -2637,9 +2663,9 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
&& bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
{
- void *memhunk = xmalloc (size);
+ bfd_byte *memhunk = NULL;
- if (!bfd_get_section_contents (ibfd, isection, memhunk, 0, size))
+ if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
{
status = 1;
bfd_nonfatal_message (NULL, ibfd, isection, NULL);
@@ -3170,6 +3196,7 @@ copy_main (int argc, char *argv[])
struct section_list *p;
struct stat statbuf;
const bfd_arch_info_type *input_arch = NULL;
+ struct dwarf_debug_section *d;
while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:w",
copy_options, (int *) 0)) != EOF)
@@ -3462,10 +3489,18 @@ copy_main (int argc, char *argv[])
change_leading_char = TRUE;
break;
+ case OPTION_COMPRESS_DEBUG_SECTIONS:
+ do_debug_sections = compress;
+ break;
+
case OPTION_DEBUGGING:
convert_debugging = TRUE;
break;
+ case OPTION_DECOMPRESS_DEBUG_SECTIONS:
+ do_debug_sections = decompress;
+ break;
+
case OPTION_GAP_FILL:
{
bfd_vma gap_fill_vma;
@@ -3877,6 +3912,22 @@ copy_main (int argc, char *argv[])
fatal (_("warning: could not create temporary file whilst copying '%s', (error: %s)"),
input_filename, strerror (errno));
+ switch (do_debug_sections)
+ {
+ case compress:
+ for (d = dwarf_debug_sections; d->uncompressed_name; d++)
+ add_section_rename (d->uncompressed_name, d->compressed_name,
+ (flagword) -1);
+ break;
+ case decompress:
+ for (d = dwarf_debug_sections; d->uncompressed_name; d++)
+ add_section_rename (d->compressed_name, d->uncompressed_name,
+ (flagword) -1);
+ break;
+ default:
+ break;
+ }
+
copy_file (input_filename, tmpname, input_target, output_target, input_arch);
if (status == 0)
{