[LLVMdev] 2.6/trunk Execution Engine question

Kenneth Uildriks kennethuil at gmail.com
Tue Oct 6 16:45:27 PDT 2009


>
> It just occurred to me... in the case where it's failing, the
> ExecutionEngine was trying to JIT a global, and it had never JITted
> any functions!  I'll work up a small test case, but I think it's
> relevant since the thing is trying to allocate the globals with the
> functions.
>

That was it!  The following small test program crashes in getPointerToGlobal:

#include "llvm/Module.h"
#include "llvm/Function.h"
#include "llvm/InlineAsm.h"
#include "llvm/Support/IRBuilder.h"
#include "llvm/ModuleProvider.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/Support/raw_os_ostream.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetSelect.h"
#include "llvm/ExecutionEngine/JIT.h"

#include <assert.h>

using namespace llvm;

static raw_stdout_ostream raw_cout;

int main(int argc, char** argv)
{
	// Test JITting a variable without JITting any functions.'
	Module* mod = new Module("test", getGlobalContext());
	GlobalVariable* gv = cast<GlobalVariable>(mod->getOrInsertGlobal("TestGV",
			Type::getInt32Ty(getGlobalContext())));
	gv->setInitializer(ConstantInt::get(
		Type::getInt32Ty(getGlobalContext()), 24601));

	ModuleProvider* modp = new ExistingModuleProvider(mod);
	InitializeNativeTarget();
	std::string errstring;

	ExecutionEngine* eeng = ExecutionEngine::create(modp, false, &errstring,
			CodeGenOpt::Default, true);
	if ( eeng == NULL )
	{
		raw_cout << errstring << "\n";
		exit(-1);
	}
	raw_cout << "Fixing to get pointer to global\n";
	void* gvp = eeng->getPointerToGlobal(gv);
	raw_cout << "Got pointer to global\n";
	raw_cout << "gv = " << *((int*)gvp) << "\n";
	exit(0);
}




More information about the llvm-dev mailing list