authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-03 12:09:32+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-31 23:09:45+02:00
log0b2d642dd130192c77f207446c1a56502ffc1ce3
treeb017a4d5903b0c73b529dbe4c8960317769ebeff
parent79f21389d27d6ae06297b7c485f65647df414315
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

zig cc: update driver files to LLVM 23


5 files changed, 97 insertions(+), 42 deletions(-)

src/zig_clang_cc1_main.cpp+14-21
......@@ -144,13 +144,13 @@ static int PrintSupportedExtensions(std::string TargetStr) {
144144 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
145145 TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));
146146 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
147 const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
147 const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
148148 const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
149 MCInfo->getAllProcessorFeatures();
149 MCInfo.getAllProcessorFeatures();
150150
151151 llvm::StringMap<llvm::StringRef> DescMap;
152152 for (const llvm::SubtargetFeatureKV &feature : Features)
153 DescMap.insert({feature.Key, feature.Desc});
153 DescMap.insert({feature.key(), feature.desc()});
154154
155155 if (MachineTriple.isRISCV())
156156 llvm::RISCVISAInfo::printSupportedExtensions(DescMap);
......@@ -187,23 +187,23 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
187187 TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
188188 BackendOptions, std::nullopt));
189189 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
190 const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();
190 const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
191191
192192 // Extract the feature names that are enabled for the given target.
193193 // We do that by capturing the key from the set of SubtargetFeatureKV entries
194194 // provided by MCSubtargetInfo, which match the '-target-feature' values.
195 const std::vector<llvm::SubtargetFeatureKV> Features =
196 MCInfo->getEnabledProcessorFeatures();
195 const std::vector<const llvm::SubtargetFeatureKV *> Features =
196 MCInfo.getEnabledProcessorFeatures();
197197 std::set<llvm::StringRef> EnabledFeatureNames;
198 for (const llvm::SubtargetFeatureKV &feature : Features)
199 EnabledFeatureNames.insert(feature.Key);
198 for (const llvm::SubtargetFeatureKV *feature : Features)
199 EnabledFeatureNames.insert(feature->key());
200200
201201 if (MachineTriple.isAArch64())
202202 llvm::AArch64::printEnabledExtensions(EnabledFeatureNames);
203203 else if (MachineTriple.isRISCV()) {
204204 llvm::StringMap<llvm::StringRef> DescMap;
205 for (const llvm::SubtargetFeatureKV &feature : Features)
206 DescMap.insert({feature.Key, feature.Desc});
205 for (const llvm::SubtargetFeatureKV *feature : Features)
206 DescMap.insert({feature->key(), feature->desc()});
207207 llvm::RISCVISAInfo::printEnabledExtensions(MachineTriple.isArch64Bit(),
208208 EnabledFeatureNames, DescMap);
209209 } else {
......@@ -289,20 +289,11 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
289289 static_cast<void*>(&Clang->getDiagnostics()));
290290
291291 DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
292 if (!Success) {
293 Clang->getDiagnosticClient().finish();
292 if (!Success)
294293 return 1;
295 }
296294
297295 // Execute the frontend actions.
298 {
299 llvm::TimeTraceScope TimeScope("ExecuteCompiler");
300 bool TimePasses = Clang->getCodeGenOpts().TimePasses;
301 if (TimePasses)
302 Clang->createFrontendTimer();
303 llvm::TimeRegion Timer(TimePasses ? &Clang->getFrontendTimer() : nullptr);
304 Success = ExecuteCompilerInvocation(Clang.get());
305 }
296 Success = ExecuteCompilerInvocation(Clang.get());
306297
307298 // If any timers were active but haven't been destroyed yet, print their
308299 // results now. This happens in -disable-free mode.
......@@ -339,6 +330,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
339330
340331 // When running with -disable-free, don't do any destruction or shutdown.
341332 if (Clang->getFrontendOpts().DisableFree) {
333 // DiagnosticConsumer must be always destroyed.
334 Clang->getDiagnosticClient().~DiagnosticConsumer();
342335 llvm::BuryPointer(std::move(Clang));
343336 return !Success;
344337 }
src/zig_clang_cc1as_main.cpp+12-4
......@@ -177,6 +177,8 @@ struct AssemblerInvocation {
177177 LLVM_PREFERRED_TYPE(bool)
178178 unsigned X86Sse2Avx : 1;
179179
180 RelocSectionSymType RelocSectionSym = RelocSectionSymType::All;
181
180182 /// The name of the relocation model to use.
181183 std::string RelocationModel;
182184
......@@ -387,6 +389,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
387389 llvm::StringSwitch<EmitDwarfUnwindType>(A->getValue())
388390 .Case("always", EmitDwarfUnwindType::Always)
389391 .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind)
392 .Case("dwarf-only", EmitDwarfUnwindType::DwarfOnly)
390393 .Case("default", EmitDwarfUnwindType::Default);
391394 }
392395
......@@ -394,6 +397,12 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
394397 Args.hasArg(OPT_femit_compact_unwind_non_canonical);
395398 Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe);
396399 Opts.Crel = Args.hasArg(OPT_crel);
400 Opts.RelocSectionSym = RelocSectionSymType::All;
401 if (auto *A = Args.getLastArg(OPT_reloc_section_sym))
402 Opts.RelocSectionSym = StringSwitch<RelocSectionSymType>(A->getValue())
403 .Case("internal", RelocSectionSymType::Internal)
404 .Case("none", RelocSectionSymType::None)
405 .Default(RelocSectionSymType::All);
397406 Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit);
398407 Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
399408 Opts.X86Sse2Avx = Args.hasArg(OPT_msse2avx);
......@@ -461,6 +470,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
461470 MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind;
462471 MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels;
463472 MCOptions.Crel = Opts.Crel;
473 MCOptions.RelocSectionSym = Opts.RelocSectionSym;
464474 MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms;
465475 MCOptions.X86RelaxRelocations = Opts.X86RelaxRelocations;
466476 MCOptions.X86Sse2Avx = Opts.X86Sse2Avx;
......@@ -497,8 +507,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
497507 << Opts.CPU << FS.empty() << FS;
498508 }
499509
500 MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr,
501 &MCOptions);
510 MCContext Ctx(Triple(Opts.Triple), *MAI, *MRI, *STI, &SrcMgr);
502511
503512 bool PIC = false;
504513 if (Opts.RelocationModel == "static") {
......@@ -617,9 +626,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
617626 std::unique_ptr<MCAsmParser> Parser(
618627 createMCAsmParser(SrcMgr, Ctx, *Str, *MAI));
619628
620 // FIXME: init MCTargetOptions from sanitizer flags here.
621629 std::unique_ptr<MCTargetAsmParser> TAP(
622 TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions));
630 TheTarget->createMCAsmParser(*STI, *Parser, *MCII));
623631 if (!TAP)
624632 Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple.str();
625633
src/zig_clang_driver.cpp+37-8
......@@ -55,6 +55,10 @@
5555#include <optional>
5656#include <set>
5757#include <system_error>
58// zig patch: don't rely on LLVM_ON_UNIX that comes from the build system
59#if !defined(_WIN32)
60#include <signal.h>
61#endif
5862
5963using namespace clang;
6064using namespace clang::driver;
......@@ -223,6 +227,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
223227 return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);
224228 if (Tool == "-cc1as")
225229 return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
230 // zig patch: no -cc1gen-reproducer
226231 // Reject unknown tools.
227232 llvm::errs()
228233 << "error: unknown integrated tool '" << Tool << "'. "
......@@ -230,11 +235,13 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
230235 return 1;
231236}
232237
238// zig patch: use custom entry point
233239static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
234240 noteBottomOfStack();
235241 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
236 " and include the crash backtrace, preprocessed "
237 "source, and associated run script.\n");
242 " and include the crash backtrace and"
243 " dumped files.\n");
244 // zig patch: fix argv offset
238245 size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1;
239246 SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc);
240247
......@@ -373,7 +380,8 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
373380 if (!UseNewCC1Process) {
374381 TheDriver.CC1Main = ExecuteCC1WithContext;
375382 // Ensure the CC1Command actually catches cc1 crashes
376 llvm::CrashRecoveryContext::Enable();
383 llvm::CrashRecoveryContext::Enable(
384 /*NeedsPOSIXUtilitySignalHandling=*/true);
377385 }
378386
379387 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(Args));
......@@ -402,6 +410,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
402410 Driver::CommandStatus CommandStatus = Driver::CommandStatus::Ok;
403411 // Pretend the first command failed if ReproStatus is Always.
404412 const Command *FailingCommand = nullptr;
413 int CommandRes = 0;
405414 if (!C->getJobs().empty())
406415 FailingCommand = &*C->getJobs().begin();
407416 if (C && !C->containsError()) {
......@@ -409,7 +418,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
409418 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
410419
411420 for (const auto &P : FailingCommands) {
412 int CommandRes = P.first;
421 CommandRes = P.first;
413422 FailingCommand = P.second;
414423 if (!Res)
415424 Res = CommandRes;
......@@ -421,8 +430,8 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
421430 IsCrash = CommandRes < 0 || CommandRes == 70;
422431#ifdef _WIN32
423432 IsCrash |= CommandRes == 3;
424#endif
425#if LLVM_ON_UNIX
433// zig patch: don't rely on LLVM_ON_UNIX that comes from the build system
434#else
426435 // When running in integrated-cc1 mode, the CrashRecoveryContext returns
427436 // the same codes as if the program crashed. See section "Exit Status for
428437 // Commands":
......@@ -445,8 +454,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
445454 *C, *FailingCommand))
446455 Res = 1;
447456
448 Diags.getClient()->finish();
449
450457 if (!UseNewCC1Process && IsCrash) {
451458 // When crashing in -fintegrated-cc1 mode, bury the timer pointers, because
452459 // the internal linked list might point to already released stack frames.
......@@ -464,6 +471,28 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
464471 // propagated.
465472 if (Res < 0)
466473 Res = 1;
474// zig patch: don't rely on LLVM_ON_UNIX that comes from the build system
475#else
476 // On Unix, signals are represented by return codes of 128 plus the signal
477 // number. If the return code indicates it was from a signal handler, raise
478 // the signal so that the exit code includes the signal number, as required
479 // by POSIX. Return code 255 is excluded because some tools, such as
480 // llvm-ifs, exit with code 255 (-1) on failure.
481 if (CommandRes > 128 && CommandRes != 255) {
482 llvm::sys::unregisterHandlers();
483 // DiagnosticConsumer must be always destroyed.
484 Diags.getClient()->~DiagnosticConsumer();
485 raise(CommandRes - 128);
486 }
487 // When cc1 runs out-of-process (CLANG_SPAWN_CC1), ExecuteAndWait returns -2
488 // if the child was killed by a signal. The signal number is not preserved,
489 // so resignal with SIGABRT to ensure the driver exits via signal.
490 if (CommandRes == -2) {
491 llvm::sys::unregisterHandlers();
492 // DiagnosticConsumer must be always destroyed.
493 Diags.getClient()->~DiagnosticConsumer();
494 raise(SIGABRT);
495 }
467496#endif
468497
469498 // If we have multiple failing commands, we return the result of the first
src/zig_llvm-ar.cpp+33-8
......@@ -83,6 +83,7 @@ static void printArHelp(StringRef ToolName) {
8383 =darwin - darwin
8484 =bsd - bsd
8585 =bigarchive - big archive (AIX OS)
86 =zos - zos archive (z/OS OS)
8687 =coff - coff
8788 --plugin=<string> - ignored for compatibility
8889 -h --help - display this help and exit
......@@ -195,7 +196,16 @@ static SmallVector<const char *, 256> PositionalArgs;
195196static bool MRI;
196197
197198namespace {
198enum Format { Default, GNU, COFF, BSD, DARWIN, BIGARCHIVE, Unknown };
199enum Format {
200 Default,
201 GNU,
202 COFF,
203 BSD,
204 DARWIN,
205 BIGARCHIVE,
206 ZOSARCHIVE,
207 Unknown
208};
199209}
200210
201211static Format FormatType = Default;
......@@ -713,8 +723,11 @@ static void performReadOperation(ArchiveOperation Operation,
713723 });
714724 if (I == Members.end())
715725 continue;
716 if (CountParam && ++MemberCount[Name] != CountParam)
717 continue;
726 if (CountParam) {
727 std::string CountKey = normalizePath(*I);
728 if (++MemberCount[CountKey] != CountParam)
729 continue;
730 }
718731 Members.erase(I);
719732 }
720733
......@@ -854,14 +867,19 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
854867 if (Operation == QuickAppend || Members.empty())
855868 return IA_AddOldMember;
856869
857 auto MI = find_if(Members, [Name](StringRef Path) {
870 std::string CountKey;
871 auto MI = find_if(Members, [Name, &CountKey](StringRef Path) {
872 SmallString<128> MatchPath(Path);
858873 if (Thin && !sys::path::is_absolute(Path)) {
859874 Expected<std::string> PathOrErr =
860875 computeArchiveRelativePath(ArchiveName, Path);
861 return comparePaths(Name, PathOrErr ? *PathOrErr : Path);
862 } else {
863 return comparePaths(Name, Path);
876 if (PathOrErr)
877 MatchPath = *PathOrErr;
864878 }
879 if (!comparePaths(Name, MatchPath))
880 return false;
881 CountKey = normalizePath(MatchPath);
882 return true;
865883 });
866884
867885 if (MI == Members.end())
......@@ -870,7 +888,7 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
870888 Pos = MI;
871889
872890 if (Operation == Delete) {
873 if (CountParam && ++MemberCount[Name] != CountParam)
891 if (CountParam && ++MemberCount[CountKey] != CountParam)
874892 return IA_AddOldMember;
875893 return IA_Delete;
876894 }
......@@ -1071,6 +1089,11 @@ static void performWriteOperation(ArchiveOperation Operation,
10711089 fail("only the gnu format has a thin mode");
10721090 Kind = object::Archive::K_AIXBIG;
10731091 break;
1092 case ZOSARCHIVE:
1093 if (Thin)
1094 fail("only the gnu format has a thin mode");
1095 Kind = object::Archive::K_ZOS;
1096 break;
10741097 case Unknown:
10751098 llvm_unreachable("");
10761099 }
......@@ -1389,6 +1412,7 @@ static int ar_main(int argc, char **argv) {
13891412 .Case("bsd", BSD)
13901413 .Case("bigarchive", BIGARCHIVE)
13911414 .Case("coff", COFF)
1415 .Case("zos", ZOSARCHIVE)
13921416 .Default(Unknown);
13931417 if (FormatType == Unknown)
13941418 fail(std::string("Invalid format ") + Match);
......@@ -1509,6 +1533,7 @@ static int ranlib_main(int argc, char **argv) {
15091533 return 0;
15101534}
15111535
1536// zig patch: use custom entry point
15121537static int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) {
15131538 ToolName = argv[0];
15141539
src/zig_llvm.cpp+1-1
......@@ -373,7 +373,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
373373 if (options->is_debug)
374374 opt_level = OptimizationLevel::O0;
375375 else if (options->is_small)
376 opt_level = OptimizationLevel::Oz;
376 opt_level = OptimizationLevel::O2;
377377 else
378378 opt_level = OptimizationLevel::O3;
379379