From 3ea4acb9b9151442da2fb6057906aff4c094bcef Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 18 Jul 2009 22:05:27 +0200 Subject: [PATCH] pe32+ target: add in various #define's --- libtcc.c | 7 +++++++ tcc.h | 2 ++ tccelf.c | 9 ++++++++- tccgen.c | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libtcc.c b/libtcc.c index 30cc5529..8a6fa0cb 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1689,6 +1689,7 @@ 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); @@ -1696,6 +1697,7 @@ int tcc_relocate(TCCState *s1, void *ptr) XXX: calculate exact size for them? */ offset *= 2; #endif +#endif if (0 == mem) return offset + 15; @@ -1722,10 +1724,12 @@ 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); diff --git a/tcc.h b/tcc.h index 60da4fae..ab95f8d2 100644 --- a/tcc.h +++ b/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: */ diff --git a/tccelf.c b/tccelf.c index f0c12c30..5981d685 100644 --- a/tccelf.c +++ b/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; diff --git a/tccgen.c b/tccgen.c index 3b623830..c59613b1 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2652,7 +2652,7 @@ the_end: /* long is never used as type */ 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; #else t = (t & ~VT_BTYPE) | VT_LLONG; -- 2.11.4.GIT