mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08: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)
|
if (s1->nb_errors)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
s1->runtime_plt_and_got_offset = 0;
|
s1->runtime_plt_and_got_offset = 0;
|
||||||
s1->runtime_plt_and_got = (char *)(mem + offset);
|
s1->runtime_plt_and_got = (char *)(mem + offset);
|
||||||
/* double the size of the buffer for got and plt entries
|
/* double the size of the buffer for got and plt entries
|
||||||
XXX: calculate exact size for them? */
|
XXX: calculate exact size for them? */
|
||||||
offset *= 2;
|
offset *= 2;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (0 == mem)
|
if (0 == mem)
|
||||||
@ -1722,9 +1724,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
set_pages_executable(s1->runtime_plt_and_got,
|
set_pages_executable(s1->runtime_plt_and_got,
|
||||||
s1->runtime_plt_and_got_offset);
|
s1->runtime_plt_and_got_offset);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1859,6 +1863,9 @@ TCCState *tcc_new(void)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
tcc_define_symbol(s, "_WIN32", NULL);
|
tcc_define_symbol(s, "_WIN32", NULL);
|
||||||
|
#ifdef TCC_TARGET_X86_64
|
||||||
|
tcc_define_symbol(s, "_WIN64", NULL);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
tcc_define_symbol(s, "__unix__", NULL);
|
tcc_define_symbol(s, "__unix__", NULL);
|
||||||
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;
|
struct InlineFunc **inline_fns;
|
||||||
int nb_inline_fns;
|
int nb_inline_fns;
|
||||||
|
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
/* write PLT and GOT here */
|
/* write PLT and GOT here */
|
||||||
char *runtime_plt_and_got;
|
char *runtime_plt_and_got;
|
||||||
unsigned int runtime_plt_and_got_offset;
|
unsigned int runtime_plt_and_got_offset;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The current value can be: */
|
/* 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
|
#ifdef TCC_TARGET_X86_64
|
||||||
#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)
|
||||||
@ -502,6 +503,7 @@ static unsigned long add_got_table(TCCState *s1, unsigned long val)
|
|||||||
return (unsigned long)p;
|
return (unsigned long)p;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* relocate a given section (CPU dependent) */
|
/* relocate a given section (CPU dependent) */
|
||||||
static void relocate_section(TCCState *s1, Section *s)
|
static void relocate_section(TCCState *s1, Section *s)
|
||||||
@ -679,6 +681,7 @@ static void relocate_section(TCCState *s1, Section *s)
|
|||||||
*(int *)ptr += val;
|
*(int *)ptr += val;
|
||||||
break;
|
break;
|
||||||
case R_X86_64_PC32: {
|
case R_X86_64_PC32: {
|
||||||
|
long long diff;
|
||||||
if (s1->output_type == TCC_OUTPUT_DLL) {
|
if (s1->output_type == TCC_OUTPUT_DLL) {
|
||||||
/* DLL relocation */
|
/* DLL relocation */
|
||||||
esym_index = s1->symtab_to_dynsym[sym_index];
|
esym_index = s1->symtab_to_dynsym[sym_index];
|
||||||
@ -690,13 +693,15 @@ static void relocate_section(TCCState *s1, Section *s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long diff = val - addr;
|
diff = (long long)val - addr;
|
||||||
if (diff <= -2147483647 || diff > 2147483647) {
|
if (diff <= -2147483647 || diff > 2147483647) {
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
/* XXX: naive support for over 32bit jump */
|
/* XXX: naive support for over 32bit jump */
|
||||||
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||||
val = add_jmp_table(s1, val);
|
val = add_jmp_table(s1, val);
|
||||||
diff = val - addr;
|
diff = val - addr;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (diff <= -2147483647 || diff > 2147483647) {
|
if (diff <= -2147483647 || diff > 2147483647) {
|
||||||
error("internal error: relocation failed");
|
error("internal error: relocation failed");
|
||||||
}
|
}
|
||||||
@ -712,11 +717,13 @@ static void relocate_section(TCCState *s1, Section *s)
|
|||||||
*(int *)ptr = val;
|
*(int *)ptr = val;
|
||||||
break;
|
break;
|
||||||
case R_X86_64_GOTPCREL:
|
case R_X86_64_GOTPCREL:
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
if (s1->output_type == TCC_OUTPUT_MEMORY) {
|
||||||
val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;
|
val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;
|
||||||
*(int *)ptr += val - addr;
|
*(int *)ptr += val - addr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
*(int *)ptr += (s1->got->sh_addr - addr +
|
*(int *)ptr += (s1->got->sh_addr - addr +
|
||||||
s1->got_offsets[sym_index] - 4);
|
s1->got_offsets[sym_index] - 4);
|
||||||
break;
|
break;
|
||||||
|
2
tccgen.c
2
tccgen.c
@ -2652,7 +2652,7 @@ the_end:
|
|||||||
|
|
||||||
/* long is never used as type */
|
/* long is never used as type */
|
||||||
if ((t & VT_BTYPE) == VT_LONG)
|
if ((t & VT_BTYPE) == VT_LONG)
|
||||||
#ifndef TCC_TARGET_X86_64
|
#if !defined TCC_TARGET_X86_64 || defined TCC_TARGET_PE
|
||||||
t = (t & ~VT_BTYPE) | VT_INT;
|
t = (t & ~VT_BTYPE) | VT_INT;
|
||||||
#else
|
#else
|
||||||
t = (t & ~VT_BTYPE) | VT_LLONG;
|
t = (t & ~VT_BTYPE) | VT_LLONG;
|
||||||
|
Loading…
Reference in New Issue
Block a user