# HG changeset patch
# User Alexander De Sousa <aphanic@hotmail.com>
# Date 1408212369 -7200
#      Sat Aug 16 20:06:09 2014 +0200
# Node ID 29b0d61134e6d94555352d8679f5eae543826819
# Parent  370d73d7bde677815f8b291f24894ea7ebccea9d
Windows: Enable support for Unicode builds.

Directly running Unicode builds is not supported though, for that to be possible the Windows build of TCC would need to be an Unicode one as well. Plus it would need to handle encoding conversions when running traditional programs with multibyte strings.

diff -r 370d73d7bde6 -r 29b0d61134e6 tccpe.c
--- a/tccpe.c	Sun Jul 27 22:17:32 2014 +0200
+++ b/tccpe.c	Sat Aug 16 20:06:09 2014 +0200
@@ -1738,19 +1738,25 @@
 {
     const char *start_symbol;
     int pe_type = 0;
+    int unicode_build = 0;
 
     if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16")))
         pe_type = PE_GUI;
-    else
-    if (TCC_OUTPUT_DLL == s1->output_type) {
+    else if (find_elf_sym(symtab_section, PE_STDSYM("wWinMain", "@16"))) {
+        pe_type = PE_GUI;
+        unicode_build = 1;
+    } else if (TCC_OUTPUT_DLL == s1->output_type) {
         pe_type = PE_DLL;
         /* need this for 'tccelf.c:relocate_section()' */
         s1->output_type = TCC_OUTPUT_EXE;
+    } else {
+        pe_type = PE_EXE;
+        unicode_build = find_elf_sym(symtab_section, "wmain");
     }
-    else
-        pe_type = PE_EXE;
 
     if (TCC_OUTPUT_MEMORY == s1->output_type) {
+        if (unicode_build)
+            tcc_error("directly executing Unicode builds is not supported.");
         if (PE_GUI == pe_type) {
             start_symbol = "__runwinmain";
         } else {
@@ -1761,9 +1767,9 @@
             start_symbol = PE_STDSYM("__dllstart", "@12");
         } else {
             if (PE_GUI == pe_type) {
-                start_symbol = "__winstart";
+                start_symbol = unicode_build? "__wwinstart" : "__winstart";
             } else {
-                start_symbol = "__start";
+                start_symbol = unicode_build? "__wstart" : "__start";
             }
         }
     }
