[LLVMdev] problems running JIT code on Mac 32-bit
Eric Christopher
echristo at apple.com
Fri Oct 14 18:10:38 PDT 2011
I can duplicate this and a quick look shows that at one point we're passing the argument on the stack and then expecting it in a different location. A bug filed about this when I can take some more time to look at it would be good.
Thanks!
-eric
On Oct 12, 2011, at 9:24 PM, Nick Walters wrote:
> Hello,
>
> I am trying to run this test program via JIT on my Mac (10.7.1) where I have compiled the latest LLVM code for 32-bit and it is not working properly. Running the same code against LLVM 2.9 works fine. I also tried recompiling my same checkout of LLVM as 64-bit and re-compiled my test program and that works fine, for some reason the 32-bit version is yielding unexpected behavior. I believe I am linking with all of the required LLVM .a files. Here's my code:
>
> #include <iostream>
>
> #include "llvm/LLVMContext.h"
> #include "llvm/Module.h"
> #include "llvm/Constants.h"
> #include "llvm/DerivedTypes.h"
> #include "llvm/Instructions.h"
> #include "llvm/ExecutionEngine/JIT.h"
> #include "llvm/ExecutionEngine/Interpreter.h"
> #include "llvm/ExecutionEngine/GenericValue.h"
> #include "llvm/Support/TargetSelect.h"
> #include "llvm/Support/ManagedStatic.h"
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/Support/IRBuilder.h"
>
> using namespace std;
> using namespace llvm;
>
> int main(int argc, char** argv){
> InitializeNativeTarget();
>
> LLVMContext context;
>
> Module* module = new Module("test", context);
>
> vector<Type*> args;
> args.push_back(Type::getInt32Ty(context));
>
> FunctionType* ft = FunctionType::get(Type::getInt32Ty(context),
> args, false);
>
> Function* f = Function::Create(ft,
> GlobalValue::ExternalLinkage,
> "f", module);
>
> Value* arg = f->arg_begin();
>
> BasicBlock* bb = BasicBlock::Create(context, "entry", f);
>
> IRBuilder<> builder(bb);
>
> Value* one = builder.getInt32(1);
>
> Value* v = builder.CreateAdd(one, arg);
> builder.CreateRet(v);
>
> ExecutionEngine* engine = EngineBuilder(module).create();
>
> void* vpf = engine->getPointerToFunction(f);
>
> int32_t (*fp)(int32_t) =
> (int32_t (*)(int32_t))(intptr_t)vpf;
>
> int32_t out = fp(10);
>
> cout << "out is: " << out << endl;
>
> return 0;
> }
>
> I appreciate your help. Thanks,
>
> Nick
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111014/179c4eca/attachment.html>
More information about the llvm-dev
mailing list