[PATCH] D18872: ELF: Implement basic support for module asm in bitcode files.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 15:19:51 PDT 2016
pcc created this revision.
pcc added reviewers: rafael, ruiu.
pcc added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.
http://reviews.llvm.org/D18872
Files:
ELF/InputFiles.cpp
ELF/LTO.cpp
test/ELF/lto/module-asm.ll
Index: test/ELF/lto/module-asm.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/module-asm.ll
@@ -0,0 +1,19 @@
+; REQUIRES: x86
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t
+; RUN: llvm-nm %t | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+module asm ".text"
+module asm ".globl foo"
+; CHECK: T foo
+module asm "foo: ret"
+
+declare void @foo()
+
+define void @_start() {
+ call void @foo()
+ ret void
+}
Index: ELF/LTO.cpp
===================================================================
--- ELF/LTO.cpp
+++ ELF/LTO.cpp
@@ -87,7 +87,9 @@
for (const BasicSymbolRef &Sym : Obj->symbols()) {
GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
- assert(GV);
+ // Ignore module asm symbols.
+ if (!GV)
+ continue;
if (GV->hasAppendingLinkage()) {
Keep.push_back(GV);
continue;
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -456,34 +456,44 @@
const IRObjectFile &Obj,
const BasicSymbolRef &Sym) {
const GlobalValue *GV = Obj.getSymbolGV(Sym.getRawDataRefImpl());
- assert(GV);
- if (const Comdat *C = GV->getComdat())
- if (!KeptComdats.count(C))
- return nullptr;
+ if (GV)
+ if (const Comdat *C = GV->getComdat())
+ if (!KeptComdats.count(C))
+ return nullptr;
- uint8_t Visibility = getGvVisibility(GV);
+ uint32_t Flags = Sym.getFlags();
+ uint8_t Visibility;
+ if (GV)
+ Visibility = getGvVisibility(GV);
+ else
+ // FIXME: Set SF_Hidden flag correctly for module asm symbols, and expose
+ // protected visibility.
+ Visibility = STV_DEFAULT;
SmallString<64> Name;
raw_svector_ostream OS(Name);
Sym.printName(OS);
StringRef NameRef = Saver.save(StringRef(Name));
const Module &M = Obj.getModule();
SymbolBody *Body;
- uint32_t Flags = Sym.getFlags();
bool IsWeak = Flags & BasicSymbolRef::SF_Weak;
if (Flags & BasicSymbolRef::SF_Undefined) {
Body = new (Alloc) UndefinedBitcode(NameRef, IsWeak, Visibility);
} else if (Flags & BasicSymbolRef::SF_Common) {
+ // FIXME: Set SF_Common flag correctly for module asm symbols, and expose
+ // size and alignment.
+ assert(GV);
const DataLayout &DL = M.getDataLayout();
uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
Body = new (Alloc)
DefinedCommon(NameRef, Size, GV->getAlignment(),
IsWeak ? STB_WEAK : STB_GLOBAL, Visibility, /*Type*/ 0);
} else {
Body = new (Alloc) DefinedBitcode(NameRef, IsWeak, Visibility);
}
- if (GV->isThreadLocal())
+ // FIXME: Expose a thread-local flag for module asm symbols.
+ if (GV && GV->isThreadLocal())
Body->Type = STT_TLS;
return Body;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18872.52960.patch
Type: text/x-patch
Size: 2964 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160407/c58a4b68/attachment.bin>
More information about the llvm-commits
mailing list