blob: 5494889bd3852be8d15bb9835e253737bcd559f0 [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();
George Rimarbcba39a2016-11-02 10:16:25 +000083 if (HasError || !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) {
Eugene Leviant825e5382016-11-08 16:26:32 +0000209 return "'" + maybeDemangle(Existing->getName()) + "' in " +
Rui Ueyama3fc0f7e2016-11-23 18:07:33 +0000210 toString(Existing->File) + " 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 Ueyama9c5a69d2016-11-08 20:02:23 +0000364 print(NewLoc + ": duplicate symbol '" + maybeDemangle(Existing->getName()) +
365 "'");
366 print(OldLoc + ": previous definition was here");
Eugene Leviant825e5382016-11-08 16:26:32 +0000367}
368
Peter Collingbourne4f952702016-05-01 04:55:03 +0000369template <typename ELFT>
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000370Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t StOther,
371 uint8_t Type, uintX_t Value, uintX_t Size,
372 uint8_t Binding,
George Rimar463984d2016-11-15 08:07:14 +0000373 InputSectionBase<ELFT> *Section,
374 InputFile *File) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000375 Symbol *S;
376 bool WasInserted;
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000377 std::tie(S, WasInserted) = insert(Name, Type, StOther & 3,
George Rimar463984d2016-11-15 08:07:14 +0000378 /*CanOmitFromDynSym*/ false, File);
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000379 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000380 if (Cmp > 0)
Rafael Espindola5ceeb602016-10-26 20:57:14 +0000381 replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, Value, Size,
George Rimar463984d2016-11-15 08:07:14 +0000382 Section, File);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000383 else if (Cmp == 0)
Eugene Leviant825e5382016-11-08 16:26:32 +0000384 reportDuplicate(S->body(), Section, Value);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000385 return S;
386}
387
388template <typename ELFT>
Eugene Leviantafaa9342016-11-16 09:49:39 +0000389Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
390 const OutputSectionBase *Section,
George Rimare1937bb2016-08-19 15:36:32 +0000391 uintX_t Value, uint8_t StOther) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000392 Symbol *S;
393 bool WasInserted;
George Rimare1937bb2016-08-19 15:36:32 +0000394 std::tie(S, WasInserted) = insert(N, STT_NOTYPE, /*Visibility*/ StOther & 0x3,
Davide Italiano786d8e32016-09-29 00:40:08 +0000395 /*CanOmitFromDynSym*/ false, nullptr);
Rafael Espindolae7553e42016-08-31 13:28:33 +0000396 int Cmp = compareDefinedNonCommon(S, WasInserted, STB_GLOBAL);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000397 if (Cmp > 0)
398 replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
399 else if (Cmp == 0)
400 reportDuplicate(S->body(), nullptr);
401 return S;
402}
403
404template <typename ELFT>
405void SymbolTable<ELFT>::addShared(SharedFile<ELFT> *F, StringRef Name,
406 const Elf_Sym &Sym,
407 const typename ELFT::Verdef *Verdef) {
408 // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
409 // as the visibility, which will leave the visibility in the symbol table
410 // unchanged.
411 Symbol *S;
412 bool WasInserted;
413 std::tie(S, WasInserted) =
Davide Italiano786d8e32016-09-29 00:40:08 +0000414 insert(Name, Sym.getType(), STV_DEFAULT, /*CanOmitFromDynSym*/ true, F);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000415 // Make sure we preempt DSO symbols with default visibility.
416 if (Sym.getVisibility() == STV_DEFAULT)
417 S->ExportDynamic = true;
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000418 if (WasInserted || isa<Undefined>(S->body())) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000419 replaceBody<SharedSymbol<ELFT>>(S, F, Name, Sym, Verdef);
Peter Collingbourneca8c9942016-06-09 18:01:35 +0000420 if (!S->isWeak())
421 F->IsUsed = true;
422 }
Peter Collingbourne4f952702016-05-01 04:55:03 +0000423}
424
425template <class ELFT>
Rafael Espindolacceb92a2016-08-30 20:53:26 +0000426Symbol *SymbolTable<ELFT>::addBitcode(StringRef Name, uint8_t Binding,
Peter Collingbourne4f952702016-05-01 04:55:03 +0000427 uint8_t StOther, uint8_t Type,
Davide Italiano786d8e32016-09-29 00:40:08 +0000428 bool CanOmitFromDynSym, BitcodeFile *F) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000429 Symbol *S;
430 bool WasInserted;
Davide Italiano35af5b32016-08-30 20:15:03 +0000431 std::tie(S, WasInserted) =
Davide Italiano786d8e32016-09-29 00:40:08 +0000432 insert(Name, Type, StOther & 3, CanOmitFromDynSym, F);
Rafael Espindolae7553e42016-08-31 13:28:33 +0000433 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000434 if (Cmp > 0)
Rui Ueyama768c6f02016-11-23 06:31:23 +0000435 replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, 0, 0, nullptr, F);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000436 else if (Cmp == 0)
437 reportDuplicate(S->body(), F);
438 return S;
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000439}
Michael J. Spencer84487f12015-07-24 21:03:07 +0000440
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000441template <class ELFT> SymbolBody *SymbolTable<ELFT>::find(StringRef Name) {
Justin Lebar3c11e932016-10-18 17:50:36 +0000442 auto It = Symtab.find(CachedHashStringRef(Name));
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000443 if (It == Symtab.end())
444 return nullptr;
Rui Ueyamae3357902016-07-18 01:35:00 +0000445 SymIndex V = It->second;
446 if (V.Idx == -1)
447 return nullptr;
448 return SymVector[V.Idx]->body();
Michael J. Spencer1b348a62015-09-04 22:28:10 +0000449}
450
Rui Ueyama82492142016-11-15 18:41:52 +0000451// Returns a list of defined symbols that match with a given pattern.
Rui Ueyama3d451792015-10-12 18:03:21 +0000452template <class ELFT>
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000453std::vector<SymbolBody *> SymbolTable<ELFT>::findAll(StringRef GlobPat) {
Rui Ueyama48e42512016-06-29 04:47:39 +0000454 std::vector<SymbolBody *> Res;
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000455 StringMatcher M({GlobPat});
Rui Ueyamad6328522016-07-18 01:34:57 +0000456 for (Symbol *Sym : SymVector) {
457 SymbolBody *B = Sym->body();
George Rimarc91930a2016-09-02 21:17:20 +0000458 StringRef Name = B->getName();
Rui Ueyamaf91282e2016-11-03 17:57:38 +0000459 if (!B->isUndefined() && M.match(Name))
Rui Ueyama48e42512016-06-29 04:47:39 +0000460 Res.push_back(B);
461 }
462 return Res;
Davide Italiano8e1131d2016-06-29 02:46:51 +0000463}
464
465template <class ELFT>
Rui Ueyama818bb2f2016-07-16 18:55:47 +0000466void SymbolTable<ELFT>::addLazyArchive(ArchiveFile *F,
467 const object::Archive::Symbol Sym) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000468 Symbol *S;
469 bool WasInserted;
Rui Ueyamadace8382016-07-21 13:13:21 +0000470 StringRef Name = Sym.getName();
471 std::tie(S, WasInserted) = insert(Name);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000472 if (WasInserted) {
Rafael Espindola07543a82016-06-14 21:40:23 +0000473 replaceBody<LazyArchive>(S, *F, Sym, SymbolBody::UnknownType);
Rui Ueyamac5b95122015-12-16 23:23:14 +0000474 return;
475 }
Peter Collingbourne4f952702016-05-01 04:55:03 +0000476 if (!S->body()->isUndefined())
477 return;
Rui Ueyamac5b95122015-12-16 23:23:14 +0000478
Peter Collingbourne4f952702016-05-01 04:55:03 +0000479 // Weak undefined symbols should not fetch members from archives. If we were
480 // to keep old symbol we would not know that an archive member was available
481 // if a strong undefined symbol shows up afterwards in the link. If a strong
482 // undefined symbol never shows up, this lazy symbol will get to the end of
483 // the link and must be treated as the weak undefined one. We already marked
484 // this symbol as used when we added it to the symbol table, but we also need
485 // to preserve its type. FIXME: Move the Type field to Symbol.
486 if (S->isWeak()) {
Rafael Espindola07543a82016-06-14 21:40:23 +0000487 replaceBody<LazyArchive>(S, *F, Sym, S->body()->Type);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000488 return;
489 }
Davide Italianobcdd6c62016-10-12 19:35:54 +0000490 std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
491 if (!MBInfo.first.getBuffer().empty())
Rui Ueyama55518e72016-10-28 20:57:25 +0000492 addFile(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
Peter Collingbourne4f952702016-05-01 04:55:03 +0000493}
494
495template <class ELFT>
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000496void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
Peter Collingbourne4f952702016-05-01 04:55:03 +0000497 Symbol *S;
498 bool WasInserted;
499 std::tie(S, WasInserted) = insert(Name);
500 if (WasInserted) {
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000501 replaceBody<LazyObject>(S, Name, Obj, SymbolBody::UnknownType);
Peter Collingbourne4f952702016-05-01 04:55:03 +0000502 return;
503 }
504 if (!S->body()->isUndefined())
505 return;
506
507 // See comment for addLazyArchive above.
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000508 if (S->isWeak()) {
509 replaceBody<LazyObject>(S, Name, Obj, S->body()->Type);
510 } else {
511 MemoryBufferRef MBRef = Obj.getBuffer();
512 if (!MBRef.getBuffer().empty())
Rui Ueyama55518e72016-10-28 20:57:25 +0000513 addFile(createObjectFile(MBRef));
Rafael Espindola65c65ce2016-06-14 21:56:36 +0000514 }
Michael J. Spencer84487f12015-07-24 21:03:07 +0000515}
Rafael Espindola0e604f92015-09-25 18:56:53 +0000516
Peter Collingbourne892d49802016-04-27 00:05:03 +0000517// Process undefined (-u) flags by loading lazy symbols named by those flags.
Peter Collingbourne4f952702016-05-01 04:55:03 +0000518template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
Peter Collingbourne892d49802016-04-27 00:05:03 +0000519 for (StringRef S : Config->Undefined)
Peter Collingbourne4f952702016-05-01 04:55:03 +0000520 if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
Rui Ueyama55518e72016-10-28 20:57:25 +0000521 if (InputFile *File = L->fetch())
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000522 addFile(File);
Peter Collingbourne892d49802016-04-27 00:05:03 +0000523}
524
Rui Ueyama93bfee52015-10-13 18:10:33 +0000525// This function takes care of the case in which shared libraries depend on
526// the user program (not the other way, which is usual). Shared libraries
527// may have undefined symbols, expecting that the user program provides
528// the definitions for them. An example is BSD's __progname symbol.
529// We need to put such symbols to the main program's .dynsym so that
530// shared libraries can find them.
531// Except this, we ignore undefined symbols in DSOs.
532template <class ELFT> void SymbolTable<ELFT>::scanShlibUndefined() {
Rui Ueyama38dbd3e2016-09-14 00:05:51 +0000533 for (SharedFile<ELFT> *File : SharedFiles)
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000534 for (StringRef U : File->getUndefinedSymbols())
535 if (SymbolBody *Sym = find(U))
536 if (Sym->isDefined())
Peter Collingbourne4f952702016-05-01 04:55:03 +0000537 Sym->symbol()->ExportDynamic = true;
Rui Ueyamaf8432d92015-10-13 16:34:14 +0000538}
539
Rui Ueyamadad2b882016-09-02 22:15:08 +0000540// This function processes --export-dynamic-symbol and --dynamic-list.
Adhemerval Zanella9df07202016-04-13 18:51:11 +0000541template <class ELFT> void SymbolTable<ELFT>::scanDynamicList() {
542 for (StringRef S : Config->DynamicList)
543 if (SymbolBody *B = find(S))
Peter Collingbourne4f952702016-05-01 04:55:03 +0000544 B->symbol()->ExportDynamic = true;
Adhemerval Zanella9df07202016-04-13 18:51:11 +0000545}
546
Rui Ueyama82492142016-11-15 18:41:52 +0000547// Initialize DemangledSyms with a map from demangled symbols to symbol
548// objects. Used to handle "extern C++" directive in version scripts.
549//
550// The map will contain all demangled symbols. That can be very large,
551// and in LLD we generally want to avoid do anything for each symbol.
552// Then, why are we doing this? Here's why.
553//
554// Users can use "extern C++ {}" directive to match against demangled
555// C++ symbols. For example, you can write a pattern such as
556// "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
557// other than trying to match a pattern against all demangled symbols.
558// So, if "extern C++" feature is used, we need to demangle all known
559// symbols.
George Rimar50dcece2016-07-16 12:26:39 +0000560template <class ELFT>
Rui Ueyama82492142016-11-15 18:41:52 +0000561void SymbolTable<ELFT>::initDemangledSyms() {
562 if (DemangledSyms)
563 return;
564 DemangledSyms.emplace();
565
Rui Ueyamad6328522016-07-18 01:34:57 +0000566 for (Symbol *Sym : SymVector) {
567 SymbolBody *B = Sym->body();
Rui Ueyama82492142016-11-15 18:41:52 +0000568 (*DemangledSyms)[demangle(B->getName())].push_back(B);
Rui Ueyamad6328522016-07-18 01:34:57 +0000569 }
George Rimar50dcece2016-07-16 12:26:39 +0000570}
571
Rui Ueyama82492142016-11-15 18:41:52 +0000572template <class ELFT>
573ArrayRef<SymbolBody *> SymbolTable<ELFT>::findDemangled(StringRef Name) {
574 initDemangledSyms();
575 auto I = DemangledSyms->find(Name);
576 if (I != DemangledSyms->end())
George Rimarc3ec9d02016-08-30 09:29:37 +0000577 return I->second;
George Rimar31c25ae2016-09-15 12:44:38 +0000578 return {};
George Rimarc3ec9d02016-08-30 09:29:37 +0000579}
580
Rui Ueyama82492142016-11-15 18:41:52 +0000581template <class ELFT>
582std::vector<SymbolBody *>
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000583SymbolTable<ELFT>::findAllDemangled(StringRef GlobPat) {
Rui Ueyama82492142016-11-15 18:41:52 +0000584 initDemangledSyms();
George Rimar397cd87a2016-08-30 09:35:03 +0000585 std::vector<SymbolBody *> Res;
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000586 StringMatcher M({GlobPat});
Rui Ueyama82492142016-11-15 18:41:52 +0000587 for (auto &P : *DemangledSyms)
588 if (M.match(P.first()))
George Rimar31c25ae2016-09-15 12:44:38 +0000589 for (SymbolBody *Body : P.second)
590 if (!Body->isUndefined())
591 Res.push_back(Body);
George Rimar397cd87a2016-08-30 09:35:03 +0000592 return Res;
593}
594
Rui Ueyamaea265042016-09-13 20:51:30 +0000595// If there's only one anonymous version definition in a version
George Rimar92ca6f42016-11-14 09:56:35 +0000596// script file, the script does not actually define any symbol version,
Rui Ueyamaea265042016-09-13 20:51:30 +0000597// but just specifies symbols visibilities. We assume that the script was
598// in the form of { global: foo; bar; local *; }. So, local is default.
599// In this function, we make specified symbols global.
600template <class ELFT> void SymbolTable<ELFT>::handleAnonymousVersion() {
Rui Ueyamabaf7ee32016-11-15 17:51:09 +0000601 for (SymbolVersion &Ver : Config->VersionScriptGlobals) {
602 if (hasWildcard(Ver.Name)) {
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000603 for (SymbolBody *B : findAll(Ver.Name))
Rui Ueyama77d917d2016-11-17 03:19:34 +0000604 B->symbol()->VersionId = VER_NDX_GLOBAL;
Rui Ueyamaea265042016-09-13 20:51:30 +0000605 continue;
606 }
Rui Ueyamabaf7ee32016-11-15 17:51:09 +0000607 if (SymbolBody *B = find(Ver.Name))
Rui Ueyamaea265042016-09-13 20:51:30 +0000608 B->symbol()->VersionId = VER_NDX_GLOBAL;
609 }
Rui Ueyamaea265042016-09-13 20:51:30 +0000610}
611
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000612// Set symbol versions to symbols. This function handles patterns
613// containing no wildcard characters.
614template <class ELFT>
Rui Ueyamada805c42016-11-17 03:39:21 +0000615void SymbolTable<ELFT>::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000616 StringRef VersionName) {
Rui Ueyama8980c922016-11-18 06:30:08 +0000617 if (Ver.HasWildcard)
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000618 return;
619
620 // Get a list of symbols which we need to assign the version to.
621 std::vector<SymbolBody *> Syms;
622 if (Ver.IsExternCpp)
623 Syms = findDemangled(Ver.Name);
624 else
625 Syms.push_back(find(Ver.Name));
626
627 // Assign the version.
628 for (SymbolBody *B : Syms) {
629 if (!B || B->isUndefined()) {
630 if (Config->NoUndefinedVersion)
Rui Ueyamad84124f2016-11-17 19:57:47 +0000631 error("version script assignment of '" + VersionName + "' to symbol '" +
632 Ver.Name + "' failed: symbol not defined");
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000633 continue;
634 }
635
636 if (B->symbol()->VersionId != Config->DefaultSymbolVersion)
Rui Ueyamaaade0e22016-11-17 03:32:41 +0000637 warn("duplicate symbol '" + Ver.Name + "' in version script");
Rui Ueyama94bcfae2016-11-17 02:09:42 +0000638 B->symbol()->VersionId = VersionId;
639 }
640}
641
Rui Ueyama82492142016-11-15 18:41:52 +0000642template <class ELFT>
643void SymbolTable<ELFT>::assignWildcardVersion(SymbolVersion Ver,
Rui Ueyamada805c42016-11-17 03:39:21 +0000644 uint16_t VersionId) {
Rui Ueyama8980c922016-11-18 06:30:08 +0000645 if (!Ver.HasWildcard)
Rui Ueyama82492142016-11-15 18:41:52 +0000646 return;
Rui Ueyama82492142016-11-15 18:41:52 +0000647 std::vector<SymbolBody *> Syms =
Rui Ueyamabac1c3c2016-11-17 16:48:53 +0000648 Ver.IsExternCpp ? findAllDemangled(Ver.Name) : findAll(Ver.Name);
Rui Ueyama82492142016-11-15 18:41:52 +0000649
650 // Exact matching takes precendence over fuzzy matching,
651 // so we set a version to a symbol only if no version has been assigned
652 // to the symbol. This behavior is compatible with GNU.
653 for (SymbolBody *B : Syms)
654 if (B->symbol()->VersionId == Config->DefaultSymbolVersion)
655 B->symbol()->VersionId = VersionId;
656}
657
Rui Ueyamadad2b882016-09-02 22:15:08 +0000658// This function processes version scripts by updating VersionId
659// member of symbols.
Peter Collingbourne66ac1d62016-04-22 20:21:26 +0000660template <class ELFT> void SymbolTable<ELFT>::scanVersionScript() {
Rui Ueyama35fa6c52016-11-23 05:48:40 +0000661 // Symbol themselves might know their versions because symbols
662 // can contain versions in the form of <name>@<version>.
663 // Let them parse their names.
664 if (!Config->VersionDefinitions.empty())
665 for (Symbol *Sym : SymVector)
666 Sym->body()->parseSymbolVersion();
667
Rui Ueyamaea265042016-09-13 20:51:30 +0000668 // Handle edge cases first.
George Rimard3566302016-06-20 11:55:12 +0000669 if (!Config->VersionScriptGlobals.empty()) {
Rui Ueyamaea265042016-09-13 20:51:30 +0000670 handleAnonymousVersion();
George Rimard3566302016-06-20 11:55:12 +0000671 return;
672 }
673
Rui Ueyamaaf469d42016-07-16 04:09:27 +0000674 if (Config->VersionDefinitions.empty())
George Rimarf73a2582016-07-07 07:45:27 +0000675 return;
676
Rui Ueyamadad2b882016-09-02 22:15:08 +0000677 // Now we have version definitions, so we need to set version ids to symbols.
678 // Each version definition has a glob pattern, and all symbols that match
679 // with the pattern get that version.
680
Rui Ueyamadad2b882016-09-02 22:15:08 +0000681 // First, we assign versions to exact matching symbols,
682 // i.e. version definitions not containing any glob meta-characters.
Rui Ueyama96db27c2016-11-17 19:57:45 +0000683 for (SymbolVersion &Ver : Config->VersionScriptLocals)
684 assignExactVersion(Ver, VER_NDX_LOCAL, "local");
George Rimar17c65af2016-11-16 18:46:23 +0000685 for (VersionDefinition &V : Config->VersionDefinitions)
Rui Ueyama96db27c2016-11-17 19:57:45 +0000686 for (SymbolVersion &Ver : V.Globals)
687 assignExactVersion(Ver, V.Id, V.Name);
George Rimarf73a2582016-07-07 07:45:27 +0000688
Rui Ueyamadad2b882016-09-02 22:15:08 +0000689 // Next, we assign versions to fuzzy matching symbols,
690 // i.e. version definitions containing glob meta-characters.
691 // Note that because the last match takes precedence over previous matches,
692 // we iterate over the definitions in the reverse order.
George Rimar17c65af2016-11-16 18:46:23 +0000693 for (SymbolVersion &Ver : Config->VersionScriptLocals)
694 assignWildcardVersion(Ver, VER_NDX_LOCAL);
Rui Ueyamacd236a92016-11-17 19:57:43 +0000695 for (VersionDefinition &V : llvm::reverse(Config->VersionDefinitions))
696 for (SymbolVersion &Ver : V.Globals)
697 assignWildcardVersion(Ver, V.Id);
Peter Collingbourne66ac1d62016-04-22 20:21:26 +0000698}
699
Rafael Espindolae0df00b2016-02-28 00:25:54 +0000700template class elf::SymbolTable<ELF32LE>;
701template class elf::SymbolTable<ELF32BE>;
702template class elf::SymbolTable<ELF64LE>;
703template class elf::SymbolTable<ELF64BE>;