blob: 5f5ce88cff144fb533f88aafef804a528ed6f7f4 [file] [log] [blame]
Rafael Espindolabeee25e2015-08-14 14:12:54 +00001//===- Symbols.h ------------------------------------------------*- C++ -*-===//
Michael J. Spencer84487f12015-07-24 21:03:07 +00002//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Rui Ueyama34f29242015-10-13 19:51:57 +00009//
10// All symbols are handled as SymbolBodies regardless of their types.
11// This file defines various types of SymbolBodies.
12//
Rui Ueyama34f29242015-10-13 19:51:57 +000013//===----------------------------------------------------------------------===//
Michael J. Spencer84487f12015-07-24 21:03:07 +000014
15#ifndef LLD_ELF_SYMBOLS_H
16#define LLD_ELF_SYMBOLS_H
17
Rafael Espindola9d06ab62015-09-22 00:01:39 +000018#include "InputSection.h"
Rafael Espindola832b93f2015-08-24 20:06:32 +000019
Michael J. Spencer84487f12015-07-24 21:03:07 +000020#include "lld/Core/LLVM.h"
Michael J. Spencer1b348a62015-09-04 22:28:10 +000021#include "llvm/Object/Archive.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000022#include "llvm/Object/ELF.h"
23
24namespace lld {
Rafael Espindolae0df00b2016-02-28 00:25:54 +000025namespace elf {
Michael J. Spencer84487f12015-07-24 21:03:07 +000026
Michael J. Spencer1b348a62015-09-04 22:28:10 +000027class ArchiveFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000028class InputFile;
29class SymbolBody;
Michael J. Spencercdae0a42015-07-28 22:58:25 +000030template <class ELFT> class ObjectFile;
Michael J. Spencer658dccd2015-09-18 22:13:25 +000031template <class ELFT> class OutputSection;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000032template <class ELFT> class OutputSectionBase;
Rui Ueyama35da9b62015-10-11 20:59:12 +000033template <class ELFT> class SharedFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000034
Rui Ueyamaa4a628f2016-01-13 18:55:39 +000035// Returns a demangled C++ symbol name. If Name is not a mangled
36// name or the system does not provide __cxa_demangle function,
37// it returns the unmodified string.
38std::string demangle(StringRef Name);
39
Michael J. Spencer84487f12015-07-24 21:03:07 +000040// A real symbol object, SymbolBody, is usually accessed indirectly
41// through a Symbol. There's always one Symbol for each symbol name.
42// The resolver updates SymbolBody pointers as it resolves symbols.
43struct Symbol {
Michael J. Spencer84487f12015-07-24 21:03:07 +000044 SymbolBody *Body;
45};
46
47// The base class for real symbol classes.
48class SymbolBody {
49public:
50 enum Kind {
Rafael Espindola84aff152015-09-25 21:20:23 +000051 DefinedFirst,
52 DefinedRegularKind = DefinedFirst,
Rafael Espindola84aff152015-09-25 21:20:23 +000053 SharedKind,
Rafael Espindola1f5b70f2016-03-11 14:21:37 +000054 DefinedElfLast = SharedKind,
Rafael Espindola11191912015-12-24 16:23:37 +000055 DefinedCommonKind,
Rafael Espindola9f77ef02016-02-12 20:54:57 +000056 DefinedBitcodeKind,
Rafael Espindola4d4b06a2015-12-24 00:47:42 +000057 DefinedSyntheticKind,
58 DefinedLast = DefinedSyntheticKind,
Rafael Espindola5d7593b2015-12-22 23:00:50 +000059 UndefinedElfKind,
Rafael Espindola84aff152015-09-25 21:20:23 +000060 UndefinedKind,
61 LazyKind
Michael J. Spencer84487f12015-07-24 21:03:07 +000062 };
63
Michael J. Spencercdae0a42015-07-28 22:58:25 +000064 Kind kind() const { return static_cast<Kind>(SymbolKind); }
Michael J. Spencer84487f12015-07-24 21:03:07 +000065
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000066 bool isWeak() const { return IsWeak; }
Rafael Espindola5d7593b2015-12-22 23:00:50 +000067 bool isUndefined() const {
68 return SymbolKind == UndefinedKind || SymbolKind == UndefinedElfKind;
69 }
Michael J. Spencer1b348a62015-09-04 22:28:10 +000070 bool isDefined() const { return SymbolKind <= DefinedLast; }
Rafael Espindola30e17972015-08-30 23:17:30 +000071 bool isCommon() const { return SymbolKind == DefinedCommonKind; }
Michael J. Spencer1b348a62015-09-04 22:28:10 +000072 bool isLazy() const { return SymbolKind == LazyKind; }
Rafael Espindola18173d42015-09-08 15:50:05 +000073 bool isShared() const { return SymbolKind == SharedKind; }
Rafael Espindola1f5b70f2016-03-11 14:21:37 +000074 bool isLocal() const { return IsLocal; }
Rafael Espindola18173d42015-09-08 15:50:05 +000075 bool isUsedInRegularObj() const { return IsUsedInRegularObj; }
Rui Ueyamac4466602016-03-13 19:48:18 +000076 bool isPreemptible() const;
Rui Ueyama7ede5432016-03-13 04:40:14 +000077
Michael J. Spencer84487f12015-07-24 21:03:07 +000078 // Returns the symbol name.
Michael J. Spencercdae0a42015-07-28 22:58:25 +000079 StringRef getName() const { return Name; }
Michael J. Spencer84487f12015-07-24 21:03:07 +000080
Rui Ueyama8f2c4da2015-10-21 18:13:47 +000081 uint8_t getVisibility() const { return Visibility; }
Rafael Espindola78471f02015-09-01 23:12:52 +000082
Rui Ueyama572a6f72016-01-29 01:49:33 +000083 unsigned DynsymIndex = 0;
George Rimar90cd0a82015-12-01 19:20:26 +000084 uint32_t GlobalDynIndex = -1;
Rui Ueyama49c68a72015-10-09 00:42:06 +000085 uint32_t GotIndex = -1;
George Rimar648a2c32015-10-20 08:54:27 +000086 uint32_t GotPltIndex = -1;
Rui Ueyama49c68a72015-10-09 00:42:06 +000087 uint32_t PltIndex = -1;
Simon Atanasyan13f6da12016-03-31 21:26:23 +000088 uint32_t ThunkIndex = -1;
George Rimar90cd0a82015-12-01 19:20:26 +000089 bool hasGlobalDynIndex() { return GlobalDynIndex != uint32_t(-1); }
Rafael Espindola5c2310c2015-09-18 14:40:19 +000090 bool isInGot() const { return GotIndex != -1U; }
Rafael Espindolaeb792732015-09-21 15:11:29 +000091 bool isInPlt() const { return PltIndex != -1U; }
Simon Atanasyan13f6da12016-03-31 21:26:23 +000092 bool hasThunk() const { return ThunkIndex != -1U; }
Rafael Espindolaeb792732015-09-21 15:11:29 +000093
Davide Italiano04d6aa22016-03-29 00:15:52 +000094 void setUsedInRegularObj() { IsUsedInRegularObj = true; }
95
Rui Ueyama71a86862016-03-14 19:37:58 +000096 template <class ELFT>
Rui Ueyama9328b2c2016-03-14 23:16:09 +000097 typename ELFT::uint getVA(typename ELFT::uint Addend = 0) const;
98
99 template <class ELFT> typename ELFT::uint getGotVA() const;
100 template <class ELFT> typename ELFT::uint getGotPltVA() const;
101 template <class ELFT> typename ELFT::uint getPltVA() const;
Simon Atanasyan13f6da12016-03-31 21:26:23 +0000102 template <class ELFT> typename ELFT::uint getThunkVA() const;
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000103 template <class ELFT> typename ELFT::uint getSize() const;
Rui Ueyamab5a69702016-02-01 21:00:35 +0000104
Michael J. Spencer84487f12015-07-24 21:03:07 +0000105 // A SymbolBody has a backreference to a Symbol. Originally they are
106 // doubly-linked. A backreference will never change. But the pointer
107 // in the Symbol may be mutated by the resolver. If you have a
108 // pointer P to a SymbolBody and are not sure whether the resolver
109 // has chosen the object among other objects having the same name,
110 // you can access P->Backref->Body to get the resolver's result.
111 void setBackref(Symbol *P) { Backref = P; }
Rafael Espindola67d72c02016-03-11 12:06:30 +0000112 SymbolBody &repl() { return Backref ? *Backref->Body : *this; }
Sean Silvae32368f2016-03-22 21:04:03 +0000113 Symbol *getSymbol() const { return Backref; }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000114
115 // Decides which symbol should "win" in the symbol table, this or
116 // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if
117 // they are duplicate (conflicting) symbols.
Rafael Espindoladaa92a62015-08-31 01:16:19 +0000118 template <class ELFT> int compare(SymbolBody *Other);
Michael J. Spencer84487f12015-07-24 21:03:07 +0000119
120protected:
Rafael Espindola1f5b70f2016-03-11 14:21:37 +0000121 SymbolBody(Kind K, StringRef Name, bool IsWeak, bool IsLocal,
122 uint8_t Visibility, uint8_t Type)
123 : SymbolKind(K), IsWeak(IsWeak), IsLocal(IsLocal), Visibility(Visibility),
George Rimar2f0fab52016-03-06 06:26:18 +0000124 MustBeInDynSym(false), NeedsCopyOrPltAddr(false), Name(Name) {
125 IsFunc = Type == llvm::ELF::STT_FUNC;
126 IsTls = Type == llvm::ELF::STT_TLS;
Rafael Espindola54322872016-03-24 12:55:27 +0000127 IsGnuIFunc = Type == llvm::ELF::STT_GNU_IFUNC;
Davide Italiano828ac5412016-03-28 15:44:21 +0000128 IsUsedInRegularObj =
129 K != SharedKind && K != LazyKind && K != DefinedBitcodeKind;
Rafael Espindola18173d42015-09-08 15:50:05 +0000130 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000131
Michael J. Spencercdae0a42015-07-28 22:58:25 +0000132 const unsigned SymbolKind : 8;
Rafael Espindola8614c562015-10-06 14:33:58 +0000133 unsigned IsWeak : 1;
Rafael Espindola1f5b70f2016-03-11 14:21:37 +0000134 unsigned IsLocal : 1;
Rui Ueyama8f2c4da2015-10-21 18:13:47 +0000135 unsigned Visibility : 2;
Rui Ueyama7d332f52015-12-25 06:55:39 +0000136
137 // True if the symbol was used for linking and thus need to be
138 // added to the output file's symbol table. It is usually true,
139 // but if it is a shared symbol that were not referenced by anyone,
140 // it can be false.
Rafael Espindola18173d42015-09-08 15:50:05 +0000141 unsigned IsUsedInRegularObj : 1;
Rui Ueyama7d332f52015-12-25 06:55:39 +0000142
Rafael Espindolaabebed92016-02-05 15:27:15 +0000143public:
Rui Ueyama7d332f52015-12-25 06:55:39 +0000144 // If true, the symbol is added to .dynsym symbol table.
Rafael Espindolaabebed92016-02-05 15:27:15 +0000145 unsigned MustBeInDynSym : 1;
Rui Ueyama7d332f52015-12-25 06:55:39 +0000146
Rafael Espindolaa0a65f92016-02-09 15:11:01 +0000147 // True if the linker has to generate a copy relocation for this shared
148 // symbol or if the symbol should point to its plt entry.
149 unsigned NeedsCopyOrPltAddr : 1;
150
George Rimar2f0fab52016-03-06 06:26:18 +0000151 unsigned IsTls : 1;
152 unsigned IsFunc : 1;
Rafael Espindola54322872016-03-24 12:55:27 +0000153 unsigned IsGnuIFunc : 1;
Rafael Espindolaa0a65f92016-02-09 15:11:01 +0000154
George Rimar2f0fab52016-03-06 06:26:18 +0000155protected:
Michael J. Spencercdae0a42015-07-28 22:58:25 +0000156 StringRef Name;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000157 Symbol *Backref = nullptr;
158};
159
Rafael Espindola02ce26a2015-12-24 14:22:24 +0000160// The base class for any defined symbols.
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000161class Defined : public SymbolBody {
162public:
Rafael Espindola1f5b70f2016-03-11 14:21:37 +0000163 Defined(Kind K, StringRef Name, bool IsWeak, bool IsLocal, uint8_t Visibility,
Davide Italiano255730c2016-03-04 01:55:28 +0000164 uint8_t Type);
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000165 static bool classof(const SymbolBody *S) { return S->isDefined(); }
166};
167
168// Any defined symbol from an ELF file.
169template <class ELFT> class DefinedElf : public Defined {
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000170protected:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000171 typedef typename ELFT::Sym Elf_Sym;
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000172
173public:
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000174 DefinedElf(Kind K, StringRef N, const Elf_Sym &Sym)
175 : Defined(K, N, Sym.getBinding() == llvm::ELF::STB_WEAK,
Rafael Espindola1f5b70f2016-03-11 14:21:37 +0000176 Sym.getBinding() == llvm::ELF::STB_LOCAL, Sym.getVisibility(),
177 Sym.getType()),
Rafael Espindola5d7593b2015-12-22 23:00:50 +0000178 Sym(Sym) {}
Rafael Espindola3a63f3f2015-08-28 20:19:34 +0000179
Rafael Espindola5d7593b2015-12-22 23:00:50 +0000180 const Elf_Sym &Sym;
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000181 static bool classof(const SymbolBody *S) {
182 return S->kind() <= DefinedElfLast;
183 }
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000184};
185
Rafael Espindola9f77ef02016-02-12 20:54:57 +0000186class DefinedBitcode : public Defined {
187public:
Rafael Espindola4f29c1a2016-03-07 17:14:36 +0000188 DefinedBitcode(StringRef Name, bool IsWeak, uint8_t Visibility);
Rafael Espindola9f77ef02016-02-12 20:54:57 +0000189 static bool classof(const SymbolBody *S);
190};
191
Rafael Espindola11191912015-12-24 16:23:37 +0000192class DefinedCommon : public Defined {
Rafael Espindola51d46902015-08-28 21:26:51 +0000193public:
Rafael Espindola11191912015-12-24 16:23:37 +0000194 DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, bool IsWeak,
195 uint8_t Visibility);
Rafael Espindola51d46902015-08-28 21:26:51 +0000196
197 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000198 return S->kind() == SymbolBody::DefinedCommonKind;
Rafael Espindola51d46902015-08-28 21:26:51 +0000199 }
Rafael Espindolace8c9c02015-08-31 22:55:21 +0000200
201 // The output offset of this common symbol in the output bss. Computed by the
202 // writer.
Rui Ueyamae57c4872016-01-05 16:35:43 +0000203 uint64_t OffsetInBss;
Rafael Espindolaf31f9612015-09-01 01:19:12 +0000204
205 // The maximum alignment we have seen for this symbol.
Rui Ueyama17d69832016-03-10 18:58:53 +0000206 uint64_t Alignment;
Rafael Espindola11191912015-12-24 16:23:37 +0000207
208 uint64_t Size;
Rafael Espindola51d46902015-08-28 21:26:51 +0000209};
210
Michael J. Spencer84487f12015-07-24 21:03:07 +0000211// Regular defined symbols read from object file symbol tables.
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000212template <class ELFT> class DefinedRegular : public DefinedElf<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000213 typedef typename ELFT::Sym Elf_Sym;
Rafael Espindolac44d17a2015-08-14 15:10:49 +0000214
Michael J. Spencer84487f12015-07-24 21:03:07 +0000215public:
Rafael Espindolac159c962015-10-19 21:00:02 +0000216 DefinedRegular(StringRef N, const Elf_Sym &Sym,
Rafael Espindola02ce26a2015-12-24 14:22:24 +0000217 InputSectionBase<ELFT> *Section)
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000218 : DefinedElf<ELFT>(SymbolBody::DefinedRegularKind, N, Sym),
Rui Ueyama0b289522016-02-25 18:43:51 +0000219 Section(Section ? Section->Repl : NullInputSection) {}
Michael J. Spencer84487f12015-07-24 21:03:07 +0000220
221 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000222 return S->kind() == SymbolBody::DefinedRegularKind;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000223 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000224
Rui Ueyama0b289522016-02-25 18:43:51 +0000225 // The input section this symbol belongs to. Notice that this is
226 // a reference to a pointer. We are using two levels of indirections
227 // because of ICF. If ICF decides two sections need to be merged, it
228 // manipulates this Section pointers so that they point to the same
229 // section. This is a bit tricky, so be careful to not be confused.
230 // If this is null, the symbol is an absolute symbol.
231 InputSectionBase<ELFT> *&Section;
232
233private:
234 static InputSectionBase<ELFT> *NullInputSection;
Rafael Espindolab13df652015-08-11 17:33:02 +0000235};
236
Rui Ueyama0b289522016-02-25 18:43:51 +0000237template <class ELFT>
238InputSectionBase<ELFT> *DefinedRegular<ELFT>::NullInputSection;
239
Rui Ueyama8b75b9a2015-12-17 00:48:16 +0000240// DefinedSynthetic is a class to represent linker-generated ELF symbols.
241// The difference from the regular symbol is that DefinedSynthetic symbols
242// don't belong to any input files or sections. Thus, its constructor
243// takes an output section to calculate output VA, etc.
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000244template <class ELFT> class DefinedSynthetic : public Defined {
Rafael Espindola0e604f92015-09-25 18:56:53 +0000245public:
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000246 typedef typename ELFT::Sym Elf_Sym;
247 typedef typename ELFT::uint uintX_t;
George Rimaraa4dc202016-03-01 16:23:13 +0000248 DefinedSynthetic(StringRef N, uintX_t Value, OutputSectionBase<ELFT> &Section,
249 uint8_t Visibility);
Rafael Espindola0e604f92015-09-25 18:56:53 +0000250
251 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000252 return S->kind() == SymbolBody::DefinedSyntheticKind;
Rafael Espindola0e604f92015-09-25 18:56:53 +0000253 }
254
Simon Atanasyan13f6da12016-03-31 21:26:23 +0000255 // Special value designates that the symbol 'points'
256 // to the end of the section.
257 static const uintX_t SectionEnd = uintX_t(-1);
258
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000259 uintX_t Value;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000260 const OutputSectionBase<ELFT> &Section;
Rafael Espindola0e604f92015-09-25 18:56:53 +0000261};
262
Rafael Espindolaf7d45f02015-08-31 01:46:20 +0000263// Undefined symbol.
Rafael Espindola5d7593b2015-12-22 23:00:50 +0000264class Undefined : public SymbolBody {
265 typedef SymbolBody::Kind Kind;
266 bool CanKeepUndefined;
267
268protected:
Davide Italiano255730c2016-03-04 01:55:28 +0000269 Undefined(Kind K, StringRef N, bool IsWeak, uint8_t Visibility, uint8_t Type);
Rafael Espindola5d7593b2015-12-22 23:00:50 +0000270
271public:
272 Undefined(StringRef N, bool IsWeak, uint8_t Visibility,
273 bool CanKeepUndefined);
274
275 static bool classof(const SymbolBody *S) { return S->isUndefined(); }
276
277 bool canKeepUndefined() const { return CanKeepUndefined; }
278};
279
280template <class ELFT> class UndefinedElf : public Undefined {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000281 typedef typename ELFT::Sym Elf_Sym;
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000282
Rafael Espindola76e24ea2015-08-11 17:57:05 +0000283public:
Rafael Espindola5d7593b2015-12-22 23:00:50 +0000284 UndefinedElf(StringRef N, const Elf_Sym &Sym);
285 const Elf_Sym &Sym;
Rafael Espindola5f2c46d2015-12-23 01:06:39 +0000286
287 static bool classof(const SymbolBody *S) {
288 return S->kind() == SymbolBody::UndefinedElfKind;
289 }
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000290};
291
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000292template <class ELFT> class SharedSymbol : public DefinedElf<ELFT> {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000293 typedef typename ELFT::Sym Elf_Sym;
294 typedef typename ELFT::uint uintX_t;
Rafael Espindola18173d42015-09-08 15:50:05 +0000295
296public:
297 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000298 return S->kind() == SymbolBody::SharedKind;
Rafael Espindola18173d42015-09-08 15:50:05 +0000299 }
300
Rui Ueyama35da9b62015-10-11 20:59:12 +0000301 SharedSymbol(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym)
Rafael Espindola4d4b06a2015-12-24 00:47:42 +0000302 : DefinedElf<ELFT>(SymbolBody::SharedKind, Name, Sym), File(F) {}
Rui Ueyama35da9b62015-10-11 20:59:12 +0000303
304 SharedFile<ELFT> *File;
George Rimarbc590fe2015-10-28 16:48:58 +0000305
Rafael Espindolaa0a65f92016-02-09 15:11:01 +0000306 // OffsetInBss is significant only when needsCopy() is true.
Rui Ueyamae57c4872016-01-05 16:35:43 +0000307 uintX_t OffsetInBss = 0;
Rafael Espindolaa0a65f92016-02-09 15:11:01 +0000308
George Rimar2f0fab52016-03-06 06:26:18 +0000309 bool needsCopy() const { return this->NeedsCopyOrPltAddr && !this->IsFunc; }
Rafael Espindola18173d42015-09-08 15:50:05 +0000310};
311
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000312// This class represents a symbol defined in an archive file. It is
313// created from an archive file header, and it knows how to load an
314// object file from an archive to replace itself with a defined
315// symbol. If the resolver finds both Undefined and Lazy for
316// the same name, it will ask the Lazy to load a file.
317class Lazy : public SymbolBody {
318public:
319 Lazy(ArchiveFile *F, const llvm::object::Archive::Symbol S)
Rafael Espindola1f5b70f2016-03-11 14:21:37 +0000320 : SymbolBody(LazyKind, S.getName(), false, false, llvm::ELF::STV_DEFAULT,
Davide Italiano255730c2016-03-04 01:55:28 +0000321 /* Type */ 0),
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000322 File(F), Sym(S) {}
323
324 static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; }
325
326 // Returns an object file for this symbol, or a nullptr if the file
327 // was already returned.
328 std::unique_ptr<InputFile> getMember();
329
Rafael Espindola8614c562015-10-06 14:33:58 +0000330 void setWeak() { IsWeak = true; }
Rafael Espindola8614c562015-10-06 14:33:58 +0000331
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000332private:
333 ArchiveFile *File;
334 const llvm::object::Archive::Symbol Sym;
335};
336
Rui Ueyamaa246e0942015-12-25 06:12:18 +0000337// Some linker-generated symbols need to be created as
338// DefinedRegular symbols, so they need Elf_Sym symbols.
339// Here we allocate such Elf_Sym symbols statically.
340template <class ELFT> struct ElfSym {
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000341 typedef typename ELFT::Sym Elf_Sym;
Rui Ueyamaa246e0942015-12-25 06:12:18 +0000342
Rafael Espindola65e80b92016-01-19 21:19:52 +0000343 // Used to represent an undefined symbol which we don't want to add to the
344 // output file's symbol table. It has weak binding and can be substituted.
345 static Elf_Sym Ignored;
Rui Ueyamaa246e0942015-12-25 06:12:18 +0000346
George Rimar9e859392016-02-26 14:36:36 +0000347 // The content for _etext and etext symbols.
348 static Elf_Sym Etext;
349
350 // The content for _edata and edata symbols.
351 static Elf_Sym Edata;
352
Rui Ueyamaa246e0942015-12-25 06:12:18 +0000353 // The content for _end and end symbols.
354 static Elf_Sym End;
355
356 // The content for _gp symbol for MIPS target.
357 static Elf_Sym MipsGp;
358
359 // __rel_iplt_start/__rel_iplt_end for signaling
360 // where R_[*]_IRELATIVE relocations do live.
361 static Elf_Sym RelaIpltStart;
362 static Elf_Sym RelaIpltEnd;
363};
364
Rui Ueyama9328b2c2016-03-14 23:16:09 +0000365template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::Ignored;
366template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::Etext;
367template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::Edata;
368template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::End;
369template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::MipsGp;
370template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::RelaIpltStart;
371template <class ELFT> typename ELFT::Sym ElfSym<ELFT>::RelaIpltEnd;
Rui Ueyamaa246e0942015-12-25 06:12:18 +0000372
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000373} // namespace elf
Michael J. Spencer84487f12015-07-24 21:03:07 +0000374} // namespace lld
375
376#endif