|
From: | Michael Kuklinski |
Subject: | RE: [Tinycc-devel] libtcc not working properly on x86-64 targets |
Date: | Mon, 21 Dec 2009 15:52:18 -0600 |
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] |