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) {...@@ -144,13 +144,13 @@ static int PrintSupportedExtensions(std::string TargetStr) {
144 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(144 std::unique_ptr<llvm::TargetMachine> TheTargetMachine(
145 TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));145 TheTarget->createTargetMachine(Triple, "", "", Options, std::nullopt));
146 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();146 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
147 const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();147 const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
148 const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =148 const llvm::ArrayRef<llvm::SubtargetFeatureKV> Features =
149 MCInfo->getAllProcessorFeatures();149 MCInfo.getAllProcessorFeatures();
150150
151 llvm::StringMap<llvm::StringRef> DescMap;151 llvm::StringMap<llvm::StringRef> DescMap;
152 for (const llvm::SubtargetFeatureKV &feature : Features)152 for (const llvm::SubtargetFeatureKV &feature : Features)
153 DescMap.insert({feature.Key, feature.Desc});153 DescMap.insert({feature.key(), feature.desc()});
154154
155 if (MachineTriple.isRISCV())155 if (MachineTriple.isRISCV())
156 llvm::RISCVISAInfo::printSupportedExtensions(DescMap);156 llvm::RISCVISAInfo::printSupportedExtensions(DescMap);
...@@ -187,23 +187,23 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {...@@ -187,23 +187,23 @@ static int PrintEnabledExtensions(const TargetOptions& TargetOpts) {
187 TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,187 TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
188 BackendOptions, std::nullopt));188 BackendOptions, std::nullopt));
189 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();189 const llvm::Triple &MachineTriple = TheTargetMachine->getTargetTriple();
190 const llvm::MCSubtargetInfo *MCInfo = TheTargetMachine->getMCSubtargetInfo();190 const llvm::MCSubtargetInfo &MCInfo = TheTargetMachine->getMCSubtargetInfo();
191191
192 // Extract the feature names that are enabled for the given target.192 // Extract the feature names that are enabled for the given target.
193 // We do that by capturing the key from the set of SubtargetFeatureKV entries193 // We do that by capturing the key from the set of SubtargetFeatureKV entries
194 // provided by MCSubtargetInfo, which match the '-target-feature' values.194 // provided by MCSubtargetInfo, which match the '-target-feature' values.
195 const std::vector<llvm::SubtargetFeatureKV> Features =195 const std::vector<const llvm::SubtargetFeatureKV *> Features =
196 MCInfo->getEnabledProcessorFeatures();196 MCInfo.getEnabledProcessorFeatures();
197 std::set<llvm::StringRef> EnabledFeatureNames;197 std::set<llvm::StringRef> EnabledFeatureNames;
198 for (const llvm::SubtargetFeatureKV &feature : Features)198 for (const llvm::SubtargetFeatureKV *feature : Features)
199 EnabledFeatureNames.insert(feature.Key);199 EnabledFeatureNames.insert(feature->key());
200200
201 if (MachineTriple.isAArch64())201 if (MachineTriple.isAArch64())
202 llvm::AArch64::printEnabledExtensions(EnabledFeatureNames);202 llvm::AArch64::printEnabledExtensions(EnabledFeatureNames);
203 else if (MachineTriple.isRISCV()) {203 else if (MachineTriple.isRISCV()) {
204 llvm::StringMap<llvm::StringRef> DescMap;204 llvm::StringMap<llvm::StringRef> DescMap;
205 for (const llvm::SubtargetFeatureKV &feature : Features)205 for (const llvm::SubtargetFeatureKV *feature : Features)
206 DescMap.insert({feature.Key, feature.Desc});206 DescMap.insert({feature->key(), feature->desc()});
207 llvm::RISCVISAInfo::printEnabledExtensions(MachineTriple.isArch64Bit(),207 llvm::RISCVISAInfo::printEnabledExtensions(MachineTriple.isArch64Bit(),
208 EnabledFeatureNames, DescMap);208 EnabledFeatureNames, DescMap);
209 } else {209 } else {
...@@ -289,20 +289,11 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {...@@ -289,20 +289,11 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
289 static_cast<void*>(&Clang->getDiagnostics()));289 static_cast<void*>(&Clang->getDiagnostics()));
290290
291 DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());291 DiagsBuffer->FlushDiagnostics(Clang->getDiagnostics());
292 if (!Success) {292 if (!Success)
293 Clang->getDiagnosticClient().finish();
294 return 1;293 return 1;
295 }
296294
297 // Execute the frontend actions.295 // Execute the frontend actions.
298 {296 Success = ExecuteCompilerInvocation(Clang.get());
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 }
306297
307 // If any timers were active but haven't been destroyed yet, print their298 // If any timers were active but haven't been destroyed yet, print their
308 // results now. This happens in -disable-free mode.299 // results now. This happens in -disable-free mode.
...@@ -339,6 +330,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {...@@ -339,6 +330,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
339330
340 // When running with -disable-free, don't do any destruction or shutdown.331 // When running with -disable-free, don't do any destruction or shutdown.
341 if (Clang->getFrontendOpts().DisableFree) {332 if (Clang->getFrontendOpts().DisableFree) {
333 // DiagnosticConsumer must be always destroyed.
334 Clang->getDiagnosticClient().~DiagnosticConsumer();
342 llvm::BuryPointer(std::move(Clang));335 llvm::BuryPointer(std::move(Clang));
343 return !Success;336 return !Success;
344 }337 }
src/zig_clang_cc1as_main.cpp+12-4
...@@ -177,6 +177,8 @@ struct AssemblerInvocation {...@@ -177,6 +177,8 @@ struct AssemblerInvocation {
177 LLVM_PREFERRED_TYPE(bool)177 LLVM_PREFERRED_TYPE(bool)
178 unsigned X86Sse2Avx : 1;178 unsigned X86Sse2Avx : 1;
179179
180 RelocSectionSymType RelocSectionSym = RelocSectionSymType::All;
181
180 /// The name of the relocation model to use.182 /// The name of the relocation model to use.
181 std::string RelocationModel;183 std::string RelocationModel;
182184
...@@ -387,6 +389,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -387,6 +389,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
387 llvm::StringSwitch<EmitDwarfUnwindType>(A->getValue())389 llvm::StringSwitch<EmitDwarfUnwindType>(A->getValue())
388 .Case("always", EmitDwarfUnwindType::Always)390 .Case("always", EmitDwarfUnwindType::Always)
389 .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind)391 .Case("no-compact-unwind", EmitDwarfUnwindType::NoCompactUnwind)
392 .Case("dwarf-only", EmitDwarfUnwindType::DwarfOnly)
390 .Case("default", EmitDwarfUnwindType::Default);393 .Case("default", EmitDwarfUnwindType::Default);
391 }394 }
392395
...@@ -394,6 +397,12 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,...@@ -394,6 +397,12 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
394 Args.hasArg(OPT_femit_compact_unwind_non_canonical);397 Args.hasArg(OPT_femit_compact_unwind_non_canonical);
395 Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe);398 Opts.EmitSFrameUnwind = Args.hasArg(OPT_gsframe);
396 Opts.Crel = Args.hasArg(OPT_crel);399 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);
397 Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit);406 Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit);
398 Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no);407 Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
399 Opts.X86Sse2Avx = Args.hasArg(OPT_msse2avx);408 Opts.X86Sse2Avx = Args.hasArg(OPT_msse2avx);
...@@ -461,6 +470,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,...@@ -461,6 +470,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
461 MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind;470 MCOptions.EmitSFrameUnwind = Opts.EmitSFrameUnwind;
462 MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels;471 MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels;
463 MCOptions.Crel = Opts.Crel;472 MCOptions.Crel = Opts.Crel;
473 MCOptions.RelocSectionSym = Opts.RelocSectionSym;
464 MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms;474 MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms;
465 MCOptions.X86RelaxRelocations = Opts.X86RelaxRelocations;475 MCOptions.X86RelaxRelocations = Opts.X86RelaxRelocations;
466 MCOptions.X86Sse2Avx = Opts.X86Sse2Avx;476 MCOptions.X86Sse2Avx = Opts.X86Sse2Avx;
...@@ -497,8 +507,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,...@@ -497,8 +507,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
497 << Opts.CPU << FS.empty() << FS;507 << Opts.CPU << FS.empty() << FS;
498 }508 }
499509
500 MCContext Ctx(Triple(Opts.Triple), MAI.get(), MRI.get(), STI.get(), &SrcMgr,510 MCContext Ctx(Triple(Opts.Triple), *MAI, *MRI, *STI, &SrcMgr);
501 &MCOptions);
502511
503 bool PIC = false;512 bool PIC = false;
504 if (Opts.RelocationModel == "static") {513 if (Opts.RelocationModel == "static") {
...@@ -617,9 +626,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,...@@ -617,9 +626,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
617 std::unique_ptr<MCAsmParser> Parser(626 std::unique_ptr<MCAsmParser> Parser(
618 createMCAsmParser(SrcMgr, Ctx, *Str, *MAI));627 createMCAsmParser(SrcMgr, Ctx, *Str, *MAI));
619628
620 // FIXME: init MCTargetOptions from sanitizer flags here.
621 std::unique_ptr<MCTargetAsmParser> TAP(629 std::unique_ptr<MCTargetAsmParser> TAP(
622 TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions));630 TheTarget->createMCAsmParser(*STI, *Parser, *MCII));
623 if (!TAP)631 if (!TAP)
624 Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple.str();632 Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple.str();
625633
src/zig_clang_driver.cpp+37-8
...@@ -55,6 +55,10 @@...@@ -55,6 +55,10 @@
55#include <optional>55#include <optional>
56#include <set>56#include <set>
57#include <system_error>57#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
59using namespace clang;63using namespace clang;
60using namespace clang::driver;64using namespace clang::driver;
...@@ -223,6 +227,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,...@@ -223,6 +227,7 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
223 return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);227 return cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);
224 if (Tool == "-cc1as")228 if (Tool == "-cc1as")
225 return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);229 return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
230 // zig patch: no -cc1gen-reproducer
226 // Reject unknown tools.231 // Reject unknown tools.
227 llvm::errs()232 llvm::errs()
228 << "error: unknown integrated tool '" << Tool << "'. "233 << "error: unknown integrated tool '" << Tool << "'. "
...@@ -230,11 +235,13 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,...@@ -230,11 +235,13 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
230 return 1;235 return 1;
231}236}
232237
238// zig patch: use custom entry point
233static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {239static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContext) {
234 noteBottomOfStack();240 noteBottomOfStack();
235 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL241 llvm::setBugReportMsg("PLEASE submit a bug report to " BUG_REPORT_URL
236 " and include the crash backtrace, preprocessed "242 " and include the crash backtrace and"
237 "source, and associated run script.\n");243 " dumped files.\n");
244 // zig patch: fix argv offset
238 size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1;245 size_t argv_offset = (strcmp(Argv[1], "-cc1") == 0 || strcmp(Argv[1], "-cc1as") == 0) ? 0 : 1;
239 SmallVector<const char *, 256> Args(Argv + argv_offset, Argv + Argc);246 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...@@ -373,7 +380,8 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
373 if (!UseNewCC1Process) {380 if (!UseNewCC1Process) {
374 TheDriver.CC1Main = ExecuteCC1WithContext;381 TheDriver.CC1Main = ExecuteCC1WithContext;
375 // Ensure the CC1Command actually catches cc1 crashes382 // Ensure the CC1Command actually catches cc1 crashes
376 llvm::CrashRecoveryContext::Enable();383 llvm::CrashRecoveryContext::Enable(
384 /*NeedsPOSIXUtilitySignalHandling=*/true);
377 }385 }
378386
379 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(Args));387 std::unique_ptr<Compilation> C(TheDriver.BuildCompilation(Args));
...@@ -402,6 +410,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex...@@ -402,6 +410,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
402 Driver::CommandStatus CommandStatus = Driver::CommandStatus::Ok;410 Driver::CommandStatus CommandStatus = Driver::CommandStatus::Ok;
403 // Pretend the first command failed if ReproStatus is Always.411 // Pretend the first command failed if ReproStatus is Always.
404 const Command *FailingCommand = nullptr;412 const Command *FailingCommand = nullptr;
413 int CommandRes = 0;
405 if (!C->getJobs().empty())414 if (!C->getJobs().empty())
406 FailingCommand = &*C->getJobs().begin();415 FailingCommand = &*C->getJobs().begin();
407 if (C && !C->containsError()) {416 if (C && !C->containsError()) {
...@@ -409,7 +418,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex...@@ -409,7 +418,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
409 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);418 Res = TheDriver.ExecuteCompilation(*C, FailingCommands);
410419
411 for (const auto &P : FailingCommands) {420 for (const auto &P : FailingCommands) {
412 int CommandRes = P.first;421 CommandRes = P.first;
413 FailingCommand = P.second;422 FailingCommand = P.second;
414 if (!Res)423 if (!Res)
415 Res = CommandRes;424 Res = CommandRes;
...@@ -421,8 +430,8 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex...@@ -421,8 +430,8 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
421 IsCrash = CommandRes < 0 || CommandRes == 70;430 IsCrash = CommandRes < 0 || CommandRes == 70;
422#ifdef _WIN32431#ifdef _WIN32
423 IsCrash |= CommandRes == 3;432 IsCrash |= CommandRes == 3;
424#endif433// zig patch: don't rely on LLVM_ON_UNIX that comes from the build system
425#if LLVM_ON_UNIX434#else
426 // When running in integrated-cc1 mode, the CrashRecoveryContext returns435 // When running in integrated-cc1 mode, the CrashRecoveryContext returns
427 // the same codes as if the program crashed. See section "Exit Status for436 // the same codes as if the program crashed. See section "Exit Status for
428 // Commands":437 // Commands":
...@@ -445,8 +454,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex...@@ -445,8 +454,6 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
445 *C, *FailingCommand))454 *C, *FailingCommand))
446 Res = 1;455 Res = 1;
447456
448 Diags.getClient()->finish();
449
450 if (!UseNewCC1Process && IsCrash) {457 if (!UseNewCC1Process && IsCrash) {
451 // When crashing in -fintegrated-cc1 mode, bury the timer pointers, because458 // When crashing in -fintegrated-cc1 mode, bury the timer pointers, because
452 // the internal linked list might point to already released stack frames.459 // 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...@@ -464,6 +471,28 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
464 // propagated.471 // propagated.
465 if (Res < 0)472 if (Res < 0)
466 Res = 1;473 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 }
467#endif496#endif
468497
469 // If we have multiple failing commands, we return the result of the first498 // 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) {...@@ -83,6 +83,7 @@ static void printArHelp(StringRef ToolName) {
83 =darwin - darwin83 =darwin - darwin
84 =bsd - bsd84 =bsd - bsd
85 =bigarchive - big archive (AIX OS)85 =bigarchive - big archive (AIX OS)
86 =zos - zos archive (z/OS OS)
86 =coff - coff87 =coff - coff
87 --plugin=<string> - ignored for compatibility88 --plugin=<string> - ignored for compatibility
88 -h --help - display this help and exit89 -h --help - display this help and exit
...@@ -195,7 +196,16 @@ static SmallVector<const char *, 256> PositionalArgs;...@@ -195,7 +196,16 @@ static SmallVector<const char *, 256> PositionalArgs;
195static bool MRI;196static bool MRI;
196197
197namespace {198namespace {
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};
199}209}
200210
201static Format FormatType = Default;211static Format FormatType = Default;
...@@ -713,8 +723,11 @@ static void performReadOperation(ArchiveOperation Operation,...@@ -713,8 +723,11 @@ static void performReadOperation(ArchiveOperation Operation,
713 });723 });
714 if (I == Members.end())724 if (I == Members.end())
715 continue;725 continue;
716 if (CountParam && ++MemberCount[Name] != CountParam)726 if (CountParam) {
717 continue;727 std::string CountKey = normalizePath(*I);
728 if (++MemberCount[CountKey] != CountParam)
729 continue;
730 }
718 Members.erase(I);731 Members.erase(I);
719 }732 }
720733
...@@ -854,14 +867,19 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,...@@ -854,14 +867,19 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
854 if (Operation == QuickAppend || Members.empty())867 if (Operation == QuickAppend || Members.empty())
855 return IA_AddOldMember;868 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);
858 if (Thin && !sys::path::is_absolute(Path)) {873 if (Thin && !sys::path::is_absolute(Path)) {
859 Expected<std::string> PathOrErr =874 Expected<std::string> PathOrErr =
860 computeArchiveRelativePath(ArchiveName, Path);875 computeArchiveRelativePath(ArchiveName, Path);
861 return comparePaths(Name, PathOrErr ? *PathOrErr : Path);876 if (PathOrErr)
862 } else {877 MatchPath = *PathOrErr;
863 return comparePaths(Name, Path);
864 }878 }
879 if (!comparePaths(Name, MatchPath))
880 return false;
881 CountKey = normalizePath(MatchPath);
882 return true;
865 });883 });
866884
867 if (MI == Members.end())885 if (MI == Members.end())
...@@ -870,7 +888,7 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,...@@ -870,7 +888,7 @@ static InsertAction computeInsertAction(ArchiveOperation Operation,
870 Pos = MI;888 Pos = MI;
871889
872 if (Operation == Delete) {890 if (Operation == Delete) {
873 if (CountParam && ++MemberCount[Name] != CountParam)891 if (CountParam && ++MemberCount[CountKey] != CountParam)
874 return IA_AddOldMember;892 return IA_AddOldMember;
875 return IA_Delete;893 return IA_Delete;
876 }894 }
...@@ -1071,6 +1089,11 @@ static void performWriteOperation(ArchiveOperation Operation,...@@ -1071,6 +1089,11 @@ static void performWriteOperation(ArchiveOperation Operation,
1071 fail("only the gnu format has a thin mode");1089 fail("only the gnu format has a thin mode");
1072 Kind = object::Archive::K_AIXBIG;1090 Kind = object::Archive::K_AIXBIG;
1073 break;1091 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;
1074 case Unknown:1097 case Unknown:
1075 llvm_unreachable("");1098 llvm_unreachable("");
1076 }1099 }
...@@ -1389,6 +1412,7 @@ static int ar_main(int argc, char **argv) {...@@ -1389,6 +1412,7 @@ static int ar_main(int argc, char **argv) {
1389 .Case("bsd", BSD)1412 .Case("bsd", BSD)
1390 .Case("bigarchive", BIGARCHIVE)1413 .Case("bigarchive", BIGARCHIVE)
1391 .Case("coff", COFF)1414 .Case("coff", COFF)
1415 .Case("zos", ZOSARCHIVE)
1392 .Default(Unknown);1416 .Default(Unknown);
1393 if (FormatType == Unknown)1417 if (FormatType == Unknown)
1394 fail(std::string("Invalid format ") + Match);1418 fail(std::string("Invalid format ") + Match);
...@@ -1509,6 +1533,7 @@ static int ranlib_main(int argc, char **argv) {...@@ -1509,6 +1533,7 @@ static int ranlib_main(int argc, char **argv) {
1509 return 0;1533 return 0;
1510}1534}
15111535
1536// zig patch: use custom entry point
1512static int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) {1537static int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) {
1513 ToolName = argv[0];1538 ToolName = argv[0];
15141539
src/zig_llvm.cpp+1-1
...@@ -373,7 +373,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi...@@ -373,7 +373,7 @@ ZIG_EXTERN_C bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machi
373 if (options->is_debug)373 if (options->is_debug)
374 opt_level = OptimizationLevel::O0;374 opt_level = OptimizationLevel::O0;
375 else if (options->is_small)375 else if (options->is_small)
376 opt_level = OptimizationLevel::Oz;376 opt_level = OptimizationLevel::O2;
377 else377 else
378 opt_level = OptimizationLevel::O3;378 opt_level = OptimizationLevel::O3;
379379