[llvm] r223656 - Fix linking of prologue data.

Rafael Espindola rafael.espindola at gmail.com
Mon Dec 8 05:44:38 PST 2014


Author: rafael
Date: Mon Dec  8 07:44:38 2014
New Revision: 223656

URL: http://llvm.org/viewvc/llvm-project?rev=223656&view=rev
Log:
Fix linking of prologue data.

It would crash when the function was lazy linked.

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/test/Linker/prologuedata.ll

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=223656&r1=223655&r2=223656&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Dec  8 07:44:38 2014
@@ -1177,6 +1177,17 @@ bool ModuleLinker::linkFunctionBody(Func
   if (std::error_code EC = Src->materialize())
     return emitError(EC.message());
 
+  // Link in the prefix data.
+  if (Src->hasPrefixData())
+    Dst->setPrefixData(MapValue(Src->getPrefixData(), ValueMap, RF_None,
+                               &TypeMap, &ValMaterializer));
+
+  // Link in the prologue data.
+  if (Src->hasPrologueData())
+    Dst->setPrologueData(MapValue(Src->getPrologueData(), ValueMap, RF_None,
+                                 &TypeMap, &ValMaterializer));
+
+
   // Go through and convert function arguments over, remembering the mapping.
   Function::arg_iterator DI = Dst->arg_begin();
   for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();
@@ -1485,17 +1496,6 @@ bool ModuleLinker::run() {
       continue;
 
     Function *DF = cast<Function>(ValueMap[&SF]);
-
-    // Link in the prefix data.
-    if (SF.hasPrefixData())
-      DF->setPrefixData(MapValue(SF.getPrefixData(), ValueMap, RF_None,
-                                 &TypeMap, &ValMaterializer));
-
-    // Link in the prologue data.
-    if (SF.hasPrologueData())
-      DF->setPrologueData(MapValue(SF.getPrologueData(), ValueMap, RF_None,
-                                   &TypeMap, &ValMaterializer));
-
     if (linkFunctionBody(DF, &SF))
       return true;
   }
@@ -1522,13 +1522,6 @@ bool ModuleLinker::run() {
     LazilyLinkFunctions.pop_back();
 
     Function *DF = cast<Function>(ValueMap[SF]);
-    if (SF->hasPrefixData()) {
-      // Link in the prefix data.
-      DF->setPrefixData(MapValue(SF->getPrefixData(), ValueMap, RF_None,
-                                 &TypeMap, &ValMaterializer));
-    }
-
-    // Link in function body.
     if (linkFunctionBody(DF, SF))
       return true;
   }

Modified: llvm/trunk/test/Linker/prologuedata.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/prologuedata.ll?rev=223656&r1=223655&r2=223656&view=diff
==============================================================================
--- llvm/trunk/test/Linker/prologuedata.ll (original)
+++ llvm/trunk/test/Linker/prologuedata.ll Mon Dec  8 07:44:38 2014
@@ -1,9 +1,21 @@
-; RUN: echo > %t.ll
-; RUN: llvm-link %t.ll %s -S -o - | FileCheck %s
+; RUN: llvm-link %s -S -o - | FileCheck %s
 
- at i = linkonce_odr global i32 1
+ at g1 = global void()* @f2
+; CHECK: @g1 = global void ()* @f2
 
-; CHECK: define void @f() prologue i32* @i
-define void @f() prologue i32* @i {
+ at p1 = global i8 42
+; CHECK: @p1 = global i8 42
+
+ at p2 = internal global i8 43
+; CHECK: @p2 = internal global i8 43
+
+define void @f1() prologue i8* @p1 {
+  ret void
+}
+; CHECK: define void @f1() prologue i8* @p1 {
+
+define internal void @f2() prologue i8* @p2 {
   ret void
 }
+
+; CHECK: define internal void @f2() prologue i8* @p2 {





More information about the llvm-commits mailing list