+// Return whether this is the merge map for section SHNDX.
+
+inline bool
+Object_merge_map::is_merge_section_for(const Merge_map* merge_map,
+ unsigned int shndx)
+{
+ Input_merge_map* map = this->get_input_merge_map(shndx);
+ return map != NULL && map->merge_map == merge_map;
+}
+
+// Initialize a mapping from input offsets to output addresses.
+
+template<int size>
+void
+Object_merge_map::initialize_input_to_output_map(
+ unsigned int shndx,
+ typename elfcpp::Elf_types<size>::Elf_Addr starting_address,
+ Unordered_map<section_offset_type,
+ typename elfcpp::Elf_types<size>::Elf_Addr>* initialize_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)
+ {
+ section_offset_type output_offset = p->output_offset;
+ if (output_offset != -1)
+ output_offset += starting_address;
+ else
+ {
+ // If we see a relocation against an address we have chosen
+ // to discard, we relocate to zero. FIXME: We could also
+ // issue a warning in this case; that would require
+ // reporting this somehow and checking it in the routines in
+ // reloc.h.
+ output_offset = 0;
+ }
+ initialize_map->insert(std::make_pair(p->input_offset, output_offset));
+ }
+}
+
+// Class Merge_map.
+
+// Add a mapping for the bytes from OFFSET to OFFSET + LENGTH in input
+// section SHNDX in object OBJECT to an OUTPUT_OFFSET in merged data
+// in an output section.
+
+void
+Merge_map::add_mapping(Relobj* object, unsigned int shndx,
+ section_offset_type offset, section_size_type length,
+ section_offset_type output_offset)
+{
+ Object_merge_map* object_merge_map = object->merge_map();
+ if (object_merge_map == NULL)
+ {
+ object_merge_map = new Object_merge_map();
+ object->set_merge_map(object_merge_map);
+ }
+
+ object_merge_map->add_mapping(this, shndx, offset, length, output_offset);
+}
+
+// Return the output offset for an input address. The input address
+// is at offset OFFSET in section SHNDX in OBJECT. This sets
+// *OUTPUT_OFFSET to the offset in the merged data in the output
+// section. This returns true if the mapping is known, false
+// otherwise.
+
+bool
+Merge_map::get_output_offset(const Relobj* object, unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type* output_offset) const
+{
+ Object_merge_map* object_merge_map = object->merge_map();
+ if (object_merge_map == NULL)
+ return false;
+ return object_merge_map->get_output_offset(this, shndx, offset,
+ output_offset);
+}
+
+// Return whether this is the merge section for SHNDX in OBJECT.
+
+bool
+Merge_map::is_merge_section_for(const Relobj* object, unsigned int shndx) const
+{
+ Object_merge_map* object_merge_map = object->merge_map();
+ if (object_merge_map == NULL)
+ return false;
+ return object_merge_map->is_merge_section_for(this, shndx);
+}
+
+// Class Output_merge_base.
+
+// Return the output offset for an input offset. The input address is
+// at offset OFFSET in section SHNDX in OBJECT. If we know the
+// offset, set *POUTPUT and return true. Otherwise return false.
+
+bool
+Output_merge_base::do_output_offset(const Relobj* object,
+ unsigned int shndx,
+ section_offset_type offset,
+ section_offset_type* poutput) const
+{
+ return this->merge_map_.get_output_offset(object, shndx, offset, poutput);
+}
+
+// Return whether this is the merge section for SHNDX in OBJECT.
+
+bool
+Output_merge_base::do_is_merge_section_for(const Relobj* object,
+ unsigned int shndx) const
+{
+ return this->merge_map_.is_merge_section_for(object, shndx);
+}
+
+// Record a merged input section for script processing.
+
+void
+Output_merge_base::record_input_section(Relobj* relobj, unsigned int shndx)
+{
+ gold_assert(this->keeps_input_sections_ && relobj != NULL);
+ // If this is the first input section, record it. We need do this because
+ // this->input_sections_ is unordered.
+ if (this->first_relobj_ == NULL)
+ {
+ this->first_relobj_ = relobj;
+ this->first_shndx_ = shndx;
+ }
+
+ std::pair<Input_sections::iterator, bool> result =
+ this->input_sections_.insert(Section_id(relobj, shndx));
+ // We should insert a merge section once only.
+ gold_assert(result.second);
+}
+
+// Class Output_merge_data.
+