win32: adjust new unicode support

- lib/Makefile: add (win)crt1_w.o

- crt1.c/_runtmain: return to tcc & only use for UNICODE
  (because it might be not 100% reliable with for example
  wildcards (tcc *.c -run ...)

- tccrun.c/tccpe.c: load -run startup_code only if called
  from tcc_run(). Otherwise main may not be defined.  See
  libtcc_test.c

- tests2/Makefile: pass extra options in FLAGS to allow
  overriding TCC

Also:
- tccpe.c: support weak attribute.  (I first tried to solve
  the problem above by using it but then didn't)
This commit is contained in:
grischka
2017-02-18 09:51:23 +01:00
parent 39b2afeb7c
commit 096125d963
11 changed files with 55 additions and 47 deletions

View File

@ -137,12 +137,12 @@ copy>nul tiny_libmaker.exe tiny_libmaker-m%T%.exe
%CC% -o tiny_libmaker-m%TX%.exe tools\tiny_libmaker.c %DX%
:libtcc1.a
@set O1=libtcc1.o crt1.o wincrt1.o crt1_w.o wincrt1_w.o dllcrt1.o dllmain.o chkstk.o bcheck.o
@set O1=libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.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/crt1w.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/wincrt1w.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/crt1w.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/wincrt1w.c
.\tcc -m64 %D64% -c lib/dllcrt1.c
.\tcc -m64 %D64% -c lib/dllmain.c
.\tcc -m64 %D64% -c lib/chkstk.S

View File

@ -65,24 +65,23 @@ void _tstart(void)
exit(ret);
}
void _runtmain(int argc0, /* as tcc passed in */ char **argv0)
int _runtmain(int argc, /* as tcc passed in */ char **argv)
{
__TRY__
int argc, ret;
_TCHAR **argv;
_TCHAR **env;
_startupinfo start_info;
#ifdef UNICODE
int wargc;
_TCHAR **wargv, **wenv;
_startupinfo start_info = {0};
__set_app_type(_CONSOLE_APP);
__tgetmainargs(&wargc, &wargv, &wenv, _dowildcard, &start_info);
if (argc < wargc)
wargv += wargc - argc;
#define argv wargv
#endif
#ifdef __i386
_controlfp(_PC_53, _MCW_PC);
#endif
start_info.newmode = 0;
__tgetmainargs( &argc, &argv, &env, _dowildcard, &start_info);
ret = _tmain(argc0, argv + argc - argc0, env);
exit(ret);
return _tmain(argc, argv, NULL);
}
// =============================================

3
win32/lib/crt1w.c Normal file
View File

@ -0,0 +1,3 @@
#define _UNICODE 1
#define UNICODE 1
#include "crt1.c"

View File

@ -68,22 +68,25 @@ int _twinstart(void)
exit(ret);
}
int _runtwinmain(int argc0, /* as tcc passed in */ char **argv0)
int _runtwinmain(int argc, /* as tcc passed in */ char **argv)
{
_TCHAR *szCmd, *p;
int argc;
_TCHAR **argv;
_TCHAR **env;
_startupinfo start_info;
#ifdef UNICODE
int wargc;
_TCHAR **wargv, **wenv;
_startupinfo start_info = {0};
start_info.newmode = 0;
__tgetmainargs(&argc, &argv, &env, 0, &start_info);
__tgetmainargs(&wargc, &wargv, &wenv, 0, &start_info);
if (argc < wargc)
wargv += wargc - argc;
#define argv wargv
#endif
p = GetCommandLine();
szCmd = NULL;
if (argc0 > 1)
szCmd = _tcsstr(p, argv[argc - argc0 + 1]);
if (argc > 1)
szCmd = _tcsstr(p, argv[1]);
if (NULL == szCmd)
szCmd = __T("");
else if (szCmd > p && szCmd[-1] == __T('\"'))

3
win32/lib/wincrt1w.c Normal file
View File

@ -0,0 +1,3 @@
#define _UNICODE 1
#define UNICODE 1
#include "wincrt1.c"