x86-64: Fix tcc -run. We need extra memory for PLT and GOT.
Size of the extra buffer is too large for now.
This commit is contained in:
parent
e6ba81b012
commit
9a7173bf69
2 changed files with 27 additions and 12 deletions
29
tcc.c
29
tcc.c
|
@ -545,6 +545,12 @@ struct TCCState {
|
||||||
|
|
||||||
/* for tcc_relocate */
|
/* for tcc_relocate */
|
||||||
int runtime_added;
|
int runtime_added;
|
||||||
|
|
||||||
|
#ifdef TCC_TARGET_X86_64
|
||||||
|
/* write PLT and GOT here */
|
||||||
|
char *runtime_plt_and_got;
|
||||||
|
unsigned int runtime_plt_and_got_offset;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The current value can be: */
|
/* The current value can be: */
|
||||||
|
@ -1311,11 +1317,6 @@ Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags)
|
||||||
|
|
||||||
static void free_section(Section *s)
|
static void free_section(Section *s)
|
||||||
{
|
{
|
||||||
#ifdef TCC_TARGET_X86_64
|
|
||||||
/* after tcc_relocate(), some sections share the data buffer.
|
|
||||||
let's check if the data is allocated not to free the shared buffers */
|
|
||||||
if (s->data_allocated)
|
|
||||||
#endif
|
|
||||||
tcc_free(s->data);
|
tcc_free(s->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10327,14 +10328,22 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||||
offset = (offset + length + 15) & ~15;
|
offset = (offset + length + 15) & ~15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TCC_TARGET_X86_64
|
||||||
|
s1->runtime_plt_and_got_offset = 0;
|
||||||
|
s1->runtime_plt_and_got = (char *)(mem + offset);
|
||||||
|
/* double the size of the buffer for got and plt entries
|
||||||
|
XXX: calculate exact size for them? */
|
||||||
|
offset *= 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (0 == mem)
|
||||||
|
return offset + 15;
|
||||||
|
|
||||||
/* relocate symbols */
|
/* relocate symbols */
|
||||||
relocate_syms(s1, 1);
|
relocate_syms(s1, 1);
|
||||||
if (s1->nb_errors)
|
if (s1->nb_errors)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (0 == mem)
|
|
||||||
return offset + 15;
|
|
||||||
|
|
||||||
/* relocate each section */
|
/* relocate each section */
|
||||||
for(i = 1; i < s1->nb_sections; i++) {
|
for(i = 1; i < s1->nb_sections; i++) {
|
||||||
s = s1->sections[i];
|
s = s1->sections[i];
|
||||||
|
@ -10357,6 +10366,10 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||||
if (s->sh_flags & SHF_EXECINSTR)
|
if (s->sh_flags & SHF_EXECINSTR)
|
||||||
set_pages_executable(ptr, length);
|
set_pages_executable(ptr, length);
|
||||||
}
|
}
|
||||||
|
#ifdef TCC_TARGET_X86_64
|
||||||
|
set_pages_executable(s1->runtime_plt_and_got,
|
||||||
|
s1->runtime_plt_and_got_offset);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
tccelf.c
8
tccelf.c
|
@ -480,7 +480,8 @@ static void relocate_syms(TCCState *s1, int do_resolve)
|
||||||
#define JMP_TABLE_ENTRY_SIZE 14
|
#define JMP_TABLE_ENTRY_SIZE 14
|
||||||
static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
|
static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
|
||||||
{
|
{
|
||||||
char *p = (char *)section_ptr_add(text_section, JMP_TABLE_ENTRY_SIZE);
|
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) */
|
/* jmp *0x0(%rip) */
|
||||||
p[0] = 0xff;
|
p[0] = 0xff;
|
||||||
p[1] = 0x25;
|
p[1] = 0x25;
|
||||||
|
@ -491,8 +492,9 @@ static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
|
||||||
|
|
||||||
static unsigned long add_got_table(TCCState *s1, unsigned long val)
|
static unsigned long add_got_table(TCCState *s1, unsigned long val)
|
||||||
{
|
{
|
||||||
unsigned long *p =
|
unsigned long *p =(unsigned long *)(s1->runtime_plt_and_got +
|
||||||
(unsigned long *)section_ptr_add(text_section, sizeof(void *));
|
s1->runtime_plt_and_got_offset);
|
||||||
|
s1->runtime_plt_and_got_offset += sizeof(void *);
|
||||||
*p = val;
|
*p = val;
|
||||||
return (unsigned long)p;
|
return (unsigned long)p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue