-// For each object with merge sections, we store an Object_merge_map.
-// This is used to map locations in input sections to a merged output
-// section. The output section itself is not recorded here--it can be
-// found in the map_to_output_ field of the Object.
-
-class Object_merge_map
-{
- public:
- Object_merge_map()
- : first_shnum_(-1U), first_map_(),
- second_shnum_(-1U), second_map_(),
- section_merge_maps_()
- { }
-
- ~Object_merge_map();
-
- // Add a mapping for MERGE_MAP, for the bytes from OFFSET to OFFSET
- // + LENGTH in the input section SHNDX to OUTPUT_OFFSET in the
- // output section. An OUTPUT_OFFSET of -1 means that the bytes are
- // discarded.
- void
- add_mapping(const Merge_map*, unsigned int shndx, section_offset_type offset,
- section_size_type length, section_offset_type output_offset);
-
- // Get the output offset for an input address in MERGE_MAP. The
- // input address is at offset OFFSET in section SHNDX. This sets
- // *OUTPUT_OFFSET to the offset in the output section; this will be
- // -1 if the bytes are not being copied to the output. This returns
- // true if the mapping is known, false otherwise.
- bool
- get_output_offset(const Merge_map*, unsigned int shndx,
- section_offset_type offset,
- section_offset_type *output_offset);
-
- private:
- // Map input section offsets to a length and an output section
- // offset. An output section offset of -1 means that this part of
- // the input section is being discarded.
- struct Input_merge_entry
- {
- // The offset in the input section.
- section_offset_type input_offset;
- // The length.
- section_size_type length;
- // The offset in the output section.
- section_offset_type output_offset;
- };
-
- // A less-than comparison routine for Input_merge_entry.
- struct Input_merge_compare
- {
- bool
- operator()(const Input_merge_entry& i1, const Input_merge_entry& i2) const
- { return i1.input_offset < i2.input_offset; }
- };
-
- // A list of entries for a particular section.
- struct Input_merge_map
- {
- // The Merge_map for this section.
- const Merge_map* merge_map;
- // The list of mappings.
- std::vector<Input_merge_entry> entries;
- // Whether the ENTRIES field is sorted by input_offset.
- bool sorted;
-
- Input_merge_map()
- : merge_map(NULL), entries(), sorted(true)
- { }
- };
-
- // Map input section indices to merge maps.
- typedef std::map<unsigned int, Input_merge_map*> Section_merge_maps;
-
- // Return a pointer to the Input_merge_map to use for the input
- // section SHNDX, or NULL.
- Input_merge_map*
- get_input_merge_map(unsigned int shndx);
-
- // Get or make the the Input_merge_map to use for the section SHNDX
- // with MERGE_MAP.
- Input_merge_map*
- get_or_make_input_merge_map(const Merge_map* merge_map, unsigned int shndx);
-
- // Any given object file will normally only have a couple of input
- // sections with mergeable contents. So we keep the first two input
- // section numbers inline, and push any further ones into a map. A
- // value of -1U in first_shnum_ or second_shnum_ means that we don't
- // have a corresponding entry.
- unsigned int first_shnum_;
- Input_merge_map first_map_;
- unsigned int second_shnum_;
- Input_merge_map second_map_;
- Section_merge_maps section_merge_maps_;
-};