tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Tinycc-devel] libtcc not working properly on x86-64 targets


From: Michael Kuklinski
Subject: RE: [Tinycc-devel] libtcc not working properly on x86-64 targets
Date: Tue, 22 Dec 2009 13:56:00 -0600

If I define TCC_TARGET_PE, I get "internal error: relocation failed" in relocate_section in tccelf.c, because diff gets assigned to 0x000000013ffb1010 - 0x000000000034fc71, which is certainly greater than 32-bits.

That's how I arrived at non-PE mode in the first place, as then when you are using TCC_OUTPUT_MEMORY, it can use the jump table, which -does- call the function though does not carry over the parameters.

Also, on that note, add_jmp_table needs to be changed to:

static uplong add_jmp_table(TCCState *s1, uplong val)

{

    char *p = s1->runtime_plt_and_got + s1->runtime_plt_and_got_offset;

    s1->runtime_plt_and_got_offset += JMP_TABLE_ENTRY_SIZE;

    /* jmp *0x0(%rip) */

    p[0] = 0xFF;

    p[1] = 0x25;

    *(unsigned long *)(p + 2) = 0;

    *(uplong *)(p + 6) = val;

    return (uplong)p;

}

The return needs to be 64-bit (as it represents a pointer), and when val is put into the memory block, it also needs to retain its 64-bit-edness, as we want what comes out to be equivalent to FF 25 00 00 00 00 PP PP PP PP PP PP PP PP, telling it that 0 instructions after this is done, call that pointer. It was being truncated before.

-Michael

-----Original Message-----
From: address@hidden [mailto:address@hidden] On Behalf Of grischka
Sent: Tuesday, December 22, 2009 9:21 AM
To: address@hidden
Subject: RE: [Tinycc-devel] libtcc not working properly on x86-64 targets

Michael Kuklinski wrote:

 > 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.

I just wonder how did you get into add_jump_table?  It's defined

only for non-PE targets and on those an unsigned long _IS_ 64 bit,

so you wont have problems with truncation.

 > 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.

FYI, your example works just fine for me without modification to tcc

on both Windows 7 (64) and Ubuntu (amd64).  Also it is not much

different to the libtcc_test example so the scenario is at least not

completely untested.

Still I don't say there aren't bugs and probably you are right that

value in put_elf_sym and also val/addr in relocate_section should be

uplong.

In any case if you are on windows, make sure to compile libtcc with

PE support.  Otherwise the generated code would use incompatible

calling convention to functions added using tcc_add_symbol.

--- grischka


_______________________________________________

Tinycc-devel mailing list

address@hidden

http://lists.nongnu.org/mailman/listinfo/tinycc-devel


reply via email to

[Prev in Thread] Current Thread [Next in Thread]