[llvm] r193570 - Adding a workaround for __main linking with remote lli and Cygwin/MinGW

Andrew Kaylor andrew.kaylor at intel.com
Mon Oct 28 18:29:56 PDT 2013


Author: akaylor
Date: Mon Oct 28 20:29:56 2013
New Revision: 193570

URL: http://llvm.org/viewvc/llvm-project?rev=193570&view=rev
Log:
Adding a workaround for __main linking with remote lli and Cygwin/MinGW

Modified:
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll
    llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll
    llvm/trunk/tools/lli/lli.cpp

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll Mon Oct 28 20:29:56 2013
@@ -1,8 +1,5 @@
 ; RUN: %lli_mcjit -extra-module=%p/Inputs/cross-module-b.ll -disable-lazy-compilation=true -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
 
-; This fails because __main is not resolved in remote mcjit.
-; XFAIL: cygwin,mingw32
-
 declare i32 @FB()
 
 define i32 @FA() {

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll Mon Oct 28 20:29:56 2013
@@ -1,8 +1,5 @@
 ; RUN: %lli_mcjit -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -disable-lazy-compilation=true -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
 
-; This fails because __main is not resolved in remote mcjit.
-; XFAIL: cygwin,mingw32
-
 declare i32 @FB()
 
 define i32 @main() {

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,8 +1,5 @@
 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
 
-; This fails because __main is not resolved in remote mcjit on cygming.
-; XFAIL: cygwin,mingw32,mips
-
 define i32 @bar() {
 	ret i32 0
 }

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,8 +1,5 @@
 ; RUN: %lli_mcjit -remote-mcjit -O0 -disable-lazy-compilation=false -mcjit-remote-process=lli-child-target %s
 
-; This fails because __main is not resolved in remote mcjit on cygming.
-; XFAIL: cygwin,mingw32,mips
-
 ; The intention of this test is to verify that symbols mapped to COMMON in ELF
 ; work as expected.
 ;

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,7 +1,6 @@
 ; RUN:  %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s
 
-; This fails because __main is not resolved in remote mcjit on cygming.
-; XFAIL: cygwin,mingw32,mips
+; XFAIL: mips
 
 ; Check that a variable is always aligned as specified.
 

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,7 +1,6 @@
 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
 
-; This fails because __main is not resolved in remote mcjit on cygming.
-; XFAIL: cygwin,mingw32,mips
+; XFAIL: mips
 
 define double @test(double* %DP, double %Arg) {
 	%D = load double* %DP		; <double> [#uses=1]

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,7 +1,6 @@
 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
 
-; This fails because __main is not resolved in remote mcjit on cygming.
-; XFAIL: cygwin,mingw32,mips
+; XFAIL: mips
 
 @count = global i32 1, align 4
 

Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll (original)
+++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll Mon Oct 28 20:29:56 2013
@@ -1,8 +1,5 @@
 ; RUN: %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s
 
-; This fails because __main is not resolved in remote mcjit.
-; XFAIL: cygwin,mingw32
-
 @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1
 @ptr = global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), align 4
 @.str1 = private unnamed_addr constant [6 x i8] c"data2\00", align 1

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=193570&r1=193569&r2=193570&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Mon Oct 28 20:29:56 2013
@@ -27,8 +27,10 @@
 #include "llvm/ExecutionEngine/JITMemoryManager.h"
 #include "llvm/ExecutionEngine/MCJIT.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
+#include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/IR/TypeBuilder.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -227,6 +229,46 @@ static void do_shutdown() {
 #endif
 }
 
+// On Mingw and Cygwin, an external symbol named '__main' is called from the
+// generated 'main' function to allow static intialization.  To avoid linking
+// problems with remote targets (because lli's remote target support does not
+// currently handle external linking) we add a secondary module which defines
+// an empty '__main' function.
+static void addCygMingExtraModule(ExecutionEngine *EE,
+                                  LLVMContext &Context,
+                                  StringRef TargetTripleStr) {
+  IRBuilder<> Builder(Context);
+  Triple TargetTriple(TargetTripleStr);
+
+  // Create a new module.
+  Module *M = new Module("CygMingHelper", Context);
+  M->setTargetTriple(TargetTripleStr);
+
+  // Create an empty function named "__main".
+  Function *Result;
+  if (TargetTriple.isArch64Bit()) {
+    Result = Function::Create(
+      TypeBuilder<int64_t(void), false>::get(Context),
+      GlobalValue::ExternalLinkage, "__main", M);
+  } else {
+    Result = Function::Create(
+      TypeBuilder<int32_t(void), false>::get(Context),
+      GlobalValue::ExternalLinkage, "__main", M);
+  }
+  BasicBlock *BB = BasicBlock::Create(Context, "__main", Result);
+  Builder.SetInsertPoint(BB);
+  Value *ReturnVal;
+  if (TargetTriple.isArch64Bit())
+    ReturnVal = ConstantInt::get(Context, APInt(64, 0));
+  else
+    ReturnVal = ConstantInt::get(Context, APInt(32, 0));
+  Builder.CreateRet(ReturnVal);
+
+  // Add this new module to the ExecutionEngine.
+  EE->addModule(M);
+}
+
+
 //===----------------------------------------------------------------------===//
 // main Driver function
 //
@@ -359,6 +401,12 @@ int main(int argc, char **argv, char * c
     EE->addModule(XMod);
   }
 
+  // If the target is Cygwin/MingW and we are generating remote code, we
+  // need an extra module to help out with linking.
+  if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) {
+    addCygMingExtraModule(EE, Context, Mod->getTargetTriple());
+  }
+
   // The following functions have no effect if their respective profiling
   // support wasn't enabled in the build configuration.
   EE->RegisterJITEventListener(





More information about the llvm-commits mailing list