+// Return a view of the decompressed contents of a section. Set *PLEN
+// to the size. Set *IS_NEW to true if the contents need to be freed
+// by the caller.
+
+template<int size, bool big_endian>
+const unsigned char*
+Sized_relobj_file<size, big_endian>::do_decompressed_section_contents(
+ unsigned int shndx,
+ section_size_type* plen,
+ bool* is_new)
+{
+ section_size_type buffer_size;
+ const unsigned char* buffer = this->do_section_contents(shndx, &buffer_size,
+ false);
+
+ if (this->compressed_sections_ == NULL)
+ {
+ *plen = buffer_size;
+ *is_new = false;
+ return buffer;
+ }
+
+ Compressed_section_map::const_iterator p =
+ this->compressed_sections_->find(shndx);
+ if (p == this->compressed_sections_->end())
+ {
+ *plen = buffer_size;
+ *is_new = false;
+ return buffer;
+ }
+
+ section_size_type uncompressed_size = p->second.size;
+ if (p->second.contents != NULL)
+ {
+ *plen = uncompressed_size;
+ *is_new = false;
+ return p->second.contents;
+ }
+
+ unsigned char* uncompressed_data = new unsigned char[uncompressed_size];
+ if (!decompress_input_section(buffer,
+ buffer_size,
+ uncompressed_data,
+ uncompressed_size))
+ this->error(_("could not decompress section %s"),
+ this->do_section_name(shndx).c_str());
+
+ // We could cache the results in p->second.contents and store
+ // false in *IS_NEW, but build_compressed_section_map() would
+ // have done so if it had expected it to be profitable. If
+ // we reach this point, we expect to need the contents only
+ // once in this pass.
+ *plen = uncompressed_size;
+ *is_new = true;
+ return uncompressed_data;
+}
+
+// Discard any buffers of uncompressed sections. This is done
+// at the end of the Add_symbols task.
+
+template<int size, bool big_endian>
+void
+Sized_relobj_file<size, big_endian>::do_discard_decompressed_sections()
+{
+ if (this->compressed_sections_ == NULL)
+ return;
+
+ for (Compressed_section_map::iterator p = this->compressed_sections_->begin();
+ p != this->compressed_sections_->end();
+ ++p)
+ {
+ if (p->second.contents != NULL)
+ {
+ delete[] p->second.contents;
+ p->second.contents = NULL;
+ }
+ }
+}
+