diff options
author | Ian Lance Taylor <iant@google.com> | 2006-08-18 22:29:20 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2006-08-18 22:29:20 +0000 |
commit | 14bfc3f55540e60253cc4aae73261325309f750a (patch) | |
tree | cb74fe438b44c7aa6e02f05e14f13ba1ae0b508a /gold/strtab.h | |
parent | 476308bf9bd077b87791da50a13a74b2698c01c7 (diff) | |
download | gdb-14bfc3f55540e60253cc4aae73261325309f750a.zip gdb-14bfc3f55540e60253cc4aae73261325309f750a.tar.gz gdb-14bfc3f55540e60253cc4aae73261325309f750a.tar.bz2 |
Another snapshot of the current state of the sources. Gets to the
point of symbol resolution and can now issue a multiple definition
error. Also added target selection infrastructure.
Diffstat (limited to 'gold/strtab.h')
-rw-r--r-- | gold/strtab.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/gold/strtab.h b/gold/strtab.h new file mode 100644 index 0000000..ab22b8f --- /dev/null +++ b/gold/strtab.h @@ -0,0 +1,73 @@ +// strtab.h -- manage an ELF string table for gold -*- C++ -*- + +#ifndef GOLD_STRTAB_H +#define GOLD_STRTAB_H + +#include <cstring> +#include <string> + +namespace gold +{ + +// This class holds an ELF string table. We keep a reference count +// for each string, which we use to determine which strings are +// actually required at the end. When all operations are done, the +// string table is finalized, which sets the offsets to use for each +// string. + +class Strtab +{ + public: + Strtab(); + + ~Strtab(); + + Strtab_ref* add(const char*); + + Strtab_ref* add(const std::string& s) + { return this->add(s.c_str()); } + + private: + Strtab(const Strtab&); + Strtab& operator=(const Strtab&); + + struct strtab_hash + { + std::size_t + operator()(const char*p); + }; + + struct strtab_eq + { + bool + operator()(const char* p1, const char* p2) + { return strcmp(p1, p2) == 0; } + }; + + Unordered_map<const char*, Strtab_ref*, strtab_hash, strtab_eq, + std::allocator<std::pair<const char* const, Strtab_ref*> >, + true> strings_; +}; + +// Users of Strtab work with pointers to Strtab_ref structures. These +// are allocated via new and should be deleted if the string is no +// longer needed. + +class Strtab_ref +{ + public: + ~Strtab_ref(); + + const char* + str() const; + + private: + Strtab_ref(const Strtab_ref&); + Strtab_ref& operator=(const Strtab_ref&); + + int refs_; +}; + +} // End namespace gold. + +#endif // !defined(GOLD_STRTAB_H) |