* elfxx-mips.c (mips_elf_merge_gots): Always use maxcnt.
[binutils.git] / gold / stringpool.h
blob01c71a135537e7c1e213758e38ae7e96fbb059be
1 // stringpool.h -- a string pool for gold -*- C++ -*-
3 #include <string>
4 #include <list>
6 // Stringpool
7 // Manage a pool of unique strings.
9 #ifndef GOLD_STRINGPOOL_H
10 #define GOLD_STRINGPOOL_H
12 namespace gold
15 class Output_file;
17 class Stringpool
19 public:
20 Stringpool();
22 ~Stringpool();
24 // Add a string to the pool. This returns a canonical permanent
25 // pointer to the string.
26 const char*
27 add(const char*);
29 const char*
30 add(const std::string& s)
31 { return this->add(s.c_str()); }
33 // Add the prefix of a string to the pool.
34 const char*
35 add(const char *, size_t);
37 // If a string is present, return the canonical string. Otherwise,
38 // return NULL.
39 const char*
40 find(const char*) const;
42 // Turn the stringpool into an ELF strtab: determine the offsets of
43 // all the strings.
44 void
45 set_string_offsets();
47 // Get the offset of a string.
48 off_t
49 get_offset(const char*) const;
51 off_t
52 get_offset(const std::string& s) const
53 { return this->get_offset(s.c_str()); }
55 // Get the size of the ELF strtab.
56 off_t
57 get_strtab_size() const
58 { return this->strtab_size_; }
60 // Write the strtab into the output file at the specified offset.
61 void
62 write(Output_file*, off_t offset);
64 private:
65 Stringpool(const Stringpool&);
66 Stringpool& operator=(const Stringpool&);
68 // We store the actual data in a list of these buffers.
69 struct Stringdata
71 // Length of data in buffer.
72 size_t len;
73 // Allocated size of buffer.
74 size_t alc;
75 // Buffer.
76 char data[1];
79 // Copy a string into the buffers, returning a canonical string.
80 const char*
81 add_string(const char*);
83 struct Stringpool_hash
85 size_t
86 operator()(const char*) const;
89 struct Stringpool_eq
91 bool
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,
104 Stringpool_eq,
105 std::allocator<std::pair<const char* const, off_t> >,
106 true> String_set_type;
107 #else
108 typedef Unordered_map<const char*, off_t, Stringpool_hash,
109 Stringpool_eq> String_set_type;
110 #endif
112 // Comparison routine used when sorting into an ELF strtab.
114 struct Stringpool_sort_comparison
116 bool
117 operator()(String_set_type::iterator,
118 String_set_type::iterator) const;
121 String_set_type string_set_;
122 std::list<Stringdata*> strings_;
123 off_t strtab_size_;
126 } // End namespace gold.
128 #endif // !defined(GOLD_STRINGPOOL_H)