aboutsummaryrefslogtreecommitdiff
path: root/gold/stringpool.h
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-05-16 17:42:48 +0000
committerIan Lance Taylor <iant@google.com>2007-05-16 17:42:48 +0000
commitb8e6aad9606384125f588d531c567f49bad346e2 (patch)
treee1172d50384713b91c329cc88cabcd2728f929a9 /gold/stringpool.h
parent60dfee729999b913a247956c4816e758afb86a4b (diff)
downloadgdb-b8e6aad9606384125f588d531c567f49bad346e2.zip
gdb-b8e6aad9606384125f588d531c567f49bad346e2.tar.gz
gdb-b8e6aad9606384125f588d531c567f49bad346e2.tar.bz2
Add support for SHF_MERGE sections.
Diffstat (limited to 'gold/stringpool.h')
-rw-r--r--gold/stringpool.h71
1 files changed, 43 insertions, 28 deletions
diff --git a/gold/stringpool.h b/gold/stringpool.h
index 05c498e..b9a65f6 100644
--- a/gold/stringpool.h
+++ b/gold/stringpool.h
@@ -14,7 +14,8 @@ namespace gold
class Output_file;
-class Stringpool
+template<typename Stringpool_char>
+class Stringpool_template
{
public:
// The type of a key into the stringpool. A key value will always
@@ -24,43 +25,47 @@ class Stringpool
// into an unordered hash table. Zero is never a valid key.
typedef size_t Key;
- Stringpool();
+ // Create a Stringpool. ZERO_NULL is true if we should reserve
+ // offset 0 to hold the empty string.
+ Stringpool_template(bool zero_null = true);
- ~Stringpool();
+ ~Stringpool_template();
// Add a string to the pool. This returns a canonical permanent
// pointer to the string. If PKEY is not NULL, this sets *PKEY to
// the key for the string.
- const char*
- add(const char*, Key* pkey);
+ const Stringpool_char*
+ add(const Stringpool_char*, Key* pkey);
- const char*
- add(const std::string& s, Key* pkey)
+ const Stringpool_char*
+ add(const std::basic_string<Stringpool_char>& s, Key* pkey)
{ return this->add(s.c_str(), pkey); }
// Add the prefix of a string to the pool.
- const char*
- add(const char *, size_t, Key* pkey);
+ const Stringpool_char*
+ add(const Stringpool_char*, size_t, Key* pkey);
// If a string is present, return the canonical string. Otherwise,
// return NULL. If PKEY is not NULL, set *PKEY to the key.
- const char*
- find(const char*, Key* pkey) const;
+ const Stringpool_char*
+ find(const Stringpool_char*, Key* pkey) const;
// Turn the stringpool into an ELF strtab: determine the offsets of
// all the strings.
void
set_string_offsets();
- // Get the offset of a string in an ELF strtab.
+ // Get the offset of a string in an ELF strtab. This returns the
+ // offset in bytes, not characters.
off_t
- get_offset(const char*) const;
+ get_offset(const Stringpool_char*) const;
off_t
- get_offset(const std::string& s) const
+ get_offset(const std::basic_string<Stringpool_char>& s) const
{ return this->get_offset(s.c_str()); }
- // Get the size of the ELF strtab.
+ // Get the size of the ELF strtab. This returns the number of
+ // bytes, not characters.
off_t
get_strtab_size() const
{
@@ -73,8 +78,12 @@ class Stringpool
write(Output_file*, off_t offset);
private:
- Stringpool(const Stringpool&);
- Stringpool& operator=(const Stringpool&);
+ Stringpool_template(const Stringpool_template&);
+ Stringpool_template& operator=(const Stringpool_template&);
+
+ // Return the length of a string.
+ static size_t
+ string_length(const Stringpool_char*);
// We store the actual data in a list of these buffers.
struct Stringdata
@@ -90,24 +99,24 @@ class Stringpool
};
// Copy a string into the buffers, returning a canonical string.
- const char*
- add_string(const char*, Key*);
+ const Stringpool_char*
+ add_string(const Stringpool_char*, Key*);
struct Stringpool_hash
{
size_t
- operator()(const char*) const;
+ operator()(const Stringpool_char*) const;
};
struct Stringpool_eq
{
bool
- operator()(const char* p1, const char* p2) const
- { return strcmp(p1, p2) == 0; }
+ operator()(const Stringpool_char* p1, const Stringpool_char* p2) const;
};
// Return whether s1 is a suffix of s2.
- static bool is_suffix(const char* s1, const char* s2);
+ static bool
+ is_suffix(const Stringpool_char* s1, const Stringpool_char* s2);
// The hash table is a map from string names to a pair of Key and
// ELF strtab offsets. We only use the offsets if we turn this into
@@ -116,12 +125,13 @@ class Stringpool
typedef std::pair<Key, off_t> Val;
#ifdef HAVE_TR1_UNORDERED_SET
- typedef Unordered_map<const char*, Val, Stringpool_hash,
+ typedef Unordered_map<const Stringpool_char*, Val, Stringpool_hash,
Stringpool_eq,
- std::allocator<std::pair<const char* const, Val> >,
+ std::allocator<std::pair<const Stringpool_char* const,
+ Val> >,
true> String_set_type;
#else
- typedef Unordered_map<const char*, Val, Stringpool_hash,
+ typedef Unordered_map<const Stringpool_char*, Val, Stringpool_hash,
Stringpool_eq> String_set_type;
#endif
@@ -130,8 +140,8 @@ class Stringpool
struct Stringpool_sort_comparison
{
bool
- operator()(String_set_type::iterator,
- String_set_type::iterator) const;
+ operator()(typename String_set_type::iterator,
+ typename String_set_type::iterator) const;
};
// List of Stringdata structures.
@@ -145,8 +155,13 @@ class Stringpool
off_t strtab_size_;
// Next Stringdata index.
unsigned int next_index_;
+ // Whether to reserve offset 0 to hold the null string.
+ bool zero_null_;
};
+// The most common type of Stringpool.
+typedef Stringpool_template<char> Stringpool;
+
} // End namespace gold.
#endif // !defined(GOLD_STRINGPOOL_H)