2005-04-17 17:11:15 +04:00
|
|
|
// =============================================
|
|
|
|
// crt1.c
|
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
// _UNICODE for tchar.h, UNICODE for API
|
|
|
|
#include <tchar.h>
|
|
|
|
|
2019-04-15 21:02:45 +03:00
|
|
|
#include <windows.h>
|
2014-12-30 06:25:52 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#define _UNKNOWN_APP 0
|
|
|
|
#define _CONSOLE_APP 1
|
|
|
|
#define _GUI_APP 2
|
2005-04-17 17:11:15 +04:00
|
|
|
|
2014-12-30 06:25:52 +03:00
|
|
|
#define _MCW_PC 0x00030000 // Precision Control
|
|
|
|
#define _PC_24 0x00020000 // 24 bits
|
|
|
|
#define _PC_53 0x00010000 // 53 bits
|
|
|
|
#define _PC_64 0x00000000 // 64 bits
|
2005-04-17 17:11:15 +04:00
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
#ifdef _UNICODE
|
|
|
|
#define __tgetmainargs __wgetmainargs
|
|
|
|
#define _tstart _wstart
|
|
|
|
#define _tmain wmain
|
|
|
|
#define _runtmain _runwmain
|
|
|
|
#else
|
|
|
|
#define __tgetmainargs __getmainargs
|
|
|
|
#define _tstart _start
|
|
|
|
#define _tmain main
|
|
|
|
#define _runtmain _runmain
|
|
|
|
#endif
|
|
|
|
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
typedef struct { int newmode; } _startupinfo;
|
2017-02-15 16:58:35 +03:00
|
|
|
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
|
2014-12-30 06:25:52 +03:00
|
|
|
void __cdecl __set_app_type(int apptype);
|
|
|
|
unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask);
|
2017-02-15 16:58:35 +03:00
|
|
|
extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
|
2020-06-27 18:15:06 +03:00
|
|
|
|
|
|
|
#include "crtinit.c"
|
2019-11-27 20:29:12 +03:00
|
|
|
|
|
|
|
static int do_main (int argc, _TCHAR * argv[], _TCHAR * env[])
|
|
|
|
{
|
|
|
|
int retval;
|
2020-06-27 18:15:06 +03:00
|
|
|
run_ctors(argc, argv, env);
|
2019-11-27 20:29:12 +03:00
|
|
|
retval = _tmain(__argc, __targv, _tenviron);
|
2020-06-27 18:15:06 +03:00
|
|
|
run_dtors();
|
2019-11-27 20:29:12 +03:00
|
|
|
return retval;
|
|
|
|
}
|
2014-12-30 06:25:52 +03:00
|
|
|
|
2016-10-01 21:27:41 +03:00
|
|
|
/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
|
|
|
|
int _dowildcard;
|
|
|
|
|
2019-04-15 21:02:45 +03:00
|
|
|
static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
|
|
|
|
{
|
|
|
|
return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
|
|
|
|
}
|
|
|
|
|
2017-02-15 16:58:35 +03:00
|
|
|
void _tstart(void)
|
2005-04-17 17:11:15 +04:00
|
|
|
{
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
_startupinfo start_info = {0};
|
2018-06-08 16:31:40 +03:00
|
|
|
SetUnhandledExceptionFilter(catch_sig);
|
2014-12-30 06:25:52 +03:00
|
|
|
// Sets the current application type
|
|
|
|
__set_app_type(_CONSOLE_APP);
|
2005-04-17 17:11:15 +04:00
|
|
|
|
2014-12-30 06:25:52 +03:00
|
|
|
// Set default FP precision to 53 bits (8-byte double)
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
// _MCW_PC (Precision control) is not supported on ARM
|
|
|
|
#if defined __i386__ || defined __x86_64__
|
2014-12-30 06:25:52 +03:00
|
|
|
_controlfp(_PC_53, _MCW_PC);
|
|
|
|
#endif
|
2005-04-17 17:11:15 +04:00
|
|
|
|
2017-10-08 12:28:02 +03:00
|
|
|
__tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info);
|
2019-11-27 20:29:12 +03:00
|
|
|
exit(do_main(__argc, __targv, _tenviron));
|
2017-02-15 16:58:35 +03:00
|
|
|
}
|
|
|
|
|
2017-02-18 11:51:23 +03:00
|
|
|
int _runtmain(int argc, /* as tcc passed in */ char **argv)
|
2017-02-15 16:58:35 +03:00
|
|
|
{
|
2017-02-18 11:51:23 +03:00
|
|
|
#ifdef UNICODE
|
|
|
|
_startupinfo start_info = {0};
|
|
|
|
|
2017-10-08 12:28:02 +03:00
|
|
|
__tgetmainargs(&__argc, &__targv, &_tenviron, _dowildcard, &start_info);
|
2017-02-20 20:58:08 +03:00
|
|
|
/* may be wrong when tcc has received wildcards (*.c) */
|
2017-10-08 12:28:02 +03:00
|
|
|
if (argc < __argc) {
|
|
|
|
__targv += __argc - argc;
|
|
|
|
__argc = argc;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
__argc = argc;
|
|
|
|
__targv = argv;
|
2017-02-18 11:51:23 +03:00
|
|
|
#endif
|
various stuff
win32/Makefile ("for cygwin") removed
- On cygwin, the normal ./configure && make can be used with either
cygwin's "GCC for Win32 Toolchain"
./configure --cross-prefix=i686-w64-mingw32-
or with an existing tcc:
./configure --cc=<old-tccdir>/tcc.exe
tcctest.c:
- exclude test_high_clobbers() on _WIN64 (does not work)
tests2/95_bitfield.c:
- use 'signed char' for ARM (where default 'char' is unsigned)
tests:
- remove -I "expr" diff option to allow tests with
busybox-diff.
libtcc.c, tcc.c:
- removed -iwithprefix option. It is supposed to be
combined with -iprefix which we don't have either.
tccgen.c:
- fix assignments and return of 'void', as in
void f() {
void *p, *q;
*p = *q:
return *p;
}
This appears to be allowed but should do nothing.
tcc.h, libtcc.c, tccpp.c:
- Revert "Introduce VIP sysinclude paths which are always searched first"
This reverts commit 1d5e386b0a78393ac6b670c209a185849ec798a1.
The patch was giving tcc's system includes priority over -I which
is not how it should be.
tccelf.c:
- add DT_TEXTREL tag only if text relocations are actually
used (which is likely not the case on x86_64)
- prepare_dynamic_rel(): avoid relocation of unresolved
(weak) symbols
tccrun.c:
- for HAVE_SELINUX, use two mappings to the same (real) file.
(it was so once except the RX mapping wasn't used at all).
tccpe.c:
- fix relocation constant used for x86_64 (by Andrei E. Warentin)
- #ifndef _WIN32 do "chmod 755 ..." to get runnable exes on cygwin.
tccasm.c:
- keep forward asm labels static, otherwise they will endup
in dynsym eventually.
configure, Makefile:
- mingw32: respect ./configure options --bindir --docdir --libdir
- allow overriding tcc when building libtcc1.a and libtcc.def with
make XTCC=<tcc program to use>
- use $(wildcard ...) for install to allow installing just
a cross compiler for example
make cross-arm
make install
- use name <target>-libtcc1.a
build-tcc.bat:
- add options: -clean, -b bindir
2017-10-11 19:13:43 +03:00
|
|
|
#if defined __i386__ || defined __x86_64__
|
2017-02-15 16:58:35 +03:00
|
|
|
_controlfp(_PC_53, _MCW_PC);
|
|
|
|
#endif
|
2020-01-18 00:58:39 +03:00
|
|
|
return _tmain(__argc, __targv, _tenviron);
|
2005-04-17 17:11:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// =============================================
|