PR ld/10515
[binutils-gdb.git] / gold / merge.cc
index 75a3eeea924f48978174dfc52e0d63a5e96c6ef8..3d9692124a0cb3a90123b01ff51faa4e9107d8a9 100644 (file)
@@ -1,6 +1,6 @@
 // merge.cc -- handle section merging for gold
 
-// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -140,7 +140,7 @@ Object_merge_map::add_mapping(const Merge_map* merge_map, unsigned int shndx,
 
 // Get the output offset for an input address.
 
-inline bool
+bool
 Object_merge_map::get_output_offset(const Merge_map* merge_map,
                                    unsigned int shndx,
                                    section_offset_type input_offset,
@@ -204,6 +204,12 @@ Object_merge_map::initialize_input_to_output_map(
   Input_merge_map* map = this->get_input_merge_map(shndx);
   gold_assert(map != NULL);
 
+  gold_assert(initialize_map->empty());
+  // We know how many entries we are going to add.
+  // reserve_unordered_map takes an expected count of buckets, not a
+  // count of elements, so double it to try to reduce collisions.
+  reserve_unordered_map(initialize_map, map->entries.size() * 2);
+
   for (Input_merge_map::Entries::const_iterator p = map->entries.begin();
        p != map->entries.end();
        ++p)
@@ -465,7 +471,7 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
   const unsigned char* pdata = object->section_contents(shndx, &len, false);
 
   const Char_type* p = reinterpret_cast<const Char_type*>(pdata);
-  const Char_type* pend = p + len;
+  const Char_type* pend = p + len / sizeof(Char_type);
 
   if (len % sizeof(Char_type) != 0)
     {
@@ -485,8 +491,10 @@ Output_merge_string<Char_type>::do_add_input_section(Relobj* object,
        {
          if (pl >= pend)
            {
-             object->error(_("entry in mergeable string section "
-                             "not null terminated"));
+             gold_warning(_("%s: last entry in mergeable string section '%s' "
+                            "not null terminated"),
+                          object->name().c_str(),
+                          object->section_name(shndx).c_str());
              break;
            }
        }
@@ -528,7 +536,9 @@ Output_merge_string<Char_type>::finalize_merged_data()
       this->add_mapping(p->object, p->shndx, p->offset, p->length, offset);
     }
 
-  // Save some memory.
+  // Save some memory.  This also ensures that this function will work
+  // if called twice, as may happen if Layout::set_segment_offsets
+  // finds a better alignment.
   this->merged_strings_.clear();
 
   return this->stringpool_.get_strtab_size();