diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index fa29d14678bf..9f352ac1c7cc 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -220,7 +220,7 @@ StringRef LinkerDriver::findDefaultEntry() { }; for (auto E : Entries) { Symbol *Sym = Symtab.find(E[0]); - if (Sym && !isa(Sym->Body)) + if (Sym && !isa(Sym->Body.load())) return E[1]; } return ""; @@ -591,7 +591,7 @@ bool LinkerDriver::link(llvm::ArrayRef ArgsArr) { Symbol *Sym = Symtab.find(From); if (!Sym) continue; - if (auto *U = dyn_cast(Sym->Body)) + if (auto *U = dyn_cast(Sym->Body.load())) if (!U->WeakAlias) U->WeakAlias = Symtab.addUndefined(To); } diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 44d943bf78e6..dc8758be4087 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -77,7 +77,7 @@ std::error_code SymbolTable::readArchives() { // Add archive member files to ObjectQueue that should resolve // existing undefined symbols. for (Symbol *Sym : LazySyms) - if (auto EC = addMemberFile(cast(Sym->Body))) + if (auto EC = addMemberFile(cast(Sym->Body.load()))) return EC; return std::error_code(); } @@ -126,7 +126,7 @@ bool SymbolTable::reportRemainingUndefines(bool Resolve) { bool Ret = false; for (auto &I : Symtab) { Symbol *Sym = I.second; - auto *Undef = dyn_cast(Sym->Body); + auto *Undef = dyn_cast(Sym->Body.load()); if (!Undef) continue; StringRef Name = Undef->getName(); @@ -140,10 +140,10 @@ bool SymbolTable::reportRemainingUndefines(bool Resolve) { // This odd rule is for compatibility with MSVC linker. if (Name.startswith("__imp_")) { Symbol *Imp = find(Name.substr(strlen("__imp_"))); - if (Imp && isa(Imp->Body)) { + if (Imp && isa(Imp->Body.load())) { if (!Resolve) continue; - auto *D = cast(Imp->Body); + auto *D = cast(Imp->Body.load()); auto *S = new (Alloc) DefinedLocalImport(Name, D); LocalImportChunks.push_back(S->getChunk()); Sym->Body = S; @@ -320,11 +320,11 @@ std::error_code SymbolTable::addCombinedLTOObject() { StringRef Name = Body->getName(); Symbol *Sym = insert(Body); - if (isa(Sym->Body)) { + if (isa(Sym->Body.load())) { Sym->Body = Body; continue; } - if (auto *L = dyn_cast(Sym->Body)) { + if (auto *L = dyn_cast(Sym->Body.load())) { // We may see new references to runtime library symbols such as __chkstk // here. These symbols must be wholly defined in non-bitcode files. if (auto EC = addMemberFile(L)) diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h index 2c12af263ecd..8694b83247ef 100644 --- a/lld/COFF/Symbols.h +++ b/lld/COFF/Symbols.h @@ -16,6 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" +#include #include #include @@ -38,7 +39,7 @@ class SymbolBody; // The resolver updates SymbolBody pointers as it resolves symbols. struct Symbol { explicit Symbol(SymbolBody *P) : Body(P) {} - SymbolBody *Body; + std::atomic Body; }; // The base class for real symbol classes. @@ -80,7 +81,7 @@ public: // has chosen the object among other objects having the same name, // you can access P->Backref->Body to get the resolver's result. void setBackref(Symbol *P) { Backref = P; } - SymbolBody *repl() { return Backref ? Backref->Body : this; } + SymbolBody *repl() { return Backref ? Backref->Body.load() : this; } // Decides which symbol should "win" in the symbol table, this or // the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 062f63111429..8814a4df79ff 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -243,7 +243,8 @@ void Writer::createImportTables() { Sec->addChunk(C); } if (!DelayIdata.empty()) { - Defined *Helper = cast(Symtab->find("__delayLoadHelper2")->Body); + Symbol *Sym = Symtab->find("__delayLoadHelper2"); + Defined *Helper = cast(Sym->Body.load()); DelayIdata.create(Helper); OutputSection *Sec = createSection(".didat"); for (Chunk *C : DelayIdata.getChunks()) @@ -535,7 +536,7 @@ OutputSection *Writer::createSection(StringRef Name) { // Dest is .reloc section. Add contents to that section. void Writer::addBaserels(OutputSection *Dest) { std::vector V; - Defined *ImageBase = cast(Symtab->find("__ImageBase")->Body); + Defined *ImageBase = cast(Symtab->find("__ImageBase")->Body.load()); for (OutputSection *Sec : OutputSections) { if (Sec == Dest) continue;