|
From: | Michael Kuklinski |
Subject: | RE: [Tinycc-devel] libtcc not working properly on x86-64 targets |
Date: | Tue, 22 Dec 2009 04:17:20 -0600 |
There appears to be a problem in how it configures the jump table
in add_jump_table… after fixing the unsigned long to a uplong, that
appears to be where the truncation occurs. However, there is no native jmp
operation for 64-bit addresses which is problematic… everything is supposed to
be handled as 32-bit offsets. There appear to be a variety of problems there and
in the functions leading up to it where things are passed as 32-bit variables
instead of 64-bit, which causes truncation before then. From:
address@hidden
[mailto:address@hidden On Behalf
Of Michael Kuklinski I'm going to try to restate my problem
since I poorly presented it originally. Using both the Master and the
Mob revisions, I have the
same problem in x86-64 mode. If I attempt to pass a pointer to a function using
tcc_add_symbol, the pointer somewhere down the line
becomes truncated to 32-bit. I have tested this two ways
(this is C++, btw): #include <libtcc.h> #include <stdio.h> #define TESTMODE 0 static const char
*s_program =
\ "
\ int main ()
\ {
\
print(\"Hello, World!\");
\
return 0;
\ }
\ "; #if TESTMODE == 1 static void *s_funcptr =
LL0x1122334455667788; #else // TESTMODE == 0 void print (const char
*str) { printf(str); } static void *s_funcptr = (void*)print; #endif // TESTMODE int main () { TCCState *compile_state = tcc_new(); tcc_add_symbol(compile_state, “print”, s_funcptr); tcc_set_output_type(compile_state, TCC_OUTPUT_MEMORY); tcc_compile_string(compile_state, s_program); tcc_run(compile_state, 0, 0); return 0; } If TESTMODE is 0, then it
returns an unhandled exception – the reason? The function print is at address 0x000000013F8D100A, and the system is truncating it to
0x000000003F8D100A... illegal access exception. The same
occurs when TESTMODE is 1 –
I receive an illegal
access exception in addressing 0x0000000055667788. The upper 32 bits are being truncated by some mechanism within
the compiler. I did find one bug: static int put_elf_sym( Section *s,
unsigned long value, unsigned long size,
int info, int other, int shndx, const char *name); The above is located at line
191 in libtcc.c (on the mob release), and the value parameter should be type uplong,
which on 64-bit builds is defined as unsigned long long. However, fixing this does not solve the problem. I am too unfamiliar with the
compiler internals to figure out where this is failing, so any assistance would
be grand. --Michael |
[Prev in Thread] | Current Thread | [Next in Thread] |