/* Whether to compress/decompress DWARF debug sections. */
static enum
{
- nothing,
- compress,
- decompress
+ nothing = 0,
+ compress = 1 << 0,
+ compress_zlib = compress | 1 << 1,
+ compress_gnu_zlib = compress | 1 << 2,
+ compress_gabi_zlib = compress | 1 << 3,
+ decompress = 1 << 4
} do_debug_sections = nothing;
/* Whether to change the leading character in symbol names. */
{"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},
+ {"compress-debug-sections", optional_argument, 0, OPTION_COMPRESS_DEBUG_SECTIONS},
{"debugging", no_argument, 0, OPTION_DEBUGGING},
{"decompress-debug-sections", no_argument, 0, OPTION_DECOMPRESS_DEBUG_SECTIONS},
{"disable-deterministic-archives", no_argument, 0, 'U'},
-w --wildcard Permit wildcard in symbol comparison\n\
-x --discard-all Remove all non-global symbols\n\
-X --discard-locals Remove any compiler-generated symbols\n\
- -i --interleave [<number>] Only copy N out of every <number> bytes\n\
+ -i --interleave[=<number>] Only copy N out of every <number> bytes\n\
--interleave-width <number> Set N for --interleave\n\
-b --byte <num> Select byte <num> in every interleaved block\n\
--gap-fill <val> Fill gaps between sections with <val>\n\
<commit>\n\
--subsystem <name>[:<version>]\n\
Set PE subsystem to <name> [& <version>]\n\
- --compress-debug-sections Compress DWARF debug sections using zlib\n\
+ --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]\n\
+ 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\
return FALSE;
}
+ if ((do_debug_sections & compress) != 0
+ && do_debug_sections != compress
+ && ibfd->xvec->flavour != bfd_target_elf_flavour)
+ {
+ non_fatal (_("--compress-debug-sections=[zlib|zlib-gnu|zlib-gabi] is unsupported on `%s'"),
+ bfd_get_archive_filename (ibfd));
+ return FALSE;
+ }
+
if (verbose)
printf (_("copy from `%s' [%s] to `%s' [%s]\n"),
bfd_get_archive_filename (ibfd), bfd_get_target (ibfd),
switch (do_debug_sections)
{
case compress:
+ case compress_zlib:
+ case compress_gnu_zlib:
+ case compress_gabi_zlib:
ibfd->flags |= BFD_COMPRESS;
+ /* Don't check if input is ELF here since this information is
+ only available after bfd_check_format_matches is called. */
+ if (do_debug_sections == compress_gabi_zlib)
+ ibfd->flags |= BFD_COMPRESS_GABI;
break;
case decompress:
ibfd->flags |= BFD_DECOMPRESS;
elf_section_type (osection) = SHT_NOBITS;
size = bfd_section_size (ibfd, isection);
+ size = bfd_convert_section_size (ibfd, isection, obfd, size);
if (copy_byte >= 0)
size = (size + interleave - 1) / interleave * copy_width;
else if (extract_symbol)
/* Copy merge entity size. */
osection->entsize = isection->entsize;
+ /* Copy compress status. */
+ osection->compress_status = isection->compress_status;
+
/* This used to be mangle_section; we do here to avoid using
bfd_get_section_by_name since some formats allow multiple
sections with the same name. */
return;
osection = isection->output_section;
- size = bfd_get_section_size (isection);
+ /* The output SHF_COMPRESSED section size is different from input if
+ ELF classes of input and output aren't the same. We must use the
+ output section size here, which has been updated in setup_section
+ via bfd_convert_section_size. */
+ size = bfd_get_section_size (osection);
if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
&& bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
{
bfd_byte *memhunk = NULL;
- if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
+ if (!bfd_get_full_section_contents (ibfd, isection, &memhunk)
+ || !bfd_convert_section_contents (ibfd, isection, obfd,
+ &memhunk))
{
status = 1;
bfd_nonfatal_message (NULL, ibfd, isection, NULL);
break;
case OPTION_COMPRESS_DEBUG_SECTIONS:
- do_debug_sections = compress;
+ if (optarg)
+ {
+ if (strcasecmp (optarg, "none") == 0)
+ do_debug_sections = decompress;
+ else if (strcasecmp (optarg, "zlib") == 0)
+ do_debug_sections = compress_zlib;
+ else if (strcasecmp (optarg, "zlib-gnu") == 0)
+ do_debug_sections = compress_gnu_zlib;
+ else if (strcasecmp (optarg, "zlib-gabi") == 0)
+ do_debug_sections = compress_gabi_zlib;
+ else
+ fatal (_("unrecognized --compress-debug-sections type `%s'"),
+ optarg);
+ }
+ else
+ do_debug_sections = compress;
break;
case OPTION_DEBUGGING: