[lld] r239385 - COFF: Allow the combined LTO object to define new symbols.

Peter Collingbourne peter at pcc.me.uk
Mon Jun 8 19:53:10 PDT 2015


Author: pcc
Date: Mon Jun  8 21:53:09 2015
New Revision: 239385

URL: http://llvm.org/viewvc/llvm-project?rev=239385&view=rev
Log:
COFF: Allow the combined LTO object to define new symbols.

The LLVM code generator can sometimes synthesize symbols, such as SSE
constants, that are not visible via the LTOModule interface. Allow such
symbols so long as they have definitions.

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

Added:
    lld/trunk/test/COFF/lto-new-symbol.ll
Modified:
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=239385&r1=239384&r2=239385&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Mon Jun  8 21:53:09 2015
@@ -269,12 +269,18 @@ std::error_code SymbolTable::addCombined
     if (!Body->isExternal())
       continue;
 
-    // Find an existing Symbol. We should not see any new symbols at this point.
+    // Find an existing Symbol. We should not see any new undefined symbols at
+    // this point.
     StringRef Name = Body->getName();
-    Symbol *Sym = Symtab[Name];
+    Symbol *&Sym = Symtab[Name];
     if (!Sym) {
-      llvm::errs() << "LTO: unexpected new symbol: " << Name << '\n';
-      return make_error_code(LLDError::BrokenFile);
+      if (!isa<Defined>(Body)) {
+        llvm::errs() << "LTO: undefined symbol: " << Name << '\n';
+        return make_error_code(LLDError::BrokenFile);
+      }
+      Sym = new (Alloc) Symbol(Body);
+      Body->setBackref(Sym);
+      continue;
     }
     Body->setBackref(Sym);
 

Added: lld/trunk/test/COFF/lto-new-symbol.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto-new-symbol.ll?rev=239385&view=auto
==============================================================================
--- lld/trunk/test/COFF/lto-new-symbol.ll (added)
+++ lld/trunk/test/COFF/lto-new-symbol.ll Mon Jun  8 21:53:09 2015
@@ -0,0 +1,16 @@
+; RUN: llvm-as -o %t.obj %s
+; RUN: lld -flavor link2 /out:%t.exe /entry:foo /subsystem:console %t.obj
+
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @foo(<4 x i32>* %p, <4 x float>* %q, i1 %t) nounwind {
+entry:
+  br label %loop
+loop:
+  store <4 x i32><i32 1073741824, i32 1073741824, i32 1073741824, i32 1073741824>, <4 x i32>* %p
+  store <4 x float><float 2.0, float 2.0, float 2.0, float 2.0>, <4 x float>* %q
+  br i1 %t, label %loop, label %ret
+ret:
+  ret void
+}





More information about the llvm-commits mailing list