From 9a0910c33e1a6962d475ee0a994fd1f5e446a888 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 30 Nov 2007 00:35:27 +0000 Subject: From Craig Silverstein: Add support for compressing .debug_str section. --- gold/stringpool.cc | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'gold/stringpool.cc') diff --git a/gold/stringpool.cc b/gold/stringpool.cc index db04b0c..42a2fda 100644 --- a/gold/stringpool.cc +++ b/gold/stringpool.cc @@ -41,12 +41,21 @@ Stringpool_template::Stringpool_template() } template -Stringpool_template::~Stringpool_template() +void +Stringpool_template::clear() { for (typename std::list::iterator p = this->strings_.begin(); p != this->strings_.end(); ++p) delete[] reinterpret_cast(*p); + this->strings_.clear(); + this->string_set_.clear(); +} + +template +Stringpool_template::~Stringpool_template() +{ + this->clear(); } // Return the length of a string of arbitrary character type. @@ -413,23 +422,38 @@ Stringpool_template::get_offset(const Stringpool_char* s) gold_unreachable(); } -// Write the ELF strtab into the output file at the specified offset. +// Write the ELF strtab into the buffer. template void -Stringpool_template::write(Output_file* of, off_t offset) +Stringpool_template::write_to_buffer(char* buffer, + size_t bufsize) { gold_assert(this->strtab_size_ != 0); - unsigned char* viewu = of->get_output_view(offset, this->strtab_size_); - char* view = reinterpret_cast(viewu); + if (bufsize < this->strtab_size_) // Quiet the compiler in opt mode. + gold_assert(bufsize >= this->strtab_size_); if (this->zero_null_) - view[0] = '\0'; + buffer[0] = '\0'; for (typename String_set_type::const_iterator p = this->string_set_.begin(); p != this->string_set_.end(); ++p) - memcpy(view + p->second.second, p->first, - (string_length(p->first) + 1) * sizeof(Stringpool_char)); - of->write_output_view(offset, this->strtab_size_, viewu); + { + const int len = (string_length(p->first) + 1) * sizeof(Stringpool_char); + gold_assert(p->second.second + len <= this->strtab_size_); + memcpy(buffer + p->second.second, p->first, len); + } +} + +// Write the ELF strtab into the output file at the specified offset. + +template +void +Stringpool_template::write(Output_file* of, off_t offset) +{ + gold_assert(this->strtab_size_ != 0); + unsigned char* view = of->get_output_view(offset, this->strtab_size_); + this->write_to_buffer(reinterpret_cast(view), this->strtab_size_); + of->write_output_view(offset, this->strtab_size_, view); } // Instantiate the templates we need. -- cgit v1.1