| 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 | 213 | bool Success = CompilerInvocation::CreateFromArgs(Clang->getInvocation(), |
| 214 | 214 | Argv, Diags, Argv0); |
| 215 | 215 | |
| 216 | if (Clang->getFrontendOpts().TimeTrace || | |
| 217 | !Clang->getFrontendOpts().TimeTracePath.empty()) { | |
| 218 | Clang->getFrontendOpts().TimeTrace = 1; | |
| 216 | if (!Clang->getFrontendOpts().TimeTracePath.empty()) { | |
| 219 | 217 | llvm::timeTraceProfilerInitialize( |
| 220 | 218 | Clang->getFrontendOpts().TimeTraceGranularity, Argv0); |
| 221 | 219 | } |
| ... | ... | @@ -257,17 +255,21 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 257 | 255 | llvm::TimerGroup::clearAll(); |
| 258 | 256 | |
| 259 | 257 | if (llvm::timeTraceProfilerEnabled()) { |
| 260 | SmallString<128> Path(Clang->getFrontendOpts().OutputFile); | |
| 261 | llvm::sys::path::replace_extension(Path, "json"); | |
| 262 | if (!Clang->getFrontendOpts().TimeTracePath.empty()) { | |
| 263 | // replace the suffix to '.json' directly | |
| 264 | SmallString<128> TracePath(Clang->getFrontendOpts().TimeTracePath); | |
| 265 | if (llvm::sys::fs::is_directory(TracePath)) | |
| 266 | llvm::sys::path::append(TracePath, llvm::sys::path::filename(Path)); | |
| 267 | Path.assign(TracePath); | |
| 268 | } | |
| 258 | // It is possible that the compiler instance doesn't own a file manager here | |
| 259 | // if we're compiling a module unit. Since the file manager are owned by AST | |
| 260 | // when we're compiling a module unit. So the file manager may be invalid | |
| 261 | // here. | |
| 262 | // | |
| 263 | // It should be fine to create file manager here since the file system | |
| 264 | // options are stored in the compiler invocation and we can recreate the VFS | |
| 265 | // from the compiler invocation. | |
| 266 | if (!Clang->hasFileManager()) | |
| 267 | Clang->createFileManager(createVFSFromCompilerInvocation( | |
| 268 | Clang->getInvocation(), Clang->getDiagnostics())); | |
| 269 | ||
| 269 | 270 | if (auto profilerOutput = Clang->createOutputFile( |
| 270 | Path.str(), /*Binary=*/false, /*RemoveFileOnSignal=*/false, | |
| 271 | Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false, | |
| 272 | /*RemoveFileOnSignal=*/false, | |
| 271 | 273 | /*useTemporary=*/false)) { |
| 272 | 274 | llvm::timeTraceProfilerWrite(*profilerOutput); |
| 273 | 275 | profilerOutput.reset(); |
src/zig_clang_cc1as_main.cpp+16-7| ... | ... | @@ -19,8 +19,8 @@ |
| 19 | 19 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 20 | 20 | #include "clang/Frontend/Utils.h" |
| 21 | 21 | #include "llvm/ADT/STLExtras.h" |
| 22 | #include "llvm/ADT/StringExtras.h" | |
| 22 | 23 | #include "llvm/ADT/StringSwitch.h" |
| 23 | #include "llvm/ADT/Triple.h" | |
| 24 | 24 | #include "llvm/IR/DataLayout.h" |
| 25 | 25 | #include "llvm/MC/MCAsmBackend.h" |
| 26 | 26 | #include "llvm/MC/MCAsmInfo.h" |
| ... | ... | @@ -44,7 +44,6 @@ |
| 44 | 44 | #include "llvm/Support/ErrorHandling.h" |
| 45 | 45 | #include "llvm/Support/FileSystem.h" |
| 46 | 46 | #include "llvm/Support/FormattedStream.h" |
| 47 | #include "llvm/Support/Host.h" | |
| 48 | 47 | #include "llvm/Support/MemoryBuffer.h" |
| 49 | 48 | #include "llvm/Support/Path.h" |
| 50 | 49 | #include "llvm/Support/Process.h" |
| ... | ... | @@ -53,6 +52,8 @@ |
| 53 | 52 | #include "llvm/Support/TargetSelect.h" |
| 54 | 53 | #include "llvm/Support/Timer.h" |
| 55 | 54 | #include "llvm/Support/raw_ostream.h" |
| 55 | #include "llvm/TargetParser/Host.h" | |
| 56 | #include "llvm/TargetParser/Triple.h" | |
| 56 | 57 | #include <memory> |
| 57 | 58 | #include <optional> |
| 58 | 59 | #include <system_error> |
| ... | ... | @@ -97,7 +98,7 @@ struct AssemblerInvocation { |
| 97 | 98 | std::string DwarfDebugFlags; |
| 98 | 99 | std::string DwarfDebugProducer; |
| 99 | 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 | 102 | llvm::DebugCompressionType CompressDebugSections = |
| 102 | 103 | llvm::DebugCompressionType::None; |
| 103 | 104 | std::string MainFileName; |
| ... | ... | @@ -142,6 +143,10 @@ struct AssemblerInvocation { |
| 142 | 143 | /// Whether to emit DWARF unwind info. |
| 143 | 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 | 150 | /// The name of the relocation model to use. |
| 146 | 151 | std::string RelocationModel; |
| 147 | 152 | |
| ... | ... | @@ -181,6 +186,7 @@ public: |
| 181 | 186 | DwarfVersion = 0; |
| 182 | 187 | EmbedBitcode = 0; |
| 183 | 188 | EmitDwarfUnwind = EmitDwarfUnwindType::Default; |
| 189 | EmitCompactUnwindNonCanonical = false; | |
| 184 | 190 | } |
| 185 | 191 | |
| 186 | 192 | static bool CreateFromArgs(AssemblerInvocation &Res, |
| ... | ... | @@ -275,8 +281,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 275 | 281 | |
| 276 | 282 | for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) { |
| 277 | 283 | auto Split = StringRef(Arg).split('='); |
| 278 | Opts.DebugPrefixMap.insert( | |
| 279 | {std::string(Split.first), std::string(Split.second)}); | |
| 284 | Opts.DebugPrefixMap.emplace_back(Split.first, Split.second); | |
| 280 | 285 | } |
| 281 | 286 | |
| 282 | 287 | // Frontend Options |
| ... | ... | @@ -349,6 +354,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 349 | 354 | .Case("default", EmitDwarfUnwindType::Default); |
| 350 | 355 | } |
| 351 | 356 | |
| 357 | Opts.EmitCompactUnwindNonCanonical = | |
| 358 | Args.hasArg(OPT_femit_compact_unwind_non_canonical); | |
| 359 | ||
| 352 | 360 | Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file); |
| 353 | 361 | |
| 354 | 362 | return Success; |
| ... | ... | @@ -384,8 +392,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 384 | 392 | MemoryBuffer::getFileOrSTDIN(Opts.InputFile, /*IsText=*/true); |
| 385 | 393 | |
| 386 | 394 | if (std::error_code EC = Buffer.getError()) { |
| 387 | Error = EC.message(); | |
| 388 | return Diags.Report(diag::err_fe_error_reading) << Opts.InputFile; | |
| 395 | return Diags.Report(diag::err_fe_error_reading) | |
| 396 | << Opts.InputFile << EC.message(); | |
| 389 | 397 | } |
| 390 | 398 | |
| 391 | 399 | SourceMgr SrcMgr; |
| ... | ... | @@ -402,6 +410,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 402 | 410 | |
| 403 | 411 | MCTargetOptions MCOptions; |
| 404 | 412 | MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind; |
| 413 | MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical; | |
| 405 | 414 | MCOptions.AsSecureLogFile = Opts.AsSecureLogFile; |
| 406 | 415 | |
| 407 | 416 | std::unique_ptr<MCAsmInfo> MAI( |
src/zig_clang_driver.cpp+37-63| ... | ... | @@ -36,8 +36,8 @@ |
| 36 | 36 | #include "llvm/Support/CrashRecoveryContext.h" |
| 37 | 37 | #include "llvm/Support/ErrorHandling.h" |
| 38 | 38 | #include "llvm/Support/FileSystem.h" |
| 39 | #include "llvm/Support/Host.h" | |
| 40 | 39 | #include "llvm/Support/InitLLVM.h" |
| 40 | #include "llvm/Support/LLVMDriver.h" | |
| 41 | 41 | #include "llvm/Support/Path.h" |
| 42 | 42 | #include "llvm/Support/PrettyStackTrace.h" |
| 43 | 43 | #include "llvm/Support/Process.h" |
| ... | ... | @@ -48,6 +48,7 @@ |
| 48 | 48 | #include "llvm/Support/TargetSelect.h" |
| 49 | 49 | #include "llvm/Support/Timer.h" |
| 50 | 50 | #include "llvm/Support/raw_ostream.h" |
| 51 | #include "llvm/TargetParser/Host.h" | |
| 51 | 52 | #include <memory> |
| 52 | 53 | #include <optional> |
| 53 | 54 | #include <set> |
| ... | ... | @@ -209,6 +210,9 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 209 | 210 | void *MainAddr); |
| 210 | 211 | extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 211 | 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 | 217 | static void insertTargetAndModeArgs(const ParsedClangName &NameParts, |
| 214 | 218 | SmallVectorImpl<const char *> &ArgVector, |
| ... | ... | @@ -303,6 +307,9 @@ static bool SetBackdoorDriverOutputsFromEnvVars(Driver &TheDriver) { |
| 303 | 307 | TheDriver.CCPrintProcessStats = |
| 304 | 308 | checkEnvVar<bool>("CC_PRINT_PROC_STAT", "CC_PRINT_PROC_STAT_FILE", |
| 305 | 309 | TheDriver.CCPrintStatReportFilename); |
| 310 | TheDriver.CCPrintInternalStats = | |
| 311 | checkEnvVar<bool>("CC_PRINT_INTERNAL_STAT", "CC_PRINT_INTERNAL_STAT_FILE", | |
| 312 | TheDriver.CCPrintInternalStatReportFilename); | |
| 306 | 313 | |
| 307 | 314 | return true; |
| 308 | 315 | } |
| ... | ... | @@ -339,7 +346,8 @@ static void SetInstallDir(SmallVectorImpl<const char *> &argv, |
| 339 | 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 | 351 | // If we call the cc1 tool from the clangDriver library (through |
| 344 | 352 | // Driver::CC1Main), we need to clean up the options usage count. The options |
| 345 | 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 | 366 | return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP); |
| 359 | 367 | if (Tool == "-cc1as") |
| 360 | 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 | 372 | // Reject unknown tools. |
| 362 | 373 | llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " |
| 363 | 374 | << "Valid tools include '-cc1' and '-cc1as'.\n"; |
| 364 | 375 | return 1; |
| 365 | 376 | } |
| 366 | 377 | |
| 367 | extern "C" int ZigClang_main(int Argc, const char **Argv); | |
| 368 | int ZigClang_main(int Argc, const char **Argv) { | |
| 378 | int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) { | |
| 369 | 379 | noteBottomOfStack(); |
| 370 | // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), | |
| 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 | ||
| 380 | llvm::InitLLVM X(Argc, Argv); | |
| 378 | 381 | llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL |
| 379 | 382 | " and include the crash backtrace, preprocessed " |
| 380 | 383 | "source, and associated run script.\n"); |
| 381 | size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1; | |
| 382 | SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc); | |
| 384 | SmallVector<const char *, 256> Args(Argv, Argv + Argc); | |
| 383 | 385 | |
| 384 | 386 | if (llvm::sys::Process::FixupStandardFileDescriptors()) |
| 385 | 387 | return 1; |
| ... | ... | @@ -389,55 +391,20 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 389 | 391 | llvm::BumpPtrAllocator A; |
| 390 | 392 | llvm::StringSaver Saver(A); |
| 391 | 393 | |
| 392 | // Parse response files using the GNU syntax, unless we're in CL mode. There | |
| 393 | // are two ways to put clang in CL compatibility mode: Args[0] is either | |
| 394 | // clang-cl or cl, or --driver-mode=cl is on the command line. The normal | |
| 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. | |
| 394 | const char *ProgName = | |
| 395 | ToolContext.NeedsPrependArg ? ToolContext.PrependArg : ToolContext.Path; | |
| 396 | ||
| 399 | 397 | bool ClangCLMode = |
| 400 | IsClangCL(getDriverMode(Args[0], 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 | } | |
| 398 | IsClangCL(getDriverMode(ProgName, llvm::ArrayRef(Args).slice(1))); | |
| 408 | 399 | |
| 409 | // Determines whether we want nullptr markers in Args to indicate response | |
| 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)) { | |
| 400 | if (llvm::Error Err = expandResponseFiles(Args, ClangCLMode, A)) { | |
| 425 | 401 | llvm::errs() << toString(std::move(Err)) << '\n'; |
| 426 | 402 | return 1; |
| 427 | 403 | } |
| 428 | 404 | |
| 429 | // Handle -cc1 integrated tools, even if -cc1 was expanded from a response | |
| 430 | // file. | |
| 431 | auto FirstArg = llvm::find_if(llvm::drop_begin(Args), | |
| 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 | } | |
| 405 | // Handle -cc1 integrated tools. | |
| 406 | if (Args.size() >= 2 && StringRef(Args[1]).startswith("-cc1")) | |
| 407 | return ExecuteCC1Tool(Args, ToolContext); | |
| 441 | 408 | |
| 442 | 409 | // Handle options that need handling before the real command line parsing in |
| 443 | 410 | // Driver::BuildCompilation() |
| ... | ... | @@ -483,9 +450,7 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 483 | 450 | ApplyQAOverride(Args, OverrideStr, SavedStrings); |
| 484 | 451 | } |
| 485 | 452 | |
| 486 | // Pass local param `Argv[0]` as fallback. | |
| 487 | // See https://github.com/ziglang/zig/pull/3292 . | |
| 488 | std::string Path = GetExecutablePath(Argv[0], CanonicalPrefixes); | |
| 453 | std::string Path = GetExecutablePath(ToolContext.Path, CanonicalPrefixes); | |
| 489 | 454 | |
| 490 | 455 | // Whether the cc1 tool should be called inside the current process, or if we |
| 491 | 456 | // should spawn a new clang subprocess (old behavior). |
| ... | ... | @@ -503,7 +468,7 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 503 | 468 | |
| 504 | 469 | TextDiagnosticPrinter *DiagClient |
| 505 | 470 | = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); |
| 506 | FixupDiagPrefixExeName(DiagClient, Path); | |
| 471 | FixupDiagPrefixExeName(DiagClient, ProgName); | |
| 507 | 472 | |
| 508 | 473 | IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); |
| 509 | 474 | |
| ... | ... | @@ -521,8 +486,15 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 521 | 486 | |
| 522 | 487 | Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags); |
| 523 | 488 | SetInstallDir(Args, TheDriver, CanonicalPrefixes); |
| 524 | auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(Args[0]); | |
| 489 | auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(ProgName); | |
| 525 | 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 | 499 | insertTargetAndModeArgs(TargetAndMode, Args, SavedStrings); |
| 528 | 500 | |
| ... | ... | @@ -530,7 +502,9 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 530 | 502 | return 1; |
| 531 | 503 | |
| 532 | 504 | if (!UseNewCC1Process) { |
| 533 | TheDriver.CC1Main = &ExecuteCC1Tool; | |
| 505 | TheDriver.CC1Main = [ToolContext](SmallVectorImpl<const char *> &ArgV) { | |
| 506 | return ExecuteCC1Tool(ArgV, ToolContext); | |
| 507 | }; | |
| 534 | 508 | // Ensure the CC1Command actually catches cc1 crashes |
| 535 | 509 | llvm::CrashRecoveryContext::Enable(); |
| 536 | 510 | } |
src/zig_llvm-ar.cpp+6-40| ... | ... | @@ -13,20 +13,11 @@ |
| 13 | 13 | |
| 14 | 14 | #include "llvm/ADT/StringExtras.h" |
| 15 | 15 | #include "llvm/ADT/StringSwitch.h" |
| 16 | #include "llvm/ADT/Triple.h" | |
| 17 | 16 | #include "llvm/BinaryFormat/Magic.h" |
| 18 | 17 | #include "llvm/IR/LLVMContext.h" |
| 19 | 18 | #include "llvm/Object/Archive.h" |
| 20 | 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 | 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 | 21 | #include "llvm/Support/Chrono.h" |
| 31 | 22 | #include "llvm/Support/CommandLine.h" |
| 32 | 23 | #include "llvm/Support/ConvertUTF.h" |
| ... | ... | @@ -34,8 +25,8 @@ |
| 34 | 25 | #include "llvm/Support/FileSystem.h" |
| 35 | 26 | #include "llvm/Support/Format.h" |
| 36 | 27 | #include "llvm/Support/FormatVariadic.h" |
| 37 | #include "llvm/Support/Host.h" | |
| 38 | 28 | #include "llvm/Support/InitLLVM.h" |
| 29 | #include "llvm/Support/LLVMDriver.h" | |
| 39 | 30 | #include "llvm/Support/LineIterator.h" |
| 40 | 31 | #include "llvm/Support/MemoryBuffer.h" |
| 41 | 32 | #include "llvm/Support/Path.h" |
| ... | ... | @@ -45,6 +36,8 @@ |
| 45 | 36 | #include "llvm/Support/ToolOutputFile.h" |
| 46 | 37 | #include "llvm/Support/WithColor.h" |
| 47 | 38 | #include "llvm/Support/raw_ostream.h" |
| 39 | #include "llvm/TargetParser/Host.h" | |
| 40 | #include "llvm/TargetParser/Triple.h" | |
| 48 | 41 | #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h" |
| 49 | 42 | #include "llvm/ToolDrivers/llvm-lib/LibDriver.h" |
| 50 | 43 | |
| ... | ... | @@ -646,31 +639,12 @@ static bool shouldCreateArchive(ArchiveOperation Op) { |
| 646 | 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 | 642 | static bool isValidInBitMode(Binary &Bin) { |
| 669 | 643 | if (BitMode == BitModeTy::Bit32_64 || BitMode == BitModeTy::Any) |
| 670 | 644 | return true; |
| 671 | 645 | |
| 672 | 646 | if (SymbolicFile *SymFile = dyn_cast<SymbolicFile>(&Bin)) { |
| 673 | bool Is64Bit = is64BitSymbolicFile(*SymFile); | |
| 647 | bool Is64Bit = SymFile->is64Bit(); | |
| 674 | 648 | if ((Is64Bit && (BitMode == BitModeTy::Bit32)) || |
| 675 | 649 | (!Is64Bit && (BitMode == BitModeTy::Bit64))) |
| 676 | 650 | return false; |
| ... | ... | @@ -1452,16 +1426,8 @@ static int ranlib_main(int argc, char **argv) { |
| 1452 | 1426 | return 0; |
| 1453 | 1427 | } |
| 1454 | 1428 | |
| 1455 | extern "C" int ZigLlvmAr_main(int argc, char **argv); | |
| 1456 | int ZigLlvmAr_main(int argc, char **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 | ||
| 1429 | int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) { | |
| 1430 | InitLLVM X(argc, argv); | |
| 1465 | 1431 | ToolName = argv[0]; |
| 1466 | 1432 | |
| 1467 | 1433 | llvm::InitializeAllTargetInfos(); |