| author | |
| committer | |
| log | 68a338cc1037531b4ba548a4c181afeb957fab9a |
| tree | a8d0b4c3d1566e2c3b97f6a28694ae924ae8851e |
| parent | 3882ce4f4bc78154dffe0768d0200a1bde067af7 |
4 files changed, 74 insertions(+), 123 deletions(-)
src/zig_clang_cc1_main.cpp+15-13| ... | @@ -213,9 +213,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { | ... | @@ -213,9 +213,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 213 | bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(), | 213 | bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(), |
| 214 | Argv, Diags, Argv0); | 214 | Argv, Diags, Argv0); |
| 215 | 215 | ||
| 216 | if (Clang->getFrontendOpts().TimeTrace || | 216 | if (!Clang->getFrontendOpts().TimeTracePath.empty()) { |
| 217 | !Clang->getFrontendOpts().TimeTracePath.empty()) { | ||
| 218 | Clang->getFrontendOpts().TimeTrace = 1; | ||
| 219 | llvm::timeTraceProfilerInitialize( | 217 | llvm::timeTraceProfilerInitialize( |
| 220 | Clang->getFrontendOpts().TimeTraceGranularity, Argv0); | 218 | Clang->getFrontendOpts().TimeTraceGranularity, Argv0); |
| 221 | } | 219 | } |
| ... | @@ -257,17 +255,21 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { | ... | @@ -257,17 +255,21 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 257 | llvm::TimerGroup::clearAll(); | 255 | llvm::TimerGroup::clearAll(); |
| 258 | 256 | ||
| 259 | if (llvm::timeTraceProfilerEnabled()) { | 257 | if (llvm::timeTraceProfilerEnabled()) { |
| 260 | SmallString<128> Path(Clang->getFrontendOpts().OutputFile); | 258 | // It is possible that the compiler instance doesn't own a file manager here |
| 261 | llvm::sys::path::replace_extension(Path, "json"); | 259 | // if we're compiling a module unit. Since the file manager are owned by AST |
| 262 | if (!Clang->getFrontendOpts().TimeTracePath.empty()) { | 260 | // when we're compiling a module unit. So the file manager may be invalid |
| 263 | // replace the suffix to '.json' directly | 261 | // here. |
| 264 | SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath); | 262 | // |
| 265 | if (llvm::sys::fs::is_directory(TracePath)) | 263 | // It should be fine to create file manager here since the file system |
| 266 | llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path)); | 264 | // options are stored in the compiler invocation and we can recreate the VFS |
| 267 | Path.assign(TracePath); | 265 | // from the compiler invocation. |
| 268 | } | 266 | if (!Clang->hasFileManager()) |
| 267 | Clang->createFileManager(createVFSFromCompilerInvocation( | ||
| 268 | Clang->getInvocation(), Clang->getDiagnostics())); | ||
| 269 | |||
| 269 | if (auto profilerOutput = Clang->createOutputFile( | 270 | if (auto profilerOutput = Clang->createOutputFile( |
| 270 | Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false, | 271 | Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false, |
| 272 | /*RemoveFileOnSignal=*/false, | ||
| 271 | /*useTemporary=*/false)) { | 273 | /*useTemporary=*/false)) { |
| 272 | llvm::timeTraceProfilerWrite(*profilerOutput); | 274 | llvm::timeTraceProfilerWrite(*profilerOutput); |
| 273 | profilerOutput.reset(); | 275 | profilerOutput.reset(); |
src/zig_clang_cc1as_main.cpp+16-7| ... | @@ -19,8 +19,8 @@ | ... | @@ -19,8 +19,8 @@ |
| 19 | #include "clang/Frontend/TextDiagnosticPrinter.h" | 19 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 20 | #include "clang/Frontend/Utils.h" | 20 | #include "clang/Frontend/Utils.h" |
| 21 | #include "llvm/ADT/STLExtras.h" | 21 | #include "llvm/ADT/STLExtras.h" |
| 22 | #include "llvm/ADT/StringExtras.h" | ||
| 22 | #include "llvm/ADT/StringSwitch.h" | 23 | #include "llvm/ADT/StringSwitch.h" |
| 23 | #include "llvm/ADT/Triple.h" | ||
| 24 | #include "llvm/IR/DataLayout.h" | 24 | #include "llvm/IR/DataLayout.h" |
| 25 | #include "llvm/MC/MCAsmBackend.h" | 25 | #include "llvm/MC/MCAsmBackend.h" |
| 26 | #include "llvm/MC/MCAsmInfo.h" | 26 | #include "llvm/MC/MCAsmInfo.h" |
| ... | @@ -44,7 +44,6 @@ | ... | @@ -44,7 +44,6 @@ |
| 44 | #include "llvm/Support/ErrorHandling.h" | 44 | #include "llvm/Support/ErrorHandling.h" |
| 45 | #include "llvm/Support/FileSystem.h" | 45 | #include "llvm/Support/FileSystem.h" |
| 46 | #include "llvm/Support/FormattedStream.h" | 46 | #include "llvm/Support/FormattedStream.h" |
| 47 | #include "llvm/Support/Host.h" | ||
| 48 | #include "llvm/Support/MemoryBuffer.h" | 47 | #include "llvm/Support/MemoryBuffer.h" |
| 49 | #include "llvm/Support/Path.h" | 48 | #include "llvm/Support/Path.h" |
| 50 | #include "llvm/Support/Process.h" | 49 | #include "llvm/Support/Process.h" |
| ... | @@ -53,6 +52,8 @@ | ... | @@ -53,6 +52,8 @@ |
| 53 | #include "llvm/Support/TargetSelect.h" | 52 | #include "llvm/Support/TargetSelect.h" |
| 54 | #include "llvm/Support/Timer.h" | 53 | #include "llvm/Support/Timer.h" |
| 55 | #include "llvm/Support/raw_ostream.h" | 54 | #include "llvm/Support/raw_ostream.h" |
| 55 | #include "llvm/TargetParser/Host.h" | ||
| 56 | #include "llvm/TargetParser/Triple.h" | ||
| 56 | #include <memory> | 57 | #include <memory> |
| 57 | #include <optional> | 58 | #include <optional> |
| 58 | #include <system_error> | 59 | #include <system_error> |
| ... | @@ -97,7 +98,7 @@ struct AssemblerInvocation { | ... | @@ -97,7 +98,7 @@ struct AssemblerInvocation { |
| 97 | std::string DwarfDebugFlags; | 98 | std::string DwarfDebugFlags; |
| 98 | std::string DwarfDebugProducer; | 99 | std::string DwarfDebugProducer; |
| 99 | std::string DebugCompilationDir; | 100 | std::string DebugCompilationDir; |
| 100 | std::map<const std::string, const std::string> DebugPrefixMap; | 101 | llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap; |
| 101 | llvm::DebugCompressionType CompressDebugSections = | 102 | llvm::DebugCompressionType CompressDebugSections = |
| 102 | llvm::DebugCompressionType::None; | 103 | llvm::DebugCompressionType::None; |
| 103 | std::string MainFileName; | 104 | std::string MainFileName; |
| ... | @@ -142,6 +143,10 @@ struct AssemblerInvocation { | ... | @@ -142,6 +143,10 @@ struct AssemblerInvocation { |
| 142 | /// Whether to emit DWARF unwind info. | 143 | /// Whether to emit DWARF unwind info. |
| 143 | EmitDwarfUnwindType EmitDwarfUnwind; | 144 | EmitDwarfUnwindType EmitDwarfUnwind; |
| 144 | 145 | ||
| 146 | // Whether to emit compact-unwind for non-canonical entries. | ||
| 147 | // Note: maybe overriden by other constraints. | ||
| 148 | unsigned EmitCompactUnwindNonCanonical : 1; | ||
| 149 | |||
| 145 | /// The name of the relocation model to use. | 150 | /// The name of the relocation model to use. |
| 146 | std::string RelocationModel; | 151 | std::string RelocationModel; |
| 147 | 152 | ||
| ... | @@ -181,6 +186,7 @@ public: | ... | @@ -181,6 +186,7 @@ public: |
| 181 | DwarfVersion = 0; | 186 | DwarfVersion = 0; |
| 182 | EmbedBitcode = 0; | 187 | EmbedBitcode = 0; |
| 183 | EmitDwarfUnwind = EmitDwarfUnwindType::Default; | 188 | EmitDwarfUnwind = EmitDwarfUnwindType::Default; |
| 189 | EmitCompactUnwindNonCanonical = false; | ||
| 184 | } | 190 | } |
| 185 | 191 | ||
| 186 | static bool CreateFromArgs(AssemblerInvocation &Res, | 192 | static bool CreateFromArgs(AssemblerInvocation &Res, |
| ... | @@ -275,8 +281,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, | ... | @@ -275,8 +281,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 275 | 281 | ||
| 276 | for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { | 282 | for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { |
| 277 | auto Split = StringRef(Arg).split('='); | 283 | auto Split = StringRef(Arg).split('='); |
| 278 | Opts.DebugPrefixMap.insert( | 284 | Opts.DebugPrefixMap.emplace_back(Split.first, Split.second); |
| 279 | {std::string(Split.first), std::string(Split.second)}); | ||
| 280 | } | 285 | } |
| 281 | 286 | ||
| 282 | // Frontend Options | 287 | // Frontend Options |
| ... | @@ -349,6 +354,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, | ... | @@ -349,6 +354,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 349 | .Case("default", EmitDwarfUnwindType::Default); | 354 | .Case("default", EmitDwarfUnwindType::Default); |
| 350 | } | 355 | } |
| 351 | 356 | ||
| 357 | Opts.EmitCompactUnwindNonCanonical = | ||
| 358 | Args.hasArg(OPT_femit_compact_unwind_non_canonical); | ||
| 359 | |||
| 352 | Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file); | 360 | Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file); |
| 353 | 361 | ||
| 354 | return Success; | 362 | return Success; |
| ... | @@ -384,8 +392,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, | ... | @@ -384,8 +392,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 384 | MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); | 392 | MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); |
| 385 | 393 | ||
| 386 | if (std::error_code EC = Buffer.getError()) { | 394 | if (std::error_code EC = Buffer.getError()) { |
| 387 | Error = EC.message(); | 395 | return Diags.Report(diag::err_fe_error_reading) |
| 388 | return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile; | 396 | << Opts.InputFile << EC.message(); |
| 389 | } | 397 | } |
| 390 | 398 | ||
| 391 | SourceMgr SrcMgr; | 399 | SourceMgr SrcMgr; |
| ... | @@ -402,6 +410,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, | ... | @@ -402,6 +410,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 402 | 410 | ||
| 403 | MCTargetOptions MCOptions; | 411 | MCTargetOptions MCOptions; |
| 404 | MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; | 412 | MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; |
| 413 | MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; | ||
| 405 | MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; | 414 | MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; |
| 406 | 415 | ||
| 407 | std::unique_ptr<MCAsmInfo> MAI( | 416 | std::unique_ptr<MCAsmInfo> MAI( |
src/zig_clang_driver.cpp+37-63| ... | @@ -36,8 +36,8 @@ | ... | @@ -36,8 +36,8 @@ |
| 36 | #include "llvm/Support/CrashRecoveryContext.h" | 36 | #include "llvm/Support/CrashRecoveryContext.h" |
| 37 | #include "llvm/Support/ErrorHandling.h" | 37 | #include "llvm/Support/ErrorHandling.h" |
| 38 | #include "llvm/Support/FileSystem.h" | 38 | #include "llvm/Support/FileSystem.h" |
| 39 | #include "llvm/Support/Host.h" | ||
| 40 | #include "llvm/Support/InitLLVM.h" | 39 | #include "llvm/Support/InitLLVM.h" |
| 40 | #include "llvm/Support/LLVMDriver.h" | ||
| 41 | #include "llvm/Support/Path.h" | 41 | #include "llvm/Support/Path.h" |
| 42 | #include "llvm/Support/PrettyStackTrace.h" | 42 | #include "llvm/Support/PrettyStackTrace.h" |
| 43 | #include "llvm/Support/Process.h" | 43 | #include "llvm/Support/Process.h" |
| ... | @@ -48,6 +48,7 @@ | ... | @@ -48,6 +48,7 @@ |
| 48 | #include "llvm/Support/TargetSelect.h" | 48 | #include "llvm/Support/TargetSelect.h" |
| 49 | #include "llvm/Support/Timer.h" | 49 | #include "llvm/Support/Timer.h" |
| 50 | #include "llvm/Support/raw_ostream.h" | 50 | #include "llvm/Support/raw_ostream.h" |
| 51 | #include "llvm/TargetParser/Host.h" | ||
| 51 | #include <memory> | 52 | #include <memory> |
| 52 | #include <optional> | 53 | #include <optional> |
| 53 | #include <set> | 54 | #include <set> |
| ... | @@ -209,6 +210,9 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, | ... | @@ -209,6 +210,9 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 209 | void *MainAddr); | 210 | void *MainAddr); |
| 210 | extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, | 211 | extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 211 | void *MainAddr); | 212 | void *MainAddr); |
| 213 | extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv, | ||
| 214 | const char *Argv0, void *MainAddr, | ||
| 215 | const llvm::ToolContext &); | ||
| 212 | 216 | ||
| 213 | static void insertTargetAndModeArgs(const ParsedClangName &NameParts, | 217 | static void insertTargetAndModeArgs(const ParsedClangName &NameParts, |
| 214 | SmallVectorImpl<const char *> &ArgVector, | 218 | SmallVectorImpl<const char *> &ArgVector, |
| ... | @@ -303,6 +307,9 @@ static bool SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) { | ... | @@ -303,6 +307,9 @@ static bool SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) { |
| 303 | TheDriver.CCPrintProcessStats = | 307 | TheDriver.CCPrintProcessStats = |
| 304 | checkEnvVar<bool>("CC_PRINT_PROC_STAT", "CC_PRINT_PROC_STAT_FILE", | 308 | checkEnvVar<bool>("CC_PRINT_PROC_STAT", "CC_PRINT_PROC_STAT_FILE", |
| 305 | TheDriver.CCPrintStatReportFilename); | 309 | TheDriver.CCPrintStatReportFilename); |
| 310 | TheDriver.CCPrintInternalStats = | ||
| 311 | checkEnvVar<bool>("CC_PRINT_INTERNAL_STAT", "CC_PRINT_INTERNAL_STAT_FILE", | ||
| 312 | TheDriver.CCPrintInternalStatReportFilename); | ||
| 306 | 313 | ||
| 307 | return true; | 314 | return true; |
| 308 | } | 315 | } |
| ... | @@ -339,7 +346,8 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv, | ... | @@ -339,7 +346,8 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv, |
| 339 | TheDriver.setInstalledDir(InstalledPathParent); | 346 | TheDriver.setInstalledDir(InstalledPathParent); |
| 340 | } | 347 | } |
| 341 | 348 | ||
| 342 | static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) { | 349 | static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV, |
| 350 | const llvm::ToolContext &ToolContext) { | ||
| 343 | // If we call the cc1 tool from the clangDriver library (through | 351 | // If we call the cc1 tool from the clangDriver library (through |
| 344 | // Driver::CC1Main), we need to clean up the options usage count. The options | 352 | // Driver::CC1Main), we need to clean up the options usage count. The options |
| 345 | // are currently global, and they might have been used previously by the | 353 | // are currently global, and they might have been used previously by the |
| ... | @@ -358,28 +366,22 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) { | ... | @@ -358,28 +366,22 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) { |
| 358 | return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP); | 366 | return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP); |
| 359 | if (Tool == "-cc1as") | 367 | if (Tool == "-cc1as") |
| 360 | return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP); | 368 | return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP); |
| 369 | if (Tool == "-cc1gen-reproducer") | ||
| 370 | return cc1gen_reproducer_main(ArrayRef(ArgV).slice(2), ArgV[0], | ||
| 371 | GetExecutablePathVP, ToolContext); | ||
| 361 | // Reject unknown tools. | 372 | // Reject unknown tools. |
| 362 | llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " | 373 | llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " |
| 363 | << "Valid tools include '-cc1' and '-cc1as'.\n"; | 374 | << "Valid tools include '-cc1' and '-cc1as'.\n"; |
| 364 | return 1; | 375 | return 1; |
| 365 | } | 376 | } |
| 366 | 377 | ||
| 367 | extern "C" int ZigClang_main(int Argc, const char **Argv); | 378 | int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) { |
| 368 | int ZigClang_main(int Argc, const char **Argv) { | ||
| 369 | noteBottomOfStack(); | 379 | noteBottomOfStack(); |
| 370 | // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), | 380 | llvm::InitLLVM X(Argc, Argv); |
| 371 | // and overwrites the args. We don't want it to do that, | ||
| 372 | // and we also don't need the signal handlers it installs | ||
| 373 | // (we have our own already), so we just use llvm_shutdown_obj | ||
| 374 | // instead. | ||
| 375 | // llvm::InitLLVM X(Argc, Argv); | ||
| 376 | llvm::llvm_shutdown_obj X; | ||
| 377 | |||
| 378 | llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL | 381 | llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL |
| 379 | " and include the crash backtrace, preprocessed " | 382 | " and include the crash backtrace, preprocessed " |
| 380 | "source, and associated run script.\n"); | 383 | "source, and associated run script.\n"); |
| 381 | size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1; | 384 | SmallVector<const char *, 256> Args(Argv, Argv + Argc); |
| 382 | SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc); | ||
| 383 | 385 | ||
| 384 | if (llvm::sys::Process::FixupStandardFileDescriptors()) | 386 | if (llvm::sys::Process::FixupStandardFileDescriptors()) |
| 385 | return 1; | 387 | return 1; |
| ... | @@ -389,55 +391,20 @@ int ZigClang_main(int Argc, const char **Argv) { | ... | @@ -389,55 +391,20 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 389 | llvm::BumpPtrAllocator A; | 391 | llvm::BumpPtrAllocator A; |
| 390 | llvm::StringSaver Saver(A); | 392 | llvm::StringSaver Saver(A); |
| 391 | 393 | ||
| 392 | // Parse response files using the GNU syntax, unless we're in CL mode. There | 394 | const char *ProgName = |
| 393 | // are two ways to put clang in CL compatibility mode: Args[0] is either | 395 | ToolContext.NeedsPrependArg ? ToolContext.PrependArg : ToolContext.Path; |
| 394 | // clang-cl or cl, or --driver-mode=cl is on the command line. The normal | 396 | |
| 395 | // command line parsing can't happen until after response file parsing, so we | ||
| 396 | // have to manually search for a --driver-mode=cl argument the hard way. | ||
| 397 | // Finally, our -cc1 tools don't care which tokenization mode we use because | ||
| 398 | // response files written by clang will tokenize the same way in either mode. | ||
| 399 | bool ClangCLMode = | 397 | bool ClangCLMode = |
| 400 | IsClangCL(getDriverMode(Args[0], llvm::ArrayRef(Args).slice(1))); | 398 | IsClangCL(getDriverMode(ProgName, llvm::ArrayRef(Args).slice(1))); |
| 401 | enum { Default, POSIX, Windows } RSPQuoting = Default; | ||
| 402 | for (const char *F : Args) { | ||
| 403 | if (strcmp(F, "--rsp-quoting=posix") == 0) | ||
| 404 | RSPQuoting = POSIX; | ||
| 405 | else if (strcmp(F, "--rsp-quoting=windows") == 0) | ||
| 406 | RSPQuoting = Windows; | ||
| 407 | } | ||
| 408 | 399 | ||
| 409 | // Determines whether we want nullptr markers in Args to indicate response | 400 | if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A)) { |
| 410 | // files end-of-lines. We only use this for the /LINK driver argument with | ||
| 411 | // clang-cl.exe on Windows. | ||
| 412 | bool MarkEOLs = ClangCLMode; | ||
| 413 | |||
| 414 | llvm::cl::TokenizerCallback Tokenizer; | ||
| 415 | if (RSPQuoting == Windows || (RSPQuoting == Default && ClangCLMode)) | ||
| 416 | Tokenizer = &llvm::cl::TokenizeWindowsCommandLine; | ||
| 417 | else | ||
| 418 | Tokenizer = &llvm::cl::TokenizeGNUCommandLine; | ||
| 419 | |||
| 420 | if (MarkEOLs && Args.size() > 1 && StringRef(Args[1]).startswith("-cc1")) | ||
| 421 | MarkEOLs = false; | ||
| 422 | llvm::cl::ExpansionContext ECtx(A, Tokenizer); | ||
| 423 | ECtx.setMarkEOLs(MarkEOLs); | ||
| 424 | if (llvm::Error Err = ECtx.expandResponseFiles(Args)) { | ||
| 425 | llvm::errs() << toString(std::move(Err)) << '\n'; | 401 | llvm::errs() << toString(std::move(Err)) << '\n'; |
| 426 | return 1; | 402 | return 1; |
| 427 | } | 403 | } |
| 428 | 404 | ||
| 429 | // Handle -cc1 integrated tools, even if -cc1 was expanded from a response | 405 | // Handle -cc1 integrated tools. |
| 430 | // file. | 406 | if (Args.size() >= 2 && StringRef(Args[1]).startswith("-cc1")) |
| 431 | auto FirstArg = llvm::find_if(llvm::drop_begin(Args), | 407 | return ExecuteCC1Tool(Args, ToolContext); |
| 432 | [](const char *A) { return A != nullptr; }); | ||
| 433 | if (FirstArg != Args.end() && StringRef(*FirstArg).startswith("-cc1")) { | ||
| 434 | // If -cc1 came from a response file, remove the EOL sentinels. | ||
| 435 | if (MarkEOLs) { | ||
| 436 | auto newEnd = std::remove(Args.begin(), Args.end(), nullptr); | ||
| 437 | Args.resize(newEnd - Args.begin()); | ||
| 438 | } | ||
| 439 | return ExecuteCC1Tool(Args); | ||
| 440 | } | ||
| 441 | 408 | ||
| 442 | // Handle options that need handling before the real command line parsing in | 409 | // Handle options that need handling before the real command line parsing in |
| 443 | // Driver::BuildCompilation() | 410 | // Driver::BuildCompilation() |
| ... | @@ -483,9 +450,7 @@ int ZigClang_main(int Argc, const char **Argv) { | ... | @@ -483,9 +450,7 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 483 | ApplyQAOverride(Args, OverrideStr, SavedStrings); | 450 | ApplyQAOverride(Args, OverrideStr, SavedStrings); |
| 484 | } | 451 | } |
| 485 | 452 | ||
| 486 | // Pass local param `Argv[0]` as fallback. | 453 | std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes); |
| 487 | // See https://github.com/ziglang/zig/pull/3292 . | ||
| 488 | std::string Path = GetExecutablePath(Argv[0], CanonicalPrefixes); | ||
| 489 | 454 | ||
| 490 | // Whether the cc1 tool should be called inside the current process, or if we | 455 | // Whether the cc1 tool should be called inside the current process, or if we |
| 491 | // should spawn a new clang subprocess (old behavior). | 456 | // should spawn a new clang subprocess (old behavior). |
| ... | @@ -503,7 +468,7 @@ int ZigClang_main(int Argc, const char **Argv) { | ... | @@ -503,7 +468,7 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 503 | 468 | ||
| 504 | TextDiagnosticPrinter *DiagClient | 469 | TextDiagnosticPrinter *DiagClient |
| 505 | = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); | 470 | = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); |
| 506 | FixupDiagPrefixExeName(DiagClient, Path); | 471 | FixupDiagPrefixExeName(DiagClient, ProgName); |
| 507 | 472 | ||
| 508 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); | 473 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 509 | 474 | ||
| ... | @@ -521,8 +486,15 @@ int ZigClang_main(int Argc, const char **Argv) { | ... | @@ -521,8 +486,15 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 521 | 486 | ||
| 522 | Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags); | 487 | Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags); |
| 523 | SetInstallDir(Args, TheDriver, CanonicalPrefixes); | 488 | SetInstallDir(Args, TheDriver, CanonicalPrefixes); |
| 524 | auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Args[0]); | 489 | auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(ProgName); |
| 525 | TheDriver.setTargetAndMode(TargetAndMode); | 490 | TheDriver.setTargetAndMode(TargetAndMode); |
| 491 | // If -canonical-prefixes is set, GetExecutablePath will have resolved Path | ||
| 492 | // to the llvm driver binary, not clang. In this case, we need to use | ||
| 493 | // PrependArg which should be clang-*. Checking just CanonicalPrefixes is | ||
| 494 | // safe even in the normal case because PrependArg will be null so | ||
| 495 | // setPrependArg will be a no-op. | ||
| 496 | if (ToolContext.NeedsPrependArg || CanonicalPrefixes) | ||
| 497 | TheDriver.setPrependArg(ToolContext.PrependArg); | ||
| 526 | 498 | ||
| 527 | insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings); | 499 | insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings); |
| 528 | 500 | ||
| ... | @@ -530,7 +502,9 @@ int ZigClang_main(int Argc, const char **Argv) { | ... | @@ -530,7 +502,9 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 530 | return 1; | 502 | return 1; |
| 531 | 503 | ||
| 532 | if (!UseNewCC1Process) { | 504 | if (!UseNewCC1Process) { |
| 533 | TheDriver.CC1Main = &ExecuteCC1Tool; | 505 | TheDriver.CC1Main = [ToolContext](SmallVectorImpl<const char *> &ArgV) { |
| 506 | return ExecuteCC1Tool(ArgV, ToolContext); | ||
| 507 | }; | ||
| 534 | // Ensure the CC1Command actually catches cc1 crashes | 508 | // Ensure the CC1Command actually catches cc1 crashes |
| 535 | llvm::CrashRecoveryContext::Enable(); | 509 | llvm::CrashRecoveryContext::Enable(); |
| 536 | } | 510 | } |
src/zig_llvm-ar.cpp+6-40| ... | @@ -13,20 +13,11 @@ | ... | @@ -13,20 +13,11 @@ |
| 13 | 13 | ||
| 14 | #include "llvm/ADT/StringExtras.h" | 14 | #include "llvm/ADT/StringExtras.h" |
| 15 | #include "llvm/ADT/StringSwitch.h" | 15 | #include "llvm/ADT/StringSwitch.h" |
| 16 | #include "llvm/ADT/Triple.h" | ||
| 17 | #include "llvm/BinaryFormat/Magic.h" | 16 | #include "llvm/BinaryFormat/Magic.h" |
| 18 | #include "llvm/IR/LLVMContext.h" | 17 | #include "llvm/IR/LLVMContext.h" |
| 19 | #include "llvm/Object/Archive.h" | 18 | #include "llvm/Object/Archive.h" |
| 20 | #include "llvm/Object/ArchiveWriter.h" | 19 | #include "llvm/Object/ArchiveWriter.h" |
| 21 | #include "llvm/Object/COFFImportFile.h" | ||
| 22 | #include "llvm/Object/ELFObjectFile.h" | ||
| 23 | #include "llvm/Object/IRObjectFile.h" | ||
| 24 | #include "llvm/Object/MachO.h" | ||
| 25 | #include "llvm/Object/ObjectFile.h" | ||
| 26 | #include "llvm/Object/SymbolicFile.h" | 20 | #include "llvm/Object/SymbolicFile.h" |
| 27 | #include "llvm/Object/TapiFile.h" | ||
| 28 | #include "llvm/Object/Wasm.h" | ||
| 29 | #include "llvm/Object/XCOFFObjectFile.h" | ||
| 30 | #include "llvm/Support/Chrono.h" | 21 | #include "llvm/Support/Chrono.h" |
| 31 | #include "llvm/Support/CommandLine.h" | 22 | #include "llvm/Support/CommandLine.h" |
| 32 | #include "llvm/Support/ConvertUTF.h" | 23 | #include "llvm/Support/ConvertUTF.h" |
| ... | @@ -34,8 +25,8 @@ | ... | @@ -34,8 +25,8 @@ |
| 34 | #include "llvm/Support/FileSystem.h" | 25 | #include "llvm/Support/FileSystem.h" |
| 35 | #include "llvm/Support/Format.h" | 26 | #include "llvm/Support/Format.h" |
| 36 | #include "llvm/Support/FormatVariadic.h" | 27 | #include "llvm/Support/FormatVariadic.h" |
| 37 | #include "llvm/Support/Host.h" | ||
| 38 | #include "llvm/Support/InitLLVM.h" | 28 | #include "llvm/Support/InitLLVM.h" |
| 29 | #include "llvm/Support/LLVMDriver.h" | ||
| 39 | #include "llvm/Support/LineIterator.h" | 30 | #include "llvm/Support/LineIterator.h" |
| 40 | #include "llvm/Support/MemoryBuffer.h" | 31 | #include "llvm/Support/MemoryBuffer.h" |
| 41 | #include "llvm/Support/Path.h" | 32 | #include "llvm/Support/Path.h" |
| ... | @@ -45,6 +36,8 @@ | ... | @@ -45,6 +36,8 @@ |
| 45 | #include "llvm/Support/ToolOutputFile.h" | 36 | #include "llvm/Support/ToolOutputFile.h" |
| 46 | #include "llvm/Support/WithColor.h" | 37 | #include "llvm/Support/WithColor.h" |
| 47 | #include "llvm/Support/raw_ostream.h" | 38 | #include "llvm/Support/raw_ostream.h" |
| 39 | #include "llvm/TargetParser/Host.h" | ||
| 40 | #include "llvm/TargetParser/Triple.h" | ||
| 48 | #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h" | 41 | #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h" |
| 49 | #include "llvm/ToolDrivers/llvm-lib/LibDriver.h" | 42 | #include "llvm/ToolDrivers/llvm-lib/LibDriver.h" |
| 50 | 43 | ||
| ... | @@ -646,31 +639,12 @@ static bool shouldCreateArchive(ArchiveOperation Op) { | ... | @@ -646,31 +639,12 @@ static bool shouldCreateArchive(ArchiveOperation Op) { |
| 646 | llvm_unreachable("Missing entry in covered switch."); | 639 | llvm_unreachable("Missing entry in covered switch."); |
| 647 | } | 640 | } |
| 648 | 641 | ||
| 649 | static bool is64BitSymbolicFile(SymbolicFile &Obj) { | ||
| 650 | if (auto *IRObj = dyn_cast<IRObjectFile>(&Obj)) | ||
| 651 | return Triple(IRObj->getTargetTriple()).isArch64Bit(); | ||
| 652 | if (isa<COFFObjectFile>(Obj) || isa<COFFImportFile>(Obj)) | ||
| 653 | return false; | ||
| 654 | if (XCOFFObjectFile *XCOFFObj = dyn_cast<XCOFFObjectFile>(&Obj)) | ||
| 655 | return XCOFFObj->is64Bit(); | ||
| 656 | if (isa<WasmObjectFile>(Obj)) | ||
| 657 | return false; | ||
| 658 | if (TapiFile *Tapi = dyn_cast<TapiFile>(&Obj)) | ||
| 659 | return Tapi->is64Bit(); | ||
| 660 | if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj)) | ||
| 661 | return MachO->is64Bit(); | ||
| 662 | if (ELFObjectFileBase *ElfO = dyn_cast<ELFObjectFileBase>(&Obj)) | ||
| 663 | return ElfO->getBytesInAddress() == 8; | ||
| 664 | |||
| 665 | fail("unsupported file format"); | ||
| 666 | } | ||
| 667 | |||
| 668 | static bool isValidInBitMode(Binary &Bin) { | 642 | static bool isValidInBitMode(Binary &Bin) { |
| 669 | if (BitMode == BitModeTy::Bit32_64 || BitMode == BitModeTy::Any) | 643 | if (BitMode == BitModeTy::Bit32_64 || BitMode == BitModeTy::Any) |
| 670 | return true; | 644 | return true; |
| 671 | 645 | ||
| 672 | if (SymbolicFile *SymFile = dyn_cast<SymbolicFile>(&Bin)) { | 646 | if (SymbolicFile *SymFile = dyn_cast<SymbolicFile>(&Bin)) { |
| 673 | bool Is64Bit = is64BitSymbolicFile(*SymFile); | 647 | bool Is64Bit = SymFile->is64Bit(); |
| 674 | if ((Is64Bit && (BitMode == BitModeTy::Bit32)) || | 648 | if ((Is64Bit && (BitMode == BitModeTy::Bit32)) || |
| 675 | (!Is64Bit && (BitMode == BitModeTy::Bit64))) | 649 | (!Is64Bit && (BitMode == BitModeTy::Bit64))) |
| 676 | return false; | 650 | return false; |
| ... | @@ -1452,16 +1426,8 @@ static int ranlib_main(int argc, char **argv) { | ... | @@ -1452,16 +1426,8 @@ static int ranlib_main(int argc, char **argv) { |
| 1452 | return 0; | 1426 | return 0; |
| 1453 | } | 1427 | } |
| 1454 | 1428 | ||
| 1455 | extern "C" int ZigLlvmAr_main(int argc, char **argv); | 1429 | int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) { |
| 1456 | int ZigLlvmAr_main(int argc, char **argv) { | 1430 | InitLLVM X(argc, argv); |
| 1457 | // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), | ||
| 1458 | // and overwrites the args. We don't want it to do that, | ||
| 1459 | // and we also don't need the signal handlers it installs | ||
| 1460 | // (we have our own already), so we just use llvm_shutdown_obj | ||
| 1461 | // instead. | ||
| 1462 | // InitLLVM X(argc, argv); | ||
| 1463 | llvm::llvm_shutdown_obj X; | ||
| 1464 | |||
| 1465 | ToolName = argv[0]; | 1431 | ToolName = argv[0]; |
| 1466 | 1432 | ||
| 1467 | llvm::InitializeAllTargetInfos(); | 1433 | llvm::InitializeAllTargetInfos(); |