History

win32 merge (grischka)

bellard committed 21 years ago

Commit fe9b1f61 parent 09f4ce94 files · +186 −145Browse files

Unified · Split

4 files
  1. tcc.c +21 −10
  2. tccelf.c +2 −9
  3. tccpe.c +61 −24
  4. win32/readme.txt +102 −102
tcc.c+21−10
@@ -711,9 +711,12 @@ int __stdcall FreeConsole(void); · 710 unmodified lines
711 711
712#define snprintf _snprintf712#define snprintf _snprintf
713#define vsnprintf _vsnprintf713#define vsnprintf _vsnprintf
714#ifndef __GNUC__
715 #define strtold (long double)strtod
716 #define strtof (float)strtod
717 #define strtoll (long long)strtol
714#endif718#endif
715 719#elif defined(TCC_UCLIBC) || defined(__FreeBSD__)
716#if defined(WIN32) || defined(TCC_UCLIBC) || defined(__FreeBSD__)
717/* currently incorrect */720/* currently incorrect */
718long double strtold(const char *nptr, char **endptr)721long double strtold(const char *nptr, char **endptr)
719{722{
@@ -2730,6 +2733,7 @@ static void pragma_parse(TCCState *s1) · 2010 unmodified lines
2730 #pragma pack(push,1) // push & set2733 #pragma pack(push,1) // push & set
2731 #pragma pack(pop) // restore previous2734 #pragma pack(pop) // restore previous
2732 */2735 */
2736 next();
2733 skip('(');2737 skip('(');
2734 if (tok == TOK_ASM_pop) {2738 if (tok == TOK_ASM_pop) {
2735 next();2739 next();
@@ -10514,8 +10518,10 @@ int main(int argc, char **argv) · 7778 unmodified lines
10514 GetModuleFileNameA(NULL, path, sizeof path);10518 GetModuleFileNameA(NULL, path, sizeof path);
10515 p = d = strlwr(path);10519 p = d = strlwr(path);
10516 while (*d)10520 while (*d)
10517 if (*d++ == '\\')10521 {
10518 (p = d)[-1] = '/';10522 if (*d == '\\') *d = '/', p = d;
10523 ++d;
10524 }
10519 *p = '\0';10525 *p = '\0';
10520 tcc_lib_path = path;10526 tcc_lib_path = path;
10521 }10527 }
@@ -10555,23 +10561,28 @@ int main(int argc, char **argv) · 33 unmodified lines
10555 error("cannot specify libraries with -c");10561 error("cannot specify libraries with -c");
10556 }10562 }
10557 10563
10564 if (output_type != TCC_OUTPUT_MEMORY) {
10565 if (!outfile) {
10558 /* compute default outfile name */10566 /* compute default outfile name */
10559 if (output_type != TCC_OUTPUT_MEMORY && !outfile) {
10560 if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
10561 char *ext;
10562 /* strip path */
10563 pstrcpy(objfilename, sizeof(objfilename) - 1, 10567 pstrcpy(objfilename, sizeof(objfilename) - 1,
10568 /* strip path */
10564 tcc_basename(files[0]));10569 tcc_basename(files[0]));
10565 /* add .o extension */10570#ifdef TCC_TARGET_PE
10566 ext = strrchr(objfilename, '.');10571 pe_guess_outfile(objfilename, output_type);
10572#else
10573 if (output_type == TCC_OUTPUT_OBJ && !reloc_output) {
10574 char *ext = strrchr(objfilename, '.');
10567 if (!ext)10575 if (!ext)
10568 goto default_outfile;10576 goto default_outfile;
10577 /* add .o extension */
10569 strcpy(ext + 1, "o");10578 strcpy(ext + 1, "o");
10570 } else {10579 } else {
10571 default_outfile:10580 default_outfile:
10572 pstrcpy(objfilename, sizeof(objfilename), "a.out");10581 pstrcpy(objfilename, sizeof(objfilename), "a.out");
10573 }10582 }
10583#endif
10574 outfile = objfilename;10584 outfile = objfilename;
10585 }
10575 }10586 }
10576 10587
10577 if (do_bench) {10588 if (do_bench) {
tccelf.c+2−9
@@ -2095,7 +2095,7 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 2094 unmodified lines
2095{ 2095{
2096 Elf32_Ehdr ehdr;2096 Elf32_Ehdr ehdr;
2097 Elf32_Shdr *shdr, *sh, *sh1;2097 Elf32_Shdr *shdr, *sh, *sh1;
2098 int i, nb_syms, nb_dts, sym_bind, ret, other;2098 int i, nb_syms, nb_dts, sym_bind, ret;
2099 Elf32_Sym *sym, *dynsym;2099 Elf32_Sym *sym, *dynsym;
2100 Elf32_Dyn *dt, *dynamic;2100 Elf32_Dyn *dt, *dynamic;
2101 unsigned char *dynstr;2101 unsigned char *dynstr;
@@ -2175,15 +2175,8 @@ static int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 73 unmodified lines
2175 if (sym_bind == STB_LOCAL)2175 if (sym_bind == STB_LOCAL)
2176 continue;2176 continue;
2177 name = dynstr + sym->st_name;2177 name = dynstr + sym->st_name;
2178#ifdef TCC_TARGET_PE
2179 /* in the PE format we need to know the DLL from which the
2180 symbol comes. XXX: add a new array for that ? */
2181 other = s1->nb_loaded_dlls - 1;
2182#else
2183 other = sym->st_other;
2184#endif
2185 add_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,2178 add_elf_sym(s1->dynsymtab_section, sym->st_value, sym->st_size,
2186 sym->st_info, other, sym->st_shndx, name);2179 sym->st_info, sym->st_other, sym->st_shndx, name);
2187 }2180 }
2188 2181
2189 /* load all referenced DLLs */2182 /* load all referenced DLLs */
tccpe.c+61−24
@@ -742,24 +742,38 @@ ST void pe_build_imports(struct pe_info *pe) · 741 unmodified lines
742}742}
743 743
744/* ------------------------------------------------------------- */744/* ------------------------------------------------------------- */
745ST int sym_cmp(const void *va, const void *vb)
746{
747 Elf32_Sym *sa = (Elf32_Sym *)symtab_section->data + *(int*)va;
748 Elf32_Sym *sb = (Elf32_Sym *)symtab_section->data + *(int*)vb;
749 const char *ca = symtab_section->link->data + sa->st_name;
750 const char *cb = symtab_section->link->data + sb->st_name;
751 return strcmp(ca, cb);
752}
753
745ST void pe_build_exports(struct pe_info *pe)754ST void pe_build_exports(struct pe_info *pe)
746{755{
747 Elf32_Sym *sym;756 Elf32_Sym *sym;
748 DWORD func_offset;757 DWORD func_offset, voffset;
749 DWORD voffset = pe->thunk->sh_addr - pe->imagebase;
750 struct pe_export_header *hdr;758 struct pe_export_header *hdr;
751 int sym_count = 0, ordinal = 0;759 int sym_count, n, ord, *sorted;
760
761 voffset = pe->thunk->sh_addr - pe->imagebase;
762 sym_count = 0, n = 1, sorted = NULL;
752 763
753 // for simplicity only functions are exported764 // for simplicity only functions are exported
754 for_sym_in_symtab(sym)765 for_sym_in_symtab(sym)
755 if (sym->st_shndx != text_section->sh_num)766 {
756 sym->st_other &= ~1;767 if ((sym->st_other & 1)
757 else if (sym->st_other & 1)768 && sym->st_shndx == text_section->sh_num)
758 ++sym_count;769 dynarray_add((void***)&sorted, &sym_count, (void*)n);
770 ++n;
771 }
759 772
760 if (0 == sym_count)773 if (0 == sym_count)
761 return;774 return;
762 775
776 qsort (sorted, sym_count, sizeof sorted[0], sym_cmp);
763 pe_align_section(pe->thunk, 16);777 pe_align_section(pe->thunk, 16);
764 778
765 pe->exp_offs = pe->thunk->data_offset;779 pe->exp_offs = pe->thunk->data_offset;
@@ -774,30 +788,28 @@ ST void pe_build_exports(struct pe_info *pe) · 8 unmodified lines
774 hdr->NumberOfFunctions = sym_count;788 hdr->NumberOfFunctions = sym_count;
775 hdr->NumberOfNames = sym_count;789 hdr->NumberOfNames = sym_count;
776 hdr->AddressOfFunctions = func_offset + voffset;790 hdr->AddressOfFunctions = func_offset + voffset;
777 hdr->AddressOfNames =791 hdr->AddressOfNames = hdr->AddressOfFunctions + sym_count * sizeof(DWORD);
778 hdr->AddressOfFunctions + sym_count * sizeof(DWORD);792 hdr->AddressOfNameOrdinals = hdr->AddressOfNames + sym_count * sizeof(DWORD);
779 hdr->AddressOfNameOrdinals =
780 hdr->AddressOfNames + sym_count * sizeof(DWORD);
781 hdr->Name = pe->thunk->data_offset + voffset;793 hdr->Name = pe->thunk->data_offset + voffset;
782 put_elf_str(pe->thunk, tcc_basename(pe->filename));794 put_elf_str(pe->thunk, tcc_basename(pe->filename));
783 795
784 for_sym_in_symtab(sym)796 for (ord = 0; ord < sym_count; ++ord)
785 if (sym->st_other & 1) {797 {
786 char *name = symtab_section->link->data + sym->st_name;798 char *name; DWORD *p, *pfunc, *pname; WORD *pord;
787 DWORD *p = (DWORD *) (pe->thunk->data + func_offset);799 sym = (Elf32_Sym *)symtab_section->data + sorted[ord];
788 DWORD *pfunc = p + ordinal;800 name = symtab_section->link->data + sym->st_name;
789 DWORD *pname = p + sym_count + ordinal;801 p = (DWORD*)(pe->thunk->data + func_offset);
790 WORD *pord = (WORD *) (p + 2 * sym_count) + ordinal;802 pfunc = p + ord;
791 *pfunc =803 pname = p + sym_count + ord;
792 sym->st_value + pe->s1->sections[sym->st_shndx]->sh_addr -804 pord = (WORD *)(p + 2*sym_count) + ord;
793 pe->imagebase;805 *pfunc = sym->st_value + pe->s1->sections[sym->st_shndx]->sh_addr - pe->imagebase;
794 *pname = pe->thunk->data_offset + voffset;806 *pname = pe->thunk->data_offset + voffset;
795 *pord = ordinal;807 *pord = ord;
796 put_elf_str(pe->thunk, name);808 put_elf_str(pe->thunk, name);
797 /* printf("export: %s\n", name); */809 /* printf("export: %s\n", name); */
798 ++ordinal;
799 }810 }
800 pe->exp_size = pe->thunk->data_offset - pe->exp_offs;811 pe->exp_size = pe->thunk->data_offset - pe->exp_offs;
812 tcc_free(sorted);
801}813}
802 814
803/* ------------------------------------------------------------- */815/* ------------------------------------------------------------- */
@@ -1119,6 +1131,24 @@ int pe_load_def_file(TCCState * s1, FILE * fp) · 315 unmodified lines
1119 return 0;1131 return 0;
1120}1132}
1121 1133
1134/* ------------------------------------------------------------- */
1135void pe_guess_outfile(char *objfilename, int output_type)
1136{
1137 char *ext = strrchr(objfilename, '.');
1138 if (NULL == ext)
1139 ext = strchr(objfilename, 0);
1140 if (output_type == TCC_OUTPUT_DLL)
1141 strcpy(ext, ".dll");
1142 else
1143 if (output_type == TCC_OUTPUT_EXE)
1144 strcpy(ext, ".exe");
1145 else
1146 if (output_type == TCC_OUTPUT_OBJ && strcmp(ext, ".o"))
1147 strcpy(ext, ".o");
1148 else
1149 error("no outputfile given");
1150}
1151
1122/* ------------------------------------------------------------- */1152/* ------------------------------------------------------------- */
1123unsigned long pe_add_runtime(TCCState * s1)1153unsigned long pe_add_runtime(TCCState * s1)
1124{1154{
@@ -1127,6 +1157,13 @@ unsigned long pe_add_runtime(TCCState * s1) · 2 unmodified lines
1127 1157
1128 if (find_elf_sym(symtab_section, "WinMain"))1158 if (find_elf_sym(symtab_section, "WinMain"))
1129 pe_type = PE_GUI;1159 pe_type = PE_GUI;
1160 else
1161 if (TCC_OUTPUT_DLL == s1->output_type)
1162 {
1163 pe_type = PE_DLL;
1164 // need this for 'tccelf.c:relocate_section()'
1165 s1->output_type = TCC_OUTPUT_EXE;
1166 }
1130 1167
1131 start_symbol =1168 start_symbol =
1132 TCC_OUTPUT_MEMORY == s1->output_type1169 TCC_OUTPUT_MEMORY == s1->output_type
@@ -1192,7 +1229,7 @@ int tcc_output_pe(TCCState * s1, const char *filename) · 59 unmodified lines
1192 {1229 {
1193 Section *s;1230 Section *s;
1194 FILE *f;1231 FILE *f;
1195 f = fopen("tccpe.log", "wb");1232 f = fopen("tccpe.log", "wt");
1196 for (i = 1; i < s1->nb_sections; ++i) {1233 for (i = 1; i < s1->nb_sections; ++i) {
1197 s = s1->sections[i];1234 s = s1->sections[i];
1198 pe_print_section(f, s);1235 pe_print_section(f, s);
win32/readme.txt+102−102
@@ -1,102 +1,102 @@
1 1
2 TinyCC-PE2 TinyCC-PE
3 ---------3 ---------
4 4
5 TinyCC (aka TCC) is a small but hyperfast C compiler,5 TinyCC (aka TCC) is a small but hyperfast C compiler,
6 written by Fabrice Bellard,6 written by Fabrice Bellard,
7 7
8 8
9 TinyCC-PE is the TinyCC compiler with an extension to9 TinyCC-PE is the TinyCC compiler with an extension to
10 write PE executables for MS-Windows.10 write PE executables for MS-Windows.
11 11
12 12
13 Features:13 Features:
14 ---------14 ---------
15 15
16 TinyCC-PE can produce console applications, native windows16 TinyCC-PE can produce console applications, native windows
17 GUI programs and DLL's.17 GUI programs and DLL's.
18 18
19 Most of the features pointed out by Fabrice Bellard for the19 Most of the features pointed out by Fabrice Bellard for the
20 original version are still valid, i.e:20 original version are still valid, i.e:
21 21
22 - SMALL! The package with ~400kb includes a complete C-compiler22 - SMALL! The package with ~400kb includes a complete C-compiler
23 with header files for console and GUI applications.23 with header files for console and GUI applications.
24 24
25 - With the -run switch you can run C-sources without any25 - With the -run switch you can run C-sources without any
26 linking directly from the command line.26 linking directly from the command line.
27 27
28 - TCC can of course compile itself.28 - TCC can of course compile itself.
29 29
30 30
31 Installation:31 Installation:
32 -------------32 -------------
33 33
34 Just unzip the package to a directory anywhere on your computer.34 Just unzip the package to a directory anywhere on your computer.
35 35
36 36
37 Examples:37 Examples:
38 ---------38 ---------
39 39
40 For the 'Fibonacci' console example type from the command line:40 For the 'Fibonacci' console example type from the command line:
41 41
42 tcc examples\fib.c42 tcc examples\fib.c
43 43
44 44
45 For the 'Hello Windows' GUI example:45 For the 'Hello Windows' GUI example:
46 46
47 tcc examples\hello_win.c47 tcc examples\hello_win.c
48 48
49 49
50 For the 'Hello DLL' example:50 For the 'Hello DLL' example:
51 51
52 tcc -shared examples\dll.c52 tcc -shared examples\dll.c
53 tcc examples\hello_dll.c examples\dll.def53 tcc examples\hello_dll.c examples\dll.def
54 54
55 55
56 Import Definitions:56 Import Definitions:
57 -------------------57 -------------------
58 58
59 TinyCC-PE searches and reads import definition files similar59 TinyCC-PE searches and reads import definition files similar
60 to libraries.60 to libraries.
61 61
62 The included 'tiny_impdef' program may be used to make .def files62 The included 'tiny_impdef' program may be used to make .def files
63 for any DLL, e.g for an 'opengl32.def':63 for any DLL, e.g for an 'opengl32.def':
64 64
65 tiny_impdef.exe opengl32.dll65 tiny_impdef.exe opengl32.dll
66 66
67 or to the same effect:67 or to the same effect:
68 68
69 tcc -lkernel32 -run tiny_impdef.c opengl32.dll69 tcc -lkernel32 -run tiny_impdef.c opengl32.dll
70 70
71 71
72 Header Files:72 Header Files:
73 -------------73 -------------
74 74
75 The system header files, except '_mingw.h', are from the75 The system header files, except '_mingw.h', are from the
76 2.0 mingw distribution. See also: http://www.mingw.org/76 2.0 mingw distribution. See also: http://www.mingw.org/
77 77
78 78
79 Compile TCC:79 Compile TCC:
80 ------------80 ------------
81 81
82 With TCC itself just say:82 With TCC itself just say:
83 83
84 tcc src\tcc.c -lkernel32 -o tcc.new.exe84 tcc src\tcc.c -lkernel32 -o tcc.new.exe
85 85
86 Other compilers like mingw-gcc or msvc work as well.86 Other compilers like mingw-gcc or msvc work as well.
87 To make libtcc1.a, you need 'ar' from the mingw binutils.87 To make libtcc1.a, you need 'ar' from the mingw binutils.
88 88
89 89
90 Documentation and License:90 Documentation and License:
91 --------------------------91 --------------------------
92 92
93 TCC is distributed under the GNU Lesser General Public License93 TCC is distributed under the GNU Lesser General Public License
94 (see COPYING file).94 (see COPYING file).
95 95
96 Please read the original tcc-doc.html to have all the features96 Please read the original tcc-doc.html to have all the features
97 of TCC. Also visit: http://fabrice.bellard.free.fr/tcc/97 of TCC. Also visit: http://fabrice.bellard.free.fr/tcc/
98 98
99 99
100 --------------------------------------------100 --------------------------------------------
101 09.Apr.2005 - grischka@users.sourceforge.net101 09.Apr.2005 - grischka@users.sourceforge.net
102 102

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