History

pe32+ target: add in various #define's

grischka committed 17 years ago

Commit 3ea4acb1 parent 719ba914 files · +18 −2Browse files

Unified · Split

4 files
  1. libtcc.c +7 −0
  2. tcc.h +2 −0
  3. tccelf.c +8 −1
  4. tccgen.c +1 −1
libtcc.c+7−0
@@ -1689,12 +1689,14 @@ int tcc_relocate(TCCState *s1, void *ptr) · 1688 unmodified lines
1689 if (s1->nb_errors)1689 if (s1->nb_errors)
1690 return -1;1690 return -1;
1691 1691
1692#ifndef TCC_TARGET_PE
1692#ifdef TCC_TARGET_X86_641693#ifdef TCC_TARGET_X86_64
1693 s1->runtime_plt_and_got_offset = 0;1694 s1->runtime_plt_and_got_offset = 0;
1694 s1->runtime_plt_and_got = (char *)(mem + offset);1695 s1->runtime_plt_and_got = (char *)(mem + offset);
1695 /* double the size of the buffer for got and plt entries1696 /* double the size of the buffer for got and plt entries
1696 XXX: calculate exact size for them? */1697 XXX: calculate exact size for them? */
1697 offset *= 2;1698 offset *= 2;
1699#endif
1698#endif1700#endif
1699 1701
1700 if (0 == mem)1702 if (0 == mem)
@@ -1722,9 +1724,11 @@ int tcc_relocate(TCCState *s1, void *ptr) · 21 unmodified lines
1722 if (s->sh_flags & SHF_EXECINSTR)1724 if (s->sh_flags & SHF_EXECINSTR)
1723 set_pages_executable(ptr, length);1725 set_pages_executable(ptr, length);
1724 }1726 }
1727#ifndef TCC_TARGET_PE
1725#ifdef TCC_TARGET_X86_641728#ifdef TCC_TARGET_X86_64
1726 set_pages_executable(s1->runtime_plt_and_got,1729 set_pages_executable(s1->runtime_plt_and_got,
1727 s1->runtime_plt_and_got_offset);1730 s1->runtime_plt_and_got_offset);
1731#endif
1728#endif1732#endif
1729 return 0;1733 return 0;
1730}1734}
@@ -1859,6 +1863,9 @@ TCCState *tcc_new(void) · 128 unmodified lines
1859#endif1863#endif
1860#ifdef TCC_TARGET_PE1864#ifdef TCC_TARGET_PE
1861 tcc_define_symbol(s, "_WIN32", NULL);1865 tcc_define_symbol(s, "_WIN32", NULL);
1866#ifdef TCC_TARGET_X86_64
1867 tcc_define_symbol(s, "_WIN64", NULL);
1868#endif
1862#else1869#else
1863 tcc_define_symbol(s, "__unix__", NULL);1870 tcc_define_symbol(s, "__unix__", NULL);
1864 tcc_define_symbol(s, "__unix", NULL);1871 tcc_define_symbol(s, "__unix", NULL);
tcc.h+2−0
@@ -491,11 +491,13 @@ struct TCCState { · 490 unmodified lines
491 struct InlineFunc **inline_fns;491 struct InlineFunc **inline_fns;
492 int nb_inline_fns;492 int nb_inline_fns;
493 493
494#ifndef TCC_TARGET_PE
494#ifdef TCC_TARGET_X86_64495#ifdef TCC_TARGET_X86_64
495 /* write PLT and GOT here */496 /* write PLT and GOT here */
496 char *runtime_plt_and_got;497 char *runtime_plt_and_got;
497 unsigned int runtime_plt_and_got_offset;498 unsigned int runtime_plt_and_got_offset;
498#endif499#endif
500#endif
499};501};
500 502
501/* The current value can be: */503/* The current value can be: */
tccelf.c+8−1
@@ -479,6 +479,7 @@ static void relocate_syms(TCCState *s1, int do_resolve) · 478 unmodified lines
479 }479 }
480}480}
481 481
482#ifndef TCC_TARGET_PE
482#ifdef TCC_TARGET_X86_64483#ifdef TCC_TARGET_X86_64
483#define JMP_TABLE_ENTRY_SIZE 14484#define JMP_TABLE_ENTRY_SIZE 14
484static unsigned long add_jmp_table(TCCState *s1, unsigned long val)485static 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) · 17 unmodified lines
502 return (unsigned long)p;503 return (unsigned long)p;
503}504}
504#endif505#endif
506#endif
505 507
506/* relocate a given section (CPU dependent) */508/* relocate a given section (CPU dependent) */
507static void relocate_section(TCCState *s1, Section *s)509static void relocate_section(TCCState *s1, Section *s)
@@ -679,6 +681,7 @@ static void relocate_section(TCCState *s1, Section *s) · 171 unmodified lines
679 *(int *)ptr += val;681 *(int *)ptr += val;
680 break;682 break;
681 case R_X86_64_PC32: {683 case R_X86_64_PC32: {
684 long long diff;
682 if (s1->output_type == TCC_OUTPUT_DLL) {685 if (s1->output_type == TCC_OUTPUT_DLL) {
683 /* DLL relocation */686 /* DLL relocation */
684 esym_index = s1->symtab_to_dynsym[sym_index];687 esym_index = s1->symtab_to_dynsym[sym_index];
@@ -690,13 +693,15 @@ static void relocate_section(TCCState *s1, Section *s) · 5 unmodified lines
690 break;693 break;
691 }694 }
692 }695 }
693 long diff = val - addr;696 diff = (long long)val - addr;
694 if (diff <= -2147483647 || diff > 2147483647) {697 if (diff <= -2147483647 || diff > 2147483647) {
698#ifndef TCC_TARGET_PE
695 /* XXX: naive support for over 32bit jump */699 /* XXX: naive support for over 32bit jump */
696 if (s1->output_type == TCC_OUTPUT_MEMORY) {700 if (s1->output_type == TCC_OUTPUT_MEMORY) {
697 val = add_jmp_table(s1, val);701 val = add_jmp_table(s1, val);
698 diff = val - addr;702 diff = val - addr;
699 }703 }
704#endif
700 if (diff <= -2147483647 || diff > 2147483647) {705 if (diff <= -2147483647 || diff > 2147483647) {
701 error("internal error: relocation failed");706 error("internal error: relocation failed");
702 }707 }
@@ -712,11 +717,13 @@ static void relocate_section(TCCState *s1, Section *s) · 9 unmodified lines
712 *(int *)ptr = val;717 *(int *)ptr = val;
713 break;718 break;
714 case R_X86_64_GOTPCREL:719 case R_X86_64_GOTPCREL:
720#ifndef TCC_TARGET_PE
715 if (s1->output_type == TCC_OUTPUT_MEMORY) {721 if (s1->output_type == TCC_OUTPUT_MEMORY) {
716 val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;722 val = add_got_table(s1, val - rel->r_addend) + rel->r_addend;
717 *(int *)ptr += val - addr;723 *(int *)ptr += val - addr;
718 break;724 break;
719 }725 }
726#endif
720 *(int *)ptr += (s1->got->sh_addr - addr +727 *(int *)ptr += (s1->got->sh_addr - addr +
721 s1->got_offsets[sym_index] - 4);728 s1->got_offsets[sym_index] - 4);
722 break;729 break;
tccgen.c+1−1
@@ -2652,7 +2652,7 @@ the_end: · 2651 unmodified lines
2652 2652
2653 /* long is never used as type */2653 /* long is never used as type */
2654 if ((t & VT_BTYPE) == VT_LONG)2654 if ((t & VT_BTYPE) == VT_LONG)
2655#ifndef TCC_TARGET_X86_642655#if !defined TCC_TARGET_X86_64 || defined TCC_TARGET_PE
2656 t = (t & ~VT_BTYPE) | VT_INT;2656 t = (t & ~VT_BTYPE) | VT_INT;
2657#else2657#else
2658 t = (t & ~VT_BTYPE) | VT_LLONG;2658 t = (t & ~VT_BTYPE) | VT_LLONG;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t