+2010-03-19  Doug Kwan  <dougkwan@google.com>
+
+       * arm.cc (Stub_table::Stub_table): Initialize new data members
+       Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_.
+       (Stub_table::add_reloc_stub): Assign stub offset and update
+       Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_.
+       (Stub_table::reloc_stubs_size_, Stub_table::reloc_stubs_addralign_):
+       New data members.
+       (Stub_table::update_data_size_and_addralign): Use
+       Stub_table::reloc_stubs_size_ and Stub_table::reloc_stubs_addralign_
+       instead of going over all reloc stubs.
+       (Stub_table::finalize_stubs): Do not assign reloc stub offsets.
+       * stringpool.cc (Stringpool_template::Stringpool_template): Initialize
+       Stringpool_template::offset_ to size of Stringpool_char.
+       (Stringpool_template::new_key_offset): Remove code to initialize
+       Stringpool_template::offset_.
+       * stringpool.h (Stringpool_template::set_no_zero_null): Set
+       Stringpool_template::offset_ to zero.
+
 2010-03-15  Doug Kwan  <dougkwan@google.com>
 
        * stringpool.cc (Stringpool_template::Stringpool_template): Initialize
 
 {
  public:
   Stub_table(Arm_input_section<big_endian>* owner)
-    : Output_data(), owner_(owner), reloc_stubs_(), cortex_a8_stubs_(),
-      arm_v4bx_stubs_(0xf), prev_data_size_(0), prev_addralign_(1)
+    : Output_data(), owner_(owner), reloc_stubs_(), reloc_stubs_size_(0),
+      reloc_stubs_addralign_(1), cortex_a8_stubs_(), arm_v4bx_stubs_(0xf),
+      prev_data_size_(0), prev_addralign_(1)
   { }
 
   ~Stub_table()
     const Stub_template* stub_template = stub->stub_template();
     gold_assert(stub_template->type() == key.stub_type());
     this->reloc_stubs_[key] = stub;
+
+    // Assign stub offset early.  We can do this because we never remove
+    // reloc stubs and they are in the beginning of the stub table.
+    uint64_t align = stub_template->alignment();
+    this->reloc_stubs_size_ = align_address(this->reloc_stubs_size_, align);
+    stub->set_offset(this->reloc_stubs_size_);
+    this->reloc_stubs_size_ += stub_template->size();
+    this->reloc_stubs_addralign_ =
+      std::max(this->reloc_stubs_addralign_, align);
   }
 
   // Add a Cortex-A8 STUB that fixes up a THUMB branch at ADDRESS.
   Arm_input_section<big_endian>* owner_;
   // The relocation stubs.
   Reloc_stub_map reloc_stubs_;
+  // Size of reloc stubs.
+  off_t reloc_stubs_size_;
+  // Maximum address alignment of reloc stubs.
+  uint64_t reloc_stubs_addralign_;
   // The cortex_a8_stubs.
   Cortex_a8_stub_list cortex_a8_stubs_;
   // The Arm V4BX relocation stubs.
 bool
 Stub_table<big_endian>::update_data_size_and_addralign()
 {
-  off_t size = 0;
-  unsigned addralign = 1;
-
   // Go over all stubs in table to compute data size and address alignment.
-  
-  for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
-      p != this->reloc_stubs_.end();
-      ++p)
-    {
-      const Stub_template* stub_template = p->second->stub_template();
-      addralign = std::max(addralign, stub_template->alignment());
-      size = (align_address(size, stub_template->alignment())
-             + stub_template->size());
-    }
+  off_t size = this->reloc_stubs_size_;
+  unsigned addralign = this->reloc_stubs_addralign_;
 
   for (Cortex_a8_stub_list::const_iterator p = this->cortex_a8_stubs_.begin();
        p != this->cortex_a8_stubs_.end();
 void
 Stub_table<big_endian>::finalize_stubs()
 {
-  off_t off = 0;
-  for (typename Reloc_stub_map::const_iterator p = this->reloc_stubs_.begin();
-      p != this->reloc_stubs_.end();
-      ++p)
-    {
-      Reloc_stub* stub = p->second;
-      const Stub_template* stub_template = stub->stub_template();
-      uint64_t stub_addralign = stub_template->alignment();
-      off = align_address(off, stub_addralign);
-      stub->set_offset(off);
-      off += stub_template->size();
-    }
-
+  off_t off = this->reloc_stubs_size_;
   for (Cortex_a8_stub_list::const_iterator p = this->cortex_a8_stubs_.begin();
        p != this->cortex_a8_stubs_.end();
        ++p)
 
 template<typename Stringpool_char>
 Stringpool_template<Stringpool_char>::Stringpool_template()
   : 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))
 {
   if (parameters->options_valid() && parameters->options().optimize() >= 2)
     this->optimize_ = true;
 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;