mirror of
https://github.com/frida/tinycc
synced 2024-12-29 08:09:41 +03:00
pe32+ target: add in various #define's
This commit is contained in:
parent
719ba918dd
commit
3ea4acb9b9
7
libtcc.c
7
libtcc.c
@ -1689,12 +1689,14 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||
if (s1->nb_errors)
|
||||
return -1;
|
||||
|
||||
#ifndef TCC_TARGET_PE
|
||||
#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
|
||||
#endif
|
||||
|
||||
if (0 == mem)
|
||||
@ -1722,9 +1724,11 @@ int tcc_relocate(TCCState *s1, void *ptr)
|
||||
if (s->sh_flags & SHF_EXECINSTR)
|
||||
set_pages_executable(ptr, length);
|
||||
}
|
||||
#ifndef TCC_TARGET_PE
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
set_pages_executable(s1->runtime_plt_and_got,
|
||||
s1->runtime_plt_and_got_offset);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -1859,6 +1863,9 @@ TCCState *tcc_new(void)
|
||||
#endif
|
||||
#ifdef TCC_TARGET_PE
|
||||
tcc_define_symbol(s, "_WIN32", NULL);
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
tcc_define_symbol(s, "_WIN64", NULL);
|
||||
#endif
|
||||
#else
|
||||
tcc_define_symbol(s, "__unix__", NULL);
|
||||
tcc_define_symbol(s, "__unix", NULL);
|
||||
|
2
tcc.h
2
tcc.h
@ -491,11 +491,13 @@ struct TCCState {
|
||||
struct InlineFunc **inline_fns;
|
||||
int nb_inline_fns;
|
||||
|
||||
#ifndef TCC_TARGET_PE
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
/* write PLT and GOT here */
|
||||
char *runtime_plt_and_got;
|
||||
unsigned int runtime_plt_and_got_offset;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
/* The current value can be: */
|
||||
|
9
tccelf.c
9
tccelf.c
@ -479,6 +479,7 @@ static void relocate_syms(TCCState *s1, int do_resolve)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef TCC_TARGET_PE
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
#define JMP_TABLE_ENTRY_SIZE 14
|
||||
static unsigned long add_jmp_table(TCCState *s1, unsigned long val)
|
||||
@ -502,6 +503,7 @@ static unsigned long add_got_table(TCCState *s1, unsigned long val)
|
||||
return (unsigned long)p;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* relocate a given section (CPU dependent) */
|
||||
static void relocate_section(TCCState *s1, Section *s)
|
||||
@ -679,6 +681,7 @@ static void relocate_section(TCCState *s1, Section *s)
|
||||
*(int *)ptr += val;
|
||||
break;
|
||||
case R_X86_64_PC32: {
|
||||
long long diff;
|
||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||
/* DLL relocation */
|
||||
esym_index = s1->symtab_to_dynsym[sym_index];
|
||||
@ -690,13 +693,15 @@ static void relocate_section(TCCState *s1, Section *s)
|
||||
break;
|
||||
}
|
||||
}
|
||||
long diff = val - addr;
|
||||
diff = (long long)val - addr;
|
||||
if (diff <= -2147483647 || diff > 2147483647) {
|
||||
#ifndef TCC_TARGET_PE
|
||||
/* XXX: naive support for over 32bit jump */
|
||||
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||
val = add_jmp_table(s1, val);
|
||||
diff = val - addr;
|
||||
}
|
||||
#endif
|
||||
if (diff <= -2147483647 || diff > 2147483647) {
|
||||
error("internal error: relocation failed");
|
||||
}
|
||||
@ -712,11 +717,13 @@ static void relocate_section(TCCState *s1, Section *s)
|
||||
*(int *)ptr = val;
|
||||
break;
|
||||
case R_X86_64_GOTPCREL:
|
||||
#ifndef TCC_TARGET_PE
|
||||
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||
val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;
|
||||
*(int *)ptr += val - addr;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
*(int *)ptr += (s1->got->sh_addr - addr +
|
||||
s1->got_offsets[sym_index] - 4);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user