blob: 2771e4012665ed3804003ae59086c09839541c33 [file] [log] [blame]
Michael J. Spencer84487f12015-07-24 21:03:07 +00001//===- SymbolTable.cpp ----------------------------------------------------===//
2//
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// Symbol table is a bag of all known symbols. We put all symbols of
Rui Ueyamac9559d92016-01-05 20:47:37 +000011// all input files to the symbol table. The symbol table is basically
Rui Ueyama34f29242015-10-13 19:51:57 +000012// a hash table with the logic to resolve symbol name conflicts using
13// the symbol types.
14//
15//===----------------------------------------------------------------------===//
Michael J. Spencer84487f12015-07-24 21:03:07 +000016
17#include "SymbolTable.h"
Rafael Espindola4340aad2015-09-11 22:42:45 +000018#include "Config.h"
Rafael Espindola192e1fa2015-08-06 15:08:23 +000019#include "Error.h"
Davide Italiano8e1131d2016-06-29 02:46:51 +000020#include "LinkerScript.h"
Rui Ueyama55518e72016-10-28 20:57:25 +000021#include "Memory.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000022#include "Symbols.h"
Rui Ueyamacd236a92016-11-17 19:57:43 +000023#include "llvm/ADT/STLExtras.h"
Michael J. Spencer84487f12015-07-24 21:03:07 +000024
25using namespace llvm;
Rafael Espindoladaa92a62015-08-31 01:16:19 +000026using namespace llvm::object;
Rafael Espindola01205f72015-09-22 18:19:46 +000027using namespace llvm::ELF;
Michael J. Spencer84487f12015-07-24 21:03:07 +000028
29using namespace lld;
Rafael Espindolae0df00b2016-02-28 00:25:54 +000030using namespace lld::elf;
Michael J. Spencer84487f12015-07-24 21:03:07 +000031
Rui Ueyamac9559d92016-01-05 20:47:37 +000032// All input object files must be for the same architecture
33// (e.g. it does not make sense to link x86 object files with
34// MIPS object files.) This function checks for that error.
George Rimardbbf60e2016-06-29 09:46:00 +000035template <class ELFT> static bool isCompatible(InputFile *F) {
36 if (!isa<ELFFileBase<ELFT>>(F) && !isa<BitcodeFile>(F))
Rui Ueyama16ba6692016-01-29 19:41:13 +000037 return true;
Simon Atanasyan9e0297b2016-11-05 22:58:01 +000038 if (F->EKind == Config->EKind && F->EMachine == Config->EMachine) {
39 if (Config->EMachine != EM_MIPS)
40 return true;
41 if (isMipsN32Abi(F) == Config->MipsN32Abi)
42 return true;
43 }
Rui Ueyama25b44c92015-12-16 23:31:22 +000044 StringRef A = F->getName();
45 StringRef B = Config->Emulation;
46 if (B.empty())
47 B = Config->FirstElf->getName();
Rui Ueyama16ba6692016-01-29 19:41:13 +000048 error(A + " is incompatible with " + B);
49 return false;
Rui Ueyama25b44c92015-12-16 23:31:22 +000050}
51
Rui Ueyamac9559d92016-01-05 20:47:37 +000052// Add symbols in File to the symbol table.
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000053template <class ELFT> void SymbolTable<ELFT>::addFile(InputFile *File) {
54 if (!isCompatible<ELFT>(File))
Rui Ueyama16ba6692016-01-29 19:41:13 +000055 return;
Rafael Espindola525914d2015-10-11 03:36:49 +000056
Michael J. Spencera9424f32016-09-09 22:08:04 +000057 // Binary file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000058 if (auto *F = dyn_cast<BinaryFile>(File)) {
Rafael Espindola093abab2016-10-27 17:45:40 +000059 BinaryFiles.push_back(F);
60 F->parse<ELFT>();
Michael J. Spencera9424f32016-09-09 22:08:04 +000061 return;
62 }
63
Rui Ueyama89575742015-12-16 22:59:13 +000064 // .a file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000065 if (auto *F = dyn_cast<ArchiveFile>(File)) {
Peter Collingbourne4f952702016-05-01 04:55:03 +000066 F->parse<ELFT>();
Michael J. Spencer1b348a62015-09-04 22:28:10 +000067 return;
68 }
Rui Ueyama3d451792015-10-12 18:03:21 +000069
George Rimar2a78fce2016-04-13 18:07:57 +000070 // Lazy object file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000071 if (auto *F = dyn_cast<LazyObjectFile>(File)) {
Peter Collingbourne4f952702016-05-01 04:55:03 +000072 F->parse<ELFT>();
George Rimar2a78fce2016-04-13 18:07:57 +000073 return;
74 }
75
76 if (Config->Trace)
Rui Ueyama3fc0f7e2016-11-23 18:07:33 +000077 outs() << toString(File) << "\n";
George Rimar2a78fce2016-04-13 18:07:57 +000078
Rui Ueyama89575742015-12-16 22:59:13 +000079 // .so file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000080 if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
Rui Ueyama89575742015-12-16 22:59:13 +000081 // DSOs are uniquified not by filename but by soname.
82 F->parseSoName();
Rui Ueyamaf373dd72016-11-24 01:43:21 +000083 if (ErrorCount || !SoNames.insert(F->getSoName()).second)
Rafael Espindola6a3b5de2015-10-01 19:52:48 +000084 return;
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000085 SharedFiles.push_back(F);
Rui Ueyama7c713312016-01-06 01:56:36 +000086 F->parseRest();
Rui Ueyama89575742015-12-16 22:59:13 +000087 return;
Rafael Espindola6a3b5de2015-10-01 19:52:48 +000088 }
Rui Ueyama89575742015-12-16 22:59:13 +000089
Rui Ueyamaf8baa662016-04-07 19:24:51 +000090 // LLVM bitcode file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000091 if (auto *F = dyn_cast<BitcodeFile>(File)) {
92 BitcodeFiles.push_back(F);
Peter Collingbourne4f952702016-05-01 04:55:03 +000093 F->parse<ELFT>(ComdatGroups);
Rafael Espindola9f77ef02016-02-12 20:54:57 +000094 return;
95 }
96
Rui Ueyamaf8baa662016-04-07 19:24:51 +000097 // Regular object file
Rui Ueyama38dbd3e2016-09-14 00:05:51 +000098 auto *F = cast<ObjectFile<ELFT>>(File);
99 ObjectFiles.push_back(F);
Rui Ueyama52d3b672016-01-06 02:06:33 +0000100 F->parse(ComdatGroups);
Michael J. Spencer84487f12015-07-24 21:03:07 +0000101}
102
Rui Ueyama42554752016-04-23 00:26:32 +0000103// This function is where all the optimizations of link-time
104// optimization happens. When LTO is in use, some input files are
105// not in native object file format but in the LLVM bitcode format.
106// This function compiles bitcode files into a few big native files
107// using LLVM functions and replaces bitcode symbols with the results.
108// Because all bitcode files that consist of a program are passed
109// to the compiler at once, it can do whole-program optimization.
Rafael Espindola9f77ef02016-02-12 20:54:57 +0000110template <class ELFT> void SymbolTable<ELFT>::addCombinedLtoObject() {
111 if (BitcodeFiles.empty())
112 return;
Rui Ueyama25992482016-03-22 20:52:10 +0000113
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000114 // Compile bitcode files and replace bitcode symbols.
Rui Ueyama25992482016-03-22 20:52:10 +0000115 Lto.reset(new BitcodeCompiler);
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000116 for (BitcodeFile *F : BitcodeFiles)
Rui Ueyama25992482016-03-22 20:52:10 +0000117 Lto->add(*F);
Rui Ueyama25992482016-03-22 20:52:10 +0000118
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000119 for (InputFile *File : Lto->compile()) {
120 ObjectFile<ELFT> *Obj = cast<ObjectFile<ELFT>>(File);
Rafael Espindola8b2c85362016-10-21 19:49:42 +0000121 DenseSet<CachedHashStringRef> DummyGroups;
Davide Italianobc176632016-04-15 22:38:10 +0000122 Obj->parse(DummyGroups);
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000123 ObjectFiles.push_back(Obj);
Rafael Espindola9f77ef02016-02-12 20:54:57 +0000124 }
125}
126
Rafael Espindola0e604f92015-09-25 18:56:53 +0000127template <class ELFT>
Rafael Espindolaccfe3cb2016-04-04 14:04:16 +0000128DefinedRegular<ELFT> *SymbolTable<ELFT>::addAbsolute(StringRef Name,
129 uint8_t Visibility) {
George Rimar463984d2016-11-15 08:07:14 +0000130 Symbol *Sym = addRegular(Name, Visibility, STT_NOTYPE, 0, 0, STB_GLOBAL,
131 nullptr, nullptr);
Rui Ueyama1bdaf3e2016-11-09 23:37:40 +0000132 return cast<DefinedRegular<ELFT>>(Sym->body());
Rafael Espindola0e604f92015-09-25 18:56:53 +0000133}
134
Rui Ueyamac9559d92016-01-05 20:47:37 +0000135// Add Name as an "ignored" symbol. An ignored symbol is a regular
Rafael Espindolaccfe3cb2016-04-04 14:04:16 +0000136// linker-synthesized defined symbol, but is only defined if needed.
Simon Atanasyan09dae7c2015-12-16 14:45:09 +0000137template <class ELFT>
Rafael Espindolaccfe3cb2016-04-04 14:04:16 +0000138DefinedRegular<ELFT> *SymbolTable<ELFT>::addIgnored(StringRef Name,
139 uint8_t Visibility) {
Rafael Espindola95eae572016-11-16 18:01:41 +0000140 SymbolBody *S = find(Name);
141 if (!S || !S->isUndefined())
Rafael Espindolaccfe3cb2016-04-04 14:04:16 +0000142 return nullptr;
143 return addAbsolute(Name, Visibility);
Rafael Espindola5d413262015-10-01 21:22:26 +0000144}
145
Rui Ueyama69c778c2016-07-17 17:50:09 +0000146// Set a flag for --trace-symbol so that we can print out a log message
147// if a new symbol with the same name is inserted into the symbol table.
148template <class ELFT> void SymbolTable<ELFT>::trace(StringRef Name) {
Justin Lebar3c11e932016-10-18 17:50:36 +0000149 Symtab.insert({CachedHashStringRef(Name), {-1, true}});
Rui Ueyama69c778c2016-07-17 17:50:09 +0000150}
151
Rui Ueyamadeb15402016-01-07 17:20:07 +0000152// Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
153// Used to implement --wrap.
154template <class ELFT> void SymbolTable<ELFT>::wrap(StringRef Name) {
Rui Ueyama1b70d662016-04-28 00:03:38 +0000155 SymbolBody *B = find(Name);
156 if (!B)
Rui Ueyamadeb15402016-01-07 17:20:07 +0000157 return;
Peter Collingbourne4f952702016-05-01 04:55:03 +0000158 Symbol *Sym = B->symbol();
159 Symbol *Real = addUndefined(Saver.save("__real_" + Name));
160 Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name));
Rui Ueyama1bdaf3e2016-11-09 23:37:40 +0000161
Peter Collingbourne4f952702016-05-01 04:55:03 +0000162 // We rename symbols by replacing the old symbol's SymbolBody with the new
163 // symbol's SymbolBody. This causes all SymbolBody pointers referring to the
164 // old symbol to instead refer to the new symbol.
165 memcpy(Real->Body.buffer, Sym->Body.buffer, sizeof(Sym->Body));
166 memcpy(Sym->Body.buffer, Wrap->Body.buffer, sizeof(Wrap->Body));
Rui Ueyamadeb15402016-01-07 17:20:07 +0000167}
168
Peter Collingbournedadcc172016-04-22 18:42:48 +0000169static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
170 if (VA == STV_DEFAULT)
171 return VB;
172 if (VB == STV_DEFAULT)
173 return VA;
174 return std::min(VA, VB);
175}
176
Rui Ueyamab4de5952016-01-08 22:01:33 +0000177// Find an existing symbol or create and insert a new one.
Peter Collingbourne4f952702016-05-01 04:55:03 +0000178template <class ELFT>
Rui Ueyama35fa6c52016-11-23 05:48:40 +0000179std::pair<Symbol *, bool> SymbolTable<ELFT>::insert(StringRef Name) {
Justin Lebar3c11e932016-10-18 17:50:36 +0000180 auto P = Symtab.insert(
181 {CachedHashStringRef(Name), SymIndex((int)SymVector.size(), false)});
Rui Ueyamae3357902016-07-18 01:35:00 +0000182 SymIndex &V = P.first->second;
Rui Ueyama69c778c2016-07-17 17:50:09 +0000183 bool IsNew = P.second;
184
Rui Ueyamae3357902016-07-18 01:35:00 +0000185 if (V.Idx == -1) {
186 IsNew = true;
George Rimarb0841252016-07-20 14:26:48 +0000187 V = SymIndex((int)SymVector.size(), true);
Rui Ueyamae3357902016-07-18 01:35:00 +0000188 }
189
Rafael Espindola7f0b7272016-04-14 20:42:43 +0000190 Symbol *Sym;
Rui Ueyama69c778c2016-07-17 17:50:09 +0000191 if (IsNew) {
Rui Ueyama55518e72016-10-28 20:57:25 +0000192 Sym = new (BAlloc) Symbol;
Peter Collingbourne4f952702016-05-01 04:55:03 +0000193 Sym->Binding = STB_WEAK;
Peter Collingbourne66ac1d62016-04-22 20:21:26 +0000194 Sym->Visibility = STV_DEFAULT;
195 Sym->IsUsedInRegularObj = false;
196 Sym->ExportDynamic = false;
Rui Ueyamae3357902016-07-18 01:35:00 +0000197 Sym->Traced = V.Traced;
Rui Ueyama35fa6c52016-11-23 05:48:40 +0000198 Sym->VersionId = Config->DefaultSymbolVersion;
Rafael Espindola7f0b7272016-04-14 20:42:43 +0000199 SymVector.push_back(Sym);
200 } else {
Rui Ueyamae3357902016-07-18 01:35:00 +0000201 Sym = SymVector[V.Idx];
Rafael Espindola7f0b7272016-04-14 20:42:43 +0000202 }
Rui Ueyama69c778c2016-07-17 17:50:09 +0000203 return {Sym, IsNew};
Peter Collingbourne4f952702016-05-01 04:55:03 +0000204}
Peter Collingbournedadcc172016-04-22 18:42:48 +0000205
Rui Ueyama8fcc3af2016-10-26 18:28:08 +0000206// Construct a string in the form of "Sym in File1 and File2".
207// Used to construct an error message.
208static std::string conflictMsg(SymbolBody *Existing, InputFile *NewFile) {
Rui Ueyamaa3ac1732016-11-24 20:24:18 +0000209 return "'" + toString(*Existing) + "' in " + toString(Existing->File) +
210 " and " + toString(NewFile);
Rui Ueyama8fcc3af2016-10-26 18:28:08 +0000211}
212
Peter Collingbourne4f952702016-05-01 04:55:03 +0000213// Find an existing symbol or create and insert a new one, then apply the given
214// attributes.
215template <class ELFT>
216std::pair<Symbol *, bool>
Rui Ueyama35fa6c52016-11-23 05:48:40 +0000217SymbolTable<ELFT>::insert(StringRef Name, uint8_t Type, uint8_t Visibility,
Davide Italiano786d8e32016-09-29 00:40:08 +0000218 bool CanOmitFromDynSym, InputFile *File) {
Rafael Espindola05098762016-08-31 13:49:23 +0000219 bool IsUsedInRegularObj = !File || File->kind() == InputFile::ObjectKind;
Peter Collingbourne4f952702016-05-01 04:55:03 +0000220 Symbol *S;
221 bool WasInserted;
222 std::tie(S, WasInserted) = insert(Name);
223
224 // Merge in the new symbol's visibility.
225 S->Visibility = getMinVisibility(S->Visibility, Visibility);
226 if (!CanOmitFromDynSym && (Config->Shared || Config->ExportDynamic))
227 S->ExportDynamic = true;
228 if (IsUsedInRegularObj)
229 S->IsUsedInRegularObj = true;
Peter Collingbournef3a2b0e2016-05-03 18:03:47 +0000230 if (!WasInserted && S->body()->Type != SymbolBody::UnknownType &&
231 ((Type == STT_TLS) != S->body()->isTls()))
Eugene Leviant825e5382016-11-08 16:26:32 +0000232 error("TLS attribute mismatch for symbol " + conflictMsg(S->body(), File));
Peter Collingbourne4f952702016-05-01 04:55:03 +0000233
234 return {S, WasInserted};
235}
236
Peter Collingbourne4f952702016-05-01 04:55:03 +0000237template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {
238 return addUndefined(Name, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0,
Davide Italiano786d8e32016-09-29 00:40:08 +0000239 /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000240}
241
242template <class ELFT>
243Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name, uint8_t Binding,
244 uint8_t StOther, uint8_t Type,
Rafael Espindolacc70da32016-06-15 17:56:10 +0000245 bool CanOmitFromDynSym,
Davide Italiano786d8e32016-09-29 00:40:08 +0000246 InputFile *File) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000247 Symbol *S;
248 bool WasInserted;
249 std::tie(S, WasInserted) =
Davide Italiano786d8e32016-09-29 00:40:08 +0000250 insert(Name, Type, StOther & 3, CanOmitFromDynSym, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000251 if (WasInserted) {
252 S->Binding = Binding;
Rui Ueyama434b5612016-07-17 03:11:46 +0000253 replaceBody<Undefined>(S, Name, StOther, Type, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000254 return S;
255 }
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000256 if (Binding != STB_WEAK) {
257 if (S->body()->isShared() || S->body()->isLazy())
258 S->Binding = Binding;
259 if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(S->body()))
Rui Ueyama434b5612016-07-17 03:11:46 +0000260 SS->file()->IsUsed = true;
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000261 }
Peter Collingbourne4f952702016-05-01 04:55:03 +0000262 if (auto *L = dyn_cast<Lazy>(S->body())) {
263 // An undefined weak will not fetch archive members, but we have to remember
264 // its type. See also comment in addLazyArchive.
265 if (S->isWeak())
266 L->Type = Type;
Rui Ueyama55518e72016-10-28 20:57:25 +0000267 else if (InputFile *F = L->fetch())
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000268 addFile(F);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000269 }
270 return S;
271}
272
273// We have a new defined symbol with the specified binding. Return 1 if the new
274// symbol should win, -1 if the new symbol should lose, or 0 if both symbols are
275// strong defined symbols.
276static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding) {
277 if (WasInserted)
278 return 1;
279 SymbolBody *Body = S->body();
280 if (Body->isLazy() || Body->isUndefined() || Body->isShared())
281 return 1;
282 if (Binding == STB_WEAK)
283 return -1;
284 if (S->isWeak())
285 return 1;
286 return 0;
287}
288
289// We have a new non-common defined symbol with the specified binding. Return 1
290// if the new symbol should win, -1 if the new symbol should lose, or 0 if there
291// is a conflict. If the new symbol wins, also update the binding.
Eugene Leviant3e6b0272016-07-28 19:24:13 +0000292static int compareDefinedNonCommon(Symbol *S, bool WasInserted,
293 uint8_t Binding) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000294 if (int Cmp = compareDefined(S, WasInserted, Binding)) {
295 if (Cmp > 0)
296 S->Binding = Binding;
297 return Cmp;
298 }
Rafael Espindolae7553e42016-08-31 13:28:33 +0000299 if (isa<DefinedCommon>(S->body())) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000300 // Non-common symbols take precedence over common symbols.
301 if (Config->WarnCommon)
Rui Ueyamad31e13f2016-09-29 21:00:23 +0000302 warn("common " + S->body()->getName() + " is overridden");
Peter Collingbourne4f952702016-05-01 04:55:03 +0000303 return 1;
304 }
305 return 0;
306}
307
308template <class ELFT>
309Symbol *SymbolTable<ELFT>::addCommon(StringRef N, uint64_t Size,
310 uint64_t Alignment, uint8_t Binding,
311 uint8_t StOther, uint8_t Type,
Davide Italiano786d8e32016-09-29 00:40:08 +0000312 InputFile *File) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000313 Symbol *S;
314 bool WasInserted;
Davide Italiano786d8e32016-09-29 00:40:08 +0000315 std::tie(S, WasInserted) =
316 insert(N, Type, StOther & 3, /*CanOmitFromDynSym*/ false, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000317 int Cmp = compareDefined(S, WasInserted, Binding);
318 if (Cmp > 0) {
319 S->Binding = Binding;
Rafael Espindolae7553e42016-08-31 13:28:33 +0000320 replaceBody<DefinedCommon>(S, N, Size, Alignment, StOther, Type, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000321 } else if (Cmp == 0) {
Rafael Espindolae7553e42016-08-31 13:28:33 +0000322 auto *C = dyn_cast<DefinedCommon>(S->body());
Peter Collingbourne4f952702016-05-01 04:55:03 +0000323 if (!C) {
324 // Non-common symbols take precedence over common symbols.
325 if (Config->WarnCommon)
Rui Ueyamad31e13f2016-09-29 21:00:23 +0000326 warn("common " + S->body()->getName() + " is overridden");
Peter Collingbourne4f952702016-05-01 04:55:03 +0000327 return S;
328 }
329
330 if (Config->WarnCommon)
Rui Ueyamad31e13f2016-09-29 21:00:23 +0000331 warn("multiple common of " + S->body()->getName());
Peter Collingbourne4f952702016-05-01 04:55:03 +0000332
Rafael Espindola8db87292016-08-31 13:42:08 +0000333 Alignment = C->Alignment = std::max(C->Alignment, Alignment);
334 if (Size > C->Size)
335 replaceBody<DefinedCommon>(S, N, Size, Alignment, StOther, Type, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000336 }
337 return S;
338}
339
Rui Ueyama9c5a69d2016-11-08 20:02:23 +0000340static void print(const Twine &Msg) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000341 if (Config->AllowMultipleDefinition)
Rui Ueyamad31e13f2016-09-29 21:00:23 +0000342 warn(Msg);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000343 else
344 error(Msg);
345}
346
Eugene Leviant825e5382016-11-08 16:26:32 +0000347static void reportDuplicate(SymbolBody *Existing, InputFile *NewFile) {
Rui Ueyama9c5a69d2016-11-08 20:02:23 +0000348 print("duplicate symbol " + conflictMsg(Existing, NewFile));
Eugene Leviant825e5382016-11-08 16:26:32 +0000349}
350
351template <class ELFT>
352static void reportDuplicate(SymbolBody *Existing,
353 InputSectionBase<ELFT> *ErrSec,
354 typename ELFT::uint ErrOffset) {
355 DefinedRegular<ELFT> *D = dyn_cast<DefinedRegular<ELFT>>(Existing);
356 if (!D || !D->Section || !ErrSec) {
357 reportDuplicate(Existing, ErrSec ? ErrSec->getFile() : nullptr);
358 return;
359 }
360
Rui Ueyamaedc183e2016-11-08 20:30:19 +0000361 std::string OldLoc = getLocation(*D->Section, D->Value);
362 std::string NewLoc = getLocation(*ErrSec, ErrOffset);
Eugene Leviant825e5382016-11-08 16:26:32 +0000363
Rui Ueyamaa3ac1732016-11-24 20:24:18 +0000364 print(NewLoc + ": duplicate symbol '" + toString(*Existing) + "'");
Rui Ueyama9c5a69d2016-11-08 20:02:23 +0000365 print(OldLoc + ": previous definition was here");
Eugene Leviant825e5382016-11-08 16:26:32 +0000366}
367
Peter Collingbourne4f952702016-05-01 04:55:03 +0000368template <typename ELFT>
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000369Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t StOther,
370 uint8_t Type, uintX_t Value, uintX_t Size,
371 uint8_t Binding,
George Rimar463984d2016-11-15 08:07:14 +0000372 InputSectionBase<ELFT> *Section,
373 InputFile *File) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000374 Symbol *S;
375 bool WasInserted;
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000376 std::tie(S, WasInserted) = insert(Name, Type, StOther & 3,
George Rimar463984d2016-11-15 08:07:14 +0000377 /*CanOmitFromDynSym*/ false, File);
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000378 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000379 if (Cmp > 0)
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000380 replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, Value, Size,
George Rimar463984d2016-11-15 08:07:14 +0000381 Section, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000382 else if (Cmp == 0)
Eugene Leviant825e5382016-11-08 16:26:32 +0000383 reportDuplicate(S->body(), Section, Value);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000384 return S;
385}
386
387template <typename ELFT>
Eugene Leviantafaa9342016-11-16 09:49:39 +0000388Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
389 const OutputSectionBase *Section,
George Rimare1937bb2016-08-19 15:36:32 +0000390 uintX_t Value, uint8_t StOther) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000391 Symbol *S;
392 bool WasInserted;
George Rimare1937bb2016-08-19 15:36:32 +0000393 std::tie(S, WasInserted) = insert(N, STT_NOTYPE, /*Visibility*/ StOther & 0x3,
Davide Italiano786d8e32016-09-29 00:40:08 +0000394 /*CanOmitFromDynSym*/ false, nullptr);
Rafael Espindolae7553e42016-08-31 13:28:33 +0000395 int Cmp = compareDefinedNonCommon(S, WasInserted, STB_GLOBAL);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000396 if (Cmp > 0)
397 replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
398 else if (Cmp == 0)
399 reportDuplicate(S->body(), nullptr);
400 return S;
401}
402
403template <typename ELFT>
404void SymbolTable<ELFT>::addShared(SharedFile<ELFT> *F, StringRef Name,
405 const Elf_Sym &Sym,
406 const typename ELFT::Verdef *Verdef) {
407 // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
408 // as the visibility, which will leave the visibility in the symbol table
409 // unchanged.
410 Symbol *S;
411 bool WasInserted;
412 std::tie(S, WasInserted) =
Davide Italiano786d8e32016-09-29 00:40:08 +0000413 insert(Name, Sym.getType(), STV_DEFAULT, /*CanOmitFromDynSym*/ true, F);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000414 // Make sure we preempt DSO symbols with default visibility.
415 if (Sym.getVisibility() == STV_DEFAULT)
416 S->ExportDynamic = true;
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000417 if (WasInserted || isa<Undefined>(S->body())) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000418 replaceBody<SharedSymbol<ELFT>>(S, F, Name, Sym, Verdef);
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000419 if (!S->isWeak())
420 F->IsUsed = true;
421 }
Peter Collingbourne4f952702016-05-01 04:55:03 +0000422}
423
424template <class ELFT>
Rafael Espindolacceb92a2016-08-30 20:53:26 +0000425Symbol *SymbolTable<ELFT>::addBitcode(StringRef Name, uint8_t Binding,
Peter Collingbourne4f952702016-05-01 04:55:03 +0000426 uint8_t StOther, uint8_t Type,
Davide Italiano786d8e32016-09-29 00:40:08 +0000427 bool CanOmitFromDynSym, BitcodeFile *F) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000428 Symbol *S;
429 bool WasInserted;
Davide Italiano35af5b32016-08-30 20:15:03 +0000430 std::tie(S, WasInserted) =
Davide Italiano786d8e32016-09-29 00:40:08 +0000431 insert(Name, Type, StOther & 3, CanOmitFromDynSym, F);
Rafael Espindolae7553e42016-08-31 13:28:33 +0000432 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000433 if (Cmp > 0)
Rui Ueyama768c6f02016-11-23 06:31:23 +0000434 replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, 0, 0, nullptr, F);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000435 else if (Cmp == 0)
436 reportDuplicate(S->body(), F);
437 return S;
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000438}
Michael J. Spencer84487f12015-07-24 21:03:07 +0000439
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000440template <class ELFT> SymbolBody *SymbolTable<ELFT>::find(StringRef Name) {
Justin Lebar3c11e932016-10-18 17:50:36 +0000441 auto It = Symtab.find(CachedHashStringRef(Name));
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000442 if (It == Symtab.end())
443 return nullptr;
Rui Ueyamae3357902016-07-18 01:35:00 +0000444 SymIndex V = It->second;
445 if (V.Idx == -1)
446 return nullptr;
447 return SymVector[V.Idx]->body();
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000448}
449
Rui Ueyama82492142016-11-15 18:41:52 +0000450// Returns a list of defined symbols that match with a given pattern.
Rui Ueyama3d451792015-10-12 18:03:21 +0000451template <class ELFT>
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000452std::vector<SymbolBody *> SymbolTable<ELFT>::findAll(StringRef GlobPat) {
Rui Ueyama48e42512016-06-29 04:47:39 +0000453 std::vector<SymbolBody *> Res;
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000454 StringMatcher M({GlobPat});
Rui Ueyamad6328522016-07-18 01:34:57 +0000455 for (Symbol *Sym : SymVector) {
456 SymbolBody *B = Sym->body();
George Rimarc91930a2016-09-02 21:17:20 +0000457 StringRef Name = B->getName();
Rui Ueyamaf91282e2016-11-03 17:57:38 +0000458 if (!B->isUndefined() && M.match(Name))
Rui Ueyama48e42512016-06-29 04:47:39 +0000459 Res.push_back(B);
460 }
461 return Res;
Davide Italiano8e1131d2016-06-29 02:46:51 +0000462}
463
464template <class ELFT>
Rui Ueyama818bb2f2016-07-16 18:55:47 +0000465void SymbolTable<ELFT>::addLazyArchive(ArchiveFile *F,
466 const object::Archive::Symbol Sym) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000467 Symbol *S;
468 bool WasInserted;
Rui Ueyamadace8382016-07-21 13:13:21 +0000469 StringRef Name = Sym.getName();
470 std::tie(S, WasInserted) = insert(Name);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000471 if (WasInserted) {
Rafael Espindola07543a82016-06-14 21:40:23 +0000472 replaceBody<LazyArchive>(S, *F, Sym, SymbolBody::UnknownType);
Rui Ueyamac5b95122015-12-16 23:23:14 +0000473 return;
474 }
Peter Collingbourne4f952702016-05-01 04:55:03 +0000475 if (!S->body()->isUndefined())
476 return;
Rui Ueyamac5b95122015-12-16 23:23:14 +0000477
Peter Collingbourne4f952702016-05-01 04:55:03 +0000478 // Weak undefined symbols should not fetch members from archives. If we were
479 // to keep old symbol we would not know that an archive member was available
480 // if a strong undefined symbol shows up afterwards in the link. If a strong
481 // undefined symbol never shows up, this lazy symbol will get to the end of
482 // the link and must be treated as the weak undefined one. We already marked
483 // this symbol as used when we added it to the symbol table, but we also need
484 // to preserve its type. FIXME: Move the Type field to Symbol.
485 if (S->isWeak()) {
Rafael Espindola07543a82016-06-14 21:40:23 +0000486 replaceBody<LazyArchive>(S, *F, Sym, S->body()->Type);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000487 return;
488 }
Davide Italianobcdd6c62016-10-12 19:35:54 +0000489 std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
490 if (!MBInfo.first.getBuffer().empty())
Rui Ueyama55518e72016-10-28 20:57:25 +0000491 addFile(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
Peter Collingbourne4f952702016-05-01 04:55:03 +0000492}
493
494template <class ELFT>
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000495void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000496 Symbol *S;
497 bool WasInserted;
498 std::tie(S, WasInserted) = insert(Name);
499 if (WasInserted) {
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000500 replaceBody<LazyObject>(S, Name, Obj, SymbolBody::UnknownType);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000501 return;
502 }
503 if (!S->body()->isUndefined())
504 return;
505
506 // See comment for addLazyArchive above.
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000507 if (S->isWeak()) {
508 replaceBody<LazyObject>(S, Name, Obj, S->body()->Type);
509 } else {
510 MemoryBufferRef MBRef = Obj.getBuffer();
511 if (!MBRef.getBuffer().empty())
Rui Ueyama55518e72016-10-28 20:57:25 +0000512 addFile(createObjectFile(MBRef));
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000513 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000514}
Rafael Espindola0e604f92015-09-25 18:56:53 +0000515
Peter Collingbourne892d49802016-04-27 00:05:03 +0000516// Process undefined (-u) flags by loading lazy symbols named by those flags.
Peter Collingbourne4f952702016-05-01 04:55:03 +0000517template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
Peter Collingbourne892d49802016-04-27 00:05:03 +0000518 for (StringRef S : Config->Undefined)
Peter Collingbourne4f952702016-05-01 04:55:03 +0000519 if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
Rui Ueyama55518e72016-10-28 20:57:25 +0000520 if (InputFile *File = L->fetch())
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000521 addFile(File);
Peter Collingbourne892d49802016-04-27 00:05:03 +0000522}
523
Rui Ueyama93bfee52015-10-13 18:10:33 +0000524// This function takes care of the case in which shared libraries depend on
525// the user program (not the other way, which is usual). Shared libraries
526// may have undefined symbols, expecting that the user program provides
527// the definitions for them. An example is BSD's __progname symbol.
528// We need to put such symbols to the main program's .dynsym so that
529// shared libraries can find them.
530// Except this, we ignore undefined symbols in DSOs.
531template <class ELFT> void SymbolTable<ELFT>::scanShlibUndefined() {
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000532 for (SharedFile<ELFT> *File : SharedFiles)
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000533 for (StringRef U : File->getUndefinedSymbols())
534 if (SymbolBody *Sym = find(U))
535 if (Sym->isDefined())
Peter Collingbourne4f952702016-05-01 04:55:03 +0000536 Sym->symbol()->ExportDynamic = true;
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000537}
538
Rui Ueyamadad2b882016-09-02 22:15:08 +0000539// This function processes --export-dynamic-symbol and --dynamic-list.
Adhemerval Zanella9df07202016-04-13 18:51:11 +0000540template <class ELFT> void SymbolTable<ELFT>::scanDynamicList() {
541 for (StringRef S : Config->DynamicList)
542 if (SymbolBody *B = find(S))
Peter Collingbourne4f952702016-05-01 04:55:03 +0000543 B->symbol()->ExportDynamic = true;
Adhemerval Zanella9df07202016-04-13 18:51:11 +0000544}
545
Rui Ueyama82492142016-11-15 18:41:52 +0000546// Initialize DemangledSyms with a map from demangled symbols to symbol
547// objects. Used to handle "extern C++" directive in version scripts.
548//
549// The map will contain all demangled symbols. That can be very large,
550// and in LLD we generally want to avoid do anything for each symbol.
551// Then, why are we doing this? Here's why.
552//
553// Users can use "extern C++ {}" directive to match against demangled
554// C++ symbols. For example, you can write a pattern such as
555// "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
556// other than trying to match a pattern against all demangled symbols.
557// So, if "extern C++" feature is used, we need to demangle all known
558// symbols.
George Rimar50dcece2016-07-16 12:26:39 +0000559template <class ELFT>
Rui Ueyama82492142016-11-15 18:41:52 +0000560void SymbolTable<ELFT>::initDemangledSyms() {
561 if (DemangledSyms)
562 return;
563 DemangledSyms.emplace();
564
Rui Ueyamad6328522016-07-18 01:34:57 +0000565 for (Symbol *Sym : SymVector) {
566 SymbolBody *B = Sym->body();
Rui Ueyama82492142016-11-15 18:41:52 +0000567 (*DemangledSyms)[demangle(B->getName())].push_back(B);
Rui Ueyamad6328522016-07-18 01:34:57 +0000568 }
George Rimar50dcece2016-07-16 12:26:39 +0000569}
570
Rui Ueyama82492142016-11-15 18:41:52 +0000571template <class ELFT>
572ArrayRef<SymbolBody *> SymbolTable<ELFT>::findDemangled(StringRef Name) {
573 initDemangledSyms();
574 auto I = DemangledSyms->find(Name);
575 if (I != DemangledSyms->end())
George Rimarc3ec9d02016-08-30 09:29:37 +0000576 return I->second;
George Rimar31c25ae2016-09-15 12:44:38 +0000577 return {};
George Rimarc3ec9d02016-08-30 09:29:37 +0000578}
579
Rui Ueyama82492142016-11-15 18:41:52 +0000580template <class ELFT>
581std::vector<SymbolBody *>
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000582SymbolTable<ELFT>::findAllDemangled(StringRef GlobPat) {
Rui Ueyama82492142016-11-15 18:41:52 +0000583 initDemangledSyms();
George Rimar397cd87a2016-08-30 09:35:03 +0000584 std::vector<SymbolBody *> Res;
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000585 StringMatcher M({GlobPat});
Rui Ueyama82492142016-11-15 18:41:52 +0000586 for (auto &P : *DemangledSyms)
587 if (M.match(P.first()))
George Rimar31c25ae2016-09-15 12:44:38 +0000588 for (SymbolBody *Body : P.second)
589 if (!Body->isUndefined())
590 Res.push_back(Body);
George Rimar397cd87a2016-08-30 09:35:03 +0000591 return Res;
592}
593
Rui Ueyamaea265042016-09-13 20:51:30 +0000594// If there's only one anonymous version definition in a version
George Rimar92ca6f42016-11-14 09:56:35 +0000595// script file, the script does not actually define any symbol version,
Rui Ueyamaea265042016-09-13 20:51:30 +0000596// but just specifies symbols visibilities. We assume that the script was
597// in the form of { global: foo; bar; local *; }. So, local is default.
598// In this function, we make specified symbols global.
599template <class ELFT> void SymbolTable<ELFT>::handleAnonymousVersion() {
Rui Ueyamabaf7ee32016-11-15 17:51:09 +0000600 for (SymbolVersion &Ver : Config->VersionScriptGlobals) {
601 if (hasWildcard(Ver.Name)) {
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000602 for (SymbolBody *B : findAll(Ver.Name))
Rui Ueyama77d917d2016-11-17 03:19:34 +0000603 B->symbol()->VersionId = VER_NDX_GLOBAL;
Rui Ueyamaea265042016-09-13 20:51:30 +0000604 continue;
605 }
Rui Ueyamabaf7ee32016-11-15 17:51:09 +0000606 if (SymbolBody *B = find(Ver.Name))
Rui Ueyamaea265042016-09-13 20:51:30 +0000607 B->symbol()->VersionId = VER_NDX_GLOBAL;
608 }
Rui Ueyamaea265042016-09-13 20:51:30 +0000609}
610
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000611// Set symbol versions to symbols. This function handles patterns
612// containing no wildcard characters.
613template <class ELFT>
Rui Ueyamada805c42016-11-17 03:39:21 +0000614void SymbolTable<ELFT>::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000615 StringRef VersionName) {
Rui Ueyama8980c922016-11-18 06:30:08 +0000616 if (Ver.HasWildcard)
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000617 return;
618
619 // Get a list of symbols which we need to assign the version to.
620 std::vector<SymbolBody *> Syms;
621 if (Ver.IsExternCpp)
622 Syms = findDemangled(Ver.Name);
623 else
624 Syms.push_back(find(Ver.Name));
625
626 // Assign the version.
627 for (SymbolBody *B : Syms) {
628 if (!B || B->isUndefined()) {
629 if (Config->NoUndefinedVersion)
Rui Ueyamad84124f2016-11-17 19:57:47 +0000630 error("version script assignment of '" + VersionName + "' to symbol '" +
631 Ver.Name + "' failed: symbol not defined");
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000632 continue;
633 }
634
635 if (B->symbol()->VersionId != Config->DefaultSymbolVersion)
Rui Ueyamaaade0e22016-11-17 03:32:41 +0000636 warn("duplicate symbol '" + Ver.Name + "' in version script");
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000637 B->symbol()->VersionId = VersionId;
638 }
639}
640
Rui Ueyama82492142016-11-15 18:41:52 +0000641template <class ELFT>
642void SymbolTable<ELFT>::assignWildcardVersion(SymbolVersion Ver,
Rui Ueyamada805c42016-11-17 03:39:21 +0000643 uint16_t VersionId) {
Rui Ueyama8980c922016-11-18 06:30:08 +0000644 if (!Ver.HasWildcard)
Rui Ueyama82492142016-11-15 18:41:52 +0000645 return;
Rui Ueyama82492142016-11-15 18:41:52 +0000646 std::vector<SymbolBody *> Syms =
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000647 Ver.IsExternCpp ? findAllDemangled(Ver.Name) : findAll(Ver.Name);
Rui Ueyama82492142016-11-15 18:41:52 +0000648
649 // Exact matching takes precendence over fuzzy matching,
650 // so we set a version to a symbol only if no version has been assigned
651 // to the symbol. This behavior is compatible with GNU.
652 for (SymbolBody *B : Syms)
653 if (B->symbol()->VersionId == Config->DefaultSymbolVersion)
654 B->symbol()->VersionId = VersionId;
655}
656
Rui Ueyamadad2b882016-09-02 22:15:08 +0000657// This function processes version scripts by updating VersionId
658// member of symbols.
Peter Collingbourne66ac1d62016-04-22 20:21:26 +0000659template <class ELFT> void SymbolTable<ELFT>::scanVersionScript() {
Rui Ueyama35fa6c52016-11-23 05:48:40 +0000660 // Symbol themselves might know their versions because symbols
661 // can contain versions in the form of <name>@<version>.
662 // Let them parse their names.
663 if (!Config->VersionDefinitions.empty())
664 for (Symbol *Sym : SymVector)
665 Sym->body()->parseSymbolVersion();
666
Rui Ueyamaea265042016-09-13 20:51:30 +0000667 // Handle edge cases first.
George Rimard3566302016-06-20 11:55:12 +0000668 if (!Config->VersionScriptGlobals.empty()) {
Rui Ueyamaea265042016-09-13 20:51:30 +0000669 handleAnonymousVersion();
George Rimard3566302016-06-20 11:55:12 +0000670 return;
671 }
672
Rui Ueyamaaf469d42016-07-16 04:09:27 +0000673 if (Config->VersionDefinitions.empty())
George Rimarf73a2582016-07-07 07:45:27 +0000674 return;
675
Rui Ueyamadad2b882016-09-02 22:15:08 +0000676 // Now we have version definitions, so we need to set version ids to symbols.
677 // Each version definition has a glob pattern, and all symbols that match
678 // with the pattern get that version.
679
Rui Ueyamadad2b882016-09-02 22:15:08 +0000680 // First, we assign versions to exact matching symbols,
681 // i.e. version definitions not containing any glob meta-characters.
Rui Ueyama96db27c2016-11-17 19:57:45 +0000682 for (SymbolVersion &Ver : Config->VersionScriptLocals)
683 assignExactVersion(Ver, VER_NDX_LOCAL, "local");
George Rimar17c65af2016-11-16 18:46:23 +0000684 for (VersionDefinition &V : Config->VersionDefinitions)
Rui Ueyama96db27c2016-11-17 19:57:45 +0000685 for (SymbolVersion &Ver : V.Globals)
686 assignExactVersion(Ver, V.Id, V.Name);
George Rimarf73a2582016-07-07 07:45:27 +0000687
Rui Ueyamadad2b882016-09-02 22:15:08 +0000688 // Next, we assign versions to fuzzy matching symbols,
689 // i.e. version definitions containing glob meta-characters.
690 // Note that because the last match takes precedence over previous matches,
691 // we iterate over the definitions in the reverse order.
George Rimar17c65af2016-11-16 18:46:23 +0000692 for (SymbolVersion &Ver : Config->VersionScriptLocals)
693 assignWildcardVersion(Ver, VER_NDX_LOCAL);
Rui Ueyamacd236a92016-11-17 19:57:43 +0000694 for (VersionDefinition &V : llvm::reverse(Config->VersionDefinitions))
695 for (SymbolVersion &Ver : V.Globals)
696 assignWildcardVersion(Ver, V.Id);
Peter Collingbourne66ac1d62016-04-22 20:21:26 +0000697}
698
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000699template class elf::SymbolTable<ELF32LE>;
700template class elf::SymbolTable<ELF32BE>;
701template class elf::SymbolTable<ELF64LE>;
702template class elf::SymbolTable<ELF64BE>;