blob: 99e8547d6013d1293aa7c2031baf458ad62ef631 [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
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000199 if (sameCanBeNull)
Rafael Espindolac778aa42016-02-28 16:27:08 +0000200 useNew = false;
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000201 else
202 useNew = (newUndef->canBeNull() < existingUndef->canBeNull());
Rui Ueyamaf347e752013-11-13 23:22:00 +0000203 break;
Rui Ueyamab4dca7f2013-11-15 03:12:24 +0000204 }
Rui Ueyamaf347e752013-11-13 23:22:00 +0000205 case NCR_DupShLib: {
Rui Ueyama01cc7182014-04-04 18:21:51 +0000206 const SharedLibraryAtom *curShLib = cast<SharedLibraryAtom>(existing);
207 const SharedLibraryAtom *newShLib = cast<SharedLibraryAtom>(&newAtom);
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000208 bool sameNullness =
209 (curShLib->canBeNullAtRuntime() == newShLib->canBeNullAtRuntime());
210 bool sameName = curShLib->loadName().equals(newShLib->loadName());
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000211 if (sameName && !sameNullness &&
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000212 _ctx.warnIfCoalesableAtomsHaveDifferentCanBeNull()) {
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000213 // FIXME: need diagonstics interface for writing warning messages
214 llvm::errs() << "lld warning: shared library symbol "
215 << curShLib->name() << " has different weakness in "
216 << curShLib->file().path() << " and in "
217 << newShLib->file().path();
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000218 }
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000219 if (!sameName && _ctx.warnIfCoalesableAtomsHaveDifferentLoadName()) {
Rui Ueyamae8af3e42014-04-04 18:21:53 +0000220 // FIXME: need diagonstics interface for writing warning messages
221 llvm::errs() << "lld warning: shared library symbol "
222 << curShLib->name() << " has different load path in "
223 << curShLib->file().path() << " and in "
224 << newShLib->file().path();
225 }
226 useNew = false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000227 break;
Rui Ueyamafb7936d2014-04-04 18:12:27 +0000228 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000229 case NCR_Error:
230 llvm::errs() << "SymbolTable: error while merging " << name << "\n";
Rui Ueyama9310e012013-11-14 06:39:31 +0000231 llvm::report_fatal_error("duplicate symbol error");
232 break;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000233 }
Rui Ueyamabcccb5d2013-11-13 23:23:38 +0000234
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000235 // Give context a chance to change which is kept.
Rui Ueyamaaabd7ca2015-04-10 21:40:59 +0000236 _ctx.notifySymbolTableCoalesce(existing, &newAtom, useNew);
Nick Kledzikbb38f7b2014-08-20 20:46:28 +0000237
Rui Ueyamaf347e752013-11-13 23:22:00 +0000238 if (useNew) {
239 // Update name table to use new atom.
240 _nameTable[name] = &newAtom;
241 // Add existing atom to replacement table.
242 _replacedAtoms[existing] = &newAtom;
243 } else {
244 // New atom is not being used. Add it to replacement table.
245 _replacedAtoms[&newAtom] = existing;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000246 }
Rui Ueyama2a522512014-05-14 17:29:27 +0000247 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000248}
249
Michael J. Spencer67f25272013-03-20 22:18:22 +0000250unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom *atom) {
251 auto content = atom->rawContent();
252 return llvm::hash_combine(atom->size(),
253 atom->contentType(),
254 llvm::hash_combine_range(content.begin(),
255 content.end()));
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000256}
257
Michael J. Spencer765792d2012-04-03 18:40:27 +0000258bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l,
Michael J. Spencer67f25272013-03-20 22:18:22 +0000259 const DefinedAtom * const r) {
Rui Ueyamaf347e752013-11-13 23:22:00 +0000260 if (l == r)
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000261 return true;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000262 if (l == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000263 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000264 if (r == getEmptyKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000265 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000266 if (l == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000267 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000268 if (r == getTombstoneKey())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000269 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000270 if (l->contentType() != r->contentType())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000271 return false;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000272 if (l->size() != r->size())
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000273 return false;
Nick Kledzik32d0d092014-10-02 17:22:05 +0000274 if (l->sectionChoice() != r->sectionChoice())
275 return false;
276 if (l->sectionChoice() == DefinedAtom::sectionCustomRequired) {
277 if (!l->customSectionName().equals(r->customSectionName()))
278 return false;
279 }
Michael J. Spencere6203a52012-04-03 18:39:40 +0000280 ArrayRef<uint8_t> lc = l->rawContent();
281 ArrayRef<uint8_t> rc = r->rawContent();
Michael J. Spencer67f25272013-03-20 22:18:22 +0000282 return memcmp(lc.data(), rc.data(), lc.size()) == 0;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000283}
284
Rui Ueyama2a522512014-05-14 17:29:27 +0000285bool SymbolTable::addByContent(const DefinedAtom &newAtom) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000286 AtomContentSet::iterator pos = _contentTable.find(&newAtom);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000287 if (pos == _contentTable.end()) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000288 _contentTable.insert(&newAtom);
Rui Ueyama2a522512014-05-14 17:29:27 +0000289 return true;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000290 }
291 const Atom* existing = *pos;
Rui Ueyamaf347e752013-11-13 23:22:00 +0000292 // New atom is not being used. Add it to replacement table.
293 _replacedAtoms[&newAtom] = existing;
Rui Ueyama2a522512014-05-14 17:29:27 +0000294 return false;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000295}
296
Michael J. Spencere6203a52012-04-03 18:39:40 +0000297const Atom *SymbolTable::findByName(StringRef sym) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000298 NameToAtom::iterator pos = _nameTable.find(sym);
299 if (pos == _nameTable.end())
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000300 return nullptr;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000301 return pos->second;
302}
303
Michael J. Spencere6203a52012-04-03 18:39:40 +0000304bool SymbolTable::isDefined(StringRef sym) {
Rui Ueyama71c02022014-04-03 22:43:42 +0000305 if (const Atom *atom = findByName(sym))
Rui Ueyama0abf6132014-10-14 21:42:08 +0000306 return !isa<UndefinedAtom>(atom);
Rui Ueyama71c02022014-04-03 22:43:42 +0000307 return false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000308}
309
Rui Ueyamae5416ec2013-09-12 19:14:05 +0000310void SymbolTable::addReplacement(const Atom *replaced,
311 const Atom *replacement) {
312 _replacedAtoms[replaced] = replacement;
313}
314
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000315const Atom *SymbolTable::replacement(const Atom *atom) {
Rui Ueyama1c3486a2014-04-03 22:58:41 +0000316 // Find the replacement for a given atom. Atoms in _replacedAtoms
317 // may be chained, so find the last one.
Rui Ueyama4f010d22014-04-03 22:36:55 +0000318 for (;;) {
319 AtomToAtom::iterator pos = _replacedAtoms.find(atom);
320 if (pos == _replacedAtoms.end())
321 return atom;
Rui Ueyama4f010d22014-04-03 22:36:55 +0000322 atom = pos->second;
323 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000324}
325
Rui Ueyama733b45f2014-06-05 07:37:29 +0000326bool SymbolTable::isCoalescedAway(const Atom *atom) {
327 return _replacedAtoms.count(atom) > 0;
328}
329
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000330std::vector<const UndefinedAtom *> SymbolTable::undefines() {
331 std::vector<const UndefinedAtom *> ret;
Rui Ueyama17e899c2013-11-25 17:09:27 +0000332 for (auto it : _nameTable) {
333 const Atom *atom = it.second;
Michael J. Spencerc9d25062012-03-29 19:39:14 +0000334 assert(atom != nullptr);
Rui Ueyama839fb2f2014-08-22 02:00:58 +0000335 if (const auto *undef = dyn_cast<const UndefinedAtom>(atom))
336 if (_replacedAtoms.count(undef) == 0)
337 ret.push_back(undef);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000338 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000339 return ret;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000340}
341
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000342std::vector<StringRef> SymbolTable::tentativeDefinitions() {
343 std::vector<StringRef> ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000344 for (auto entry : _nameTable) {
345 const Atom *atom = entry.second;
346 StringRef name = entry.first;
347 assert(atom != nullptr);
Rui Ueyamaf347e752013-11-13 23:22:00 +0000348 if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
349 if (defAtom->merge() == DefinedAtom::mergeAsTentative)
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000350 ret.push_back(name);
Nick Kledzik20e652d2012-04-20 01:24:37 +0000351 }
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000352 return ret;
Nick Kledzik20e652d2012-04-20 01:24:37 +0000353}
Rui Ueyama8dc9f0a2014-04-04 00:15:52 +0000354
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000355} // namespace lld