Unified · Split
| @@ -1256,7 +1256,6 @@ static void put_dt(Section *dynamic, int dt, addr_t val) · 1255 unmodified lines | ||
| 1256 | 1256 | dyn->d_un.d_val = val; |
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | −#ifndef TCC_TARGET_PE | |
| 1260 | 1259 | static void add_init_array_defines(TCCState *s1, const char *section_name) |
| 1261 | 1260 | { |
| 1262 | 1261 | Section *s; |
| @@ -1285,6 +1284,7 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) · 22 unmodified lines | ||
| 1285 | 1284 | s->sh_num, sym_end); |
| 1286 | 1285 | } |
| 1287 | 1286 | |
| 1287 | +#ifndef TCC_TARGET_PE | |
| 1288 | 1288 | static int tcc_add_support(TCCState *s1, const char *filename) |
| 1289 | 1289 | { |
| 1290 | 1290 | char buf[1024]; |
| @@ -1402,12 +1402,10 @@ static void tcc_add_linker_symbols(TCCState *s1) · 111 unmodified lines | ||
| 1402 | 1402 | ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, |
| 1403 | 1403 | data_section->sh_num, "__global_pointer$"); |
| 1404 | 1404 | #endif |
| 1405 | −#ifndef TCC_TARGET_PE | |
| 1406 | 1405 | /* horrible new standard ldscript defines */ |
| 1407 | 1406 | add_init_array_defines(s1, ".preinit_array"); |
| 1408 | 1407 | add_init_array_defines(s1, ".init_array"); |
| 1409 | 1408 | add_init_array_defines(s1, ".fini_array"); |
| 1410 | −#endif | |
| 1411 | 1409 | |
| 1412 | 1410 | /* add start and stop symbols for sections whose name can be |
| 1413 | 1411 | expressed in C */ |
| @@ -33,7 +33,6 @@ ifeq (-$(CONFIG_WIN32)-$(CONFIG_i386)$(CONFIG_arm)-,--yes-) · 32 unmodified lines | ||
| 33 | 33 | endif |
| 34 | 34 | ifneq (-$(CONFIG_WIN32)$(CONFIG_WIN64)-,--) |
| 35 | 35 | SKIP += 106_pthread.test # No pthread support |
| 36 | − SKIP += 108_constructor.test # No contructor/destructor support | |
| 37 | 36 | endif |
| 38 | 37 | |
| 39 | 38 | # Some tests might need arguments |
| @@ -34,6 +34,27 @@ int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int glob · 33 unmodified lines | ||
| 34 | 34 | void __cdecl __set_app_type(int apptype); |
| 35 | 35 | unsigned int __cdecl _controlfp(unsigned int new_value, unsigned int mask); |
| 36 | 36 | extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); |
| 37 | +extern void (*__init_array_start[]) (void); | |
| 38 | +extern void (*__init_array_end[]) (void); | |
| 39 | +extern void (*__fini_array_start[]) (void); | |
| 40 | +extern void (*__fini_array_end[]) (void); | |
| 41 | + | |
| 42 | +static int do_main (int argc, _TCHAR * argv[], _TCHAR * env[]) | |
| 43 | +{ | |
| 44 | + int retval; | |
| 45 | + long i; | |
| 46 | + | |
| 47 | + i = 0; | |
| 48 | + while (&__init_array_start[i] != __init_array_end) { | |
| 49 | + (*__init_array_start[i++])(); | |
| 50 | + } | |
| 51 | + retval = _tmain(__argc, __targv, _tenviron); | |
| 52 | + i = 0; | |
| 53 | + while (&__fini_array_end[i] != __fini_array_start) { | |
| 54 | + (*__fini_array_end[--i])(); | |
| 55 | + } | |
| 56 | + return retval; | |
| 57 | +} | |
| 37 | 58 | |
| 38 | 59 | /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */ |
| 39 | 60 | int _dowildcard; |
| @@ -57,7 +78,7 @@ void _tstart(void) · 17 unmodified lines | ||
| 57 | 78 | #endif |
| 58 | 79 | |
| 59 | 80 | __tgetmainargs( &__argc, &__targv, &_tenviron, _dowildcard, &start_info); |
| 60 | − exit(_tmain(__argc, __targv, _tenviron)); | |
| 81 | + exit(do_main(__argc, __targv, _tenviron)); | |
| 61 | 82 | } |
| 62 | 83 | |
| 63 | 84 | int _runtmain(int argc, /* as tcc passed in */ char **argv) |
| @@ -78,7 +99,7 @@ int _runtmain(int argc, /* as tcc passed in */ char **argv) · 14 unmodified lines | ||
| 78 | 99 | #if defined __i386__ || defined __x86_64__ |
| 79 | 100 | _controlfp(_PC_53, _MCW_PC); |
| 80 | 101 | #endif |
| 81 | − return _tmain(__argc, __targv, _tenviron); | |
| 102 | + return do_main(__argc, __targv, _tenviron); | |
| 82 | 103 | } |
| 83 | 104 | |
| 84 | 105 | // ============================================= |
| @@ -2,12 +2,31 @@ · 1 unmodified line | ||
| 2 | 2 | |
| 3 | 3 | #include <windows.h> |
| 4 | 4 | |
| 5 | +extern void (*__init_array_start[]) (void); | |
| 6 | +extern void (*__init_array_end[]) (void); | |
| 7 | +extern void (*__fini_array_start[]) (void); | |
| 8 | +extern void (*__fini_array_end[]) (void); | |
| 9 | + | |
| 5 | 10 | BOOL WINAPI DllMain (HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved); |
| 6 | 11 | |
| 7 | 12 | BOOL WINAPI _dllstart(HINSTANCE hDll, DWORD dwReason, LPVOID lpReserved) |
| 8 | 13 | { |
| 9 | − BOOL bRet; | |
| 10 | − bRet = DllMain (hDll, dwReason, lpReserved); | |
| 11 | − return bRet; | |
| 14 | + BOOL bRet; | |
| 15 | + int i; | |
| 16 | + | |
| 17 | + if (dwReason == DLL_PROCESS_ATTACH) { /* ignore DLL_THREAD_ATTACH */ | |
| 18 | + i = 0; | |
| 19 | + while (&__init_array_start[i] != __init_array_end) { | |
| 20 | + (*__init_array_start[i++])(); | |
| 21 | + } | |
| 22 | + } | |
| 23 | + if (dwReason == DLL_PROCESS_DETACH) { /* ignore DLL_THREAD_DETACH */ | |
| 24 | + i = 0; | |
| 25 | + while (&__fini_array_end[i] != __fini_array_start) { | |
| 26 | + (*__fini_array_end[--i])(); | |
| 27 | + } | |
| 28 | + } | |
| 29 | + bRet = DllMain (hDll, dwReason, lpReserved); | |
| 30 | + return bRet; | |
| 12 | 31 | } |
| 13 | 32 | |
| @@ -23,6 +23,11 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); · 22 unmodified lines | ||
| 23 | 23 | #define _runtwinmain _runwinmain |
| 24 | 24 | #endif |
| 25 | 25 | |
| 26 | +extern void (*__init_array_start[]) (void); | |
| 27 | +extern void (*__init_array_end[]) (void); | |
| 28 | +extern void (*__fini_array_start[]) (void); | |
| 29 | +extern void (*__fini_array_end[]) (void); | |
| 30 | + | |
| 26 | 31 | typedef struct { int newmode; } _startupinfo; |
| 27 | 32 | int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*); |
| 28 | 33 | |
| @@ -31,6 +36,8 @@ static int go_winmain(TCHAR *arg1) · 2 unmodified lines | ||
| 31 | 36 | STARTUPINFO si; |
| 32 | 37 | _TCHAR *szCmd, *p; |
| 33 | 38 | int fShow; |
| 39 | + int retval; | |
| 40 | + int i; | |
| 34 | 41 | |
| 35 | 42 | GetStartupInfo(&si); |
| 36 | 43 | if (si.dwFlags & STARTF_USESHOWWINDOW) |
| @@ -48,7 +55,16 @@ static int go_winmain(TCHAR *arg1) · 11 unmodified lines | ||
| 48 | 55 | #if defined __i386__ || defined __x86_64__ |
| 49 | 56 | _controlfp(0x10000, 0x30000); |
| 50 | 57 | #endif |
| 51 | − return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); | |
| 58 | + i = 0; | |
| 59 | + while (&__init_array_start[i] != __init_array_end) { | |
| 60 | + (*__init_array_start[i++])(); | |
| 61 | + } | |
| 62 | + retval = _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow); | |
| 63 | + i = 0; | |
| 64 | + while (&__fini_array_end[i] != __fini_array_start) { | |
| 65 | + (*__fini_array_end[--i])(); | |
| 66 | + } | |
| 67 | + return retval; | |
| 52 | 68 | } |
| 53 | 69 | |
| 54 | 70 | static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex) |