[PATCH] D17527: Handle bitcode files in archive files with --whole-archive.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 15:38:04 PST 2016


ruiu created this revision.
ruiu added a reviewer: rafael.
ruiu added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.

This patch moves BitcodeFile instantiation into createObjectFile.
Previously, we handle bitcode files outside that function and did
not handle for --whole-archive.

http://reviews.llvm.org/D17527

Files:
  ELF/Driver.cpp
  ELF/InputFiles.cpp
  ELF/Symbols.cpp
  test/ELF/lto/archive.ll

Index: test/ELF/lto/archive.ll
===================================================================
--- test/ELF/lto/archive.ll
+++ test/ELF/lto/archive.ll
@@ -5,6 +5,8 @@
 ; RUN: llvm-as %s -o %t2.o
 ; RUN: ld.lld -m elf_x86_64 %t2.o %t.a -o %t3 -shared
 ; RUN: llvm-readobj -t %t3 | FileCheck %s
+; RUN: ld.lld -m elf_x86_64 %t2.o --whole-archive %t.a -o %t3 -shared
+; RUN: llvm-readobj -t %t3 | FileCheck %s
 
 
 ; CHECK:      Name: g (
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -209,13 +209,6 @@
   // read from the library.
   if (MBRef.getBuffer().empty())
     return std::unique_ptr<InputFile>(nullptr);
-
-  if (sys::fs::identify_magic(MBRef.getBuffer()) ==
-      sys::fs::file_magic::bitcode) {
-    auto Ret = make_unique<BitcodeFile>(MBRef);
-    Ret->ArchiveName = File->getName();
-    return std::move(Ret);
-  }
   return createObjectFile(MBRef, File->getName());
 }
 
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -456,22 +456,20 @@
 }
 
 template <typename T>
-static std::unique_ptr<InputFile> createELFFileAux(MemoryBufferRef MB) {
-  std::unique_ptr<T> Ret = llvm::make_unique<T>(MB);
+static InputFile *createELFFileAux(MemoryBufferRef MB) {
+  T *Ret = new T(MB);
 
   if (!Config->FirstElf)
-    Config->FirstElf = Ret.get();
-
+    Config->FirstElf = Ret;
   if (Config->EKind == ELFNoneKind) {
     Config->EKind = Ret->getELFKind();
     Config->EMachine = Ret->getEMachine();
   }
-
-  return std::move(Ret);
+  return Ret;
 }
 
 template <template <class> class T>
-static std::unique_ptr<InputFile> createELFFile(MemoryBufferRef MB) {
+static InputFile *createELFFile(MemoryBufferRef MB) {
   std::pair<unsigned char, unsigned char> Type = getElfArchType(MB.getBuffer());
   if (Type.second != ELF::ELFDATA2LSB && Type.second != ELF::ELFDATA2MSB)
     fatal("Invalid data encoding: " + MB.getBufferIdentifier());
@@ -491,13 +489,18 @@
 
 std::unique_ptr<InputFile> elf2::createObjectFile(MemoryBufferRef MB,
                                                   StringRef ArchiveName) {
-  std::unique_ptr<InputFile> F = createELFFile<ObjectFile>(MB);
+  using namespace sys::fs;
+  std::unique_ptr<InputFile> F;
+  if (identify_magic(MB.getBuffer()) == file_magic::bitcode)
+    F.reset(new BitcodeFile(MB));
+  else
+    F.reset(createELFFile<ObjectFile>(MB));
   F->ArchiveName = ArchiveName;
   return F;
 }
 
 std::unique_ptr<InputFile> elf2::createSharedFile(MemoryBufferRef MB) {
-  return createELFFile<SharedFile>(MB);
+  return std::unique_ptr<InputFile>(createELFFile<SharedFile>(MB));
 }
 
 template class elf2::ELFFileBase<ELF32LE>;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -113,9 +113,6 @@
   case file_magic::elf_shared_object:
     Files.push_back(createSharedFile(MBRef));
     return;
-  case sys::fs::file_magic::bitcode:
-    Files.push_back(make_unique<BitcodeFile>(MBRef));
-    return;
   default:
     Files.push_back(createObjectFile(MBRef));
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17527.48744.patch
Type: text/x-patch
Size: 3180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160222/89a19cd0/attachment.bin>


More information about the llvm-commits mailing list