* elf64-ppc.c (enum _ppc64_sec_type): New.
[deliverable/binutils-gdb.git] / gold / stringpool.h
CommitLineData
14bfc3f5
ILT
1// stringpool.h -- a string pool for gold -*- C++ -*-
2
3#include <string>
4#include <list>
5
6// Stringpool
7// Manage a pool of unique strings.
8
9#ifndef GOLD_STRINGPOOL_H
10#define GOLD_STRINGPOOL_H
11
12namespace gold
13{
14
61ba1cf9
ILT
15class Output_file;
16
14bfc3f5
ILT
17class Stringpool
18{
19 public:
20 Stringpool();
21
22 ~Stringpool();
23
24 // Add a string to the pool. This returns a canonical permanent
25 // pointer to the string.
61ba1cf9
ILT
26 const char*
27 add(const char*);
14bfc3f5 28
61ba1cf9
ILT
29 const char*
30 add(const std::string& s)
14bfc3f5
ILT
31 { return this->add(s.c_str()); }
32
33 // Add the prefix of a string to the pool.
61ba1cf9
ILT
34 const char*
35 add(const char *, size_t);
36
37 // If a string is present, return the canonical string. Otherwise,
38 // return NULL.
39 const char*
40 find(const char*) const;
41
42 // Turn the stringpool into an ELF strtab: determine the offsets of
43 // all the strings.
44 void
45 set_string_offsets();
46
47 // Get the offset of a string.
48 off_t
49 get_offset(const char*) const;
50
51 off_t
52 get_offset(const std::string& s) const
53 { return this->get_offset(s.c_str()); }
54
55 // Get the size of the ELF strtab.
56 off_t
57 get_strtab_size() const
58 { return this->strtab_size_; }
59
60 // Write the strtab into the output file at the specified offset.
61 void
62 write(Output_file*, off_t offset);
14bfc3f5
ILT
63
64 private:
65 Stringpool(const Stringpool&);
66 Stringpool& operator=(const Stringpool&);
67
61ba1cf9
ILT
68 // We store the actual data in a list of these buffers.
69 struct Stringdata
14bfc3f5
ILT
70 {
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];
77 };
78
61ba1cf9
ILT
79 // Copy a string into the buffers, returning a canonical string.
80 const char*
81 add_string(const char*);
14bfc3f5
ILT
82
83 struct Stringpool_hash
84 {
85 size_t
86 operator()(const char*) const;
87 };
88
89 struct Stringpool_eq
90 {
91 bool
92 operator()(const char* p1, const char* p2) const
93 { return strcmp(p1, p2) == 0; }
94 };
95
61ba1cf9
ILT
96 // Return whether s1 is a suffix of s2.
97 static bool is_suffix(const char* s1, const char* s2);
98
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.
101
274e99f9 102#ifdef HAVE_TR1_UNORDERED_SET
61ba1cf9
ILT
103 typedef Unordered_map<const char*, off_t, Stringpool_hash,
104 Stringpool_eq,
105 std::allocator<std::pair<const char* const, off_t> >,
14bfc3f5 106 true> String_set_type;
274e99f9 107#else
61ba1cf9
ILT
108 typedef Unordered_map<const char*, off_t, Stringpool_hash,
109 Stringpool_eq> String_set_type;
274e99f9
ILT
110#endif
111
61ba1cf9
ILT
112 // Comparison routine used when sorting into an ELF strtab.
113
114 struct Stringpool_sort_comparison
115 {
116 bool
117 operator()(String_set_type::iterator,
118 String_set_type::iterator) const;
119 };
120
14bfc3f5 121 String_set_type string_set_;
61ba1cf9
ILT
122 std::list<Stringdata*> strings_;
123 off_t strtab_size_;
14bfc3f5
ILT
124};
125
126} // End namespace gold.
127
128#endif // !defined(GOLD_STRINGPOOL_H)
This page took 0.03958 seconds and 4 git commands to generate.