This caused tests failures on windows (gcc, normal configure and make, the
build succeeds) - missing symbol "main" when running libtcc test, and many
later tests too which probably use libtcc in memory.
Attached are two orthogonal patches, i.e. the test failures happen with or
without also building the unicode variants of the crt files, and the tests pass
(with the tccpe.c fix) regardless if building with or without the unicode
variants.
I'm not entirely sure the tccpe.c fix is correct, and also not sure whether the
wrapper c file is an acceptable solution for re-compiling the same files with
different defines and to different .o files. Please either someone pushes a
better fix, or tell me how to improve the patches, or just tell me to push it
as is.
Thanks.
On Thursday, February 16, 2017 10:35 PM, grischka <[email protected]> wrote:
YX Hao wrote:
> Dear grischka and group,
> Unicode entry support for windows platform is useful. Especially when
> developing programs which relays on the Unicode version APIs and takes
> Unicode arguments, it will help.
>
> Here is my patch for this feature. I have used it for about 1 year. It has
> followed the recent commits (7b99c3ac2c9c1761d68be1192f975a39199be28d).
>
> '-run' option is useable. And arguments converted.
>
> Since I'm not experienced as you guys. Please give me a review.
Looks good. Please push. I will adjust the Makefiles later.
Thanks,
--- grischka
>
> Best Regards,
>
> YX Hao
>
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
From f5126397c1c96b3ffe866303c8177c4458df3e0e Mon Sep 17 00:00:00 2001
From: "Avi Halachmi (:avih)" <[email protected]>
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
From 2a0355f51019af84c1bf34c75920e89148149aa9 Mon Sep 17 00:00:00 2001
From: "Avi Halachmi (:avih)" <[email protected]>
Date: Sat, 18 Feb 2017 08:13:16 +0200
Subject: [PATCH 2/2] win: makefiles: add upport for wmain and wWinMain
Prior to this commit, wmain and wWinMain were only supported at build-tcc.bat
Since crt1.c and wincrt1.c need to be compiled twice with different
defines and to different .o files, it's easier to add wrapper .c file
for each which sets the defines and includes the original file. This
makes the makefiles, and especially the main makefile, much simpler to handle.
We also change win32/build-tcc.bat to use the same wrappers and method
instead of manually specifying the defines and output files.
---
lib/Makefile | 2 +-
win32/Makefile | 8 ++++++--
win32/build-tcc.bat | 8 ++++----
win32/lib/crt1_w.c | 3 +++
win32/lib/wincrt1_w.c | 3 +++
5 files changed, 17 insertions(+), 7 deletions(-)
create mode 100644 win32/lib/crt1_w.c
create mode 100644 win32/lib/wincrt1_w.c
diff --git a/lib/Makefile b/lib/Makefile
index 9596cbb..b8ce1d5 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -41,7 +41,7 @@ I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O)
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O)
ARM_O = libtcc1.o armeabi.o alloca-arm.o
ARM64_O = lib-arm64.o
-WIN32_O = crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
+WIN32_O = crt1.o crt1_w.o wincrt1.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o
ifeq "$(TARGET)" "i386-win32"
OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
diff --git a/win32/Makefile b/win32/Makefile
index 854aa93..62ca222 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -77,11 +77,13 @@ lib/32/libtcc1.a: tiny_libmaker32.exe
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86.S
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c ../lib/alloca86-bt.S
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1.c
+ @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/crt1_w.c
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1.c
+ @./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/wincrt1_w.c
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllcrt1.c
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/dllmain.c
@./tcc -m32 -DTCC_TARGET_PE -DTCC_TARGET_I386 -c lib/chkstk.S
- @./tiny_libmaker32 lib/32/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
+ @./tiny_libmaker32 lib/32/libtcc1.a libtcc1.o alloca86.o alloca86-bt.o crt1.o crt1_w.o wincrt1.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o
@rm *.o
lib/64/libtcc1.a: tiny_libmaker64.exe
@@ -90,11 +92,13 @@ lib/64/libtcc1.a: tiny_libmaker64.exe
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64.S
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c ../lib/alloca86_64-bt.S
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1.c
+ @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/crt1_w.c
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1.c
+ @./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/wincrt1_w.c
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllcrt1.c
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/dllmain.c
@./tcc -m64 -DTCC_TARGET_PE -DTCC_TARGET_X86_64 -c lib/chkstk.S
- @./tiny_libmaker64 lib/64/libtcc1.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o wincrt1.o dllcrt1.o dllmain.o chkstk.o
+ @./tiny_libmaker64 lib/64/libtcc1.a libtcc1.o alloca86_64.o alloca86_64-bt.o crt1.o crt1_w.o wincrt1.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o
@rm *.o
libs: lib/32/libtcc1.a lib/64/libtcc1.a
diff --git a/win32/build-tcc.bat b/win32/build-tcc.bat
index 8da1404..231171e 100644
--- a/win32/build-tcc.bat
+++ b/win32/build-tcc.bat
@@ -140,9 +140,9 @@ copy>nul tiny_libmaker.exe tiny_libmaker-m%T%.exe
@set O1=libtcc1.o crt1.o wincrt1.o crt1_w.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
.\tcc -m32 %D32% -c ../lib/libtcc1.c
.\tcc -m32 %D32% -c lib/crt1.c
-.\tcc -m32 %D32% -c lib/crt1.c -D_UNICODE -DUNICODE -o crt1_w.o
+.\tcc -m32 %D32% -c lib/crt1_w.c
.\tcc -m32 %D32% -c lib/wincrt1.c
-.\tcc -m32 %D32% -c lib/wincrt1.c -D_UNICODE -DUNICODE -o wincrt1_w.o
+.\tcc -m32 %D32% -c lib/wincrt1_w.c
.\tcc -m32 %D32% -c lib/dllcrt1.c
.\tcc -m32 %D32% -c lib/dllmain.c
.\tcc -m32 %D32% -c lib/chkstk.S
@@ -153,9 +153,9 @@ tiny_libmaker-m32 lib/32/libtcc1.a %O1% alloca86.o alloca86-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m64 %D64% -c ../lib/libtcc1.c
.\tcc -m64 %D64% -c lib/crt1.c
-.\tcc -m64 %D64% -c lib/crt1.c -D_UNICODE -DUNICODE -o crt1_w.o
+.\tcc -m64 %D64% -c lib/crt1_w.c
.\tcc -m64 %D64% -c lib/wincrt1.c
-.\tcc -m64 %D64% -c lib/wincrt1.c -D_UNICODE -DUNICODE -o wincrt1_w.o
+.\tcc -m64 %D64% -c lib/wincrt1_w.c
.\tcc -m64 %D64% -c lib/dllcrt1.c
.\tcc -m64 %D64% -c lib/dllmain.c
.\tcc -m64 %D64% -c lib/chkstk.S
diff --git a/win32/lib/crt1_w.c b/win32/lib/crt1_w.c
new file mode 100644
index 0000000..771294a
--- /dev/null
+++ b/win32/lib/crt1_w.c
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define UNICODE
+#include "crt1.c"
diff --git a/win32/lib/wincrt1_w.c b/win32/lib/wincrt1_w.c
new file mode 100644
index 0000000..b537abb
--- /dev/null
+++ b/win32/lib/wincrt1_w.c
@@ -0,0 +1,3 @@
+#define _UNICODE
+#define UNICODE
+#include "wincrt1.c"
--
2.11.0
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel