[lld] r263179 - [lto] Make sure that ctors are added to the combined module.
Sean Silva via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 10 16:50:05 PST 2016
Author: silvas
Date: Thu Mar 10 18:50:05 2016
New Revision: 263179
URL: http://llvm.org/viewvc/llvm-project?rev=263179&view=rev
Log:
[lto] Make sure that ctors are added to the combined module.
Summary:
More generally, appending linkage is a special case that we don't want
to create a SymbolBody for.
Reviewers: rafael, ruiu
Subscribers: Bigcheese, llvm-commits, joker.eph
Differential Revision: http://reviews.llvm.org/D18012
Added:
lld/trunk/test/ELF/lto/ctors.ll
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/InputFiles.h
lld/trunk/ELF/SymbolTable.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=263179&r1=263178&r2=263179&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Mar 10 18:50:05 2016
@@ -450,8 +450,10 @@ void BitcodeFile::parse(DenseSet<StringR
continue;
if (!(Flags & BasicSymbolRef::SF_Global))
continue;
- if (Flags & BasicSymbolRef::SF_FormatSpecific)
+ if (GV->hasAppendingLinkage()) {
+ ExtraKeeps.push_back(GV->getName().copy(Alloc));
continue;
+ }
uint8_t Visibility = getGvVisibility(GV);
SmallString<64> Name;
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=263179&r1=263178&r2=263179&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu Mar 10 18:50:05 2016
@@ -185,9 +185,17 @@ public:
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;
+ // Some symbols like llvm.global_ctors are internal to the IR and so
+ // don't show up in SymbolBodies, but must be kept when creating the
+ // combined LTO module. We track them here.
+ // We currently use a different Module for creating SymbolBody's vs when
+ // we are creating the combined LTO module, and so we can't store IR
+ // pointers directly and must rely on the IR names.
+ std::vector<StringRef> ExtraKeeps;
llvm::BumpPtrAllocator Alloc;
llvm::StringSaver Saver{Alloc};
};
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=263179&r1=263178&r2=263179&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Mar 10 18:50:05 2016
@@ -155,6 +155,11 @@ static void addBitcodeFile(IRMover &Move
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) {});
}
Added: lld/trunk/test/ELF/lto/ctors.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/ctors.ll?rev=263179&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/ctors.ll (added)
+++ lld/trunk/test/ELF/lto/ctors.ll Thu Mar 10 18:50:05 2016
@@ -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
More information about the llvm-commits
mailing list