From f5126397c1c96b3ffe866303c8177c4458df3e0e Mon Sep 17 00:00:00 2001 From: "Avi Halachmi (:avih)" Date: Sat, 18 Feb 2017 08:04:07 +0200 Subject: [PATCH 1/2] win: fix usage of libtcc in memory This also fixes test failures for libtcc and other tests which were introduced at "86e3cd0 Add support for Unicode entries 'wmain' and 'wWinMain' ..." This fix is orthogonal to building also with the unicode variants of crt1.c and wincrt1.c (adding those does add tcc support for wmain and wWinMain, but the build/tests don't use them anyway, and the failures happened with or without them). --- tccpe.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tccpe.c b/tccpe.c index 8bb3d85..5c1339d 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1760,6 +1760,7 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) const char *start_symbol; int pe_type = 0; int unicode_entry = 0; + int user_entry = 1; if (find_elf_sym(symtab_section, PE_STDSYM("WinMain","@16"))) pe_type = PE_GUI; @@ -1778,12 +1779,15 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) pe_type = PE_EXE; if (find_elf_sym(symtab_section, "wmain")) unicode_entry = PE_EXE; + else if (!find_elf_sym(symtab_section, "main")) + user_entry = 0; /* hopefully we're using libtcc in memory */ } start_symbol = TCC_OUTPUT_MEMORY == s1->output_type ? PE_GUI == pe_type ? (unicode_entry ? "__runwwinmain" : "__runwinmain") - : (unicode_entry ? "__runwmain" : "__runmain") + : user_entry ? (unicode_entry ? "__runwmain" : "__runmain") + : "_main" /* not used except to report if "main" is missing */ : PE_DLL == pe_type ? PE_STDSYM("__dllstart","@12") : PE_GUI == pe_type ? (unicode_entry ? "__wwinstart": "__winstart") : (unicode_entry ? "__wstart" : "__start") @@ -1793,12 +1797,12 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) ++start_symbol; /* grab the startup code from libtcc1 */ - /* 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); + if (user_entry) { + set_elf_sym(symtab_section, + 0, 0, + ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, + SHN_UNDEF, start_symbol); + } tcc_add_pragma_libs(s1); -- 2.11.0