From 86e3cd0c5ac9d6e8e80306f9f5fdcce4a4c38dc5 Mon Sep 17 00:00:00 2001 From: YX Hao Date: Wed, 15 Feb 2017 21:58:35 +0800 Subject: Add support for Unicode entries 'wmain' and 'wWinMain' on Windows '-run' suported. argvs are converted. But don't use compliled Unicode CLI exe-file to get inputs interactively in other codepage! Please add other compliling supports than 'build-tcc.bat' (Who is good at them). --- tccpe.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'tccpe.c') diff --git a/tccpe.c b/tccpe.c index 8d29070..8bb3d85 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1759,34 +1759,46 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) { const char *start_symbol; int pe_type = 0; + int unicode_entry = 0; if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16"))) pe_type = PE_GUI; else + if (find_elf_sym(symtab_section, PE_STDSYM("wWinMain","@16"))) { + pe_type = PE_GUI; + unicode_entry = PE_GUI; + } + 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 + else { pe_type = PE_EXE; + if (find_elf_sym(symtab_section, "wmain")) + unicode_entry = PE_EXE; + } start_symbol = TCC_OUTPUT_MEMORY == s1->output_type - ? PE_GUI == pe_type ? "__runwinmain" : "_main" + ? PE_GUI == pe_type ? (unicode_entry ? "__runwwinmain" : "__runwinmain") + : (unicode_entry ? "__runwmain" : "__runmain") : PE_DLL == pe_type ? PE_STDSYM("__dllstart","@12") - : PE_GUI == pe_type ? "__winstart" : "__start" + : PE_GUI == pe_type ? (unicode_entry ? "__wwinstart": "__winstart") + : (unicode_entry ? "__wstart" : "__start") ; if (!s1->leading_underscore || strchr(start_symbol, '@')) ++start_symbol; /* grab the startup code from libtcc1 */ - if (TCC_OUTPUT_MEMORY != s1->output_type || PE_GUI == pe_type) - set_elf_sym(symtab_section, - 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - SHN_UNDEF, start_symbol); + /* only (PE_Dll == pe_type) doesn't need it, + (TCC_OUTPUT_MEMORY == s1->output_type && PE_Dll == pe_type) is illegal */ + set_elf_sym(symtab_section, + 0, 0, + ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, + SHN_UNDEF, start_symbol); tcc_add_pragma_libs(s1); -- cgit v1.3.1