- if (decompress_dumps)
- {
- uint64_t new_size = section_size;
- uint64_t uncompressed_size = 0;
- bool is_zstd = false;
-
- if ((section->sh_flags & SHF_COMPRESSED) != 0)
- {
- Elf_Internal_Chdr chdr;
- unsigned int compression_header_size
- = get_compression_header (& chdr, start, section_size);
-
- if (compression_header_size == 0)
- /* An error message will have already been generated
- by get_compression_header. */
- goto error_out;
-
- if (chdr.ch_type == ch_compress_zlib)
- ;
-#ifdef HAVE_ZSTD
- else if (chdr.ch_type == ch_compress_zstd)
- is_zstd = true;
-#endif
- else
- {
- warn (_("section '%s' has unsupported compress type: %d\n"),
- printable_section_name (filedata, section), chdr.ch_type);
- goto error_out;
- }
- uncompressed_size = chdr.ch_size;
- start += compression_header_size;
- new_size -= compression_header_size;
- }
- else if (new_size > 12 && streq ((char *) start, "ZLIB"))
- {
- /* Read the zlib header. In this case, it should be "ZLIB"
- followed by the uncompressed section size, 8 bytes in
- big-endian order. */
- uncompressed_size = start[4]; uncompressed_size <<= 8;
- uncompressed_size += start[5]; uncompressed_size <<= 8;
- uncompressed_size += start[6]; uncompressed_size <<= 8;
- uncompressed_size += start[7]; uncompressed_size <<= 8;
- uncompressed_size += start[8]; uncompressed_size <<= 8;
- uncompressed_size += start[9]; uncompressed_size <<= 8;
- uncompressed_size += start[10]; uncompressed_size <<= 8;
- uncompressed_size += start[11];
- start += 12;
- new_size -= 12;
- }
-
- if (uncompressed_size)
- {
- if (uncompress_section_contents (is_zstd, &start, uncompressed_size,
- &new_size, filedata->file_size))
- {
- section_size = new_size;
- }
- else
- {
- error (_("Unable to decompress section %s\n"),
- printable_section_name (filedata, section));
- /* FIXME: Print the section anyway ? */
- goto error_out;
- }
- }
- else
- start = real_start;
- }
-
- if (relocate)
- {
- if (! apply_relocations (filedata, section, start, section_size, NULL, NULL))
- goto error_out;
- }
- else
- {
- /* If the section being dumped has relocations against it the user might
- be expecting these relocations to have been applied. Check for this
- case and issue a warning message in order to avoid confusion.
- FIXME: Maybe we ought to have an option that dumps a section with
- relocs applied ? */
- for (relsec = filedata->section_headers;
- relsec < filedata->section_headers + filedata->file_header.e_shnum;
- ++relsec)
- {
- if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
- || relsec->sh_info >= filedata->file_header.e_shnum
- || filedata->section_headers + relsec->sh_info != section
- || relsec->sh_size == 0
- || relsec->sh_link >= filedata->file_header.e_shnum)
- continue;
-
- printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
- break;
- }
- }