[lld] r241477 - COFF: Support isa<> for Symbol::Body, whose type is std::atomic<SymbolBody *>.

Rui Ueyama ruiu at google.com
Mon Jul 6 10:45:23 PDT 2015


Author: ruiu
Date: Mon Jul  6 12:45:22 2015
New Revision: 241477

URL: http://llvm.org/viewvc/llvm-project?rev=241477&view=rev
Log:
COFF: Support isa<> for Symbol::Body, whose type is std::atomic<SymbolBody *>.

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/SymbolTable.cpp
    lld/trunk/COFF/Symbols.h
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=241477&r1=241476&r2=241477&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Jul  6 12:45:22 2015
@@ -220,7 +220,7 @@ StringRef LinkerDriver::findDefaultEntry
   };
   for (auto E : Entries) {
     Symbol *Sym = Symtab.find(E[0]);
-    if (Sym && !isa<Undefined>(Sym->Body.load()))
+    if (Sym && !isa<Undefined>(Sym->Body))
       return E[1];
   }
   return "";
@@ -591,7 +591,7 @@ bool LinkerDriver::link(llvm::ArrayRef<c
       Symbol *Sym = Symtab.find(From);
       if (!Sym)
         continue;
-      if (auto *U = dyn_cast<Undefined>(Sym->Body.load()))
+      if (auto *U = dyn_cast<Undefined>(Sym->Body))
         if (!U->WeakAlias)
           U->WeakAlias = Symtab.addUndefined(To);
     }

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241477&r1=241476&r2=241477&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Mon Jul  6 12:45:22 2015
@@ -77,7 +77,7 @@ std::error_code SymbolTable::readArchive
   // Add archive member files to ObjectQueue that should resolve
   // existing undefined symbols.
   for (Symbol *Sym : LazySyms)
-    if (auto EC = addMemberFile(cast<Lazy>(Sym->Body.load())))
+    if (auto EC = addMemberFile(cast<Lazy>(Sym->Body)))
       return EC;
   return std::error_code();
 }
@@ -126,7 +126,7 @@ bool SymbolTable::reportRemainingUndefin
   bool Ret = false;
   for (auto &I : Symtab) {
     Symbol *Sym = I.second;
-    auto *Undef = dyn_cast<Undefined>(Sym->Body.load());
+    auto *Undef = dyn_cast<Undefined>(Sym->Body);
     if (!Undef)
       continue;
     StringRef Name = Undef->getName();
@@ -140,10 +140,10 @@ bool SymbolTable::reportRemainingUndefin
     // This odd rule is for compatibility with MSVC linker.
     if (Name.startswith("__imp_")) {
       Symbol *Imp = find(Name.substr(strlen("__imp_")));
-      if (Imp && isa<Defined>(Imp->Body.load())) {
+      if (Imp && isa<Defined>(Imp->Body)) {
         if (!Resolve)
           continue;
-        auto *D = cast<Defined>(Imp->Body.load());
+        auto *D = cast<Defined>(Imp->Body);
         auto *S = new (Alloc) DefinedLocalImport(Name, D);
         LocalImportChunks.push_back(S->getChunk());
         Sym->Body = S;
@@ -332,11 +332,11 @@ std::error_code SymbolTable::addCombined
     StringRef Name = Body->getName();
     Symbol *Sym = insert(Body);
 
-    if (isa<DefinedBitcode>(Sym->Body.load())) {
+    if (isa<DefinedBitcode>(Sym->Body)) {
       Sym->Body = Body;
       continue;
     }
-    if (auto *L = dyn_cast<Lazy>(Sym->Body.load())) {
+    if (auto *L = dyn_cast<Lazy>(Sym->Body)) {
       // 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))

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=241477&r1=241476&r2=241477&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Mon Jul  6 12:45:22 2015
@@ -359,4 +359,13 @@ private:
 } // namespace coff
 } // namespace lld
 
+// Support isa<>, cast<> and dyn_cast<> for Symbol::Body.
+namespace llvm {
+template <typename T>
+struct simplify_type<std::atomic<T *>> {
+  typedef T *SimpleType;
+  static T *getSimplifiedValue(std::atomic<T *> &A) { return A.load(); }
+};
+}
+
 #endif

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241477&r1=241476&r2=241477&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Jul  6 12:45:22 2015
@@ -244,7 +244,7 @@ void Writer::createImportTables() {
   }
   if (!DelayIdata.empty()) {
     Symbol *Sym = Symtab->find("__delayLoadHelper2");
-    Defined *Helper = cast<Defined>(Sym->Body.load());
+    Defined *Helper = cast<Defined>(Sym->Body);
     DelayIdata.create(Helper);
     OutputSection *Sec = createSection(".didat");
     for (Chunk *C : DelayIdata.getChunks())
@@ -416,7 +416,7 @@ void Writer::writeHeader() {
     Dir[EXCEPTION_TABLE].Size = Sec->getVirtualSize();
   }
   if (Symbol *Sym = Symtab->find("_tls_used")) {
-    if (Defined *B = dyn_cast<Defined>(Sym->Body.load())) {
+    if (Defined *B = dyn_cast<Defined>(Sym->Body)) {
       Dir[TLS_TABLE].RelativeVirtualAddress = B->getRVA();
       Dir[TLS_TABLE].Size = 40;
     }
@@ -542,7 +542,7 @@ OutputSection *Writer::createSection(Str
 // Dest is .reloc section. Add contents to that section.
 void Writer::addBaserels(OutputSection *Dest) {
   std::vector<uint32_t> V;
-  Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase")->Body.load());
+  Defined *ImageBase = cast<Defined>(Symtab->find("__ImageBase")->Body);
   for (OutputSection *Sec : OutputSections) {
     if (Sec == Dest)
       continue;





More information about the llvm-commits mailing list