Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 1 | //===- 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 Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 9 | // |
| 10 | // Symbol table is a bag of all known symbols. We put all symbols of |
Rui Ueyama | c9559d9 | 2016-01-05 20:47:37 +0000 | [diff] [blame] | 11 | // all input files to the symbol table. The symbol table is basically |
Rui Ueyama | 34f2924 | 2015-10-13 19:51:57 +0000 | [diff] [blame] | 12 | // a hash table with the logic to resolve symbol name conflicts using |
| 13 | // the symbol types. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 16 | |
| 17 | #include "SymbolTable.h" |
Rafael Espindola | 4340aad | 2015-09-11 22:42:45 +0000 | [diff] [blame] | 18 | #include "Config.h" |
Rafael Espindola | 192e1fa | 2015-08-06 15:08:23 +0000 | [diff] [blame] | 19 | #include "Error.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 20 | #include "Symbols.h" |
Rui Ueyama | deb1540 | 2016-01-07 17:20:07 +0000 | [diff] [blame] | 21 | #include "llvm/Support/StringSaver.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
Rafael Espindola | daa92a6 | 2015-08-31 01:16:19 +0000 | [diff] [blame] | 24 | using namespace llvm::object; |
Rafael Espindola | 01205f7 | 2015-09-22 18:19:46 +0000 | [diff] [blame] | 25 | using namespace llvm::ELF; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace lld; |
| 28 | using namespace lld::elf2; |
| 29 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 30 | template <class ELFT> SymbolTable<ELFT>::SymbolTable() {} |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 31 | |
Rui Ueyama | c9559d9 | 2016-01-05 20:47:37 +0000 | [diff] [blame] | 32 | // 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. |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 35 | template <class ELFT> |
Rui Ueyama | 25b44c9 | 2015-12-16 23:31:22 +0000 | [diff] [blame] | 36 | static void checkCompatibility(InputFile *FileP) { |
| 37 | auto *F = dyn_cast<ELFFileBase<ELFT>>(FileP); |
| 38 | if (!F) |
| 39 | return; |
| 40 | if (F->getELFKind() == Config->EKind && F->getEMachine() == Config->EMachine) |
| 41 | return; |
| 42 | StringRef A = F->getName(); |
| 43 | StringRef B = Config->Emulation; |
| 44 | if (B.empty()) |
| 45 | B = Config->FirstElf->getName(); |
| 46 | error(A + " is incompatible with " + B); |
| 47 | } |
| 48 | |
Rui Ueyama | c9559d9 | 2016-01-05 20:47:37 +0000 | [diff] [blame] | 49 | // Add symbols in File to the symbol table. |
Rui Ueyama | 25b44c9 | 2015-12-16 23:31:22 +0000 | [diff] [blame] | 50 | template <class ELFT> |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 51 | void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) { |
Rafael Espindola | 21f7bd4 | 2015-12-23 14:35:51 +0000 | [diff] [blame] | 52 | InputFile *FileP = File.get(); |
Rui Ueyama | 25b44c9 | 2015-12-16 23:31:22 +0000 | [diff] [blame] | 53 | checkCompatibility<ELFT>(FileP); |
Rafael Espindola | 525914d | 2015-10-11 03:36:49 +0000 | [diff] [blame] | 54 | |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 55 | // .a file |
| 56 | if (auto *F = dyn_cast<ArchiveFile>(FileP)) { |
Rafael Espindola | 21f7bd4 | 2015-12-23 14:35:51 +0000 | [diff] [blame] | 57 | ArchiveFiles.emplace_back(cast<ArchiveFile>(File.release())); |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 58 | F->parse(); |
| 59 | for (Lazy &Sym : F->getLazySymbols()) |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 60 | addLazy(&Sym); |
| 61 | return; |
| 62 | } |
Rui Ueyama | 3d45179 | 2015-10-12 18:03:21 +0000 | [diff] [blame] | 63 | |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 64 | // .so file |
| 65 | if (auto *F = dyn_cast<SharedFile<ELFT>>(FileP)) { |
| 66 | // DSOs are uniquified not by filename but by soname. |
| 67 | F->parseSoName(); |
Rafael Espindola | 21f7bd4 | 2015-12-23 14:35:51 +0000 | [diff] [blame] | 68 | if (!IncludedSoNames.insert(F->getSoName()).second) |
Rafael Espindola | 6a3b5de | 2015-10-01 19:52:48 +0000 | [diff] [blame] | 69 | return; |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 70 | |
Rafael Espindola | 21f7bd4 | 2015-12-23 14:35:51 +0000 | [diff] [blame] | 71 | SharedFiles.emplace_back(cast<SharedFile<ELFT>>(File.release())); |
Rui Ueyama | 7c71331 | 2016-01-06 01:56:36 +0000 | [diff] [blame] | 72 | F->parseRest(); |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 73 | for (SharedSymbol<ELFT> &B : F->getSharedSymbols()) |
| 74 | resolve(&B); |
| 75 | return; |
Rafael Espindola | 6a3b5de | 2015-10-01 19:52:48 +0000 | [diff] [blame] | 76 | } |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 77 | |
| 78 | // .o file |
| 79 | auto *F = cast<ObjectFile<ELFT>>(FileP); |
Rafael Espindola | 21f7bd4 | 2015-12-23 14:35:51 +0000 | [diff] [blame] | 80 | ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(File.release())); |
Rui Ueyama | 52d3b67 | 2016-01-06 02:06:33 +0000 | [diff] [blame] | 81 | F->parse(ComdatGroups); |
Rui Ueyama | 8957574 | 2015-12-16 22:59:13 +0000 | [diff] [blame] | 82 | for (SymbolBody *B : F->getSymbols()) |
| 83 | resolve(B); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Rui Ueyama | 01a65b1 | 2015-12-24 10:37:32 +0000 | [diff] [blame] | 86 | // Add an undefined symbol. |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 87 | template <class ELFT> |
| 88 | SymbolBody *SymbolTable<ELFT>::addUndefined(StringRef Name) { |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 89 | auto *Sym = new (Alloc) Undefined(Name, false, STV_DEFAULT, false); |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 90 | resolve(Sym); |
| 91 | return Sym; |
Rafael Espindola | 1d6063e | 2015-09-22 21:24:52 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Rui Ueyama | 01a65b1 | 2015-12-24 10:37:32 +0000 | [diff] [blame] | 94 | // Add an undefined symbol. Unlike addUndefined, that symbol |
| 95 | // doesn't have to be resolved, thus "opt" (optional). |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 96 | template <class ELFT> |
| 97 | SymbolBody *SymbolTable<ELFT>::addUndefinedOpt(StringRef Name) { |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 98 | auto *Sym = new (Alloc) Undefined(Name, false, STV_HIDDEN, true); |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 99 | resolve(Sym); |
| 100 | return Sym; |
Denis Protivensky | 22220d5 | 2015-10-05 09:43:57 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 103 | template <class ELFT> |
Rui Ueyama | 79c7373 | 2016-01-08 21:53:28 +0000 | [diff] [blame] | 104 | SymbolBody *SymbolTable<ELFT>::addAbsolute(StringRef Name, Elf_Sym &ESym) { |
| 105 | // Pass nullptr because absolute symbols have no corresponding input sections. |
| 106 | auto *Sym = new (Alloc) DefinedRegular<ELFT>(Name, ESym, nullptr); |
| 107 | resolve(Sym); |
| 108 | return Sym; |
Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | template <class ELFT> |
Rui Ueyama | 79c7373 | 2016-01-08 21:53:28 +0000 | [diff] [blame] | 112 | SymbolBody *SymbolTable<ELFT>::addSynthetic(StringRef Name, |
| 113 | OutputSectionBase<ELFT> &Section, |
| 114 | uintX_t Value) { |
Rafael Espindola | 4d4b06a | 2015-12-24 00:47:42 +0000 | [diff] [blame] | 115 | auto *Sym = new (Alloc) DefinedSynthetic<ELFT>(Name, Value, Section); |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 116 | resolve(Sym); |
Rui Ueyama | 79c7373 | 2016-01-08 21:53:28 +0000 | [diff] [blame] | 117 | return Sym; |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Rui Ueyama | c9559d9 | 2016-01-05 20:47:37 +0000 | [diff] [blame] | 120 | // Add Name as an "ignored" symbol. An ignored symbol is a regular |
| 121 | // linker-synthesized defined symbol, but it is not recorded to the output |
| 122 | // file's symbol table. Such symbols are useful for some linker-defined symbols. |
Simon Atanasyan | 09dae7c | 2015-12-16 14:45:09 +0000 | [diff] [blame] | 123 | template <class ELFT> |
Rui Ueyama | dd7d998 | 2015-12-16 22:31:14 +0000 | [diff] [blame] | 124 | SymbolBody *SymbolTable<ELFT>::addIgnored(StringRef Name) { |
Rui Ueyama | 79c7373 | 2016-01-08 21:53:28 +0000 | [diff] [blame] | 125 | return addAbsolute(Name, ElfSym<ELFT>::IgnoreUndef); |
Rafael Espindola | 5d41326 | 2015-10-01 21:22:26 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Rui Ueyama | deb1540 | 2016-01-07 17:20:07 +0000 | [diff] [blame] | 128 | // Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM. |
| 129 | // Used to implement --wrap. |
| 130 | template <class ELFT> void SymbolTable<ELFT>::wrap(StringRef Name) { |
| 131 | if (Symtab.count(Name) == 0) |
| 132 | return; |
| 133 | StringSaver Saver(Alloc); |
| 134 | Symbol *Sym = addUndefined(Name)->getSymbol(); |
| 135 | Symbol *Real = addUndefined(Saver.save("__real_" + Name))->getSymbol(); |
| 136 | Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name))->getSymbol(); |
| 137 | Real->Body = Sym->Body; |
| 138 | Sym->Body = Wrap->Body; |
| 139 | } |
| 140 | |
Rui Ueyama | 533336a | 2015-12-16 22:26:48 +0000 | [diff] [blame] | 141 | // Returns a file from which symbol B was created. |
Rui Ueyama | 2a65a49 | 2016-01-05 20:01:29 +0000 | [diff] [blame] | 142 | // If B does not belong to any file, returns a nullptr. |
Rafael Espindola | 1a49e58 | 2015-09-23 14:10:24 +0000 | [diff] [blame] | 143 | template <class ELFT> |
Rui Ueyama | 2a65a49 | 2016-01-05 20:01:29 +0000 | [diff] [blame] | 144 | ELFFileBase<ELFT> *SymbolTable<ELFT>::findFile(SymbolBody *B) { |
Rui Ueyama | 533336a | 2015-12-16 22:26:48 +0000 | [diff] [blame] | 145 | for (const std::unique_ptr<ObjectFile<ELFT>> &F : ObjectFiles) { |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 146 | ArrayRef<SymbolBody *> Syms = F->getSymbols(); |
| 147 | if (std::find(Syms.begin(), Syms.end(), B) != Syms.end()) |
Rui Ueyama | 533336a | 2015-12-16 22:26:48 +0000 | [diff] [blame] | 148 | return F.get(); |
Rafael Espindola | 1a49e58 | 2015-09-23 14:10:24 +0000 | [diff] [blame] | 149 | } |
Rui Ueyama | 533336a | 2015-12-16 22:26:48 +0000 | [diff] [blame] | 150 | return nullptr; |
| 151 | } |
| 152 | |
Rui Ueyama | b4de595 | 2016-01-08 22:01:33 +0000 | [diff] [blame^] | 153 | // Construct a string in the form of "Sym in File1 and File2". |
| 154 | // Used to construct an error message. |
Rui Ueyama | 533336a | 2015-12-16 22:26:48 +0000 | [diff] [blame] | 155 | template <class ELFT> |
| 156 | std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Old, SymbolBody *New) { |
Rui Ueyama | 2a65a49 | 2016-01-05 20:01:29 +0000 | [diff] [blame] | 157 | ELFFileBase<ELFT> *OldFile = findFile(Old); |
| 158 | ELFFileBase<ELFT> *NewFile = findFile(New); |
Rafael Espindola | 1a49e58 | 2015-09-23 14:10:24 +0000 | [diff] [blame] | 159 | |
Rui Ueyama | f090401 | 2015-12-16 22:26:45 +0000 | [diff] [blame] | 160 | StringRef Sym = Old->getName(); |
| 161 | StringRef F1 = OldFile ? OldFile->getName() : "(internal)"; |
| 162 | StringRef F2 = NewFile ? NewFile->getName() : "(internal)"; |
| 163 | return (Sym + " in " + F1 + " and " + F2).str(); |
Rafael Espindola | 1a49e58 | 2015-09-23 14:10:24 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 166 | // This function resolves conflicts if there's an existing symbol with |
| 167 | // the same name. Decisions are made based on symbol type. |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 168 | template <class ELFT> void SymbolTable<ELFT>::resolve(SymbolBody *New) { |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 169 | Symbol *Sym = insert(New); |
| 170 | if (Sym->Body == New) |
| 171 | return; |
| 172 | |
| 173 | SymbolBody *Existing = Sym->Body; |
| 174 | |
| 175 | if (Lazy *L = dyn_cast<Lazy>(Existing)) { |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 176 | if (auto *Undef = dyn_cast<Undefined>(New)) { |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 177 | addMemberFile(Undef, L); |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 178 | return; |
| 179 | } |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 180 | // Found a definition for something also in an archive. |
| 181 | // Ignore the archive definition. |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 182 | Sym->Body = New; |
| 183 | return; |
| 184 | } |
| 185 | |
Rui Ueyama | 62d0e32 | 2015-12-17 00:04:18 +0000 | [diff] [blame] | 186 | if (New->isTls() != Existing->isTls()) |
Rui Ueyama | f090401 | 2015-12-16 22:26:45 +0000 | [diff] [blame] | 187 | error("TLS attribute mismatch for symbol: " + conflictMsg(Existing, New)); |
Igor Kudrin | 65bddea | 2015-10-09 09:58:39 +0000 | [diff] [blame] | 188 | |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 189 | // compare() returns -1, 0, or 1 if the lhs symbol is less preferable, |
| 190 | // equivalent (conflicting), or more preferable, respectively. |
Rui Ueyama | 2e0a9ff | 2016-01-06 00:09:39 +0000 | [diff] [blame] | 191 | int Comp = Existing->compare<ELFT>(New); |
| 192 | if (Comp == 0) { |
Rui Ueyama | f090401 | 2015-12-16 22:26:45 +0000 | [diff] [blame] | 193 | std::string S = "duplicate symbol: " + conflictMsg(Existing, New); |
| 194 | if (!Config->AllowMultipleDefinition) |
| 195 | error(S); |
| 196 | warning(S); |
| 197 | return; |
| 198 | } |
Rui Ueyama | 2e0a9ff | 2016-01-06 00:09:39 +0000 | [diff] [blame] | 199 | if (Comp < 0) |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 200 | Sym->Body = New; |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Rui Ueyama | b4de595 | 2016-01-08 22:01:33 +0000 | [diff] [blame^] | 203 | // Find an existing symbol or create and insert a new one. |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 204 | template <class ELFT> Symbol *SymbolTable<ELFT>::insert(SymbolBody *New) { |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 205 | StringRef Name = New->getName(); |
| 206 | Symbol *&Sym = Symtab[Name]; |
Rui Ueyama | 38dcc9e | 2015-12-16 23:25:31 +0000 | [diff] [blame] | 207 | if (!Sym) |
Rui Ueyama | 3554f59 | 2015-12-17 00:01:25 +0000 | [diff] [blame] | 208 | Sym = new (Alloc) Symbol{New}; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 209 | New->setBackref(Sym); |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 210 | return Sym; |
| 211 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 212 | |
Rui Ueyama | f8432d9 | 2015-10-13 16:34:14 +0000 | [diff] [blame] | 213 | template <class ELFT> SymbolBody *SymbolTable<ELFT>::find(StringRef Name) { |
| 214 | auto It = Symtab.find(Name); |
| 215 | if (It == Symtab.end()) |
| 216 | return nullptr; |
| 217 | return It->second->Body; |
| 218 | } |
| 219 | |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 220 | template <class ELFT> void SymbolTable<ELFT>::addLazy(Lazy *L) { |
| 221 | Symbol *Sym = insert(L); |
| 222 | if (Sym->Body == L) |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 223 | return; |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 224 | if (auto *Undef = dyn_cast<Undefined>(Sym->Body)) { |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 225 | Sym->Body = L; |
| 226 | addMemberFile(Undef, L); |
Rafael Espindola | 8614c56 | 2015-10-06 14:33:58 +0000 | [diff] [blame] | 227 | } |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Rui Ueyama | 3d45179 | 2015-10-12 18:03:21 +0000 | [diff] [blame] | 230 | template <class ELFT> |
Rafael Espindola | 5d7593b | 2015-12-22 23:00:50 +0000 | [diff] [blame] | 231 | void SymbolTable<ELFT>::addMemberFile(Undefined *Undef, Lazy *L) { |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 232 | // Weak undefined symbols should not fetch members from archives. |
| 233 | // If we were to keep old symbol we would not know that an archive member was |
| 234 | // available if a strong undefined symbol shows up afterwards in the link. |
| 235 | // If a strong undefined symbol never shows up, this lazy symbol will |
| 236 | // get to the end of the link and must be treated as the weak undefined one. |
| 237 | // We set UsedInRegularObj in a similar way to what is done with shared |
| 238 | // symbols and mark it as weak to reduce how many special cases are needed. |
| 239 | if (Undef->isWeak()) { |
| 240 | L->setUsedInRegularObj(); |
| 241 | L->setWeak(); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | // Fetch a member file that has the definition for L. |
Michael J. Spencer | 1b348a6 | 2015-09-04 22:28:10 +0000 | [diff] [blame] | 246 | // getMember returns nullptr if the member was already read from the library. |
Rui Ueyama | c5b9512 | 2015-12-16 23:23:14 +0000 | [diff] [blame] | 247 | if (std::unique_ptr<InputFile> File = L->getMember()) |
Rui Ueyama | 690db67 | 2015-10-14 22:32:10 +0000 | [diff] [blame] | 248 | addFile(std::move(File)); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 249 | } |
Rafael Espindola | 0e604f9 | 2015-09-25 18:56:53 +0000 | [diff] [blame] | 250 | |
Rui Ueyama | 93bfee5 | 2015-10-13 18:10:33 +0000 | [diff] [blame] | 251 | // This function takes care of the case in which shared libraries depend on |
| 252 | // the user program (not the other way, which is usual). Shared libraries |
| 253 | // may have undefined symbols, expecting that the user program provides |
| 254 | // the definitions for them. An example is BSD's __progname symbol. |
| 255 | // We need to put such symbols to the main program's .dynsym so that |
| 256 | // shared libraries can find them. |
| 257 | // Except this, we ignore undefined symbols in DSOs. |
| 258 | template <class ELFT> void SymbolTable<ELFT>::scanShlibUndefined() { |
Rui Ueyama | f8432d9 | 2015-10-13 16:34:14 +0000 | [diff] [blame] | 259 | for (std::unique_ptr<SharedFile<ELFT>> &File : SharedFiles) |
| 260 | for (StringRef U : File->getUndefinedSymbols()) |
| 261 | if (SymbolBody *Sym = find(U)) |
| 262 | if (Sym->isDefined()) |
| 263 | Sym->setUsedInDynamicReloc(); |
| 264 | } |
| 265 | |
Rui Ueyama | f588ac4 | 2016-01-06 00:09:41 +0000 | [diff] [blame] | 266 | template class elf2::SymbolTable<ELF32LE>; |
| 267 | template class elf2::SymbolTable<ELF32BE>; |
| 268 | template class elf2::SymbolTable<ELF64LE>; |
| 269 | template class elf2::SymbolTable<ELF64BE>; |