[PATCH] D18012: [lto] Make sure that ctors are added to the combined module.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 14:31:50 PST 2016


silvas created this revision.
silvas added reviewers: rafael, ruiu.
silvas added subscribers: llvm-commits, Bigcheese.
Herald added a subscriber: joker.eph.

This is actually a bit too broad and will result in issues with intrinsics.
That will be addressed in the next patch.

http://reviews.llvm.org/D18012

Files:
  ELF/InputFiles.cpp
  ELF/InputFiles.h
  ELF/SymbolTable.cpp
  test/ELF/lto/ctors.ll

Index: test/ELF/lto/ctors.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/ctors.ll
@@ -0,0 +1,15 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared
+; RUN: llvm-readobj -sections %t.so | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null }]
+define void @ctor() {
+  ret void
+}
+
+; The llvm.global_ctors should end up producing constructors.
+; CHECK: Name: .ctors
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -144,6 +144,11 @@
     assert(GV);
     Keep.push_back(GV);
   }
+  for (StringRef S : F.getExtraKeeps()) {
+    GlobalValue *GV = M->getNamedValue(S);
+    assert(GV);
+    Keep.push_back(GV);
+  }
   Mover.move(std::move(M), Keep, [](GlobalValue &, IRMover::ValueAdder) {});
 }
 
Index: ELF/InputFiles.h
===================================================================
--- ELF/InputFiles.h
+++ ELF/InputFiles.h
@@ -185,9 +185,11 @@
   static bool classof(const InputFile *F);
   void parse(llvm::DenseSet<StringRef> &ComdatGroups);
   ArrayRef<SymbolBody *> getSymbols() { return SymbolBodies; }
+  ArrayRef<StringRef> getExtraKeeps() { return ExtraKeeps; }
 
 private:
   std::vector<SymbolBody *> SymbolBodies;
+  std::vector<StringRef> ExtraKeeps;
   llvm::BumpPtrAllocator Alloc;
   llvm::StringSaver Saver{Alloc};
 };
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -450,8 +450,10 @@
         continue;
     if (!(Flags & BasicSymbolRef::SF_Global))
         continue;
-    if (Flags & BasicSymbolRef::SF_FormatSpecific)
+    if (Flags & BasicSymbolRef::SF_FormatSpecific) {
+      ExtraKeeps.push_back(GV->getName().copy(Alloc));
       continue;
+    }
     uint8_t Visibility = getGvVisibility(GV);
 
     SmallString<64> Name;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18012.50198.patch
Type: text/x-patch
Size: 2151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160309/33e357f1/attachment.bin>


More information about the llvm-commits mailing list