59 if (system(std::string(
"mkdir -p \"./tmp\"").c_str()))
60 std::cerr <<
"ERROR: GCCJIT failed to create ./tmp folder. this may lead to a failure to compile code."
63 path_ =
"./tmp/XXXXXX";
66 if (mkdtemp(&
path_[0]) == 0)
68 std::cerr <<
"ERROR: GCCJIT failed to get unique working folder. Resulting compilations my be unrelyable"
72 if (system(std::string(
"mkdir -p \"" +
path_ +
"\"").c_str()))
73 std::cerr <<
"ERROR: GCCJIT failed to create compilation path. this may lead to a failure to compile code."
82 if (
path_.substr(0, 6) ==
"./tmp/")
83 if (system(std::string(
"rm -R \"" +
path_ +
"\"").c_str()))
84 std::cerr <<
"ERROR: GCCJIT failed to clean up compilation files located in " <<
path_ << std::endl;
87 void *
GCCJIT::translate(std::string code, std::set<std::string> headerpaths, std::set<std::string> librarypaths,
88 std::set<std::string> libraries, std::string &error,
bool debug)
91 if (system(
NULL) == 0)
93 error =
"system command execution not available";
99 std::string codefilename;
101 std::ofstream codeFile;
102 std::stringstream ss;
103 ss <<
"code_" << lid;
104 codefilename = ss.str();
105 codeFile.open((
path_ + codefilename + std::string(
".c")).c_str());
106 if (!codeFile.is_open())
108 error =
"failed to create code file";
115 std::stringstream ss;
116 ss <<
"gcc -c -std=c99 -fPIC -march=native -mtune=native -pipe ";
118 ss <<
"-g -O0 -Wall -Wno-unused-label ";
121 for (std::set<std::string>::const_iterator iter = headerpaths.begin(); iter != headerpaths.end(); iter++)
123 ss <<
"-I\"" << *iter <<
"\" ";
125 ss <<
path_ << codefilename <<
".c"
126 <<
" -o " <<
path_ << codefilename <<
".o";
130 int eval = system(ss.str().c_str());
135 std::cout <<
"compiler failed with code: " << eval << std::endl;
140 ss <<
"gcc -shared ";
146 for (std::set<std::string>::const_iterator iter = librarypaths.begin();iter != librarypaths.end();iter++){
147 ss <<
" -L" << *iter <<
" ";
150 ss <<
" -o " <<
path_ <<
"lib" << codefilename <<
".so " <<
path_ << codefilename <<
".o ";
153 for (std::set<std::string>::const_iterator iter = libraries.begin();iter != libraries.end();iter++){
154 ss <<
" -l\"" << *iter <<
"\" ";
157 if(!librarypaths.empty())
160 for (std::set<std::string>::const_iterator iter = librarypaths.begin();iter != librarypaths.end();iter++){
161 ss <<
",-rpath," << *iter;
165 eval = system(ss.str().c_str());
170 std::cout <<
"compiler failed with code: " << eval << std::endl;
173 void *lib = dlopen((
path_ +
"lib" + codefilename + std::string(
".so")).c_str(), RTLD_NOW | RTLD_LOCAL);
185 void *ret = dlsym(handle, name.c_str());
virtual void free(void *handle)
clean up handled returned by etiss::JIT::translate
virtual void * translate(std::string code, std::set< std::string > headerpaths, std::set< std::string > librarypaths, std::set< std::string > libraries, std::string &error, bool debug=false)
translate C code to executable code and return a handle/pointer that identifies the compilation resul...
GCCJIT(bool cleanup=true)
virtual void * getFunction(void *handle, std::string name, std::string &error)
returns a function pointer to a compiled function from the handle returned by etiss::JIT::translate
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.