mirror of
https://github.com/TinyCC/tinycc.git
synced 2025-11-16 12:34:45 +00:00
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:
committed by
grischka
parent
830b7533c9
commit
fcf2e5981f
30
tccelf.c
30
tccelf.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user