@@ -42,20 +42,6 @@ class SharedSymbol;
42
42
class Symbol ;
43
43
class Undefined ;
44
44
45
- // This is a StringRef-like container that doesn't run strlen().
46
- //
47
- // ELF string tables contain a lot of null-terminated strings. Most of them
48
- // are not necessary for the linker because they are names of local symbols,
49
- // and the linker doesn't use local symbol names for name resolution. So, we
50
- // use this class to represents strings read from string tables.
51
- struct StringRefZ {
52
- StringRefZ (const char *s) : data(s), size(-1 ) {}
53
- StringRefZ (StringRef s) : data(s.data()), size(s.size()) {}
54
-
55
- const char *data;
56
- const uint32_t size;
57
- };
58
-
59
45
// Some index properties of a symbol are stored separately in this auxiliary
60
46
// struct to decrease sizeof(SymbolUnion) in the majority of cases.
61
47
struct SymbolAux {
@@ -87,7 +73,8 @@ class Symbol {
87
73
88
74
protected:
89
75
const char *nameData;
90
- mutable uint32_t nameSize;
76
+ // 32-bit size saves space.
77
+ uint32_t nameSize;
91
78
92
79
public:
93
80
// A symAux index used to access GOT/PLT entry indexes. This is allocated in
@@ -179,11 +166,7 @@ class Symbol {
179
166
// all input files have been added.
180
167
bool isUndefWeak () const { return isWeak () && isUndefined (); }
181
168
182
- StringRef getName () const {
183
- if (nameSize == (uint32_t )-1 )
184
- nameSize = strlen (nameData);
185
- return {nameData, nameSize};
186
- }
169
+ StringRef getName () const { return {nameData, nameSize}; }
187
170
188
171
void setName (StringRef s) {
189
172
nameData = s.data ();
@@ -196,10 +179,7 @@ class Symbol {
196
179
//
197
180
// For @@, the name has been truncated by insert(). For @, the name has been
198
181
// truncated by Symbol::parseSymbolVersion().
199
- const char *getVersionSuffix () const {
200
- (void )getName ();
201
- return nameData + nameSize;
202
- }
182
+ const char *getVersionSuffix () const { return nameData + nameSize; }
203
183
204
184
uint32_t getGotIdx () const {
205
185
return auxIdx == uint32_t (-1 ) ? uint32_t (-1 ) : symAux[auxIdx].gotIdx ;
@@ -266,10 +246,11 @@ class Symbol {
266
246
inline size_t getSymbolSize () const ;
267
247
268
248
protected:
269
- Symbol (Kind k, InputFile *file, StringRefZ name, uint8_t binding,
249
+ Symbol (Kind k, InputFile *file, StringRef name, uint8_t binding,
270
250
uint8_t stOther, uint8_t type)
271
- : file(file), nameData(name.data), nameSize(name.size), binding(binding),
272
- type (type), stOther(stOther), symbolKind(k), visibility(stOther & 3 ),
251
+ : file(file), nameData(name.data()), nameSize(name.size()),
252
+ binding (binding), type(type), stOther(stOther), symbolKind(k),
253
+ visibility(stOther & 3 ),
273
254
isUsedInRegularObj(!file || file->kind () == InputFile::ObjKind),
274
255
exportDynamic(isExportDynamic(k, visibility)), inDynamicList(false ),
275
256
canInline(false ), referenced(false ), traced(false ),
@@ -348,7 +329,7 @@ class Symbol {
348
329
// Represents a symbol that is defined in the current output file.
349
330
class Defined : public Symbol {
350
331
public:
351
- Defined (InputFile *file, StringRefZ name, uint8_t binding, uint8_t stOther,
332
+ Defined (InputFile *file, StringRef name, uint8_t binding, uint8_t stOther,
352
333
uint8_t type, uint64_t value, uint64_t size, SectionBase *section)
353
334
: Symbol(DefinedKind, file, name, binding, stOther, type), value(value),
354
335
size (size), section(section) {}
@@ -383,7 +364,7 @@ class Defined : public Symbol {
383
364
// section. (Therefore, the later passes don't see any CommonSymbols.)
384
365
class CommonSymbol : public Symbol {
385
366
public:
386
- CommonSymbol (InputFile *file, StringRefZ name, uint8_t binding,
367
+ CommonSymbol (InputFile *file, StringRef name, uint8_t binding,
387
368
uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size)
388
369
: Symbol(CommonKind, file, name, binding, stOther, type),
389
370
alignment (alignment), size(size) {}
@@ -396,7 +377,7 @@ class CommonSymbol : public Symbol {
396
377
397
378
class Undefined : public Symbol {
398
379
public:
399
- Undefined (InputFile *file, StringRefZ name, uint8_t binding, uint8_t stOther,
380
+ Undefined (InputFile *file, StringRef name, uint8_t binding, uint8_t stOther,
400
381
uint8_t type, uint32_t discardedSecIdx = 0 )
401
382
: Symbol(UndefinedKind, file, name, binding, stOther, type),
402
383
discardedSecIdx (discardedSecIdx) {}
0 commit comments