[lld] r240229 - COFF: Combine add{Object, Archive, Bitcode, Import} functions. NFC.

Rui Ueyama ruiu at google.com
Sat Jun 20 16:10:05 PDT 2015


Author: ruiu
Date: Sat Jun 20 18:10:05 2015
New Revision: 240229

URL: http://llvm.org/viewvc/llvm-project?rev=240229&view=rev
Log:
COFF: Combine add{Object,Archive,Bitcode,Import} functions. NFC.

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

Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=240229&r1=240228&r2=240229&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Sat Jun 20 18:10:05 2015
@@ -129,7 +129,7 @@ std::error_code ObjectFile::initializeCh
     if (Name == ".drectve") {
       ArrayRef<uint8_t> Data;
       COFFObj->getSectionContents(Sec, Data);
-      Directives = StringRef((const char *)Data.data(), Data.size()).trim();
+      Directives = std::string((const char *)Data.data(), Data.size());
       continue;
     }
     if (Name.startswith(".debug"))

Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=240229&r1=240228&r2=240229&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Sat Jun 20 18:10:05 2015
@@ -55,11 +55,12 @@ public:
   void setParentName(StringRef N) { ParentName = N; }
 
   // Returns .drectve section contents if exist.
-  virtual StringRef getDirectives() { return ""; }
+  StringRef getDirectives() { return StringRef(Directives).trim(); }
 
 protected:
   explicit InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
   MemoryBufferRef MB;
+  std::string Directives;
 
 private:
   const Kind FileKind;
@@ -105,8 +106,6 @@ public:
   // Returns the underying COFF file.
   COFFObjectFile *getCOFFObj() { return COFFObj.get(); }
 
-  StringRef getDirectives() override { return Directives; }
-
 private:
   std::error_code initializeChunks();
   std::error_code initializeSymbols();
@@ -115,7 +114,6 @@ private:
                                bool IsFirst);
 
   std::unique_ptr<COFFObjectFile> COFFObj;
-  StringRef Directives;
   llvm::BumpPtrAllocator Alloc;
 
   // List of all chunks defined by this file. This includes both section
@@ -168,16 +166,12 @@ public:
   LTOModule *getModule() const { return M.get(); }
   LTOModule *releaseModule() { return M.release(); }
 
-  // Returns linker directives from module flags metadata if present.
-  StringRef getDirectives() override { return Directives; }
-
 private:
   std::error_code parse() override;
 
   std::vector<SymbolBody *> SymbolBodies;
   llvm::BumpPtrAllocator Alloc;
   std::unique_ptr<LTOModule> M;
-  std::string Directives;
 };
 
 } // namespace coff

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=240229&r1=240228&r2=240229&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Sat Jun 20 18:10:05 2015
@@ -30,14 +30,25 @@ SymbolTable::SymbolTable() {
 std::error_code SymbolTable::addFile(std::unique_ptr<InputFile> File) {
   if (auto EC = File->parse())
     return EC;
-  InputFile *FileP = File.release();
-  if (auto *P = dyn_cast<ObjectFile>(FileP))
-    return addObject(P);
-  if (auto *P = dyn_cast<ArchiveFile>(FileP))
-    return addArchive(P);
-  if (auto *P = dyn_cast<BitcodeFile>(FileP))
-    return addBitcode(P);
-  return addImport(cast<ImportFile>(FileP));
+  InputFile *F = File.release();
+  if (auto *P = dyn_cast<ObjectFile>(F)) {
+    ObjectFiles.emplace_back(P);
+  } else if (auto *P = dyn_cast<ArchiveFile>(F)) {
+    ArchiveFiles.emplace_back(P);
+  } else if (auto *P = dyn_cast<BitcodeFile>(F)) {
+    BitcodeFiles.emplace_back(P);
+  } else {
+    ImportFiles.emplace_back(cast<ImportFile>(F));
+  }
+
+  for (SymbolBody *B : F->getSymbols())
+    if (B->isExternal())
+      if (auto EC = resolve(B))
+        return EC;
+
+  // If a object file contains .drectve section,
+  // read that and add files listed there.
+  return addDirectives(F);
 }
 
 std::error_code SymbolTable::addDirectives(InputFile *File) {
@@ -57,45 +68,6 @@ std::error_code SymbolTable::addDirectiv
   return std::error_code();
 }
 
-std::error_code SymbolTable::addObject(ObjectFile *File) {
-  ObjectFiles.emplace_back(File);
-  for (SymbolBody *Body : File->getSymbols())
-    if (Body->isExternal())
-      if (auto EC = resolve(Body))
-        return EC;
-
-  // If an object file contains .drectve section, read it and add
-  // files listed in the section.
-  return addDirectives(File);
-}
-
-std::error_code SymbolTable::addArchive(ArchiveFile *File) {
-  ArchiveFiles.emplace_back(File);
-  for (SymbolBody *Body : File->getSymbols())
-    if (auto EC = resolve(Body))
-      return EC;
-  return std::error_code();
-}
-
-std::error_code SymbolTable::addBitcode(BitcodeFile *File) {
-  BitcodeFiles.emplace_back(File);
-  for (SymbolBody *Body : File->getSymbols())
-    if (Body->isExternal())
-      if (auto EC = resolve(Body))
-        return EC;
-
-  // Add any linker directives from the module flags metadata.
-  return addDirectives(File);
-}
-
-std::error_code SymbolTable::addImport(ImportFile *File) {
-  ImportFiles.emplace_back(File);
-  for (SymbolBody *Body : File->getSymbols())
-    if (auto EC = resolve(Body))
-      return EC;
-  return std::error_code();
-}
-
 bool SymbolTable::reportRemainingUndefines() {
   bool Ret = false;
   for (auto &I : Symtab) {

Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=240229&r1=240228&r2=240229&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Sat Jun 20 18:10:05 2015
@@ -82,11 +82,6 @@ public:
 private:
   std::error_code addDirectives(InputFile *File);
 
-  std::error_code addObject(ObjectFile *File);
-  std::error_code addArchive(ArchiveFile *File);
-  std::error_code addImport(ImportFile *File);
-  std::error_code addBitcode(BitcodeFile *File);
-
   std::error_code resolve(SymbolBody *Body);
   std::error_code resolveLazy(StringRef Name);
   std::error_code addMemberFile(Lazy *Body);





More information about the llvm-commits mailing list