[lld] r261374 - Handle undef symbols in LTO.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 14:50:16 PST 2016
Author: rafael
Date: Fri Feb 19 16:50:16 2016
New Revision: 261374
URL: http://llvm.org/viewvc/llvm-project?rev=261374&view=rev
Log:
Handle undef symbols in LTO.
This also handles bc files is archives.
Added:
lld/trunk/test/ELF/lto/Inputs/
lld/trunk/test/ELF/lto/Inputs/archive.ll
lld/trunk/test/ELF/lto/archive.ll
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/ELF/Symbols.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=261374&r1=261373&r2=261374&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Feb 19 16:50:16 2016
@@ -446,7 +446,11 @@ void BitcodeFile::parse() {
raw_svector_ostream OS(Name);
Sym.printName(OS);
StringRef NameRef = Saver.save(StringRef(Name));
- SymbolBody *Body = new (Alloc) DefinedBitcode(NameRef);
+ SymbolBody *Body;
+ if (Sym.getFlags() & object::BasicSymbolRef::SF_Undefined)
+ Body = new (Alloc) Undefined(NameRef, false, STV_DEFAULT, false);
+ else
+ Body = new (Alloc) DefinedBitcode(NameRef);
SymbolBodies.push_back(Body);
}
}
Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=261374&r1=261373&r2=261374&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Feb 19 16:50:16 2016
@@ -209,6 +209,13 @@ std::unique_ptr<InputFile> Lazy::getMemb
// 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());
}
Added: lld/trunk/test/ELF/lto/Inputs/archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/archive.ll?rev=261374&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/Inputs/archive.ll (added)
+++ lld/trunk/test/ELF/lto/Inputs/archive.ll Fri Feb 19 16:50:16 2016
@@ -0,0 +1,6 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @f() {
+ ret void
+}
Added: lld/trunk/test/ELF/lto/archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/archive.ll?rev=261374&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/archive.ll (added)
+++ lld/trunk/test/ELF/lto/archive.ll Fri Feb 19 16:50:16 2016
@@ -0,0 +1,35 @@
+; REQUIRES: x86
+; RUN: llvm-as %S/Inputs/archive.ll -o %t1.o
+; RUN: rm -f %t.a
+; RUN: llvm-ar rcs %t.a %t1.o
+; 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
+
+
+; CHECK: Name: g (
+; CHECK-NEXT: Value:
+; CHECK-NEXT: Size:
+; CHECK-NEXT: Binding: Global
+; CHECK-NEXT: Type: Function
+; CHECK-NEXT: Other: 0
+; CHECK-NEXT: Section: .text
+
+; CHECK: Name: f (
+; CHECK-NEXT: Value:
+; CHECK-NEXT: Size:
+; CHECK-NEXT: Binding: Global
+; CHECK-NEXT: Type: Function
+; CHECK-NEXT: Other: 0
+; CHECK-NEXT: Section: .text
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @g() {
+ call void @f()
+ ret void
+}
+
+declare void @f()
+
More information about the llvm-commits
mailing list