aboutsummaryrefslogtreecommitdiff
path: root/gold/stringpool.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-11-30 00:35:27 +0000
committerIan Lance Taylor <iant@google.com>2007-11-30 00:35:27 +0000
commit9a0910c33e1a6962d475ee0a994fd1f5e446a888 (patch)
treef30e7b369cc05383699fbe4780ee0839b8dbcdde /gold/stringpool.cc
parent71195202dfb59bb7b61b35dc4cc5d202fab12020 (diff)
downloadgdb-9a0910c33e1a6962d475ee0a994fd1f5e446a888.zip
gdb-9a0910c33e1a6962d475ee0a994fd1f5e446a888.tar.gz
gdb-9a0910c33e1a6962d475ee0a994fd1f5e446a888.tar.bz2
From Craig Silverstein: Add support for compressing .debug_str section.
Diffstat (limited to 'gold/stringpool.cc')
-rw-r--r--gold/stringpool.cc42
1 files changed, 33 insertions, 9 deletions
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_char>::Stringpool_template()
}
template<typename Stringpool_char>
-Stringpool_template<Stringpool_char>::~Stringpool_template()
+void
+Stringpool_template<Stringpool_char>::clear()
{
for (typename std::list<Stringdata*>::iterator p = this->strings_.begin();
p != this->strings_.end();
++p)
delete[] reinterpret_cast<char*>(*p);
+ this->strings_.clear();
+ this->string_set_.clear();
+}
+
+template<typename Stringpool_char>
+Stringpool_template<Stringpool_char>::~Stringpool_template()
+{
+ this->clear();
}
// Return the length of a string of arbitrary character type.
@@ -413,23 +422,38 @@ Stringpool_template<Stringpool_char>::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<typename Stringpool_char>
void
-Stringpool_template<Stringpool_char>::write(Output_file* of, off_t offset)
+Stringpool_template<Stringpool_char>::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<char*>(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<typename Stringpool_char>
+void
+Stringpool_template<Stringpool_char>::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<char*>(view), this->strtab_size_);
+ of->write_output_view(offset, this->strtab_size_, view);
}
// Instantiate the templates we need.