blob: b388bcf246abb7d59578c85405a45e00645a51c5 [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//
13// File-scope symbols in ELF objects are the only exception of SymbolBody
14// instantiation. We will never create SymbolBodies for them for performance
15// reason. They are often represented as nullptrs. This is fine for symbol
16// resolution because the symbol table naturally cares only about
17// externally-visible symbols. For relocations, you have to deal with both
18// local and non-local functions, and we have two different functions
19// where we need them.
20//
21//===----------------------------------------------------------------------===//
Michael J. Spencer84487f12015-07-24 21:03:07 +000022
23#ifndef LLD_ELF_SYMBOLS_H
24#define LLD_ELF_SYMBOLS_H
25
Rafael Espindola9d06ab62015-09-22 00:01:39 +000026#include "InputSection.h"
Rafael Espindola832b93f2015-08-24 20:06:32 +000027
Michael J. Spencer84487f12015-07-24 21:03:07 +000028#include "lld/Core/LLVM.h"
Michael J. Spencer1b348a62015-09-04 22:28:10 +000029#include "llvm/Object/Archive.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000030#include "llvm/Object/ELF.h"
31
32namespace lld {
33namespace elf2 {
34
Michael J. Spencer1b348a62015-09-04 22:28:10 +000035class ArchiveFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000036class InputFile;
37class SymbolBody;
Michael J. Spencercdae0a42015-07-28 22:58:25 +000038template <class ELFT> class ObjectFile;
Michael J. Spencer658dccd2015-09-18 22:13:25 +000039template <class ELFT> class OutputSection;
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +000040template <class ELFT> class OutputSectionBase;
Rui Ueyama35da9b62015-10-11 20:59:12 +000041template <class ELFT> class SharedFile;
Michael J. Spencer84487f12015-07-24 21:03:07 +000042
Rui Ueyama9ea49c72015-10-07 23:46:11 +000043// Initializes global objects defined in this file.
44// Called at the beginning of main().
45void initSymbols();
46
Michael J. Spencer84487f12015-07-24 21:03:07 +000047// A real symbol object, SymbolBody, is usually accessed indirectly
48// through a Symbol. There's always one Symbol for each symbol name.
49// The resolver updates SymbolBody pointers as it resolves symbols.
50struct Symbol {
Michael J. Spencer84487f12015-07-24 21:03:07 +000051 SymbolBody *Body;
52};
53
54// The base class for real symbol classes.
55class SymbolBody {
56public:
57 enum Kind {
Rafael Espindola84aff152015-09-25 21:20:23 +000058 DefinedFirst,
59 DefinedRegularKind = DefinedFirst,
60 DefinedAbsoluteKind,
61 DefinedCommonKind,
62 DefinedSyntheticKind,
63 SharedKind,
64 DefinedLast = SharedKind,
65 UndefinedKind,
66 LazyKind
Michael J. Spencer84487f12015-07-24 21:03:07 +000067 };
68
Michael J. Spencercdae0a42015-07-28 22:58:25 +000069 Kind kind() const { return static_cast<Kind>(SymbolKind); }
Michael J. Spencer84487f12015-07-24 21:03:07 +000070
Rafael Espindola3a63f3f2015-08-28 20:19:34 +000071 bool isWeak() const { return IsWeak; }
Rafael Espindolaf7d45f02015-08-31 01:46:20 +000072 bool isUndefined() const { return SymbolKind == UndefinedKind; }
Michael J. Spencer1b348a62015-09-04 22:28:10 +000073 bool isDefined() const { return SymbolKind <= DefinedLast; }
Rafael Espindola30e17972015-08-30 23:17:30 +000074 bool isCommon() const { return SymbolKind == DefinedCommonKind; }
Michael J. Spencer1b348a62015-09-04 22:28:10 +000075 bool isLazy() const { return SymbolKind == LazyKind; }
Rafael Espindola18173d42015-09-08 15:50:05 +000076 bool isShared() const { return SymbolKind == SharedKind; }
77 bool isUsedInRegularObj() const { return IsUsedInRegularObj; }
Rafael Espindola05a3dd22015-09-22 23:38:23 +000078 bool isUsedInDynamicReloc() const { return IsUsedInDynamicReloc; }
79 void setUsedInDynamicReloc() { IsUsedInDynamicReloc = true; }
Rui Ueyama61805ec2015-12-17 00:12:03 +000080 bool isTls() const { return IsTls; }
Rafael Espindola1bd885a2015-08-14 16:46:28 +000081
Michael J. Spencer84487f12015-07-24 21:03:07 +000082 // Returns the symbol name.
Michael J. Spencercdae0a42015-07-28 22:58:25 +000083 StringRef getName() const { return Name; }
Michael J. Spencer84487f12015-07-24 21:03:07 +000084
Rui Ueyama8f2c4da2015-10-21 18:13:47 +000085 uint8_t getVisibility() const { return Visibility; }
Rafael Espindola78471f02015-09-01 23:12:52 +000086
Rui Ueyamaa02bba62015-12-17 00:12:04 +000087 unsigned DynamicSymbolTableIndex = 0;
George Rimar90cd0a82015-12-01 19:20:26 +000088 uint32_t GlobalDynIndex = -1;
Rui Ueyama49c68a72015-10-09 00:42:06 +000089 uint32_t GotIndex = -1;
George Rimar648a2c32015-10-20 08:54:27 +000090 uint32_t GotPltIndex = -1;
Rui Ueyama49c68a72015-10-09 00:42:06 +000091 uint32_t PltIndex = -1;
George Rimar90cd0a82015-12-01 19:20:26 +000092 bool hasGlobalDynIndex() { return GlobalDynIndex != uint32_t(-1); }
Rafael Espindola5c2310c2015-09-18 14:40:19 +000093 bool isInGot() const { return GotIndex != -1U; }
George Rimar648a2c32015-10-20 08:54:27 +000094 bool isInGotPlt() const { return GotPltIndex != -1U; }
Rafael Espindolaeb792732015-09-21 15:11:29 +000095 bool isInPlt() const { return PltIndex != -1U; }
Rafael Espindolaeb792732015-09-21 15:11:29 +000096
Michael J. Spencer84487f12015-07-24 21:03:07 +000097 // A SymbolBody has a backreference to a Symbol. Originally they are
98 // doubly-linked. A backreference will never change. But the pointer
99 // in the Symbol may be mutated by the resolver. If you have a
100 // pointer P to a SymbolBody and are not sure whether the resolver
101 // has chosen the object among other objects having the same name,
102 // you can access P->Backref->Body to get the resolver's result.
103 void setBackref(Symbol *P) { Backref = P; }
Rui Ueyamae66e0012015-10-07 23:20:23 +0000104 SymbolBody *repl() { return Backref ? Backref->Body : this; }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000105
106 // Decides which symbol should "win" in the symbol table, this or
107 // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if
108 // they are duplicate (conflicting) symbols.
Rafael Espindoladaa92a62015-08-31 01:16:19 +0000109 template <class ELFT> int compare(SymbolBody *Other);
Michael J. Spencer84487f12015-07-24 21:03:07 +0000110
111protected:
Igor Kudrin65bddea2015-10-09 09:58:39 +0000112 SymbolBody(Kind K, StringRef Name, bool IsWeak, uint8_t Visibility,
Rui Ueyama61805ec2015-12-17 00:12:03 +0000113 bool IsTls)
114 : SymbolKind(K), IsWeak(IsWeak), Visibility(Visibility), IsTls(IsTls),
Rui Ueyama8f2c4da2015-10-21 18:13:47 +0000115 Name(Name) {
Rafael Espindola18173d42015-09-08 15:50:05 +0000116 IsUsedInRegularObj = K != SharedKind && K != LazyKind;
Rafael Espindola05a3dd22015-09-22 23:38:23 +0000117 IsUsedInDynamicReloc = 0;
Rafael Espindola18173d42015-09-08 15:50:05 +0000118 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000119
Michael J. Spencercdae0a42015-07-28 22:58:25 +0000120 const unsigned SymbolKind : 8;
Rafael Espindola8614c562015-10-06 14:33:58 +0000121 unsigned IsWeak : 1;
Rui Ueyama8f2c4da2015-10-21 18:13:47 +0000122 unsigned Visibility : 2;
Rafael Espindola18173d42015-09-08 15:50:05 +0000123 unsigned IsUsedInRegularObj : 1;
Rafael Espindola05a3dd22015-09-22 23:38:23 +0000124 unsigned IsUsedInDynamicReloc : 1;
Rui Ueyama61805ec2015-12-17 00:12:03 +0000125 unsigned IsTls : 1;
Michael J. Spencercdae0a42015-07-28 22:58:25 +0000126 StringRef Name;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000127 Symbol *Backref = nullptr;
128};
129
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000130// This is for symbols created from elf files and not from the command line.
131// Since they come from object files, they have a Elf_Sym.
132//
133// FIXME: Another alternative is to give every symbol an Elf_Sym. To do that
134// we have to delay creating the symbol table until the output format is
135// known and some of its methods will be templated. We should experiment with
136// that once we have a bit more code.
137template <class ELFT> class ELFSymbolBody : public SymbolBody {
138protected:
Rafael Espindolac44d17a2015-08-14 15:10:49 +0000139 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000140 ELFSymbolBody(Kind K, StringRef Name, const Elf_Sym &Sym)
Rafael Espindola78471f02015-09-01 23:12:52 +0000141 : SymbolBody(K, Name, Sym.getBinding() == llvm::ELF::STB_WEAK,
Igor Kudrin65bddea2015-10-09 09:58:39 +0000142 Sym.getVisibility(), Sym.getType() == llvm::ELF::STT_TLS),
Rafael Espindola78471f02015-09-01 23:12:52 +0000143 Sym(Sym) {}
Rafael Espindolac44d17a2015-08-14 15:10:49 +0000144
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000145public:
146 const Elf_Sym &Sym;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000147
148 static bool classof(const SymbolBody *S) {
149 Kind K = S->kind();
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000150 return K >= DefinedFirst && K <= UndefinedKind;
151 }
152};
153
Rui Ueyama34f29242015-10-13 19:51:57 +0000154// The base class for any defined symbols, including absolute symbols, etc.
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000155template <class ELFT> class Defined : public ELFSymbolBody<ELFT> {
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000156protected:
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000157 typedef typename SymbolBody::Kind Kind;
Rafael Espindola88dddf92015-12-21 21:07:31 +0000158 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000159
160public:
Rui Ueyama294b1362015-09-30 02:06:17 +0000161 Defined(Kind K, StringRef N, const Elf_Sym &Sym)
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000162 : ELFSymbolBody<ELFT>(K, N, Sym) {}
Rafael Espindola3a63f3f2015-08-28 20:19:34 +0000163
164 static bool classof(const SymbolBody *S) { return S->isDefined(); }
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000165};
166
167template <class ELFT> class DefinedAbsolute : public Defined<ELFT> {
Rafael Espindola88dddf92015-12-21 21:07:31 +0000168 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola0e0c1902015-08-27 12:40:06 +0000169
170public:
Rafael Espindolad27adc42e2015-09-24 13:34:01 +0000171 static Elf_Sym IgnoreUndef;
172
Igor Kudrinb044af52015-11-20 02:32:35 +0000173 // The following symbols must be added early to reserve their places
174 // in symbol tables. The value of the symbols are set when all sections
175 // are finalized and their addresses are determined.
176
177 // The content for _end and end symbols.
178 static Elf_Sym End;
179
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000180 // The content for _gp symbol for MIPS target.
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000181 static Elf_Sym MipsGp;
182
George Rimara07ff662015-12-21 10:12:06 +0000183 // __rel_iplt_start/__rel_iplt_end for signaling
184 // where R_[*]_IRELATIVE relocations do live.
185 static Elf_Sym RelaIpltStart;
186 static Elf_Sym RelaIpltEnd;
187
Rui Ueyama294b1362015-09-30 02:06:17 +0000188 DefinedAbsolute(StringRef N, const Elf_Sym &Sym)
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000189 : Defined<ELFT>(SymbolBody::DefinedAbsoluteKind, N, Sym) {}
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000190
191 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000192 return S->kind() == SymbolBody::DefinedAbsoluteKind;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000193 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000194};
195
Rafael Espindolad27adc42e2015-09-24 13:34:01 +0000196template <class ELFT>
197typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::IgnoreUndef;
198
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000199template <class ELFT>
Igor Kudrinb044af52015-11-20 02:32:35 +0000200typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::End;
201
202template <class ELFT>
Igor Kudrin15cd9ff2015-11-06 07:43:03 +0000203typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::MipsGp;
204
George Rimara07ff662015-12-21 10:12:06 +0000205template <class ELFT>
206typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::RelaIpltStart;
207
208template <class ELFT>
209typename DefinedAbsolute<ELFT>::Elf_Sym DefinedAbsolute<ELFT>::RelaIpltEnd;
210
Rafael Espindola51d46902015-08-28 21:26:51 +0000211template <class ELFT> class DefinedCommon : public Defined<ELFT> {
Rafael Espindola88dddf92015-12-21 21:07:31 +0000212 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola51d46902015-08-28 21:26:51 +0000213
214public:
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000215 typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
Rui Ueyama294b1362015-09-30 02:06:17 +0000216 DefinedCommon(StringRef N, const Elf_Sym &Sym)
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000217 : Defined<ELFT>(SymbolBody::DefinedCommonKind, N, Sym) {
Rafael Espindolaf31f9612015-09-01 01:19:12 +0000218 MaxAlignment = Sym.st_value;
219 }
Rafael Espindola51d46902015-08-28 21:26:51 +0000220
221 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000222 return S->kind() == SymbolBody::DefinedCommonKind;
Rafael Espindola51d46902015-08-28 21:26:51 +0000223 }
Rafael Espindolace8c9c02015-08-31 22:55:21 +0000224
225 // The output offset of this common symbol in the output bss. Computed by the
226 // writer.
227 uintX_t OffsetInBSS;
Rafael Espindolaf31f9612015-09-01 01:19:12 +0000228
229 // The maximum alignment we have seen for this symbol.
230 uintX_t MaxAlignment;
Rafael Espindola51d46902015-08-28 21:26:51 +0000231};
232
Michael J. Spencer84487f12015-07-24 21:03:07 +0000233// Regular defined symbols read from object file symbol tables.
Rafael Espindola3a63f3f2015-08-28 20:19:34 +0000234template <class ELFT> class DefinedRegular : public Defined<ELFT> {
Rafael Espindola88dddf92015-12-21 21:07:31 +0000235 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindolac44d17a2015-08-14 15:10:49 +0000236
Michael J. Spencer84487f12015-07-24 21:03:07 +0000237public:
Rafael Espindolac159c962015-10-19 21:00:02 +0000238 DefinedRegular(StringRef N, const Elf_Sym &Sym,
239 InputSectionBase<ELFT> &Section)
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000240 : Defined<ELFT>(SymbolBody::DefinedRegularKind, N, Sym),
241 Section(Section) {}
Michael J. Spencer84487f12015-07-24 21:03:07 +0000242
243 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000244 return S->kind() == SymbolBody::DefinedRegularKind;
Michael J. Spencer84487f12015-07-24 21:03:07 +0000245 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000246
Rui Ueyamac4aaed92015-10-22 18:49:53 +0000247 InputSectionBase<ELFT> &Section;
Rafael Espindolab13df652015-08-11 17:33:02 +0000248};
249
Rui Ueyama8b75b9a2015-12-17 00:48:16 +0000250// DefinedSynthetic is a class to represent linker-generated ELF symbols.
251// The difference from the regular symbol is that DefinedSynthetic symbols
252// don't belong to any input files or sections. Thus, its constructor
253// takes an output section to calculate output VA, etc.
Rafael Espindola0e604f92015-09-25 18:56:53 +0000254template <class ELFT> class DefinedSynthetic : public Defined<ELFT> {
Rafael Espindola0e604f92015-09-25 18:56:53 +0000255public:
Rafael Espindola88dddf92015-12-21 21:07:31 +0000256 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rui Ueyama294b1362015-09-30 02:06:17 +0000257 DefinedSynthetic(StringRef N, const Elf_Sym &Sym,
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000258 OutputSectionBase<ELFT> &Section)
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000259 : Defined<ELFT>(SymbolBody::DefinedSyntheticKind, N, Sym),
260 Section(Section) {}
Rafael Espindola0e604f92015-09-25 18:56:53 +0000261
262 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000263 return S->kind() == SymbolBody::DefinedSyntheticKind;
Rafael Espindola0e604f92015-09-25 18:56:53 +0000264 }
265
Rui Ueyamac7cc6ec2015-10-15 22:27:29 +0000266 const OutputSectionBase<ELFT> &Section;
Rafael Espindola0e604f92015-09-25 18:56:53 +0000267};
268
Rafael Espindolaf7d45f02015-08-31 01:46:20 +0000269// Undefined symbol.
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000270template <class ELFT> class Undefined : public ELFSymbolBody<ELFT> {
Rafael Espindola88dddf92015-12-21 21:07:31 +0000271 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000272
Rafael Espindola76e24ea2015-08-11 17:57:05 +0000273public:
Rui Ueyama833ce282015-10-08 00:29:00 +0000274 static Elf_Sym Required;
275 static Elf_Sym Optional;
Rafael Espindolaf7d45f02015-08-31 01:46:20 +0000276
Rui Ueyama294b1362015-09-30 02:06:17 +0000277 Undefined(StringRef N, const Elf_Sym &Sym)
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000278 : ELFSymbolBody<ELFT>(SymbolBody::UndefinedKind, N, Sym) {}
Rafael Espindola76e24ea2015-08-11 17:57:05 +0000279
280 static bool classof(const SymbolBody *S) {
Rafael Espindola1e2967e2015-12-21 20:47:33 +0000281 return S->kind() == SymbolBody::UndefinedKind;
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000282 }
Denis Protivensky22220d52015-10-05 09:43:57 +0000283
Rui Ueyama833ce282015-10-08 00:29:00 +0000284 bool canKeepUndefined() const { return &this->Sym == &Optional; }
Rafael Espindola1bd885a2015-08-14 16:46:28 +0000285};
286
Rafael Espindolaf7d45f02015-08-31 01:46:20 +0000287template <class ELFT>
Rui Ueyama833ce282015-10-08 00:29:00 +0000288typename Undefined<ELFT>::Elf_Sym Undefined<ELFT>::Required;
Denis Protivensky22220d52015-10-05 09:43:57 +0000289template <class ELFT>
Rui Ueyama833ce282015-10-08 00:29:00 +0000290typename Undefined<ELFT>::Elf_Sym Undefined<ELFT>::Optional;
Rafael Espindolaf7d45f02015-08-31 01:46:20 +0000291
Rafael Espindola38af1272015-09-25 15:34:03 +0000292template <class ELFT> class SharedSymbol : public Defined<ELFT> {
Rafael Espindola88dddf92015-12-21 21:07:31 +0000293 typedef typename llvm::object::ELFFile<ELFT>::Elf_Sym Elf_Sym;
George Rimarbc590fe2015-10-28 16:48:58 +0000294 typedef typename llvm::object::ELFFile<ELFT>::uintX_t 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 Espindola1e2967e2015-12-21 20:47:33 +0000302 : Defined<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
Rui Ueyamabb936062015-12-17 01:14:23 +0000306 // True if the linker has to generate a copy relocation for this shared
307 // symbol. OffsetInBSS is significant only when NeedsCopy is true.
308 bool NeedsCopy = false;
309 uintX_t OffsetInBSS = 0;
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)
Igor Kudrin65bddea2015-10-09 09:58:39 +0000320 : SymbolBody(LazyKind, S.getName(), false, llvm::ELF::STV_DEFAULT, false),
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000321 File(F), Sym(S) {}
322
323 static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; }
324
325 // Returns an object file for this symbol, or a nullptr if the file
326 // was already returned.
327 std::unique_ptr<InputFile> getMember();
328
Rafael Espindola8614c562015-10-06 14:33:58 +0000329 void setWeak() { IsWeak = true; }
330 void setUsedInRegularObj() { IsUsedInRegularObj = true; }
331
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000332private:
333 ArchiveFile *File;
334 const llvm::object::Archive::Symbol Sym;
335};
336
Michael J. Spencer84487f12015-07-24 21:03:07 +0000337} // namespace elf2
338} // namespace lld
339
340#endif