blob: d264cb78d958d79eb2bcba243f2986a77b33d1e1 [file] [log] [blame]
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00001//===- Core/SymbolTable.cpp - Main Symbol Table ---------------------------===//
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//===----------------------------------------------------------------------===//
9
10#include "lld/Core/SymbolTable.h"
Nick Kledzik6bc04c62012-02-22 21:56:59 +000011#include "lld/Core/AbsoluteAtom.h"
Michael J. Spencer4586fbc2013-01-22 20:49:42 +000012#include "lld/Core/Atom.h"
Michael J. Spencercfd029f2012-03-28 19:04:02 +000013#include "lld/Core/DefinedAtom.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000014#include "lld/Core/File.h"
Michael J. Spencere6203a52012-04-03 18:39:40 +000015#include "lld/Core/LLVM.h"
Shankar Easwaran2b67fca2014-10-18 05:33:55 +000016#include "lld/Core/LinkingContext.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000017#include "lld/Core/Resolver.h"
Michael J. Spencercfd029f2012-03-28 19:04:02 +000018#include "lld/Core/SharedLibraryAtom.h"
19#include "lld/Core/UndefinedAtom.h"
Nick Kledzikbfedfc12012-01-09 20:18:15 +000020#include "llvm/ADT/ArrayRef.h"
Michael J. Spencercfd029f2012-03-28 19:04:02 +000021#include "llvm/ADT/DenseMapInfo.h"
Michael J. Spencer67f25272013-03-20 22:18:22 +000022#include "llvm/ADT/Hashing.h"
Michael J. Spencercfd029f2012-03-28 19:04:02 +000023#include "llvm/Support/ErrorHandling.h"
Nick Kledzikbb963df2012-04-18 21:55:06 +000024#include "llvm/Support/raw_ostream.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000025#include <algorithm>
26#include <cassert>
Michael J. Spencercfd029f2012-03-28 19:04:02 +000027#include <cstdlib>
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000028#include <vector>
29
30namespace lld {
Simon Atanasyan07000872014-09-08 09:43:38 +000031SymbolTable::SymbolTable(LinkingContext &context) : _context(context) {}
Nick Kledzik38eec3d2011-12-22 02:38:01 +000032
Rui Ueyama2a522512014-05-14 17:29:27 +000033bool SymbolTable::add(const UndefinedAtom &atom) { return addByName(atom); }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000034
Rui Ueyama2a522512014-05-14 17:29:27 +000035bool SymbolTable::add(const SharedLibraryAtom &atom) { return addByName(atom); }
Michael J. Spencer765792d2012-04-03 18:40:27 +000036
Rui Ueyama2a522512014-05-14 17:29:27 +000037bool SymbolTable::add(const AbsoluteAtom &atom) { return addByName(atom); }
Nick Kledzik6bc04c62012-02-22 21:56:59 +000038
Rui Ueyama2a522512014-05-14 17:29:27 +000039bool SymbolTable::add(const DefinedAtom &atom) {
Shankar Easwaran8962feb2013-03-14 16:09:49 +000040 if (!atom.name().empty() &&
Rui Ueyama8b08c372013-11-25 17:09:29 +000041 atom.scope() != DefinedAtom::scopeTranslationUnit) {
Nick Kledzik233f5372013-01-15 00:17:57 +000042 // Named atoms cannot be merged by content.
43 assert(atom.merge() != DefinedAtom::mergeByContent);
44 // Track named atoms that are not scoped to file (static).
Rui Ueyama2a522512014-05-14 17:29:27 +000045 return addByName(atom);
Rui Ueyama8b08c372013-11-25 17:09:29 +000046 }
47 if (atom.merge() == DefinedAtom::mergeByContent) {
Nick Kledzik233f5372013-01-15 00:17:57 +000048 // Named atoms cannot be merged by content.
49 assert(atom.name().empty());
Nick Kledzik388f3d02014-05-28 01:16:35 +000050 // Currently only read-only constants can be merged.
51 if (atom.permissions() == DefinedAtom::permR__)
52 return addByContent(atom);
53 // TODO: support mergeByContent of data atoms by comparing content & fixups.
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000054 }
Rui Ueyama2a522512014-05-14 17:29:27 +000055 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000056}
57
Shankar Easwaran7ac2a3d2014-03-26 16:37:13 +000058const Atom *SymbolTable::findGroup(StringRef sym) {
59 NameToAtom::iterator pos = _groupTable.find(sym);
60 if (pos == _groupTable.end())
61 return nullptr;
62 return pos->second;
63}
64
65bool SymbolTable::addGroup(const DefinedAtom &da) {
66 StringRef name = da.name();
67 assert(!name.empty());
68 const Atom *existing = findGroup(name);
69 if (existing == nullptr) {
70 _groupTable[name] = &da;
71 return true;
72 }
73 _replacedAtoms[&da] = existing;
74 return false;
75}
76
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000077enum NameCollisionResolution {
78 NCR_First,
79 NCR_Second,
Nick Kledzik6bc04c62012-02-22 21:56:59 +000080 NCR_DupDef,
81 NCR_DupUndef,
82 NCR_DupShLib,
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000083 NCR_Error
84};
85
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000086static NameCollisionResolution cases[4][4] = {
87 //regular absolute undef sharedLib
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000088 {
89 // first is regular
Nick Kledzik6bc04c62012-02-22 21:56:59 +000090 NCR_DupDef, NCR_Error, NCR_First, NCR_First
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000091 },
92 {
93 // first is absolute
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000094 NCR_Error, NCR_Error, NCR_First, NCR_First
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000095 },
96 {
97 // first is undef
Nick Kledzik6bc04c62012-02-22 21:56:59 +000098 NCR_Second, NCR_Second, NCR_DupUndef, NCR_Second
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000099 },
100 {
101 // first is sharedLib
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000102 NCR_Second, NCR_Second, NCR_First, NCR_DupShLib
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000103 }
104};
105
106static NameCollisionResolution collide(Atom::Definition first,
107 Atom::Definition second) {
108 return cases[first][second];
109}
110
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000111enum MergeResolution {
112 MCR_First,
113 MCR_Second,
114 MCR_Largest,
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000115 MCR_SameSize,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000116 MCR_Error
117};
118
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000119static MergeResolution mergeCases[][6] = {
120 // no tentative weak weakAddress sameNameAndSize largest
121 {MCR_Error, MCR_First, MCR_First, MCR_First, MCR_SameSize, MCR_Largest}, // no
122 {MCR_Second, MCR_Largest, MCR_Second, MCR_Second, MCR_SameSize, MCR_Largest}, // tentative
123 {MCR_Second, MCR_First, MCR_First, MCR_Second, MCR_SameSize, MCR_Largest}, // weak
124 {MCR_Second, MCR_First, MCR_First, MCR_First, MCR_SameSize, MCR_Largest}, // weakAddress
125 {MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize}, // sameSize
126 {MCR_Largest, MCR_Largest, MCR_Largest, MCR_Largest, MCR_SameSize, MCR_Largest}, // largest
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000127};
128
Michael J. Spencer765792d2012-04-03 18:40:27 +0000129static MergeResolution mergeSelect(DefinedAtom::Merge first,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000130 DefinedAtom::Merge second) {
Rui Ueyama7caea312014-03-08 00:44:01 +0000131 assert(first != DefinedAtom::mergeByContent);
132 assert(second != DefinedAtom::mergeByContent);
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000133 return mergeCases[first][second];
134}
135
Rui Ueyama2a522512014-05-14 17:29:27 +0000136bool SymbolTable::addByName(const Atom &newAtom) {
Michael J. Spencere6203a52012-04-03 18:39:40 +0000137 StringRef name = newAtom.name();
Nick Kledzik233f5372013-01-15 00:17:57 +0000138 assert(!name.empty());
Shankar Easwaran7ac2a3d2014-03-26 16:37:13 +0000139 const Atom *existing = findByName(name);
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000140 if (existing == nullptr) {
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000141 // Name is not in symbol table yet, add it associate with this atom.
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000142 _context.notifySymbolTableAdd(&newAtom);
Nick Kledzik38eec3d2011-12-22 02:38:01 +0000143 _nameTable[name] = &newAtom;
Rui Ueyama2a522512014-05-14 17:29:27 +0000144 return true;
Michael J. Spencer765792d2012-04-03 18:40:27 +0000145 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000146
Rui Ueyama2a522512014-05-14 17:29:27 +0000147 // Do nothing if the same object is added more than once.
148 if (existing == &newAtom)
149 return false;
150
Rui Ueyamaf347e752013-11-13 23:22:00 +0000151 // Name is already in symbol table and associated with another atom.
152 bool useNew = true;
153 switch (collide(existing->definition(), newAtom.definition())) {
154 case NCR_First:
155 useNew = false;
156 break;
157 case NCR_Second:
158 useNew = true;
159 break;
Simon Atanasyan55c26992014-11-14 07:15:43 +0000160 case NCR_DupDef: {
161 const auto *existingDef = cast<DefinedAtom>(existing);
162 const auto *newDef = cast<DefinedAtom>(&newAtom);
163 switch (mergeSelect(existingDef->merge(), newDef->merge())) {
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000164 case MCR_First:
165 useNew = false;
166 break;
167 case MCR_Second:
168 useNew = true;
169 break;
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000170 case MCR_Largest: {
Rui Ueyama77a4da12015-03-04 21:40:46 +0000171 uint64_t existingSize = existingDef->sectionSize();
172 uint64_t newSize = newDef->sectionSize();
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000173 useNew = (newSize >= existingSize);
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000174 break;
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000175 }
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000176 case MCR_SameSize: {
Rui Ueyama77a4da12015-03-04 21:40:46 +0000177 uint64_t existingSize = existingDef->sectionSize();
178 uint64_t newSize = newDef->sectionSize();
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000179 if (existingSize == newSize) {
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000180 useNew = true;
181 break;
182 }
183 llvm::errs() << "Size mismatch: "
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000184 << existing->name() << " (" << existingSize << ") "
185 << newAtom.name() << " (" << newSize << ")\n";
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000186 // fallthrough
187 }
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000188 case MCR_Error:
Rui Ueyamaa9a51292014-03-28 16:26:38 +0000189 if (!_context.getAllowDuplicates()) {
190 llvm::errs() << "Duplicate symbols: "
191 << existing->name()
192 << ":"
193 << existing->file().path()
194 << " and "
195 << newAtom.name()
196 << ":"
197 << newAtom.file().path()
198 << "\n";
199 llvm::report_fatal_error("duplicate symbol error");
200 }
201 useNew = false;
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000202 break;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000203 }
204 break;
Simon Atanasyan55c26992014-11-14 07:15:43 +0000205 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000206 case NCR_DupUndef: {
Rui Ueyama01cc7182014-04-04 18:21:51 +0000207 const UndefinedAtom* existingUndef = cast<UndefinedAtom>(existing);
208 const UndefinedAtom* newUndef = cast<UndefinedAtom>(&newAtom);
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000209
210 bool sameCanBeNull = (existingUndef->canBeNull() == newUndef->canBeNull());
211 if (!sameCanBeNull &&
212 _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
213 llvm::errs() << "lld warning: undefined symbol "
214 << existingUndef->name()
215 << " has different weakness in "
216 << existingUndef->file().path()
217 << " and in " << newUndef->file().path() << "\n";
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000218 }
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000219
220 const UndefinedAtom *existingFallback = existingUndef->fallback();
221 const UndefinedAtom *newFallback = newUndef->fallback();
222 bool hasDifferentFallback =
223 (existingFallback && newFallback &&
224 existingFallback->name() != newFallback->name());
225 if (hasDifferentFallback) {
226 llvm::errs() << "lld warning: undefined symbol "
227 << existingUndef->name() << " has different fallback: "
228 << existingFallback->name() << " in "
229 << existingUndef->file().path() << " and "
230 << newFallback->name() << " in "
231 << newUndef->file().path() << "\n";
232 }
233
234 bool hasNewFallback = newUndef->fallback();
235 if (sameCanBeNull)
236 useNew = hasNewFallback;
237 else
238 useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
Rui Ueyamaf347e752013-11-13 23:22:00 +0000239 break;
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000240 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000241 case NCR_DupShLib: {
Rui Ueyama01cc7182014-04-04 18:21:51 +0000242 const SharedLibraryAtom *curShLib = cast<SharedLibraryAtom>(existing);
243 const SharedLibraryAtom *newShLib = cast<SharedLibraryAtom>(&newAtom);
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000244 bool sameNullness =
245 (curShLib->canBeNullAtRuntime() == newShLib->canBeNullAtRuntime());
246 bool sameName = curShLib->loadName().equals(newShLib->loadName());
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000247 if (sameName && !sameNullness &&
248 _context.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
249 // FIXME: need diagonstics interface for writing warning messages
250 llvm::errs() << "lld warning: shared library symbol "
251 << curShLib->name() << " has different weakness in "
252 << curShLib->file().path() << " and in "
253 << newShLib->file().path();
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000254 }
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000255 if (!sameName && _context.warnIfCoalesableAtomsHaveDifferentLoadName()) {
256 // FIXME: need diagonstics interface for writing warning messages
257 llvm::errs() << "lld warning: shared library symbol "
258 << curShLib->name() << " has different load path in "
259 << curShLib->file().path() << " and in "
260 << newShLib->file().path();
261 }
262 useNew = false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000263 break;
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000264 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000265 case NCR_Error:
266 llvm::errs() << "SymbolTable: error while merging " << name << "\n";
Rui Ueyama9310e012013-11-14 06:39:31 +0000267 llvm::report_fatal_error("duplicate symbol error");
268 break;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000269 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000270
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000271 // Give context a chance to change which is kept.
272 _context.notifySymbolTableCoalesce(existing, &newAtom, useNew);
273
Rui Ueyamaf347e752013-11-13 23:22:00 +0000274 if (useNew) {
275 // Update name table to use new atom.
276 _nameTable[name] = &newAtom;
277 // Add existing atom to replacement table.
278 _replacedAtoms[existing] = &newAtom;
279 } else {
280 // New atom is not being used. Add it to replacement table.
281 _replacedAtoms[&newAtom] = existing;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000282 }
Rui Ueyama2a522512014-05-14 17:29:27 +0000283 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000284}
285
Michael J. Spencer67f25272013-03-20 22:18:22 +0000286unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom *atom) {
287 auto content = atom->rawContent();
288 return llvm::hash_combine(atom->size(),
289 atom->contentType(),
290 llvm::hash_combine_range(content.begin(),
291 content.end()));
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000292}
293
Michael J. Spencer765792d2012-04-03 18:40:27 +0000294bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l,
Michael J. Spencer67f25272013-03-20 22:18:22 +0000295 const DefinedAtom * const r) {
Rui Ueyamaf347e752013-11-13 23:22:00 +0000296 if (l == r)
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000297 return true;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000298 if (l == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000299 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000300 if (r == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000301 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000302 if (l == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000303 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000304 if (r == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000305 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000306 if (l->contentType() != r->contentType())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000307 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000308 if (l->size() != r->size())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000309 return false;
Nick Kledzik32d0d092014-10-02 17:22:05 +0000310 if (l->sectionChoice() != r->sectionChoice())
311 return false;
312 if (l->sectionChoice() == DefinedAtom::sectionCustomRequired) {
313 if (!l->customSectionName().equals(r->customSectionName()))
314 return false;
315 }
Michael J. Spencere6203a52012-04-03 18:39:40 +0000316 ArrayRef<uint8_t> lc = l->rawContent();
317 ArrayRef<uint8_t> rc = r->rawContent();
Michael J. Spencer67f25272013-03-20 22:18:22 +0000318 return memcmp(lc.data(), rc.data(), lc.size()) == 0;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000319}
320
Rui Ueyama2a522512014-05-14 17:29:27 +0000321bool SymbolTable::addByContent(const DefinedAtom &newAtom) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000322 AtomContentSet::iterator pos = _contentTable.find(&newAtom);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000323 if (pos == _contentTable.end()) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000324 _contentTable.insert(&newAtom);
Rui Ueyama2a522512014-05-14 17:29:27 +0000325 return true;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000326 }
327 const Atom* existing = *pos;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000328 // New atom is not being used. Add it to replacement table.
329 _replacedAtoms[&newAtom] = existing;
Rui Ueyama2a522512014-05-14 17:29:27 +0000330 return false;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000331}
332
Michael J. Spencere6203a52012-04-03 18:39:40 +0000333const Atom *SymbolTable::findByName(StringRef sym) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000334 NameToAtom::iterator pos = _nameTable.find(sym);
335 if (pos == _nameTable.end())
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000336 return nullptr;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000337 return pos->second;
338}
339
Michael J. Spencere6203a52012-04-03 18:39:40 +0000340bool SymbolTable::isDefined(StringRef sym) {
Rui Ueyama71c02022014-04-03 22:43:42 +0000341 if (const Atom *atom = findByName(sym))
Rui Ueyama0abf6132014-10-14 21:42:08 +0000342 return !isa<UndefinedAtom>(atom);
Rui Ueyama71c02022014-04-03 22:43:42 +0000343 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000344}
345
Rui Ueyamae5416ec2013-09-12 19:14:05 +0000346void SymbolTable::addReplacement(const Atom *replaced,
347 const Atom *replacement) {
348 _replacedAtoms[replaced] = replacement;
349}
350
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000351const Atom *SymbolTable::replacement(const Atom *atom) {
Rui Ueyama1c3486a2014-04-03 22:58:41 +0000352 // Find the replacement for a given atom. Atoms in _replacedAtoms
353 // may be chained, so find the last one.
Rui Ueyama4f010d22014-04-03 22:36:55 +0000354 for (;;) {
355 AtomToAtom::iterator pos = _replacedAtoms.find(atom);
356 if (pos == _replacedAtoms.end())
357 return atom;
Rui Ueyama4f010d22014-04-03 22:36:55 +0000358 atom = pos->second;
359 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000360}
361
Rui Ueyama733b45f2014-06-05 07:37:29 +0000362bool SymbolTable::isCoalescedAway(const Atom *atom) {
363 return _replacedAtoms.count(atom) > 0;
364}
365
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000366unsigned int SymbolTable::size() {
367 return _nameTable.size();
368}
369
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000370std::vector<const UndefinedAtom *> SymbolTable::undefines() {
371 std::vector<const UndefinedAtom *> ret;
Rui Ueyama17e899c2013-11-25 17:09:27 +0000372 for (auto it : _nameTable) {
373 const Atom *atom = it.second;
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000374 assert(atom != nullptr);
Rui Ueyama839fb2f2014-08-22 02:00:58 +0000375 if (const auto *undef = dyn_cast<const UndefinedAtom>(atom))
376 if (_replacedAtoms.count(undef) == 0)
377 ret.push_back(undef);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000378 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000379 return ret;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000380}
381
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000382std::vector<StringRef> SymbolTable::tentativeDefinitions() {
383 std::vector<StringRef> ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000384 for (auto entry : _nameTable) {
385 const Atom *atom = entry.second;
386 StringRef name = entry.first;
387 assert(atom != nullptr);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000388 if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
389 if (defAtom->merge() == DefinedAtom::mergeAsTentative)
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000390 ret.push_back(name);
Nick Kledzik20e652d2012-04-20 01:24:37 +0000391 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000392 return ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000393}
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000394
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000395} // namespace lld