[lld] r265956 - ELF: Implement basic support for module asm in bitcode files.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 09:39:45 PDT 2016


Author: pcc
Date: Mon Apr 11 11:39:43 2016
New Revision: 265956

URL: http://llvm.org/viewvc/llvm-project?rev=265956&view=rev
Log:
ELF: Implement basic support for module asm in bitcode files.

Differential Revision: http://reviews.llvm.org/D18872

Added:
    lld/trunk/test/ELF/lto/module-asm.ll
Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=265956&r1=265955&r2=265956&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Apr 11 11:39:43 2016
@@ -461,12 +461,19 @@ BitcodeFile::createSymbolBody(const Dens
                               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);
@@ -475,11 +482,13 @@ BitcodeFile::createSymbolBody(const Dens
 
   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)
@@ -488,7 +497,8 @@ BitcodeFile::createSymbolBody(const Dens
   } 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;
 }

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=265956&r1=265955&r2=265956&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Mon Apr 11 11:39:43 2016
@@ -87,7 +87,9 @@ void BitcodeCompiler::add(BitcodeFile &F
 
   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;

Added: lld/trunk/test/ELF/lto/module-asm.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/module-asm.ll?rev=265956&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/module-asm.ll (added)
+++ lld/trunk/test/ELF/lto/module-asm.ll Mon Apr 11 11:39:43 2016
@@ -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
+}




More information about the llvm-commits mailing list