diff --git a/tcc-doc.texi b/tcc-doc.texi index ae39462d..267a0d3c 100644 --- a/tcc-doc.texi +++ b/tcc-doc.texi @@ -175,11 +175,6 @@ In a script, it gives the following header: @example #!/usr/local/bin/tcc -run -L/usr/X11R6/lib -lX11 @end example -On native Windows ARM64 builds, CLI @option{-run} currently uses a -temporary executable for ordinary runs as a compatibility workaround. -@code{libtcc} @code{tcc_run()} remains in-process, and CLI keeps the -in-process path for @option{-dt} and @option{-rstdin}. - @item -v Display TCC version. diff --git a/tcc.c b/tcc.c index 22d38319..46d3d83b 100644 --- a/tcc.c +++ b/tcc.c @@ -23,9 +23,6 @@ #endif #include "tcc.h" -#if defined(TCC_IS_NATIVE) && defined(_WIN32) && defined(__aarch64__) -# include -#endif #if ONE_SOURCE # include "libtcc.c" #endif @@ -319,125 +316,6 @@ static unsigned getclock_ms(void) #endif } -#if defined(TCC_IS_NATIVE) && defined(_WIN32) && defined(__aarch64__) -static char *tcc_append_windows_arg(char *dst, const char *arg) -{ - const char *p = arg; - int quote = *arg == '\0' || strpbrk(arg, " \t\"") != NULL; - - if (quote) - *dst++ = '"'; - for (;;) { - int bs = 0; - while (*p == '\\') - ++bs, ++p; - if (*p == '\0') { - if (quote) - while (bs--) - *dst++ = '\\', *dst++ = '\\'; - break; - } - if (*p == '"') { - while (bs--) - *dst++ = '\\', *dst++ = '\\'; - *dst++ = '\\'; - } else { - while (bs--) - *dst++ = '\\'; - } - *dst++ = *p++; - } - if (quote) - *dst++ = '"'; - return dst; -} - -static int tcc_run_via_temp_exe(TCCState *s, int argc, char **argv) -{ - char tmpdir[MAX_PATH], tmppath[MAX_PATH]; - PROCESS_INFORMATION pi; - STARTUPINFOA si; - DWORD exit_code; - char *cmdline = NULL, *p; - char *saved_outfile, *tmp_outfile; - int saved_output_type, ret, i; - size_t len; - TCCState *s1 = s; - - if (!GetTempPathA(sizeof tmpdir, tmpdir)) - return tcc_error_noabort("could not get temp directory"), -1; - if (!GetTempFileNameA(tmpdir, "tcc", 0, tmppath)) - return tcc_error_noabort("could not create temp file name"), -1; - - saved_outfile = s->outfile; - saved_output_type = s->output_type; - tmp_outfile = tcc_strdup(tmppath); - if (!tmp_outfile) - return -1; - s->outfile = tmp_outfile; - s->output_type = TCC_OUTPUT_EXE; - - ret = tcc_output_file(s, s->outfile); - s->output_type = saved_output_type; - s->outfile = saved_outfile; - if (ret < 0) { - tcc_free(tmp_outfile); - DeleteFileA(tmppath); - return ret; - } - - len = 1; - for (i = 0; i < argc; ++i) - len += strlen(argv[i]) * 2 + 3; - if (argc == 0) - len += strlen(tmppath) * 2 + 3; - cmdline = tcc_malloc(len); - if (!cmdline) { - tcc_free(tmp_outfile); - DeleteFileA(tmppath); - return -1; - } - p = cmdline; - p = tcc_append_windows_arg(p, argc > 0 ? argv[0] : tmppath); - for (i = 1; i < argc; ++i) { - *p++ = ' '; - p = tcc_append_windows_arg(p, argv[i]); - } - *p = '\0'; - - memset(&si, 0, sizeof(si)); - memset(&pi, 0, sizeof(pi)); - si.cb = sizeof(si); - SetLastError(0); - ret = CreateProcessA(tmppath, cmdline, NULL, NULL, TRUE, 0, - NULL, NULL, &si, &pi); - if (!ret) { - tcc_error_noabort("could not run '%s'", tmppath); - ret = 1; - } else { - WaitForSingleObject(pi.hProcess, INFINITE); - if (!GetExitCodeProcess(pi.hProcess, &exit_code)) - exit_code = 1; - CloseHandle(pi.hThread); - CloseHandle(pi.hProcess); - ret = (int)exit_code; - } - - tcc_free(cmdline); - tcc_free(tmp_outfile); - DeleteFileA(tmppath); - return ret; -} - -static int tcc_run_requires_inprocess(const TCCState *s) -{ - /* Temporary Windows ARM64 workaround: keep the generic in-process path - where CLI features rely on it, but run ordinary `tcc -run` through a - child process until the native runtime path is fully equivalent. */ - return (s->dflag & 16) || s->run_stdin != NULL; -} -#endif - int main(int argc, char **argv) { TCCState *s, *s1; @@ -548,14 +426,7 @@ redo: } else if (0 == ret) { if (s->output_type == TCC_OUTPUT_MEMORY) { #ifdef TCC_IS_NATIVE -#if defined(_WIN32) && defined(__aarch64__) - if (tcc_run_requires_inprocess(s)) - ret = tcc_run(s, argc, argv); - else - ret = tcc_run_via_temp_exe(s, argc, argv); -#else ret = tcc_run(s, argc, argv); -#endif #endif } else { if (!s->outfile) diff --git a/tccrun.c b/tccrun.c index 77bd001e..01f40f32 100644 --- a/tccrun.c +++ b/tccrun.c @@ -1522,7 +1522,6 @@ static void rt_restore_context_from_jmpbuf(void *p_jmp_buf, int code) static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info) { rt_frame f; - TCCState *s; unsigned code; rt_getcontext(ex_info->ContextRecord, &f); @@ -1546,6 +1545,7 @@ static long __stdcall cpu_exception_handler(EXCEPTION_POINTERS *ex_info) break; } #if defined(_WIN64) && defined(__aarch64__) && !defined(CONFIG_TCC_BACKTRACE_ONLY) + TCCState *s; rt_wait_sem(); s = rt_find_state(&f); rt_post_sem(); diff --git a/tests/libtcc_test_mt.c b/tests/libtcc_test_mt.c index f9c90bd6..4db027f7 100644 --- a/tests/libtcc_test_mt.c +++ b/tests/libtcc_test_mt.c @@ -338,7 +338,11 @@ int main(int argc, char **argv) #else #include +#ifdef _WIN32 +void __stdcall Sleep(unsigned int milliseconds); +#else unsigned int sleep(unsigned int seconds); +#endif int fib(n) { @@ -347,7 +351,11 @@ int fib(n) int main(int argc, char **argv) { +#ifdef _WIN32 + Sleep(1000); +#else sleep(1); +#endif printf(" %d", fib(atoi(argv[1]))); return 0; }