| author | |
| committer | |
| log | 3479294b6e7cae323f2e2f05dbc173e2b1a4b9e1 |
| tree | 1427cfac72a0bc1e7036a04395dca876d910d02a |
| parent | 308f72701af0a44bdb2cb2893f3175b7d37f657b |
upstream commit 91632c8ac97fa3daffe4ff8f1391735b5d6805e64 files changed, 62 insertions(+), 78 deletions(-)
src/zig_clang_cc1_main.cpp+5-3| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | #include "llvm/ADT/Statistic.h" |
| 29 | 29 | #include "llvm/Config/llvm-config.h" |
| 30 | 30 | #include "llvm/LinkAllPasses.h" |
| 31 | #include "llvm/MC/TargetRegistry.h" | |
| 31 | 32 | #include "llvm/Option/Arg.h" |
| 32 | 33 | #include "llvm/Option/ArgList.h" |
| 33 | 34 | #include "llvm/Option/OptTable.h" |
| ... | ... | @@ -38,7 +39,6 @@ |
| 38 | 39 | #include "llvm/Support/Path.h" |
| 39 | 40 | #include "llvm/Support/Process.h" |
| 40 | 41 | #include "llvm/Support/Signals.h" |
| 41 | #include "llvm/Support/TargetRegistry.h" | |
| 42 | 42 | #include "llvm/Support/TargetSelect.h" |
| 43 | 43 | #include "llvm/Support/TimeProfiler.h" |
| 44 | 44 | #include "llvm/Support/Timer.h" |
| ... | ... | @@ -57,7 +57,7 @@ using namespace llvm::opt; |
| 57 | 57 | // Main driver |
| 58 | 58 | //===----------------------------------------------------------------------===// |
| 59 | 59 | |
| 60 | static void LLVMErrorHandler(void *UserData, const std::string &Message, | |
| 60 | static void LLVMErrorHandler(void *UserData, const char *Message, | |
| 61 | 61 | bool GenCrashDiag) { |
| 62 | 62 | DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData); |
| 63 | 63 | |
| ... | ... | @@ -237,8 +237,10 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) { |
| 237 | 237 | static_cast<void*>(&Clang->getDiagnostics())); |
| 238 | 238 | |
| 239 | 239 | DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics()); |
| 240 | if (!Success) | |
| 240 | if (!Success) { | |
| 241 | Clang->getDiagnosticClient().finish(); | |
| 241 | 242 | return 1; |
| 243 | } | |
| 242 | 244 | |
| 243 | 245 | // Execute the frontend actions. |
| 244 | 246 | { |
src/zig_clang_cc1as_main.cpp+3-4| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 | #include "llvm/MC/MCStreamer.h" |
| 37 | 37 | #include "llvm/MC/MCSubtargetInfo.h" |
| 38 | 38 | #include "llvm/MC/MCTargetOptions.h" |
| 39 | #include "llvm/MC/TargetRegistry.h" | |
| 39 | 40 | #include "llvm/Option/Arg.h" |
| 40 | 41 | #include "llvm/Option/ArgList.h" |
| 41 | 42 | #include "llvm/Option/OptTable.h" |
| ... | ... | @@ -49,7 +50,6 @@ |
| 49 | 50 | #include "llvm/Support/Process.h" |
| 50 | 51 | #include "llvm/Support/Signals.h" |
| 51 | 52 | #include "llvm/Support/SourceMgr.h" |
| 52 | #include "llvm/Support/TargetRegistry.h" | |
| 53 | 53 | #include "llvm/Support/TargetSelect.h" |
| 54 | 54 | #include "llvm/Support/Timer.h" |
| 55 | 55 | #include "llvm/Support/raw_ostream.h" |
| ... | ... | @@ -228,7 +228,6 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts, |
| 228 | 228 | llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue()) |
| 229 | 229 | .Case("none", llvm::DebugCompressionType::None) |
| 230 | 230 | .Case("zlib", llvm::DebugCompressionType::Z) |
| 231 | .Case("zlib-gnu", llvm::DebugCompressionType::GNU) | |
| 232 | 231 | .Default(llvm::DebugCompressionType::None); |
| 233 | 232 | } |
| 234 | 233 | |
| ... | ... | @@ -490,7 +489,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts, |
| 490 | 489 | T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI, |
| 491 | 490 | Opts.RelaxAll, Opts.IncrementalLinkerCompatible, |
| 492 | 491 | /*DWARFMustBeAtTheEnd*/ true)); |
| 493 | Str.get()->InitSections(Opts.NoExecStack); | |
| 492 | Str.get()->initSections(Opts.NoExecStack, *STI); | |
| 494 | 493 | } |
| 495 | 494 | |
| 496 | 495 | // When -fembed-bitcode is passed to clang_as, a 1-byte marker |
| ... | ... | @@ -550,7 +549,7 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts, |
| 550 | 549 | return Failed; |
| 551 | 550 | } |
| 552 | 551 | |
| 553 | static void LLVMErrorHandler(void *UserData, const std::string &Message, | |
| 552 | static void LLVMErrorHandler(void *UserData, const char *Message, | |
| 554 | 553 | bool GenCrashDiag) { |
| 555 | 554 | DiagnosticsEngine &Diags = *static_cast<DiagnosticsEngine*>(UserData); |
| 556 | 555 |
src/zig_clang_driver.cpp+22-44| ... | ... | @@ -120,7 +120,7 @@ static void ApplyOneQAOverride(raw_ostream &OS, |
| 120 | 120 | OS << "### Adding argument " << Str << " at end\n"; |
| 121 | 121 | Args.push_back(Str); |
| 122 | 122 | } else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") && |
| 123 | Edit.slice(2, Edit.size()-1).find('/') != StringRef::npos) { | |
| 123 | Edit.slice(2, Edit.size() - 1).contains('/')) { | |
| 124 | 124 | StringRef MatchPattern = Edit.substr(2).split('/').first; |
| 125 | 125 | StringRef ReplPattern = Edit.substr(2).split('/').second; |
| 126 | 126 | ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1); |
| ... | ... | @@ -207,6 +207,8 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 207 | 207 | void *MainAddr); |
| 208 | 208 | extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, |
| 209 | 209 | void *MainAddr); |
| 210 | extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv, | |
| 211 | const char *Argv0, void *MainAddr); | |
| 210 | 212 | |
| 211 | 213 | static void insertTargetAndModeArgs(const ParsedClangName &NameParts, |
| 212 | 214 | SmallVectorImpl<const char *> &ArgVector, |
| ... | ... | @@ -276,27 +278,6 @@ static void FixupDiagPrefixExeName(TextDiagnosticPrinter *DiagClient, |
| 276 | 278 | DiagClient->setPrefix(std::string(ExeBasename)); |
| 277 | 279 | } |
| 278 | 280 | |
| 279 | // This lets us create the DiagnosticsEngine with a properly-filled-out | |
| 280 | // DiagnosticOptions instance. | |
| 281 | static DiagnosticOptions * | |
| 282 | CreateAndPopulateDiagOpts(ArrayRef<const char *> argv, bool &UseNewCC1Process) { | |
| 283 | auto *DiagOpts = new DiagnosticOptions; | |
| 284 | unsigned MissingArgIndex, MissingArgCount; | |
| 285 | InputArgList Args = getDriverOptTable().ParseArgs( | |
| 286 | argv.slice(1), MissingArgIndex, MissingArgCount); | |
| 287 | // We ignore MissingArgCount and the return value of ParseDiagnosticArgs. | |
| 288 | // Any errors that would be diagnosed here will also be diagnosed later, | |
| 289 | // when the DiagnosticsEngine actually exists. | |
| 290 | (void)ParseDiagnosticArgs(*DiagOpts, Args); | |
| 291 | ||
| 292 | UseNewCC1Process = | |
| 293 | Args.hasFlag(clang::driver::options::OPT_fno_integrated_cc1, | |
| 294 | clang::driver::options::OPT_fintegrated_cc1, | |
| 295 | /*Default=*/CLANG_SPAWN_CC1); | |
| 296 | ||
| 297 | return DiagOpts; | |
| 298 | } | |
| 299 | ||
| 300 | 281 | static void SetInstallDir(SmallVectorImpl<const char *> &argv, |
| 301 | 282 | Driver &TheDriver, bool CanonicalPrefixes) { |
| 302 | 283 | // Attempt to find the original path used to invoke the driver, to determine |
| ... | ... | @@ -337,28 +318,22 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) { |
| 337 | 318 | if (Tool == "-cc1as") |
| 338 | 319 | return cc1as_main(makeArrayRef(ArgV).slice(2), ArgV[0], |
| 339 | 320 | GetExecutablePathVP); |
| 321 | if (Tool == "-cc1gen-reproducer") | |
| 322 | return cc1gen_reproducer_main(makeArrayRef(ArgV).slice(2), ArgV[0], | |
| 323 | GetExecutablePathVP); | |
| 340 | 324 | // Reject unknown tools. |
| 341 | 325 | llvm::errs() << "error: unknown integrated tool '" << Tool << "'. " |
| 342 | 326 | << "Valid tools include '-cc1' and '-cc1as'.\n"; |
| 343 | 327 | return 1; |
| 344 | 328 | } |
| 345 | 329 | |
| 346 | extern "C" int ZigClang_main(int Argc, const char **Argv); | |
| 347 | int ZigClang_main(int Argc, const char **Argv) { | |
| 330 | int main(int Argc, const char **Argv) { | |
| 348 | 331 | noteBottomOfStack(); |
| 349 | // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), | |
| 350 | // and overwrites the args. We don't want it to do that, | |
| 351 | // and we also don't need the signal handlers it installs | |
| 352 | // (we have our own already), so we just use llvm_shutdown_obj | |
| 353 | // instead. | |
| 354 | // llvm::InitLLVM X(Argc, Argv); | |
| 355 | llvm::llvm_shutdown_obj X; | |
| 356 | ||
| 332 | llvm::InitLLVM X(Argc, Argv); | |
| 357 | 333 | llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL |
| 358 | 334 | " and include the crash backtrace, preprocessed " |
| 359 | 335 | "source, and associated run script.\n"); |
| 360 | size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1; | |
| 361 | SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc); | |
| 336 | SmallVector<const char *, 256> Args(Argv, Argv + Argc); | |
| 362 | 337 | |
| 363 | 338 | if (llvm::sys::Process::FixupStandardFileDescriptors()) |
| 364 | 339 | return 1; |
| ... | ... | @@ -402,8 +377,8 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 402 | 377 | |
| 403 | 378 | // Handle -cc1 integrated tools, even if -cc1 was expanded from a response |
| 404 | 379 | // file. |
| 405 | auto FirstArg = std::find_if(Args.begin() + 1, Args.end(), | |
| 406 | [](const char *A) { return A != nullptr; }); | |
| 380 | auto FirstArg = llvm::find_if(llvm::drop_begin(Args), | |
| 381 | [](const char *A) { return A != nullptr; }); | |
| 407 | 382 | if (FirstArg != Args.end() && StringRef(*FirstArg).startswith("-cc1")) { |
| 408 | 383 | // If -cc1 came from a response file, remove the EOL sentinels. |
| 409 | 384 | if (MarkEOLs) { |
| ... | ... | @@ -420,10 +395,10 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 420 | 395 | // Skip end-of-line response file markers |
| 421 | 396 | if (Args[i] == nullptr) |
| 422 | 397 | continue; |
| 423 | if (StringRef(Args[i]) == "-no-canonical-prefixes") { | |
| 398 | if (StringRef(Args[i]) == "-canonical-prefixes") | |
| 399 | CanonicalPrefixes = true; | |
| 400 | else if (StringRef(Args[i]) == "-no-canonical-prefixes") | |
| 424 | 401 | CanonicalPrefixes = false; |
| 425 | break; | |
| 426 | } | |
| 427 | 402 | } |
| 428 | 403 | |
| 429 | 404 | // Handle CL and _CL_ which permits additional command line options to be |
| ... | ... | @@ -457,18 +432,21 @@ int ZigClang_main(int Argc, const char **Argv) { |
| 457 | 432 | ApplyQAOverride(Args, OverrideStr, SavedStrings); |
| 458 | 433 | } |
| 459 | 434 | |
| 460 | // Pass local param `Argv[0]` as fallback. | |
| 461 | // See https://github.com/ziglang/zig/pull/3292 . | |
| 462 | std::string Path = GetExecutablePath(Argv[0], CanonicalPrefixes); | |
| 435 | std::string Path = GetExecutablePath(Args[0], CanonicalPrefixes); | |
| 463 | 436 | |
| 464 | 437 | // Whether the cc1 tool should be called inside the current process, or if we |
| 465 | 438 | // should spawn a new clang subprocess (old behavior). |
| 466 | 439 | // Not having an additional process saves some execution time of Windows, |
| 467 | 440 | // and makes debugging and profiling easier. |
| 468 | bool UseNewCC1Process; | |
| 441 | bool UseNewCC1Process = CLANG_SPAWN_CC1; | |
| 442 | for (const char *Arg : Args) | |
| 443 | UseNewCC1Process = llvm::StringSwitch<bool>(Arg) | |
| 444 | .Case("-fno-integrated-cc1", true) | |
| 445 | .Case("-fintegrated-cc1", false) | |
| 446 | .Default(UseNewCC1Process); | |
| 469 | 447 | |
| 470 | 448 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = |
| 471 | CreateAndPopulateDiagOpts(Args, UseNewCC1Process); | |
| 449 | CreateAndPopulateDiagOpts(Args); | |
| 472 | 450 | |
| 473 | 451 | TextDiagnosticPrinter *DiagClient |
| 474 | 452 | = new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); |
src/zig_llvm-ar.cpp+32-27| ... | ... | @@ -90,17 +90,18 @@ OPTIONS: |
| 90 | 90 | --rsp-quoting - quoting style for response files |
| 91 | 91 | =posix - posix |
| 92 | 92 | =windows - windows |
| 93 | --thin - create a thin archive | |
| 93 | 94 | --version - print the version and exit |
| 94 | 95 | @<file> - read options from <file> |
| 95 | 96 | |
| 96 | 97 | OPERATIONS: |
| 97 | 98 | d - delete [files] from the archive |
| 98 | 99 | m - move [files] in the archive |
| 99 | p - print [files] found in the archive | |
| 100 | p - print contents of [files] found in the archive | |
| 100 | 101 | q - quick append [files] to the archive |
| 101 | 102 | r - replace or insert [files] into the archive |
| 102 | 103 | s - act as ranlib |
| 103 | t - display contents of archive | |
| 104 | t - display list of files in archive | |
| 104 | 105 | x - extract [files] from the archive |
| 105 | 106 | |
| 106 | 107 | MODIFIERS: |
| ... | ... | @@ -118,7 +119,7 @@ MODIFIERS: |
| 118 | 119 | [P] - use full names when matching (implied for thin archives) |
| 119 | 120 | [s] - create an archive index (cf. ranlib) |
| 120 | 121 | [S] - do not build a symbol table |
| 121 | [T] - create a thin archive | |
| 122 | [T] - deprecated, use --thin instead | |
| 122 | 123 | [u] - update only [files] newer than archive contents |
| 123 | 124 | [U] - use actual timestamps and uids/gids |
| 124 | 125 | [v] - be verbose about actions taken |
| ... | ... | @@ -136,14 +137,14 @@ static unsigned MRILineNumber; |
| 136 | 137 | static bool ParsingMRIScript; |
| 137 | 138 | |
| 138 | 139 | // Show the error plus the usage message, and exit. |
| 139 | LLVM_ATTRIBUTE_NORETURN static void badUsage(Twine Error) { | |
| 140 | [[noreturn]] static void badUsage(Twine Error) { | |
| 140 | 141 | WithColor::error(errs(), ToolName) << Error << "\n"; |
| 141 | 142 | printHelpMessage(); |
| 142 | 143 | exit(1); |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | 146 | // Show the error message and exit. |
| 146 | LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) { | |
| 147 | [[noreturn]] static void fail(Twine Error) { | |
| 147 | 148 | if (ParsingMRIScript) { |
| 148 | 149 | WithColor::error(errs(), ToolName) |
| 149 | 150 | << "script line " << MRILineNumber << ": " << Error << "\n"; |
| ... | ... | @@ -232,7 +233,7 @@ static std::string ArchiveName; |
| 232 | 233 | static std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers; |
| 233 | 234 | static std::vector<std::unique_ptr<object::Archive>> Archives; |
| 234 | 235 | |
| 235 | // This variable holds the list of member files to process, as given | |
| 236 | // This variable holds the list of member files to proecess, as given | |
| 236 | 237 | // on the command line. |
| 237 | 238 | static std::vector<StringRef> Members; |
| 238 | 239 | |
| ... | ... | @@ -390,8 +391,6 @@ static ArchiveOperation parseCommandLine() { |
| 390 | 391 | break; |
| 391 | 392 | case 'T': |
| 392 | 393 | Thin = true; |
| 393 | // Thin archives store path names, so P should be forced. | |
| 394 | CompareFullPath = true; | |
| 395 | 394 | break; |
| 396 | 395 | case 'L': |
| 397 | 396 | AddLibrary = true; |
| ... | ... | @@ -407,6 +406,10 @@ static ArchiveOperation parseCommandLine() { |
| 407 | 406 | } |
| 408 | 407 | } |
| 409 | 408 | |
| 409 | // Thin archives store path names, so P should be forced. | |
| 410 | if (Thin) | |
| 411 | CompareFullPath = true; | |
| 412 | ||
| 410 | 413 | // At this point, the next thing on the command line must be |
| 411 | 414 | // the archive name. |
| 412 | 415 | getArchive(); |
| ... | ... | @@ -965,6 +968,8 @@ static void createSymbolTable(object::Archive *OldArchive) { |
| 965 | 968 | if (OldArchive->hasSymbolTable()) |
| 966 | 969 | return; |
| 967 | 970 | |
| 971 | if (OldArchive->isThin()) | |
| 972 | Thin = true; | |
| 968 | 973 | performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr); |
| 969 | 974 | } |
| 970 | 975 | |
| ... | ... | @@ -1003,12 +1008,17 @@ static int performOperation(ArchiveOperation Operation, |
| 1003 | 1008 | fail("unable to open '" + ArchiveName + "': " + EC.message()); |
| 1004 | 1009 | |
| 1005 | 1010 | if (!EC) { |
| 1006 | Error Err = Error::success(); | |
| 1007 | object::Archive Archive(Buf.get()->getMemBufferRef(), Err); | |
| 1008 | failIfError(std::move(Err), "unable to load '" + ArchiveName + "'"); | |
| 1009 | if (Archive.isThin()) | |
| 1011 | Expected<std::unique_ptr<object::Archive>> ArchiveOrError = | |
| 1012 | object::Archive::create(Buf.get()->getMemBufferRef()); | |
| 1013 | if (!ArchiveOrError) | |
| 1014 | failIfError(ArchiveOrError.takeError(), | |
| 1015 | "unable to load '" + ArchiveName + "'"); | |
| 1016 | ||
| 1017 | std::unique_ptr<object::Archive> Archive = std::move(ArchiveOrError.get()); | |
| 1018 | if (Archive->isThin()) | |
| 1010 | 1019 | CompareFullPath = true; |
| 1011 | performOperation(Operation, &Archive, std::move(Buf.get()), NewMembers); | |
| 1020 | performOperation(Operation, Archive.get(), std::move(Buf.get()), | |
| 1021 | NewMembers); | |
| 1012 | 1022 | return 0; |
| 1013 | 1023 | } |
| 1014 | 1024 | |
| ... | ... | @@ -1111,11 +1121,11 @@ static void runMRIScript() { |
| 1111 | 1121 | } |
| 1112 | 1122 | |
| 1113 | 1123 | static bool handleGenericOption(StringRef arg) { |
| 1114 | if (arg == "-help" || arg == "--help" || arg == "-h") { | |
| 1124 | if (arg == "--help" || arg == "-h") { | |
| 1115 | 1125 | printHelpMessage(); |
| 1116 | 1126 | return true; |
| 1117 | 1127 | } |
| 1118 | if (arg == "-version" || arg == "--version") { | |
| 1128 | if (arg == "--version") { | |
| 1119 | 1129 | cl::PrintVersionMessage(); |
| 1120 | 1130 | return true; |
| 1121 | 1131 | } |
| ... | ... | @@ -1129,8 +1139,6 @@ static const char *matchFlagWithArg(StringRef Expected, |
| 1129 | 1139 | |
| 1130 | 1140 | if (Arg.startswith("--")) |
| 1131 | 1141 | Arg = Arg.substr(2); |
| 1132 | else if (Arg.startswith("-")) | |
| 1133 | Arg = Arg.substr(1); | |
| 1134 | 1142 | |
| 1135 | 1143 | size_t len = Expected.size(); |
| 1136 | 1144 | if (Arg == Expected) { |
| ... | ... | @@ -1199,6 +1207,11 @@ static int ar_main(int argc, char **argv) { |
| 1199 | 1207 | continue; |
| 1200 | 1208 | } |
| 1201 | 1209 | |
| 1210 | if (strcmp(*ArgIt, "--thin") == 0) { | |
| 1211 | Thin = true; | |
| 1212 | continue; | |
| 1213 | } | |
| 1214 | ||
| 1202 | 1215 | Match = matchFlagWithArg("format", ArgIt, Argv); |
| 1203 | 1216 | if (Match) { |
| 1204 | 1217 | FormatType = StringSwitch<Format>(Match) |
| ... | ... | @@ -1261,16 +1274,8 @@ static int ranlib_main(int argc, char **argv) { |
| 1261 | 1274 | return performOperation(CreateSymTab, nullptr); |
| 1262 | 1275 | } |
| 1263 | 1276 | |
| 1264 | extern "C" int ZigLlvmAr_main(int argc, char **argv); | |
| 1265 | int ZigLlvmAr_main(int argc, char **argv) { | |
| 1266 | // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), | |
| 1267 | // and overwrites the args. We don't want it to do that, | |
| 1268 | // and we also don't need the signal handlers it installs | |
| 1269 | // (we have our own already), so we just use llvm_shutdown_obj | |
| 1270 | // instead. | |
| 1271 | // InitLLVM X(argc, argv); | |
| 1272 | llvm::llvm_shutdown_obj X; | |
| 1273 | ||
| 1277 | int main(int argc, char **argv) { | |
| 1278 | InitLLVM X(argc, argv); | |
| 1274 | 1279 | ToolName = argv[0]; |
| 1275 | 1280 | |
| 1276 | 1281 | llvm::InitializeAllTargetInfos(); |