[lld] r245200 - COFF: Simplify Writer::createImportTables.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 00:27:45 PDT 2015


Author: ruiu
Date: Mon Aug 17 02:27:45 2015
New Revision: 245200

URL: http://llvm.org/viewvc/llvm-project?rev=245200&view=rev
Log:
COFF: Simplify Writer::createImportTables.

A short import library has up to two symbols, so we don't have
to do a for-loop and type dispatch in createImportTables.

Modified:
    lld/trunk/COFF/InputFiles.cpp
    lld/trunk/COFF/InputFiles.h
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=245200&r1=245199&r2=245200&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Mon Aug 17 02:27:45 2015
@@ -298,16 +298,16 @@ void ImportFile::parse() {
     ExtName = ExtName.substr(0, ExtName.find('@'));
     break;
   }
-  auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
+  ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, ExtName, Hdr);
   SymbolBodies.push_back(ImpSym);
 
   // If type is function, we need to create a thunk which jump to an
   // address pointed by the __imp_ symbol. (This allows you to call
   // DLL functions just like regular non-DLL functions.)
-  if (Hdr->getType() == llvm::COFF::IMPORT_CODE) {
-    auto *B = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
-    SymbolBodies.push_back(B);
-  }
+  if (Hdr->getType() != llvm::COFF::IMPORT_CODE)
+    return;
+  ThunkSym = new (Alloc) DefinedImportThunk(Name, ImpSym, Hdr->Machine);
+  SymbolBodies.push_back(ThunkSym);
 }
 
 void BitcodeFile::parse() {

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=245200&r1=245199&r2=245200&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Mon Aug 17 02:27:45 2015
@@ -33,6 +33,8 @@ using llvm::object::coff_section;
 
 class Chunk;
 class Defined;
+class DefinedImportData;
+class DefinedImportThunk;
 class Lazy;
 class SymbolBody;
 class Undefined;
@@ -182,6 +184,9 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
   std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
 
+  DefinedImportData *ImpSym = nullptr;
+  DefinedImportThunk *ThunkSym = nullptr;
+
 private:
   void parse() override;
 

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=245200&r1=245199&r2=245200&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Aug 17 02:27:45 2015
@@ -367,19 +367,13 @@ void Writer::createImportTables() {
     return;
   OutputSection *Text = createSection(".text");
   for (ImportFile *File : Symtab->ImportFiles) {
-    for (SymbolBody *B : File->getSymbols()) {
-      auto *Import = dyn_cast<DefinedImportData>(B);
-      if (!Import) {
-        // Linker-created function thunks for DLL symbols are added to
-        // .text section.
-        Text->addChunk(cast<DefinedImportThunk>(B)->getChunk());
-        continue;
-      }
-      if (Config->DelayLoads.count(Import->getDLLName().lower())) {
-        DelayIdata.add(Import);
-      } else {
-        Idata.add(Import);
-      }
+    if (DefinedImportThunk *Thunk = File->ThunkSym)
+      Text->addChunk(Thunk->getChunk());
+    DefinedImportData *Imp = File->ImpSym;
+    if (Config->DelayLoads.count(Imp->getDLLName().lower())) {
+      DelayIdata.add(Imp);
+    } else {
+      Idata.add(Imp);
     }
   }
   if (!Idata.empty()) {




More information about the llvm-commits mailing list