annotate lld/MachO/SymbolTable.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===- SymbolTable.cpp ----------------------------------------------------===//
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #include "SymbolTable.h"
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
10 #include "Config.h"
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "InputFiles.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "Symbols.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "lld/Common/ErrorHandler.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "lld/Common/Memory.h"
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 using namespace llvm;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 using namespace lld;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 using namespace lld::macho;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
20 Symbol *SymbolTable::find(CachedHashStringRef cachedName) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
21 auto it = symMap.find(cachedName);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 if (it == symMap.end())
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 return nullptr;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 return symVector[it->second];
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
27 std::pair<Symbol *, bool> SymbolTable::insert(StringRef name,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
28 const InputFile *file) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 auto p = symMap.insert({CachedHashStringRef(name), (int)symVector.size()});
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
31 Symbol *sym;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
32 if (!p.second) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
33 // Name already present in the symbol table.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
34 sym = symVector[p.first->second];
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
35 } else {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
36 // Name is a new symbol.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
37 sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
38 symVector.push_back(sym);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
39 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
41 sym->isUsedInRegularObj |= !file || isa<ObjFile>(file);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
42 return {sym, p.second};
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
45 Defined *SymbolTable::addDefined(StringRef name, InputFile *file,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
46 InputSection *isec, uint64_t value,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
47 uint64_t size, bool isWeakDef,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
48 bool isPrivateExtern, bool isThumb,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
49 bool isReferencedDynamically,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
50 bool noDeadStrip) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 Symbol *s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 bool wasInserted;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
53 bool overridesWeakDef = false;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
54 std::tie(s, wasInserted) = insert(name, file);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
56 assert(!isWeakDef || (isa<BitcodeFile>(file) && !isec) ||
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
57 (isa<ObjFile>(file) && file == isec->file));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
58
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
59 if (!wasInserted) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
60 if (auto *defined = dyn_cast<Defined>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
61 if (isWeakDef) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
62 if (defined->isWeakDef()) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
63 // Both old and new symbol weak (e.g. inline function in two TUs):
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
64 // If one of them isn't private extern, the merged symbol isn't.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
65 defined->privateExtern &= isPrivateExtern;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
66 defined->referencedDynamically |= isReferencedDynamically;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
67 defined->noDeadStrip |= noDeadStrip;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
68
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
69 // FIXME: Handle this for bitcode files.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
70 // FIXME: We currently only do this if both symbols are weak.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
71 // We could do this if either is weak (but getting the
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
72 // case where !isWeakDef && defined->isWeakDef() right
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
73 // requires some care and testing).
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
74 if (isec)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
75 isec->wasCoalesced = true;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
76 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
78 return defined;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
79 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
80 if (!defined->isWeakDef())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
81 error("duplicate symbol: " + name + "\n>>> defined in " +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
82 toString(defined->getFile()) + "\n>>> defined in " +
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
83 toString(file));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
84 } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
85 overridesWeakDef = !isWeakDef && dysym->isWeakDef();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
86 dysym->unreference();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
87 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
88 // Defined symbols take priority over other types of symbols, so in case
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
89 // of a name conflict, we fall through to the replaceSymbol() call below.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
90 }
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
92 Defined *defined = replaceSymbol<Defined>(
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
93 s, name, file, isec, value, size, isWeakDef, /*isExternal=*/true,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
94 isPrivateExtern, isThumb, isReferencedDynamically, noDeadStrip);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
95 defined->overridesWeakDef = overridesWeakDef;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
96 return defined;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
97 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
98
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
99 Symbol *SymbolTable::addUndefined(StringRef name, InputFile *file,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
100 bool isWeakRef) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
101 Symbol *s;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
102 bool wasInserted;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
103 std::tie(s, wasInserted) = insert(name, file);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
104
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
105 RefState refState = isWeakRef ? RefState::Weak : RefState::Strong;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
106
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
107 if (wasInserted)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
108 replaceSymbol<Undefined>(s, name, file, refState);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
109 else if (auto *lazy = dyn_cast<LazySymbol>(s))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
110 lazy->fetchArchiveMember();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
111 else if (auto *dynsym = dyn_cast<DylibSymbol>(s))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
112 dynsym->reference(refState);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
113 else if (auto *undefined = dyn_cast<Undefined>(s))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
114 undefined->refState = std::max(undefined->refState, refState);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 return s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
118 Symbol *SymbolTable::addCommon(StringRef name, InputFile *file, uint64_t size,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
119 uint32_t align, bool isPrivateExtern) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 Symbol *s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 bool wasInserted;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
122 std::tie(s, wasInserted) = insert(name, file);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
124 if (!wasInserted) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
125 if (auto *common = dyn_cast<CommonSymbol>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
126 if (size < common->size)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
127 return s;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
128 } else if (isa<Defined>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
129 return s;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
130 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
131 // Common symbols take priority over all non-Defined symbols, so in case of
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
132 // a name conflict, we fall through to the replaceSymbol() call below.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
133 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
134
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
135 replaceSymbol<CommonSymbol>(s, name, file, size, align, isPrivateExtern);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 return s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
139 Symbol *SymbolTable::addDylib(StringRef name, DylibFile *file, bool isWeakDef,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
140 bool isTlv) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 Symbol *s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 bool wasInserted;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
143 std::tie(s, wasInserted) = insert(name, file);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
145 RefState refState = RefState::Unreferenced;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
146 if (!wasInserted) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
147 if (auto *defined = dyn_cast<Defined>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
148 if (isWeakDef && !defined->isWeakDef())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
149 defined->overridesWeakDef = true;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
150 } else if (auto *undefined = dyn_cast<Undefined>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
151 refState = undefined->refState;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
152 } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
153 refState = dysym->getRefState();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
154 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
155 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
156
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
157 bool isDynamicLookup = file == nullptr;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
158 if (wasInserted || isa<Undefined>(s) ||
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
159 (isa<DylibSymbol>(s) &&
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
160 ((!isWeakDef && s->isWeakDef()) ||
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
161 (!isDynamicLookup && cast<DylibSymbol>(s)->isDynamicLookup())))) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
162 if (auto *dynsym = dyn_cast<DylibSymbol>(s))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
163 dynsym->unreference();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
164 replaceSymbol<DylibSymbol>(s, file, name, isWeakDef, refState, isTlv);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
165 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
166
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 return s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
170 Symbol *SymbolTable::addDynamicLookup(StringRef name) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
171 return addDylib(name, /*file=*/nullptr, /*isWeakDef=*/false, /*isTlv=*/false);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
172 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
173
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 Symbol *SymbolTable::addLazy(StringRef name, ArchiveFile *file,
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
175 const object::Archive::Symbol &sym) {
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 Symbol *s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 bool wasInserted;
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
178 std::tie(s, wasInserted) = insert(name, file);
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 if (wasInserted)
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 replaceSymbol<LazySymbol>(s, file, sym);
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
182 else if (isa<Undefined>(s) || (isa<DylibSymbol>(s) && s->isWeakDef()))
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 file->fetch(sym);
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 return s;
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 }
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
187 Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
188 uint64_t value, bool isPrivateExtern,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
189 bool includeInSymtab,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
190 bool referencedDynamically) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
191 Defined *s = addDefined(name, nullptr, isec, value, /*size=*/0,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
192 /*isWeakDef=*/false, isPrivateExtern,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
193 /*isThumb=*/false, referencedDynamically,
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
194 /*noDeadStrip=*/false);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
195 s->includeInSymtab = includeInSymtab;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
196 return s;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
197 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
198
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
199 void lld::macho::treatUndefinedSymbol(const Undefined &sym, StringRef source) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
200 auto message = [source, &sym]() {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
201 std::string message = "undefined symbol: " + toString(sym);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
202 if (!source.empty())
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
203 message += "\n>>> referenced by " + source.str();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
204 else
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
205 message += "\n>>> referenced by " + toString(sym.getFile());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
206 return message;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
207 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
208 switch (config->undefinedSymbolTreatment) {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
209 case UndefinedSymbolTreatment::error:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
210 error(message());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
211 break;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
212 case UndefinedSymbolTreatment::warning:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
213 warn(message());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
214 LLVM_FALLTHROUGH;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
215 case UndefinedSymbolTreatment::dynamic_lookup:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
216 case UndefinedSymbolTreatment::suppress:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
217 symtab->addDynamicLookup(sym.getName());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
218 break;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
219 case UndefinedSymbolTreatment::unknown:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
220 llvm_unreachable("unknown -undefined TREATMENT");
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
221 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
222 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 173
diff changeset
223
173
0572611fdcc8 reorgnization done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 SymbolTable *macho::symtab;