1 // stringpool.h -- a string pool for gold -*- C++ -*-
7 // Manage a pool of unique strings.
9 #ifndef GOLD_STRINGPOOL_H
10 #define GOLD_STRINGPOOL_H
24 // Add a string to the pool. This returns a canonical permanent
25 // pointer to the string.
30 add(const std::string
& s
)
31 { return this->add(s
.c_str()); }
33 // Add the prefix of a string to the pool.
35 add(const char *, size_t);
37 // If a string is present, return the canonical string. Otherwise,
40 find(const char*) const;
42 // Turn the stringpool into an ELF strtab: determine the offsets of
47 // Get the offset of a string.
49 get_offset(const char*) const;
52 get_offset(const std::string
& s
) const
53 { return this->get_offset(s
.c_str()); }
55 // Get the size of the ELF strtab.
57 get_strtab_size() const
58 { return this->strtab_size_
; }
60 // Write the strtab into the output file at the specified offset.
62 write(Output_file
*, off_t offset
);
65 Stringpool(const Stringpool
&);
66 Stringpool
& operator=(const Stringpool
&);
68 // We store the actual data in a list of these buffers.
71 // Length of data in buffer.
73 // Allocated size of buffer.
79 // Copy a string into the buffers, returning a canonical string.
81 add_string(const char*);
83 struct Stringpool_hash
86 operator()(const char*) const;
92 operator()(const char* p1
, const char* p2
) const
93 { return strcmp(p1
, p2
) == 0; }
96 // Return whether s1 is a suffix of s2.
97 static bool is_suffix(const char* s1
, const char* s2
);
99 // The hash table is a map from string names to offsets. We only
100 // use the offsets if we turn this into an ELF strtab section.
102 #ifdef HAVE_TR1_UNORDERED_SET
103 typedef Unordered_map
<const char*, off_t
, Stringpool_hash
,
105 std::allocator
<std::pair
<const char* const, off_t
> >,
106 true> String_set_type
;
108 typedef Unordered_map
<const char*, off_t
, Stringpool_hash
,
109 Stringpool_eq
> String_set_type
;
112 // Comparison routine used when sorting into an ELF strtab.
114 struct Stringpool_sort_comparison
117 operator()(String_set_type::iterator
,
118 String_set_type::iterator
) const;
121 String_set_type string_set_
;
122 std::list
<Stringdata
*> strings_
;
126 } // End namespace gold.
128 #endif // !defined(GOLD_STRINGPOOL_H)