From 84a544f96c4ece6b6e4eba4bd40c9d29dd74ec49 Mon Sep 17 00:00:00 2001 From: Martin Wickham Date: Fri, 9 Jul 2021 17:53:08 -0500 Subject: [PATCH] Fix argument forwarding to LLVM on Windows --- src/zig_clang_driver.cpp | 10 +++++++++- src/zig_llvm-ar.cpp | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/zig_clang_driver.cpp b/src/zig_clang_driver.cpp index 468c437a7d..e358fea83a 100644 --- a/src/zig_clang_driver.cpp +++ b/src/zig_clang_driver.cpp @@ -338,7 +338,15 @@ static int ExecuteCC1Tool(SmallVectorImpl &ArgV) { extern "C" int ZigClang_main(int argc_, const char **argv_); int ZigClang_main(int argc_, const char **argv_) { noteBottomOfStack(); - llvm::InitLLVM X(argc_, argv_); + + // ZIG MOD: On windows, InitLLVM calls GetCommandLineW(), + // and overwrites the args. We don't want it to do that, + // and we also don't need the signal handlers it installs + // (we have our own already), so we just use llvm_shutdown_obj + // instead. + // llvm::InitLLVM X(argc_, argv_); + llvm::llvm_shutdown_obj X; + llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL " and include the crash backtrace, preprocessed " "source, and associated run script.\n"); diff --git a/src/zig_llvm-ar.cpp b/src/zig_llvm-ar.cpp index 158a0a6836..e4c376adbc 100644 --- a/src/zig_llvm-ar.cpp +++ b/src/zig_llvm-ar.cpp @@ -1522,7 +1522,14 @@ static int ranlib_main(int argc, char **argv) { extern "C" int ZigLlvmAr_main(int argc, char **argv); int ZigLlvmAr_main(int argc, char **argv) { - InitLLVM X(argc, argv); + // ZIG MOD: On windows, InitLLVM calls GetCommandLineW(), + // and overwrites the args. We don't want it to do that, + // and we also don't need the signal handlers it installs + // (we have our own already), so we just use llvm_shutdown_obj + // instead. + // InitLLVM X(argc, argv); + llvm::llvm_shutdown_obj X; + ToolName = argv[0]; llvm::InitializeAllTargetInfos();