some smaller fixes

- libtcc.c/tccpp.c: fix -U option for multiple input files
- libtcc: remove decl of tcc_add_crt() for PE
- tcc.h: define __i386__ and __x86_64__ for msvc
- tcc.h: undef __attribute__ for __TINYC__ on gnu/linux platforms
- tccelf.c: disable prepare_dynamic_rel unless x86/x64
- tccpe.c: construct rather than predefine PE section flags
- tccpp.c: (alt.) fix access of dead stack variable after error/longjmp
- x86_64-gen.c: fix func_alloca chain for nocode_wanted
- tccpp.c/tccgen.c: improve file:line info for inline functions
- winapi/winnt.h: correct position for DECLSPEC_ALIGN attribute
- win32/lib/crt: simplify top exception handler (needed for signal)
- arm64-gen.c: remove dprintf left from VT_CMP commit
- tccgen.c: limit binary scan with gcase to > 8 (= smaller code)
- tccgen.c: call save_regs(4) in gen_opl for cmp-ops (see test in tcctest.c)
This commit is contained in:
grischka
2018-06-08 15:31:40 +02:00
parent 4bb5bc4401
commit ce1ef5b8fc
14 changed files with 111 additions and 231 deletions

View File

@@ -76,18 +76,12 @@
#define _M_AMD64 100 /* Visual Studio */
#define USE_MINGW_SETJMP_TWO_ARGS
#define mingw_getsp tinyc_getbp
#define __TRY__
#else
#define __stdcall __attribute__((__stdcall__))
#define _X86_ 1
#define _M_IX86 300 /* Visual Studio */
#define WIN32 1
#define _USE_32BIT_TIME_T
#ifdef __arm__
#define __TRY__
#else
#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
#endif
#endif
/* in stddef.h */

View File

@@ -1310,7 +1310,7 @@ typedef DWORD LCID;
#define INITIAL_MXCSR 0x1f80
#define INITIAL_FPCSR 0x027f
typedef DECLSPEC_ALIGN(16) struct _M128A {
typedef struct DECLSPEC_ALIGN(16) _M128A {
ULONGLONG Low;
LONGLONG High;
} M128A,*PM128A;
@@ -1336,7 +1336,7 @@ typedef DWORD LCID;
#define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32)
typedef DECLSPEC_ALIGN(16) struct _CONTEXT {
typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
DWORD64 P1Home;
DWORD64 P2Home;
DWORD64 P3Home;
@@ -3150,7 +3150,7 @@ typedef DWORD LCID;
DWORD Type;
} MEMORY_BASIC_INFORMATION32,*PMEMORY_BASIC_INFORMATION32;
typedef DECLSPEC_ALIGN(16) struct _MEMORY_BASIC_INFORMATION64 {
typedef struct DECLSPEC_ALIGN(16) _MEMORY_BASIC_INFORMATION64 {
ULONGLONG BaseAddress;
ULONGLONG AllocationBase;
DWORD AllocationProtect;
@@ -4949,7 +4949,7 @@ typedef DWORD LCID;
#ifdef _WIN64
typedef struct _SLIST_ENTRY *PSLIST_ENTRY;
typedef DECLSPEC_ALIGN(16) struct _SLIST_ENTRY {
typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
PSLIST_ENTRY Next;
} SLIST_ENTRY;
#else
@@ -4961,7 +4961,7 @@ typedef DWORD LCID;
#if defined(_WIN64)
typedef DECLSPEC_ALIGN(16) struct _SLIST_HEADER {
typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
ULONGLONG Alignment;
ULONGLONG Region;
} SLIST_HEADER;

View File

@@ -67,125 +67,3 @@ tinyc_getbp:
/* ---------------------------------------------- */
/* ---------------------------------------------- */
#ifndef __x86_64__
/* ---------------------------------------------- */
/*
int _except_handler3(
PEXCEPTION_RECORD exception_record,
PEXCEPTION_REGISTRATION registration,
PCONTEXT context,
PEXCEPTION_REGISTRATION dispatcher
);
int __cdecl _XcptFilter(
unsigned long xcptnum,
PEXCEPTION_POINTERS pxcptinfoptrs
);
struct _sehrec {
void *esp; // 0
void *exception_pointers; // 1
void *prev; // 2
void *handler; // 3
void *scopetable; // 4
int trylevel; // 5
void *ebp // 6
};
// this is what the assembler code below means:
__try
{
// ...
}
__except (_XcptFilter(GetExceptionCode(), GetExceptionInformation()))
{
exit(GetExceptionCode());
}
*/
.globl _exception_info
_exception_info:
mov 1*4-24(%ebp),%eax
ret
.globl _exception_code
_exception_code:
call _exception_info
mov (%eax),%eax
mov (%eax),%eax
ret
seh_filter:
call _exception_info
push %eax
call _exception_code
push %eax
call _XcptFilter
add $ 8,%esp
ret
seh_except:
mov 0*4-24(%ebp),%esp
call _exception_code
push %eax
call _exit
// msvcrt wants scopetables aligned and in read-only segment (using .text)
.align 4
seh_scopetable:
.long -1
.long seh_filter
.long seh_except
seh_handler:
jmp _except_handler3
.globl ___try__
___try__:
.globl __try__
__try__:
push %ebp
mov 8(%esp),%ebp
// void *esp;
lea 12(%esp),%eax
mov %eax,0*4(%ebp)
// void *exception_pointers;
xor %eax,%eax
mov %eax,1*4(%ebp)
// void *prev;
mov %fs:0,%eax
mov %eax,2*4(%ebp)
// void *handler;
mov $ seh_handler,%eax
mov %eax,3*4(%ebp)
// void *scopetable;
mov $ seh_scopetable,%eax
mov %eax,4*4(%ebp)
// int trylevel;
xor %eax,%eax
mov %eax,5*4(%ebp)
// register new SEH
lea 2*4(%ebp),%eax
mov %eax,%fs:0
pop %ebp
ret
/* ---------------------------------------------- */
#else
/* ---------------------------------------------- */
/* SEH on x86-64 not implemented */
/* ---------------------------------------------- */
#endif
/* ---------------------------------------------- */

View File

@@ -38,21 +38,15 @@ extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]);
/* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
int _dowildcard;
#ifdef __x86_64__
static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
{
return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
}
#endif
void _tstart(void)
{
__TRY__
#ifdef __x86_64__
SetUnhandledExceptionFilter(catch_sig);
#endif
_startupinfo start_info = {0};
SetUnhandledExceptionFilter(catch_sig);
// Sets the current application type
__set_app_type(_CONSOLE_APP);

View File

@@ -26,13 +26,6 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
typedef struct { int newmode; } _startupinfo;
int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
#ifdef __x86_64__
static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
{
return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
}
#endif
static int go_winmain(TCHAR *arg1)
{
STARTUPINFO si;
@@ -58,13 +51,15 @@ static int go_winmain(TCHAR *arg1)
return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
}
static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
{
return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
}
int _twinstart(void)
{
__TRY__
#ifdef __x86_64__
SetUnhandledExceptionFilter(catch_sig);
#endif
_startupinfo start_info_con = {0};
SetUnhandledExceptionFilter(catch_sig);
__set_app_type(__GUI_APP);
__tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
exit(go_winmain(__argc > 1 ? __targv[1] : NULL));