x86-64: Combine buffers of sections before we call tcc_run().

- Now we can run tcc -run tcc.c successfully, though there are some bugs.
- Remove jmp_table and got_table and use text_section for got and plt entries.
- Combine buffers in tcc_relocate().
- Use R_X86_64_64 instead of R_X86_64_32 for R_DATA_32 (now the name R_DATA_32 is inappropriate...).
This commit is contained in:
Shinichiro Hamaji
2009-04-13 03:22:08 +09:00
committed by grischka
parent 830b7533c9
commit fcf2e5981f
3 changed files with 56 additions and 47 deletions

View File

@@ -479,22 +479,9 @@ static void relocate_syms(TCCState *s1, int do_resolve)
#ifdef TCC_TARGET_X86_64
#define JMP_TABLE_ENTRY_SIZE 14
#define JMP_TABLE_ENTRY_MAX_NUM 4096
static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
{
char *p;
if (!s1->jmp_table) {
int size = JMP_TABLE_ENTRY_SIZE * JMP_TABLE_ENTRY_MAX_NUM;
s1->jmp_table_num = 0;
s1->jmp_table = (char *)tcc_malloc(size);
set_pages_executable(s1->jmp_table, size);
}
if (s1->jmp_table_num == JMP_TABLE_ENTRY_MAX_NUM) {
error("relocating >%d symbols are not supported",
JMP_TABLE_ENTRY_MAX_NUM);
}
p = s1->jmp_table + s1->jmp_table_num * JMP_TABLE_ENTRY_SIZE;
s1->jmp_table_num++;
char *p = (char *)section_ptr_add(text_section, JMP_TABLE_ENTRY_SIZE);
/* jmp *0x0(%rip) */
p[0] = 0xff;
p[1] = 0x25;
@@ -503,21 +490,10 @@ static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
return (unsigned long)p;
}
#define GOT_TABLE_ENTRY_MAX_NUM 4096
static unsigned long add_got_table(TCCState *s1, unsigned long val)
{
unsigned long *p;
if (!s1->got_table) {
int size = sizeof(void *) * GOT_TABLE_ENTRY_MAX_NUM;
s1->got_table_num = 0;
s1->got_table = (char *)tcc_malloc(size);
}
if (s1->got_table_num == GOT_TABLE_ENTRY_MAX_NUM) {
error("relocating >%d symbols are not supported",
GOT_TABLE_ENTRY_MAX_NUM);
}
p = s1->got_table + s1->got_table_num;
s1->got_table_num++;
unsigned long *p =
(unsigned long *)section_ptr_add(text_section, sizeof(void *));
*p = val;
return (unsigned long)p;
}