blob: 9382db9af2593aef036d6496d35195a6fa17b2b0 [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 {
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +000031SymbolTable::SymbolTable(LinkingContext &context) : _ctx(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
58enum NameCollisionResolution {
59 NCR_First,
60 NCR_Second,
Nick Kledzik6bc04c62012-02-22 21:56:59 +000061 NCR_DupDef,
62 NCR_DupUndef,
63 NCR_DupShLib,
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000064 NCR_Error
65};
66
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000067static NameCollisionResolution cases[4][4] = {
68 //regular absolute undef sharedLib
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000069 {
70 // first is regular
Nick Kledzik6bc04c62012-02-22 21:56:59 +000071 NCR_DupDef, NCR_Error, NCR_First, NCR_First
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000072 },
73 {
74 // first is absolute
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000075 NCR_Error, NCR_Error, NCR_First, NCR_First
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000076 },
77 {
78 // first is undef
Nick Kledzik6bc04c62012-02-22 21:56:59 +000079 NCR_Second, NCR_Second, NCR_DupUndef, NCR_Second
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000080 },
81 {
82 // first is sharedLib
Nick Kledzik6bc04c62012-02-22 21:56:59 +000083 NCR_Second, NCR_Second, NCR_First, NCR_DupShLib
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000084 }
85};
86
87static NameCollisionResolution collide(Atom::Definition first,
88 Atom::Definition second) {
89 return cases[first][second];
90}
91
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000092enum MergeResolution {
93 MCR_First,
94 MCR_Second,
95 MCR_Largest,
Rui Ueyamac79dd2f2014-03-07 23:05:10 +000096 MCR_SameSize,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +000097 MCR_Error
98};
99
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000100static MergeResolution mergeCases[][6] = {
101 // no tentative weak weakAddress sameNameAndSize largest
102 {MCR_Error, MCR_First, MCR_First, MCR_First, MCR_SameSize, MCR_Largest}, // no
103 {MCR_Second, MCR_Largest, MCR_Second, MCR_Second, MCR_SameSize, MCR_Largest}, // tentative
104 {MCR_Second, MCR_First, MCR_First, MCR_Second, MCR_SameSize, MCR_Largest}, // weak
105 {MCR_Second, MCR_First, MCR_First, MCR_First, MCR_SameSize, MCR_Largest}, // weakAddress
106 {MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize, MCR_SameSize}, // sameSize
107 {MCR_Largest, MCR_Largest, MCR_Largest, MCR_Largest, MCR_SameSize, MCR_Largest}, // largest
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000108};
109
Michael J. Spencer765792d2012-04-03 18:40:27 +0000110static MergeResolution mergeSelect(DefinedAtom::Merge first,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000111 DefinedAtom::Merge second) {
Rui Ueyama7caea312014-03-08 00:44:01 +0000112 assert(first != DefinedAtom::mergeByContent);
113 assert(second != DefinedAtom::mergeByContent);
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000114 return mergeCases[first][second];
115}
116
Rui Ueyama2a522512014-05-14 17:29:27 +0000117bool SymbolTable::addByName(const Atom &newAtom) {
Michael J. Spencere6203a52012-04-03 18:39:40 +0000118 StringRef name = newAtom.name();
Nick Kledzik233f5372013-01-15 00:17:57 +0000119 assert(!name.empty());
Shankar Easwaran7ac2a3d2014-03-26 16:37:13 +0000120 const Atom *existing = findByName(name);
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000121 if (existing == nullptr) {
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000122 // Name is not in symbol table yet, add it associate with this atom.
Nick Kledzik38eec3d2011-12-22 02:38:01 +0000123 _nameTable[name] = &newAtom;
Rui Ueyama2a522512014-05-14 17:29:27 +0000124 return true;
Michael J. Spencer765792d2012-04-03 18:40:27 +0000125 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000126
Rui Ueyama2a522512014-05-14 17:29:27 +0000127 // Do nothing if the same object is added more than once.
128 if (existing == &newAtom)
129 return false;
130
Rui Ueyamaf347e752013-11-13 23:22:00 +0000131 // Name is already in symbol table and associated with another atom.
132 bool useNew = true;
133 switch (collide(existing->definition(), newAtom.definition())) {
134 case NCR_First:
135 useNew = false;
136 break;
137 case NCR_Second:
138 useNew = true;
139 break;
Simon Atanasyan55c26992014-11-14 07:15:43 +0000140 case NCR_DupDef: {
141 const auto *existingDef = cast<DefinedAtom>(existing);
142 const auto *newDef = cast<DefinedAtom>(&newAtom);
143 switch (mergeSelect(existingDef->merge(), newDef->merge())) {
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000144 case MCR_First:
145 useNew = false;
146 break;
147 case MCR_Second:
148 useNew = true;
149 break;
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000150 case MCR_Largest: {
Rui Ueyama77a4da12015-03-04 21:40:46 +0000151 uint64_t existingSize = existingDef->sectionSize();
152 uint64_t newSize = newDef->sectionSize();
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000153 useNew = (newSize >= existingSize);
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000154 break;
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000155 }
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000156 case MCR_SameSize: {
Rui Ueyama77a4da12015-03-04 21:40:46 +0000157 uint64_t existingSize = existingDef->sectionSize();
158 uint64_t newSize = newDef->sectionSize();
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000159 if (existingSize == newSize) {
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000160 useNew = true;
161 break;
162 }
163 llvm::errs() << "Size mismatch: "
Rui Ueyama7ad72eb2014-03-18 19:37:50 +0000164 << existing->name() << " (" << existingSize << ") "
165 << newAtom.name() << " (" << newSize << ")\n";
Rui Ueyamac79dd2f2014-03-07 23:05:10 +0000166 // fallthrough
167 }
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000168 case MCR_Error:
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000169 if (!_ctx.getAllowDuplicates()) {
Rui Ueyamaa9a51292014-03-28 16:26:38 +0000170 llvm::errs() << "Duplicate symbols: "
171 << existing->name()
172 << ":"
173 << existing->file().path()
174 << " and "
175 << newAtom.name()
176 << ":"
177 << newAtom.file().path()
178 << "\n";
179 llvm::report_fatal_error("duplicate symbol error");
180 }
181 useNew = false;
Rui Ueyama5a3804f2013-11-25 17:09:25 +0000182 break;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000183 }
184 break;
Simon Atanasyan55c26992014-11-14 07:15:43 +0000185 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000186 case NCR_DupUndef: {
Rui Ueyama01cc7182014-04-04 18:21:51 +0000187 const UndefinedAtom* existingUndef = cast<UndefinedAtom>(existing);
188 const UndefinedAtom* newUndef = cast<UndefinedAtom>(&newAtom);
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000189
190 bool sameCanBeNull = (existingUndef->canBeNull() == newUndef->canBeNull());
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000191 if (!sameCanBeNull && _ctx.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000192 llvm::errs() << "lld warning: undefined symbol "
193 << existingUndef->name()
194 << " has different weakness in "
195 << existingUndef->file().path()
196 << " and in " << newUndef->file().path() << "\n";
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000197 }
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000198
199 const UndefinedAtom *existingFallback = existingUndef->fallback();
200 const UndefinedAtom *newFallback = newUndef->fallback();
201 bool hasDifferentFallback =
202 (existingFallback && newFallback &&
203 existingFallback->name() != newFallback->name());
204 if (hasDifferentFallback) {
205 llvm::errs() << "lld warning: undefined symbol "
206 << existingUndef->name() << " has different fallback: "
207 << existingFallback->name() << " in "
208 << existingUndef->file().path() << " and "
209 << newFallback->name() << " in "
210 << newUndef->file().path() << "\n";
211 }
212
213 bool hasNewFallback = newUndef->fallback();
214 if (sameCanBeNull)
215 useNew = hasNewFallback;
216 else
217 useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
Rui Ueyamaf347e752013-11-13 23:22:00 +0000218 break;
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000219 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000220 case NCR_DupShLib: {
Rui Ueyama01cc7182014-04-04 18:21:51 +0000221 const SharedLibraryAtom *curShLib = cast<SharedLibraryAtom>(existing);
222 const SharedLibraryAtom *newShLib = cast<SharedLibraryAtom>(&newAtom);
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000223 bool sameNullness =
224 (curShLib->canBeNullAtRuntime() == newShLib->canBeNullAtRuntime());
225 bool sameName = curShLib->loadName().equals(newShLib->loadName());
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000226 if (sameName && !sameNullness &&
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000227 _ctx.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000228 // FIXME: need diagonstics interface for writing warning messages
229 llvm::errs() << "lld warning: shared library symbol "
230 << curShLib->name() << " has different weakness in "
231 << curShLib->file().path() << " and in "
232 << newShLib->file().path();
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000233 }
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000234 if (!sameName && _ctx.warnIfCoalesableAtomsHaveDifferentLoadName()) {
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000235 // FIXME: need diagonstics interface for writing warning messages
236 llvm::errs() << "lld warning: shared library symbol "
237 << curShLib->name() << " has different load path in "
238 << curShLib->file().path() << " and in "
239 << newShLib->file().path();
240 }
241 useNew = false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000242 break;
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000243 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000244 case NCR_Error:
245 llvm::errs() << "SymbolTable: error while merging " << name << "\n";
Rui Ueyama9310e012013-11-14 06:39:31 +0000246 llvm::report_fatal_error("duplicate symbol error");
247 break;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000248 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000249
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000250 // Give context a chance to change which is kept.
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000251 _ctx.notifySymbolTableCoalesce(existing, &newAtom, useNew);
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000252
Rui Ueyamaf347e752013-11-13 23:22:00 +0000253 if (useNew) {
254 // Update name table to use new atom.
255 _nameTable[name] = &newAtom;
256 // Add existing atom to replacement table.
257 _replacedAtoms[existing] = &newAtom;
258 } else {
259 // New atom is not being used. Add it to replacement table.
260 _replacedAtoms[&newAtom] = existing;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000261 }
Rui Ueyama2a522512014-05-14 17:29:27 +0000262 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000263}
264
Michael J. Spencer67f25272013-03-20 22:18:22 +0000265unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom *atom) {
266 auto content = atom->rawContent();
267 return llvm::hash_combine(atom->size(),
268 atom->contentType(),
269 llvm::hash_combine_range(content.begin(),
270 content.end()));
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000271}
272
Michael J. Spencer765792d2012-04-03 18:40:27 +0000273bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l,
Michael J. Spencer67f25272013-03-20 22:18:22 +0000274 const DefinedAtom * const r) {
Rui Ueyamaf347e752013-11-13 23:22:00 +0000275 if (l == r)
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000276 return true;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000277 if (l == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000278 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000279 if (r == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000280 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000281 if (l == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000282 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000283 if (r == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000284 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000285 if (l->contentType() != r->contentType())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000286 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000287 if (l->size() != r->size())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000288 return false;
Nick Kledzik32d0d092014-10-02 17:22:05 +0000289 if (l->sectionChoice() != r->sectionChoice())
290 return false;
291 if (l->sectionChoice() == DefinedAtom::sectionCustomRequired) {
292 if (!l->customSectionName().equals(r->customSectionName()))
293 return false;
294 }
Michael J. Spencere6203a52012-04-03 18:39:40 +0000295 ArrayRef<uint8_t> lc = l->rawContent();
296 ArrayRef<uint8_t> rc = r->rawContent();
Michael J. Spencer67f25272013-03-20 22:18:22 +0000297 return memcmp(lc.data(), rc.data(), lc.size()) == 0;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000298}
299
Rui Ueyama2a522512014-05-14 17:29:27 +0000300bool SymbolTable::addByContent(const DefinedAtom &newAtom) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000301 AtomContentSet::iterator pos = _contentTable.find(&newAtom);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000302 if (pos == _contentTable.end()) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000303 _contentTable.insert(&newAtom);
Rui Ueyama2a522512014-05-14 17:29:27 +0000304 return true;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000305 }
306 const Atom* existing = *pos;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000307 // New atom is not being used. Add it to replacement table.
308 _replacedAtoms[&newAtom] = existing;
Rui Ueyama2a522512014-05-14 17:29:27 +0000309 return false;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000310}
311
Michael J. Spencere6203a52012-04-03 18:39:40 +0000312const Atom *SymbolTable::findByName(StringRef sym) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000313 NameToAtom::iterator pos = _nameTable.find(sym);
314 if (pos == _nameTable.end())
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000315 return nullptr;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000316 return pos->second;
317}
318
Michael J. Spencere6203a52012-04-03 18:39:40 +0000319bool SymbolTable::isDefined(StringRef sym) {
Rui Ueyama71c02022014-04-03 22:43:42 +0000320 if (const Atom *atom = findByName(sym))
Rui Ueyama0abf6132014-10-14 21:42:08 +0000321 return !isa<UndefinedAtom>(atom);
Rui Ueyama71c02022014-04-03 22:43:42 +0000322 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000323}
324
Rui Ueyamae5416ec2013-09-12 19:14:05 +0000325void SymbolTable::addReplacement(const Atom *replaced,
326 const Atom *replacement) {
327 _replacedAtoms[replaced] = replacement;
328}
329
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000330const Atom *SymbolTable::replacement(const Atom *atom) {
Rui Ueyama1c3486a2014-04-03 22:58:41 +0000331 // Find the replacement for a given atom. Atoms in _replacedAtoms
332 // may be chained, so find the last one.
Rui Ueyama4f010d22014-04-03 22:36:55 +0000333 for (;;) {
334 AtomToAtom::iterator pos = _replacedAtoms.find(atom);
335 if (pos == _replacedAtoms.end())
336 return atom;
Rui Ueyama4f010d22014-04-03 22:36:55 +0000337 atom = pos->second;
338 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000339}
340
Rui Ueyama733b45f2014-06-05 07:37:29 +0000341bool SymbolTable::isCoalescedAway(const Atom *atom) {
342 return _replacedAtoms.count(atom) > 0;
343}
344
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000345std::vector<const UndefinedAtom *> SymbolTable::undefines() {
346 std::vector<const UndefinedAtom *> ret;
Rui Ueyama17e899c2013-11-25 17:09:27 +0000347 for (auto it : _nameTable) {
348 const Atom *atom = it.second;
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000349 assert(atom != nullptr);
Rui Ueyama839fb2f2014-08-22 02:00:58 +0000350 if (const auto *undef = dyn_cast<const UndefinedAtom>(atom))
351 if (_replacedAtoms.count(undef) == 0)
352 ret.push_back(undef);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000353 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000354 return ret;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000355}
356
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000357std::vector<StringRef> SymbolTable::tentativeDefinitions() {
358 std::vector<StringRef> ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000359 for (auto entry : _nameTable) {
360 const Atom *atom = entry.second;
361 StringRef name = entry.first;
362 assert(atom != nullptr);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000363 if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
364 if (defAtom->merge() == DefinedAtom::mergeAsTentative)
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000365 ret.push_back(name);
Nick Kledzik20e652d2012-04-20 01:24:37 +0000366 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000367 return ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000368}
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000369
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000370} // namespace lld