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