+ return true;
+ }
+}
+
+// Return TRUE if this is a section whose contents will be needed in the
+// Add_symbols task. This function is only called for sections that have
+// already passed the test in is_compressed_debug_section(), so we know
+// that the section name begins with ".zdebug".
+
+static bool
+need_decompressed_section(const char* name)
+{
+ // Skip over the ".zdebug" and a quick check for the "_".
+ name += 7;
+ if (*name++ != '_')
+ return false;
+
+#ifdef ENABLE_THREADS
+ // Decompressing these sections now will help only if we're
+ // multithreaded.
+ if (parameters->options().threads())
+ {
+ // We will need .zdebug_str if this is not an incremental link
+ // (i.e., we are processing string merge sections) or if we need
+ // to build a gdb index.
+ if ((!parameters->incremental() || parameters->options().gdb_index())
+ && strcmp(name, "str") == 0)
+ return true;
+
+ // We will need these other sections when building a gdb index.
+ if (parameters->options().gdb_index()
+ && (strcmp(name, "info") == 0
+ || strcmp(name, "types") == 0
+ || strcmp(name, "pubnames") == 0
+ || strcmp(name, "pubtypes") == 0
+ || strcmp(name, "ranges") == 0
+ || strcmp(name, "abbrev") == 0))
+ return true;
+ }
+#endif
+
+ // Even when single-threaded, we will need .zdebug_str if this is
+ // not an incremental link and we are building a gdb index.
+ // Otherwise, we would decompress the section twice: once for
+ // string merge processing, and once for building the gdb index.
+ if (!parameters->incremental()
+ && parameters->options().gdb_index()
+ && strcmp(name, "str") == 0)
+ return true;
+
+ return false;
+}
+
+// Build a table for any compressed debug sections, mapping each section index
+// to the uncompressed size and (if needed) the decompressed contents.
+
+template<int size, bool big_endian>
+Compressed_section_map*
+build_compressed_section_map(
+ const unsigned char* pshdrs,
+ unsigned int shnum,
+ const char* names,
+ section_size_type names_size,
+ Sized_relobj_file<size, big_endian>* obj)
+{
+ Compressed_section_map* uncompressed_map = new Compressed_section_map();
+ const unsigned int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
+ const unsigned char* p = pshdrs + shdr_size;
+
+ for (unsigned int i = 1; i < shnum; ++i, p += shdr_size)
+ {
+ typename elfcpp::Shdr<size, big_endian> shdr(p);
+ if (shdr.get_sh_type() == elfcpp::SHT_PROGBITS
+ && (shdr.get_sh_flags() & elfcpp::SHF_ALLOC) == 0)