Ok apparently I messed something while building shared library. It works
Dnia 1 stycznia 2019 16:05 [email protected]
<[email protected]> napisał(a):
Hi I recently downloaded version tcc-0.9.27.tar.bz2 and
built it with Visual Studio compiler. I tried to write code with compiles and
run from memory just like in libtcc_test.c example from
tcc-0.9.27-win32-bin.zip (I could not find this example in tcc-0.9.27.tar.bz2
package) There are few things wrong with version I don't know if previous
versions work I did not try them. 1. DLL built from tcc-0.9.27.tar.bz2 does
not export tcc_relocate function but dll in tcc-0.9.27-win32-bin.zip has it.
Why ? 2. tcc_get_symbol does not work properly in DLL from tcc-0.9.27.tar.bz2
or tcc-0.9.27-win32-bin.zip. Instead of returning address of function in memory
it returns byte offset from .text section to that function. In case of failure
this function returns 0 but in case of symbol being at the begin of bytecode it
will also return 0. 3. I'm not sure if compilation in memory ever worked
in Windows newer than XP. Even in case where tcc_get_symbol would return proper
address it's not gonna work because of DEP protection. Can somebody confirm
that it works on Windows ? My test program: #include
<libtcc/libtcc.h> typedef int(*func)(); void compileTest() {
HMODULE libtccHandle = GetModuleHandleA("libtcc"); void*
p_tcc_relocate = GetProcAddress(libtccHandle, "tcc_relocate");
TCCState *s; func z; s = tcc_new(); tcc_set_output_type(s,
TCC_OUTPUT_MEMORY); const char* program = "int test(int a){\n"
"return 5;\n" "}\n" "int test1(int a){\n"
"return 2;" "}\n" "int main() {\n" "return
test(5)\n;" "}\n"; int status = tcc_compile_string(s, program);
//tcc_relocate(s, TCC_RELOCATE_AUTO); z = (func)tcc_get_symbol(s,
"main"); void* pT = tcc_get_symbol(s, "test"); void* pT1 =
tcc_get_symbol(s, "test1"); /* run the code */ int r = z();
tcc_delete(s); } ______________________________
Tinycc-devel mailing list
[email protected]
lists.nongnu.org lists.nongnu.org
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel