* ldexp.c: Add LOG2CEIL() builtin function to linker script language
[binutils-gdb.git] / gold / stringpool.cc
index bbbe975989366e5da2befcf62b7ccd4f045741ff..665fcc8ce59d7e62dcebd9c36dbdda88b2dfa097 100644 (file)
@@ -34,9 +34,10 @@ namespace gold
 {
 
 template<typename Stringpool_char>
-Stringpool_template<Stringpool_char>::Stringpool_template()
+Stringpool_template<Stringpool_char>::Stringpool_template(uint64_t addralign)
   : string_set_(), key_to_offset_(), strings_(), strtab_size_(0),
-    zero_null_(true), optimize_(false), offset_(0)
+    zero_null_(true), optimize_(false), offset_(sizeof(Stringpool_char)),
+    addralign_(addralign)
 {
   if (parameters->options_valid() && parameters->options().optimize() >= 2)
     this->optimize_ = true;
@@ -87,28 +88,6 @@ Stringpool_template<Stringpool_char>::reserve(unsigned int n)
   this->string_set_.swap(new_string_set);
 }
 
-// Return the length of a string of arbitrary character type.
-
-template<typename Stringpool_char>
-size_t
-Stringpool_template<Stringpool_char>::string_length(const Stringpool_char* p)
-{
-  size_t len = 0;
-  for (; *p != 0; ++p)
-    ++len;
-  return len;
-}
-
-// Specialize string_length for char.  Maybe we could just use
-// std::char_traits<>::length?
-
-template<>
-inline size_t
-Stringpool_template<char>::string_length(const char* p)
-{
-  return strlen(p);
-}
-
 // Compare two strings of arbitrary character type for equality.
 
 template<typename Stringpool_char>
@@ -191,7 +170,7 @@ Stringpool_template<Stringpool_char>::add_string(const Stringpool_char* s,
     alc = sizeof(Stringdata) + buffer_size;
   else
     {
-      Stringdata *psd = this->strings_.front();
+      Stringdatapsd = this->strings_.front();
       if (len > psd->alc - psd->len)
        alc = sizeof(Stringdata) + buffer_size;
       else
@@ -207,7 +186,7 @@ Stringpool_template<Stringpool_char>::add_string(const Stringpool_char* s,
        }
     }
 
-  Stringdata *psd = reinterpret_cast<Stringdata*>(new char[alc]);
+  Stringdatapsd = reinterpret_cast<Stringdata*>(new char[alc]);
   psd->alc = alc - sizeof(Stringdata);
   memcpy(psd->data, s, len - sizeof(Stringpool_char));
   memset(psd->data + len - sizeof(Stringpool_char), 0,
@@ -238,16 +217,16 @@ template<typename Stringpool_char>
 void
 Stringpool_template<Stringpool_char>::new_key_offset(size_t length)
 {
-  if (this->key_to_offset_.size() == 0)
-    this->offset_ = this->zero_null_ ? sizeof(Stringpool_char) : 0;
-    
   section_offset_type offset;
   if (this->zero_null_ && length == 0)
     offset = 0;
   else
     {
       offset = this->offset_;
-      this->offset_ += (length + 1) * sizeof(Stringpool_char);
+      // Align non-zero length strings.
+      if (length != 0)
+       offset = align_address(offset, this->addralign_);
+      this->offset_ = offset + (length + 1) * sizeof(Stringpool_char);
     }
   this->key_to_offset_.push_back(offset);
 }
@@ -446,8 +425,8 @@ Stringpool_template<Stringpool_char>::set_string_offsets()
                              * charsize));
           else
             {
-              this_offset = offset;
-              offset += ((*curr)->first.length + 1) * charsize;
+              this_offset = align_address(offset, this->addralign_);
+              offset = this_offset + ((*curr)->first.length + 1) * charsize;
             }
          this->key_to_offset_[(*curr)->second - 1] = this_offset;
          last_offset = this_offset;