aboutsummaryrefslogtreecommitdiff
path: root/gold/stringpool.h
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2006-09-29 19:58:17 +0000
committerIan Lance Taylor <iant@google.com>2006-09-29 19:58:17 +0000
commit61ba1cf93601b0a0877a8ade94ba3c674a09f77e (patch)
treeffa744ec1dffd7f2dae13150b1dd7784728ed0a4 /gold/stringpool.h
parent4dba4b2419ccdbf48fd016edb7e0e10016897827 (diff)
downloadgdb-61ba1cf93601b0a0877a8ade94ba3c674a09f77e.zip
gdb-61ba1cf93601b0a0877a8ade94ba3c674a09f77e.tar.gz
gdb-61ba1cf93601b0a0877a8ade94ba3c674a09f77e.tar.bz2
Snapshot. Now able to produce a minimal executable which actually
runs.
Diffstat (limited to 'gold/stringpool.h')
-rw-r--r--gold/stringpool.h72
1 files changed, 62 insertions, 10 deletions
diff --git a/gold/stringpool.h b/gold/stringpool.h
index 79632e0..01c71a1 100644
--- a/gold/stringpool.h
+++ b/gold/stringpool.h
@@ -12,6 +12,8 @@
namespace gold
{
+class Output_file;
+
class Stringpool
{
public:
@@ -21,19 +23,50 @@ class Stringpool
// Add a string to the pool. This returns a canonical permanent
// pointer to the string.
- const char* add(const char*);
+ const char*
+ add(const char*);
- const char* add(const std::string& s)
+ const char*
+ add(const std::string& s)
{ return this->add(s.c_str()); }
// Add the prefix of a string to the pool.
- const char* add(const char *, size_t);
+ const char*
+ add(const char *, size_t);
+
+ // If a string is present, return the canonical string. Otherwise,
+ // return NULL.
+ const char*
+ find(const char*) 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.
+ off_t
+ get_offset(const char*) const;
+
+ off_t
+ get_offset(const std::string& s) const
+ { return this->get_offset(s.c_str()); }
+
+ // Get the size of the ELF strtab.
+ off_t
+ get_strtab_size() const
+ { return this->strtab_size_; }
+
+ // Write the strtab into the output file at the specified offset.
+ void
+ write(Output_file*, off_t offset);
private:
Stringpool(const Stringpool&);
Stringpool& operator=(const Stringpool&);
- struct stringdata
+ // We store the actual data in a list of these buffers.
+ struct Stringdata
{
// Length of data in buffer.
size_t len;
@@ -43,7 +76,9 @@ class Stringpool
char data[1];
};
- const char* add_string(const char*);
+ // Copy a string into the buffers, returning a canonical string.
+ const char*
+ add_string(const char*);
struct Stringpool_hash
{
@@ -58,17 +93,34 @@ class Stringpool
{ return strcmp(p1, p2) == 0; }
};
+ // Return whether s1 is a suffix of s2.
+ static bool is_suffix(const char* s1, const char* s2);
+
+ // The hash table is a map from string names to offsets. We only
+ // use the offsets if we turn this into an ELF strtab section.
+
#ifdef HAVE_TR1_UNORDERED_SET
- typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
- std::allocator<const char*>,
+ typedef Unordered_map<const char*, off_t, Stringpool_hash,
+ Stringpool_eq,
+ std::allocator<std::pair<const char* const, off_t> >,
true> String_set_type;
#else
- typedef Unordered_set<const char*, Stringpool_hash, Stringpool_eq,
- std::allocator<const char*> > String_set_type;
+ typedef Unordered_map<const char*, off_t, Stringpool_hash,
+ Stringpool_eq> String_set_type;
#endif
+ // Comparison routine used when sorting into an ELF strtab.
+
+ struct Stringpool_sort_comparison
+ {
+ bool
+ operator()(String_set_type::iterator,
+ String_set_type::iterator) const;
+ };
+
String_set_type string_set_;
- std::list<stringdata*> strings_;
+ std::list<Stringdata*> strings_;
+ off_t strtab_size_;
};
} // End namespace gold.