[lld] r262489 - Handle comdat in LTO.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 2 07:43:50 PST 2016
Author: rafael
Date: Wed Mar 2 09:43:50 2016
New Revision: 262489
URL: http://llvm.org/viewvc/llvm-project?rev=262489&view=rev
Log:
Handle comdat in LTO.
Added:
lld/trunk/test/ELF/lto/comdat.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=262489&r1=262488&r2=262489&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Mar 2 09:43:50 2016
@@ -13,6 +13,7 @@
#include "Symbols.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
#include "llvm/Object/IRObjectFile.h"
#include "llvm/Support/raw_ostream.h"
@@ -441,13 +442,27 @@ bool BitcodeFile::classof(const InputFil
return F->kind() == BitcodeKind;
}
-void BitcodeFile::parse() {
+void BitcodeFile::parse(DenseSet<StringRef> &ComdatGroups) {
LLVMContext Context;
ErrorOr<std::unique_ptr<IRObjectFile>> ObjOrErr =
IRObjectFile::create(MB, Context);
fatal(ObjOrErr);
IRObjectFile &Obj = **ObjOrErr;
+ const Module &M = Obj.getModule();
+
+ DenseSet<const Comdat *> KeptComdats;
+ for (const auto &P : M.getComdatSymbolTable()) {
+ StringRef N = Saver.save(P.first());
+ if (ComdatGroups.insert(N).second)
+ KeptComdats.insert(&P.second);
+ }
+
for (const BasicSymbolRef &Sym : Obj.symbols()) {
+ if (const GlobalValue *GV = Obj.getSymbolGV(Sym.getRawDataRefImpl()))
+ if (const Comdat *C = GV->getComdat())
+ if (!KeptComdats.count(C))
+ continue;
+
SmallString<64> Name;
raw_svector_ostream OS(Name);
Sym.printName(OS);
Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=262489&r1=262488&r2=262489&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Wed Mar 2 09:43:50 2016
@@ -183,7 +183,7 @@ class BitcodeFile : public InputFile {
public:
explicit BitcodeFile(MemoryBufferRef M);
static bool classof(const InputFile *F);
- void parse();
+ void parse(llvm::DenseSet<StringRef> &ComdatGroups);
ArrayRef<SymbolBody *> getSymbols() { return SymbolBodies; }
private:
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=262489&r1=262488&r2=262489&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Mar 2 09:43:50 2016
@@ -82,7 +82,7 @@ void SymbolTable<ELFT>::addFile(std::uni
// LLVM bitcode file.
if (auto *F = dyn_cast<BitcodeFile>(FileP)) {
BitcodeFiles.emplace_back(cast<BitcodeFile>(File.release()));
- F->parse();
+ F->parse(ComdatGroups);
for (SymbolBody *B : F->getSymbols())
resolve(B);
return;
@@ -151,8 +151,8 @@ template <class ELFT> void SymbolTable<E
if (BitcodeFiles.empty())
return;
ObjectFile<ELFT> *Obj = createCombinedLtoObject();
- // FIXME: We probably have to ignore comdats here.
- Obj->parse(ComdatGroups);
+ llvm::DenseSet<StringRef> DummyGroups;
+ Obj->parse(DummyGroups);
for (SymbolBody *Body : Obj->getSymbols()) {
Symbol *Sym = insert(Body);
Sym->Body = Body;
Added: lld/trunk/test/ELF/lto/comdat.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/comdat.ll?rev=262489&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/comdat.ll (added)
+++ lld/trunk/test/ELF/lto/comdat.ll Wed Mar 2 09:43:50 2016
@@ -0,0 +1,21 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o %t.o -o %t.so -shared
+; RUN: llvm-readobj -t %t.so | FileCheck %s
+
+; CHECK: Name: foo
+; CHECK-NEXT: Value:
+; CHECK-NEXT: Size: 1
+; CHECK-NEXT: Binding: Global
+; CHECK-NEXT: Type: Function
+; CHECK-NEXT: Other: 0
+; CHECK-NEXT: Section: .text
+
+target triple = "x86_64-unknown-linux-gnu"
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+$foo = comdat any
+define void @foo() comdat {
+ ret void
+}
+
More information about the llvm-commits
mailing list