| author | |
| committer | |
| log | 1b7ec080c9dd2215482b66bbe0602acb9720a497 |
| tree | c3748eb36e878b4dd4245fd5e52c0baae4916291 |
| parent | 3e7678a761a37adcdd56aecdce87c1247d34f399 |
| signature |
5 files changed, 98 insertions(+), 69 deletions(-)
src/zig_clang_cc1_main.cpp+26-27| ... | ... | @@ -12,19 +12,20 @@ |
| 12 | 12 | // |
| 13 | 13 | //===----------------------------------------------------------------------===// |
| 14 | 14 | |
| 15 | #include "clang/Basic/DiagnosticFrontend.h" | |
| 15 | 16 | #include "clang/Basic/Stack.h" |
| 16 | 17 | #include "clang/Basic/TargetOptions.h" |
| 17 | 18 | #include "clang/CodeGen/ObjectFilePCHContainerWriter.h" |
| 18 | 19 | #include "clang/Config/config.h" |
| 20 | #include "clang/Driver/Driver.h" | |
| 19 | 21 | #include "clang/Driver/DriverDiagnostic.h" |
| 20 | #include "clang/Driver/Options.h" | |
| 21 | 22 | #include "clang/Frontend/CompilerInstance.h" |
| 22 | 23 | #include "clang/Frontend/CompilerInvocation.h" |
| 23 | #include "clang/Frontend/FrontendDiagnostic.h" | |
| 24 | 24 | #include "clang/Frontend/TextDiagnosticBuffer.h" |
| 25 | 25 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 26 | 26 | #include "clang/Frontend/Utils.h" |
| 27 | 27 | #include "clang/FrontendTool/Utils.h" |
| 28 | #include "clang/Options/Options.h" | |
| 28 | 29 | #include "clang/Serialization/ObjectFilePCHContainerReader.h" |
| 29 | 30 | #include "llvm/ADT/Statistic.h" |
| 30 | 31 | #include "llvm/ADT/StringExtras.h" |
| ... | ... | @@ -38,6 +39,7 @@ |
| 38 | 39 | #include "llvm/Support/BuryPointer.h" |
| 39 | 40 | #include "llvm/Support/Compiler.h" |
| 40 | 41 | #include "llvm/Support/ErrorHandling.h" |
| 42 | #include "llvm/Support/IOSandbox.h" | |
| 41 | 43 | #include "llvm/Support/ManagedStatic.h" |
| 42 | 44 | #include "llvm/Support/Path.h" |
| 43 | 45 | #include "llvm/Support/Process.h" |
| ... | ... | @@ -217,7 +219,7 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) { |
| 217 | 219 | int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 218 | 220 | ensureSufficientStack(); |
| 219 | 221 | |
| 220 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); | |
| 222 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID = DiagnosticIDs::create(); | |
| 221 | 223 | |
| 222 | 224 | // Register the support for object-file-wrapped Clang modules. |
| 223 | 225 | auto PCHOps = std::make_shared<PCHContainerOperations>(); |
| ... | ... | @@ -269,12 +271,17 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 269 | 271 | if (Clang->getHeaderSearchOpts().UseBuiltinIncludes && |
| 270 | 272 | Clang->getHeaderSearchOpts().ResourceDir.empty()) |
| 271 | 273 | Clang->getHeaderSearchOpts().ResourceDir = |
| 272 | CompilerInvocation::GetResourcesPath(Argv0, MainAddr); | |
| 274 | GetResourcesPath(Argv0, MainAddr); | |
| 275 | ||
| 276 | /// Create the actual file system. | |
| 277 | auto VFS = [] { | |
| 278 | auto BypassSandbox = llvm::sys::sandbox::scopedDisable(); | |
| 279 | return llvm::vfs::getRealFileSystem(); | |
| 280 | }(); | |
| 281 | Clang->createVirtualFileSystem(std::move(VFS), DiagsBuffer); | |
| 273 | 282 | |
| 274 | 283 | // Create the actual diagnostics engine. |
| 275 | Clang->createDiagnostics(*llvm::vfs::getRealFileSystem()); | |
| 276 | if (!Clang->hasDiagnostics()) | |
| 277 | return 1; | |
| 284 | Clang->createDiagnostics(); | |
| 278 | 285 | |
| 279 | 286 | // Set an error handler, so that any LLVM backend diagnostics go through our |
| 280 | 287 | // error handler. |
| ... | ... | @@ -299,29 +306,21 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 299 | 306 | |
| 300 | 307 | // If any timers were active but haven't been destroyed yet, print their |
| 301 | 308 | // results now. This happens in -disable-free mode. |
| 302 | std::unique_ptr<raw_ostream> IOFile = llvm::CreateInfoOutputFile(); | |
| 303 | if (Clang->getCodeGenOpts().TimePassesJson) { | |
| 304 | *IOFile << "{\n"; | |
| 305 | llvm::TimerGroup::printAllJSONValues(*IOFile, ""); | |
| 306 | *IOFile << "\n}\n"; | |
| 307 | } else { | |
| 308 | llvm::TimerGroup::printAll(*IOFile); | |
| 309 | { | |
| 310 | // This isn't a formal input or output of the compiler. | |
| 311 | auto BypassSandbox = llvm::sys::sandbox::scopedDisable(); | |
| 312 | std::unique_ptr<raw_ostream> IOFile = llvm::CreateInfoOutputFile(); | |
| 313 | if (Clang->getCodeGenOpts().TimePassesJson) { | |
| 314 | *IOFile << "{\n"; | |
| 315 | llvm::TimerGroup::printAllJSONValues(*IOFile, ""); | |
| 316 | *IOFile << "\n}\n"; | |
| 317 | } else if (!Clang->getCodeGenOpts().TimePassesStatsFile) { | |
| 318 | llvm::TimerGroup::printAll(*IOFile); | |
| 319 | } | |
| 320 | llvm::TimerGroup::clearAll(); | |
| 309 | 321 | } |
| 310 | llvm::TimerGroup::clearAll(); | |
| 311 | 322 | |
| 312 | 323 | if (llvm::timeTraceProfilerEnabled()) { |
| 313 | // It is possible that the compiler instance doesn't own a file manager here | |
| 314 | // if we're compiling a module unit. Since the file manager are owned by AST | |
| 315 | // when we're compiling a module unit. So the file manager may be invalid | |
| 316 | // here. | |
| 317 | // | |
| 318 | // It should be fine to create file manager here since the file system | |
| 319 | // options are stored in the compiler invocation and we can recreate the VFS | |
| 320 | // from the compiler invocation. | |
| 321 | if (!Clang->hasFileManager()) | |
| 322 | Clang->createFileManager(createVFSFromCompilerInvocation( | |
| 323 | Clang->getInvocation(), Clang->getDiagnostics())); | |
| 324 | ||
| 325 | 324 | if (auto profilerOutput = Clang->createOutputFile( |
| 326 | 325 | Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false, |
| 327 | 326 | /*RemoveFileOnSignal=*/false, |
src/zig_clang_cc1as_main.cpp+48-27| ... | ... | @@ -12,12 +12,12 @@ |
| 12 | 12 | //===----------------------------------------------------------------------===// |
| 13 | 13 | |
| 14 | 14 | #include "clang/Basic/Diagnostic.h" |
| 15 | #include "clang/Basic/DiagnosticFrontend.h" | |
| 15 | 16 | #include "clang/Basic/DiagnosticOptions.h" |
| 16 | 17 | #include "clang/Driver/DriverDiagnostic.h" |
| 17 | #include "clang/Driver/Options.h" | |
| 18 | #include "clang/Frontend/FrontendDiagnostic.h" | |
| 19 | 18 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 20 | 19 | #include "clang/Frontend/Utils.h" |
| 20 | #include "clang/Options/Options.h" | |
| 21 | 21 | #include "llvm/ADT/STLExtras.h" |
| 22 | 22 | #include "llvm/ADT/StringExtras.h" |
| 23 | 23 | #include "llvm/ADT/StringSwitch.h" |
| ... | ... | @@ -45,6 +45,7 @@ |
| 45 | 45 | #include "llvm/Support/ErrorHandling.h" |
| 46 | 46 | #include "llvm/Support/FileSystem.h" |
| 47 | 47 | #include "llvm/Support/FormattedStream.h" |
| 48 | #include "llvm/Support/IOSandbox.h" | |
| 48 | 49 | #include "llvm/Support/MemoryBuffer.h" |
| 49 | 50 | #include "llvm/Support/Path.h" |
| 50 | 51 | #include "llvm/Support/Process.h" |
| ... | ... | @@ -59,8 +60,7 @@ |
| 59 | 60 | #include <optional> |
| 60 | 61 | #include <system_error> |
| 61 | 62 | using namespace clang; |
| 62 | using namespace clang::driver; | |
| 63 | using namespace clang::driver::options; | |
| 63 | using namespace clang::options; | |
| 64 | 64 | using namespace llvm; |
| 65 | 65 | using namespace llvm::opt; |
| 66 | 66 | |
| ... | ... | @@ -71,8 +71,8 @@ struct AssemblerInvocation { |
| 71 | 71 | /// @name Target Options |
| 72 | 72 | /// @{ |
| 73 | 73 | |
| 74 | /// The name of the target triple to assemble for. | |
| 75 | std::string Triple; | |
| 74 | /// The target triple to assemble for. | |
| 75 | llvm::Triple Triple; | |
| 76 | 76 | |
| 77 | 77 | /// If given, the name of the target CPU to determine which instructions |
| 78 | 78 | /// are legal. |
| ... | ... | @@ -163,6 +163,10 @@ struct AssemblerInvocation { |
| 163 | 163 | LLVM_PREFERRED_TYPE(bool) |
| 164 | 164 | unsigned EmitCompactUnwindNonCanonical : 1; |
| 165 | 165 | |
| 166 | // Whether to emit sframe unwind sections. | |
| 167 | LLVM_PREFERRED_TYPE(bool) | |
| 168 | unsigned EmitSFrameUnwind : 1; | |
| 169 | ||
| 166 | 170 | LLVM_PREFERRED_TYPE(bool) |
| 167 | 171 | unsigned Crel : 1; |
| 168 | 172 | LLVM_PREFERRED_TYPE(bool) |
| ... | ... | @@ -192,9 +196,12 @@ struct AssemblerInvocation { |
| 192 | 196 | std::string AsSecureLogFile; |
| 193 | 197 | /// @} |
| 194 | 198 | |
| 199 | void setTriple(llvm::StringRef Str) { | |
| 200 | Triple = llvm::Triple(llvm::Triple::normalize(Str)); | |
| 201 | } | |
| 202 | ||
| 195 | 203 | public: |
| 196 | 204 | AssemblerInvocation() { |
| 197 | Triple = ""; | |
| 198 | 205 | NoInitialTextSection = 0; |
| 199 | 206 | InputFile = "-"; |
| 200 | 207 | OutputPath = "-"; |
| ... | ... | @@ -261,7 +268,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 261 | 268 | // Construct the invocation. |
| 262 | 269 | |
| 263 | 270 | // Target Options |
| 264 | Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple)); | |
| 271 | Opts.setTriple(Args.getLastArgValue(OPT_triple)); | |
| 265 | 272 | if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple)) |
| 266 | 273 | Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue()); |
| 267 | 274 | if (Arg *A = Args.getLastArg(OPT_darwin_target_variant_sdk_version_EQ)) { |
| ... | ... | @@ -278,7 +285,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 278 | 285 | |
| 279 | 286 | // Use the default target triple if unspecified. |
| 280 | 287 | if (Opts.Triple.empty()) |
| 281 | Opts.Triple = llvm::sys::getDefaultTargetTriple(); | |
| 288 | Opts.setTriple(llvm::sys::getDefaultTargetTriple()); | |
| 282 | 289 | |
| 283 | 290 | // Language Options |
| 284 | 291 | Opts.IncludePaths = Args.getAllArgValues(OPT_I); |
| ... | ... | @@ -385,6 +392,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 385 | 392 | |
| 386 | 393 | Opts.EmitCompactUnwindNonCanonical = |
| 387 | 394 | Args.hasArg(OPT_femit_compact_unwind_non_canonical); |
| 395 | Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe); | |
| 388 | 396 | Opts.Crel = Args.hasArg(OPT_crel); |
| 389 | 397 | Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit); |
| 390 | 398 | Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no); |
| ... | ... | @@ -414,15 +422,19 @@ getOutputStream(StringRef Path, DiagnosticsEngine &Diags, bool Binary) { |
| 414 | 422 | } |
| 415 | 423 | |
| 416 | 424 | static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 417 | DiagnosticsEngine &Diags) { | |
| 425 | DiagnosticsEngine &Diags, | |
| 426 | IntrusiveRefCntPtr<vfs::FileSystem> VFS) { | |
| 418 | 427 | // Get the target specific parser. |
| 419 | 428 | std::string Error; |
| 420 | 429 | const Target *TheTarget = TargetRegistry::lookupTarget(Opts.Triple, Error); |
| 421 | 430 | if (!TheTarget) |
| 422 | return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; | |
| 431 | return Diags.Report(diag::err_target_unknown_triple) << Opts.Triple.str(); | |
| 423 | 432 | |
| 424 | ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer = | |
| 425 | MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); | |
| 433 | ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer = [&] { | |
| 434 | // FIXME(sandboxing): Make this a proper input file. | |
| 435 | auto BypassSandbox = sys::sandbox::scopedDisable(); | |
| 436 | return MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); | |
| 437 | }(); | |
| 426 | 438 | |
| 427 | 439 | if (std::error_code EC = Buffer.getError()) { |
| 428 | 440 | return Diags.Report(diag::err_fe_error_reading) |
| ... | ... | @@ -437,6 +449,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 437 | 449 | // Record the location of the include directories so that the lexer can find |
| 438 | 450 | // it later. |
| 439 | 451 | SrcMgr.setIncludeDirs(Opts.IncludePaths); |
| 452 | SrcMgr.setVirtualFileSystem(VFS); | |
| 440 | 453 | |
| 441 | 454 | std::unique_ptr<MCRegisterInfo> MRI(TheTarget->createMCRegInfo(Opts.Triple)); |
| 442 | 455 | assert(MRI && "Unable to create target register info!"); |
| ... | ... | @@ -445,11 +458,13 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 445 | 458 | MCOptions.MCRelaxAll = Opts.RelaxAll; |
| 446 | 459 | MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; |
| 447 | 460 | MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; |
| 461 | MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind; | |
| 448 | 462 | MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels; |
| 449 | 463 | MCOptions.Crel = Opts.Crel; |
| 450 | 464 | MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms; |
| 451 | 465 | MCOptions.X86RelaxRelocations = Opts.X86RelaxRelocations; |
| 452 | 466 | MCOptions.X86Sse2Avx = Opts.X86Sse2Avx; |
| 467 | MCOptions.MCNoExecStack = Opts.NoExecStack; | |
| 453 | 468 | MCOptions.CompressDebugSections = Opts.CompressDebugSections; |
| 454 | 469 | MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; |
| 455 | 470 | |
| ... | ... | @@ -477,7 +492,10 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 477 | 492 | |
| 478 | 493 | std::unique_ptr<MCSubtargetInfo> STI( |
| 479 | 494 | TheTarget->createMCSubtargetInfo(Opts.Triple, Opts.CPU, FS)); |
| 480 | assert(STI && "Unable to create subtarget info!"); | |
| 495 | if (!STI) { | |
| 496 | return Diags.Report(diag::err_fe_unable_to_create_subtarget) | |
| 497 | << Opts.CPU << FS.empty() << FS; | |
| 498 | } | |
| 481 | 499 | |
| 482 | 500 | MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr, |
| 483 | 501 | &MCOptions); |
| ... | ... | @@ -509,9 +527,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 509 | 527 | Ctx.setCompilationDir(Opts.DebugCompilationDir); |
| 510 | 528 | else { |
| 511 | 529 | // If no compilation dir is set, try to use the current directory. |
| 512 | SmallString<128> CWD; | |
| 513 | if (!sys::fs::current_path(CWD)) | |
| 514 | Ctx.setCompilationDir(CWD); | |
| 530 | if (auto CWD = VFS->getCurrentWorkingDirectory()) | |
| 531 | Ctx.setCompilationDir(*CWD); | |
| 515 | 532 | } |
| 516 | 533 | if (!Opts.DebugPrefixMap.empty()) |
| 517 | 534 | for (const auto &KV : Opts.DebugPrefixMap) |
| ... | ... | @@ -577,7 +594,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 577 | 594 | Triple T(Opts.Triple); |
| 578 | 595 | Str.reset(TheTarget->createMCObjectStreamer( |
| 579 | 596 | T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI)); |
| 580 | Str->initSections(Opts.NoExecStack, *STI); | |
| 581 | 597 | if (T.isOSBinFormatMachO() && T.isOSDarwin()) { |
| 582 | 598 | Triple *TVT = Opts.DarwinTargetVariantTriple |
| 583 | 599 | ? &*Opts.DarwinTargetVariantTriple |
| ... | ... | @@ -605,7 +621,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 605 | 621 | std::unique_ptr<MCTargetAsmParser> TAP( |
| 606 | 622 | TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions)); |
| 607 | 623 | if (!TAP) |
| 608 | Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple; | |
| 624 | Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple.str(); | |
| 609 | 625 | |
| 610 | 626 | // Set values for symbols, if any. |
| 611 | 627 | for (auto &S : Opts.SymbolDefs) { |
| ... | ... | @@ -627,8 +643,9 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 627 | 643 | } |
| 628 | 644 | |
| 629 | 645 | static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 630 | DiagnosticsEngine &Diags) { | |
| 631 | bool Failed = ExecuteAssemblerImpl(Opts, Diags); | |
| 646 | DiagnosticsEngine &Diags, | |
| 647 | IntrusiveRefCntPtr<vfs::FileSystem> VFS) { | |
| 648 | bool Failed = ExecuteAssemblerImpl(Opts, Diags, VFS); | |
| 632 | 649 | |
| 633 | 650 | // Delete output file if there were errors. |
| 634 | 651 | if (Failed) { |
| ... | ... | @@ -662,8 +679,12 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 662 | 679 | TextDiagnosticPrinter *DiagClient = |
| 663 | 680 | new TextDiagnosticPrinter(errs(), DiagOpts); |
| 664 | 681 | DiagClient->setPrefix("clang -cc1as"); |
| 665 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); | |
| 666 | DiagnosticsEngine Diags(DiagID, DiagOpts, DiagClient); | |
| 682 | DiagnosticsEngine Diags(DiagnosticIDs::create(), DiagOpts, DiagClient); | |
| 683 | ||
| 684 | auto VFS = [] { | |
| 685 | auto BypassSandbox = sys::sandbox::scopedDisable(); | |
| 686 | return vfs::getRealFileSystem(); | |
| 687 | }(); | |
| 667 | 688 | |
| 668 | 689 | // Set an error handler, so that any LLVM backend diagnostics go through our |
| 669 | 690 | // error handler. |
| ... | ... | @@ -679,8 +700,7 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 679 | 700 | getDriverOptTable().printHelp( |
| 680 | 701 | llvm::outs(), "clang -cc1as [options] file...", |
| 681 | 702 | "Clang Integrated Assembler", /*ShowHidden=*/false, |
| 682 | /*ShowAllAliases=*/false, | |
| 683 | llvm::opt::Visibility(driver::options::CC1AsOption)); | |
| 703 | /*ShowAllAliases=*/false, llvm::opt::Visibility(options::CC1AsOption)); | |
| 684 | 704 | |
| 685 | 705 | return 0; |
| 686 | 706 | } |
| ... | ... | @@ -703,11 +723,12 @@ int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 703 | 723 | for (unsigned i = 0; i != NumArgs; ++i) |
| 704 | 724 | Args[i + 1] = Asm.LLVMArgs[i].c_str(); |
| 705 | 725 | Args[NumArgs + 1] = nullptr; |
| 706 | llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get()); | |
| 726 | llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get(), /*Overview=*/"", | |
| 727 | /*Errs=*/nullptr, /*VFS=*/VFS.get()); | |
| 707 | 728 | } |
| 708 | 729 | |
| 709 | 730 | // Execute the invocation, unless there were parsing errors. |
| 710 | bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags); | |
| 731 | bool Failed = Diags.hasErrorOccurred() || ExecuteAssembler(Asm, Diags, VFS); | |
| 711 | 732 | |
| 712 | 733 | // If any timers were active but haven't been destroyed yet, print their |
| 713 | 734 | // results now. |
src/zig_clang_driver.cpp+22-14| ... | ... | @@ -18,13 +18,13 @@ |
| 18 | 18 | #include "clang/Config/config.h" |
| 19 | 19 | #include "clang/Driver/Compilation.h" |
| 20 | 20 | #include "clang/Driver/DriverDiagnostic.h" |
| 21 | #include "clang/Driver/Options.h" | |
| 22 | 21 | #include "clang/Driver/ToolChain.h" |
| 23 | 22 | #include "clang/Frontend/ChainedDiagnosticConsumer.h" |
| 24 | 23 | #include "clang/Frontend/CompilerInvocation.h" |
| 25 | 24 | #include "clang/Frontend/SerializedDiagnosticPrinter.h" |
| 26 | 25 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 27 | 26 | #include "clang/Frontend/Utils.h" |
| 27 | #include "clang/Options/Options.h" | |
| 28 | 28 | #include "llvm/ADT/ArrayRef.h" |
| 29 | 29 | #include "llvm/ADT/SmallString.h" |
| 30 | 30 | #include "llvm/ADT/SmallVector.h" |
| ... | ... | @@ -38,6 +38,7 @@ |
| 38 | 38 | #include "llvm/Support/CrashRecoveryContext.h" |
| 39 | 39 | #include "llvm/Support/ErrorHandling.h" |
| 40 | 40 | #include "llvm/Support/FileSystem.h" |
| 41 | #include "llvm/Support/IOSandbox.h" | |
| 41 | 42 | #include "llvm/Support/LLVMDriver.h" |
| 42 | 43 | #include "llvm/Support/Path.h" |
| 43 | 44 | #include "llvm/Support/PrettyStackTrace.h" |
| ... | ... | @@ -201,7 +202,8 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient, |
| 201 | 202 | } |
| 202 | 203 | |
| 203 | 204 | static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV, |
| 204 | const llvm::ToolContext &ToolContext) { | |
| 205 | const llvm::ToolContext &ToolContext, | |
| 206 | IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { | |
| 205 | 207 | // If we call the cc1 tool from the clangDriver library (through |
| 206 | 208 | // Driver::CC1Main), we need to clean up the options usage count. The options |
| 207 | 209 | // are currently global, and they might have been used previously by the |
| ... | ... | @@ -209,7 +211,8 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV, |
| 209 | 211 | llvm::cl::ResetAllOptionOccurrences(); |
| 210 | 212 | |
| 211 | 213 | llvm::BumpPtrAllocator A; |
| 212 | llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine); | |
| 214 | llvm::cl::ExpansionContext ECtx(A, llvm::cl::TokenizeGNUCommandLine, | |
| 215 | VFS.get()); | |
| 213 | 216 | if (llvm::Error Err = ECtx.expandResponseFiles(ArgV)) { |
| 214 | 217 | llvm::errs() << toString(std::move(Err)) << '\n'; |
| 215 | 218 | return 1; |
| ... | ... | @@ -249,14 +252,22 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex |
| 249 | 252 | bool ClangCLMode = |
| 250 | 253 | IsClangCL(getDriverMode(ProgName, llvm::ArrayRef(Args).slice(1))); |
| 251 | 254 | |
| 252 | if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A)) { | |
| 255 | auto VFS = llvm::vfs::getRealFileSystem(); | |
| 256 | ||
| 257 | if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A, VFS.get())) { | |
| 253 | 258 | llvm::errs() << toString(std::move(Err)) << '\n'; |
| 254 | 259 | return 1; |
| 255 | 260 | } |
| 256 | 261 | |
| 257 | 262 | // Handle -cc1 integrated tools. |
| 258 | if (Args.size() >= 2 && StringRef(Args[1]).starts_with("-cc1")) | |
| 259 | return ExecuteCC1Tool(Args, ToolContext); | |
| 263 | if (Args.size() >= 2 && StringRef(Args[1]).starts_with("-cc1")) { | |
| 264 | // Note that this only enables the sandbox for direct -cc1 invocations and | |
| 265 | // out-of-process -cc1 invocations launched by the driver. For in-process | |
| 266 | // -cc1 invocations launched by the driver, the sandbox is enabled in | |
| 267 | // CC1Command::Execute() for better crash recovery. | |
| 268 | auto EnableSandbox = llvm::sys::sandbox::scopedEnable(); | |
| 269 | return ExecuteCC1Tool(Args, ToolContext, VFS); | |
| 270 | } | |
| 260 | 271 | |
| 261 | 272 | // Handle options that need handling before the real command line parsing in |
| 262 | 273 | // Driver::BuildCompilation() |
| ... | ... | @@ -326,9 +337,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex |
| 326 | 337 | new TextDiagnosticPrinter(llvm::errs(), *DiagOpts); |
| 327 | 338 | FixupDiagPrefixExeName(DiagClient, ProgName); |
| 328 | 339 | |
| 329 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); | |
| 330 | ||
| 331 | DiagnosticsEngine Diags(DiagID, *DiagOpts, DiagClient); | |
| 340 | DiagnosticsEngine Diags(DiagnosticIDs::create(), *DiagOpts, DiagClient); | |
| 332 | 341 | |
| 333 | 342 | if (!DiagOpts->DiagnosticSerializationFile.empty()) { |
| 334 | 343 | auto SerializedConsumer = |
| ... | ... | @@ -338,7 +347,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex |
| 338 | 347 | Diags.takeClient(), std::move(SerializedConsumer))); |
| 339 | 348 | } |
| 340 | 349 | |
| 341 | auto VFS = llvm::vfs::getRealFileSystem(); | |
| 342 | 350 | ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false); |
| 343 | 351 | |
| 344 | 352 | Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags, |
| ... | ... | @@ -358,10 +366,10 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex |
| 358 | 366 | if (!SetBackdoorDriverOutputsFromEnvVars(TheDriver)) |
| 359 | 367 | return 1; |
| 360 | 368 | |
| 361 | auto ExecuteCC1WithContext = | |
| 362 | [&ToolContext](SmallVectorImpl<const char *> &ArgV) { | |
| 363 | return ExecuteCC1Tool(ArgV, ToolContext); | |
| 364 | }; | |
| 369 | auto ExecuteCC1WithContext = [&ToolContext, | |
| 370 | &VFS](SmallVectorImpl<const char *> &ArgV) { | |
| 371 | return ExecuteCC1Tool(ArgV, ToolContext, VFS); | |
| 372 | }; | |
| 365 | 373 | if (!UseNewCC1Process) { |
| 366 | 374 | TheDriver.CC1Main = ExecuteCC1WithContext; |
| 367 | 375 | // Ensure the CC1Command actually catches cc1 crashes |
src/zig_llvm-ar.cpp+1| ... | ... | @@ -12,6 +12,7 @@ |
| 12 | 12 | //===----------------------------------------------------------------------===// |
| 13 | 13 | |
| 14 | 14 | #include "llvm/ADT/StringExtras.h" |
| 15 | #include "llvm/ADT/StringMap.h" | |
| 15 | 16 | #include "llvm/ADT/StringSwitch.h" |
| 16 | 17 | #include "llvm/BinaryFormat/Magic.h" |
| 17 | 18 | #include "llvm/IR/LLVMContext.h" |
src/zig_llvm.cpp+1-1| ... | ... | @@ -439,7 +439,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi |
| 439 | 439 | |
| 440 | 440 | void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit) { |
| 441 | 441 | static OptBisect opt_bisect; |
| 442 | opt_bisect.setLimit(limit); | |
| 442 | opt_bisect.setIntervals({0, limit}); | |
| 443 | 443 | unwrap(context_ref)->setOptPassGate(opt_bisect); |
| 444 | 444 | } |
| 445 | 445 |