llvm.org GIT mirror llvm / 47b7fd5
Adding a workaround for __main linking with remote lli and Cygwin/MinGW git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193570 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Kaylor 6 years ago
9 changed file(s) with 51 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
0 ; 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
1
2 ; This fails because __main is not resolved in remote mcjit.
3 ; XFAIL: cygwin,mingw32
41
52 declare i32 @FB()
63
0 ; 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
1
2 ; This fails because __main is not resolved in remote mcjit.
3 ; XFAIL: cygwin,mingw32
41
52 declare i32 @FB()
63
0 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
1
2 ; This fails because __main is not resolved in remote mcjit on cygming.
3 ; XFAIL: cygwin,mingw32,mips
41
52 define i32 @bar() {
63 ret i32 0
0 ; RUN: %lli_mcjit -remote-mcjit -O0 -disable-lazy-compilation=false -mcjit-remote-process=lli-child-target %s
1
2 ; This fails because __main is not resolved in remote mcjit on cygming.
3 ; XFAIL: cygwin,mingw32,mips
41
52 ; The intention of this test is to verify that symbols mapped to COMMON in ELF
63 ; work as expected.
0 ; RUN: %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s
11
2 ; This fails because __main is not resolved in remote mcjit on cygming.
3 ; XFAIL: cygwin,mingw32,mips
2 ; XFAIL: mips
43
54 ; Check that a variable is always aligned as specified.
65
0 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
11
2 ; This fails because __main is not resolved in remote mcjit on cygming.
3 ; XFAIL: cygwin,mingw32,mips
2 ; XFAIL: mips
43
54 define double @test(double* %DP, double %Arg) {
65 %D = load double* %DP ; [#uses=1]
0 ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
11
2 ; This fails because __main is not resolved in remote mcjit on cygming.
3 ; XFAIL: cygwin,mingw32,mips
2 ; XFAIL: mips
43
54 @count = global i32 1, align 4
65
0 ; RUN: %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s
1
2 ; This fails because __main is not resolved in remote mcjit.
3 ; XFAIL: cygwin,mingw32
41
52 @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1
63 @ptr = global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), align 4
2626 #include "llvm/ExecutionEngine/JITMemoryManager.h"
2727 #include "llvm/ExecutionEngine/MCJIT.h"
2828 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
29 #include "llvm/IR/IRBuilder.h"
2930 #include "llvm/IR/Module.h"
3031 #include "llvm/IR/Type.h"
32 #include "llvm/IR/TypeBuilder.h"
3133 #include "llvm/IRReader/IRReader.h"
3234 #include "llvm/Support/CommandLine.h"
3335 #include "llvm/Support/Debug.h"
226228 #endif
227229 }
228230
231 // On Mingw and Cygwin, an external symbol named '__main' is called from the
232 // generated 'main' function to allow static intialization. To avoid linking
233 // problems with remote targets (because lli's remote target support does not
234 // currently handle external linking) we add a secondary module which defines
235 // an empty '__main' function.
236 static void addCygMingExtraModule(ExecutionEngine *EE,
237 LLVMContext &Context,
238 StringRef TargetTripleStr) {
239 IRBuilder<> Builder(Context);
240 Triple TargetTriple(TargetTripleStr);
241
242 // Create a new module.
243 Module *M = new Module("CygMingHelper", Context);
244 M->setTargetTriple(TargetTripleStr);
245
246 // Create an empty function named "__main".
247 Function *Result;
248 if (TargetTriple.isArch64Bit()) {
249 Result = Function::Create(
250 TypeBuilder::get(Context),
251 GlobalValue::ExternalLinkage, "__main", M);
252 } else {
253 Result = Function::Create(
254 TypeBuilder::get(Context),
255 GlobalValue::ExternalLinkage, "__main", M);
256 }
257 BasicBlock *BB = BasicBlock::Create(Context, "__main", Result);
258 Builder.SetInsertPoint(BB);
259 Value *ReturnVal;
260 if (TargetTriple.isArch64Bit())
261 ReturnVal = ConstantInt::get(Context, APInt(64, 0));
262 else
263 ReturnVal = ConstantInt::get(Context, APInt(32, 0));
264 Builder.CreateRet(ReturnVal);
265
266 // Add this new module to the ExecutionEngine.
267 EE->addModule(M);
268 }
269
270
229271 //===----------------------------------------------------------------------===//
230272 // main Driver function
231273 //
356398 return 1;
357399 }
358400 EE->addModule(XMod);
401 }
402
403 // If the target is Cygwin/MingW and we are generating remote code, we
404 // need an extra module to help out with linking.
405 if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) {
406 addCygMingExtraModule(EE, Context, Mod->getTargetTriple());
359407 }
360408
361409 // The following functions have no effect if their respective profiling