Skip to content

Commit f21bac0

Browse files
committed
zig cc: Update driver files to Clang 20.
1 parent 0712115 commit f21bac0

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

src/zig_clang_cc1_main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include "clang/Basic/Stack.h"
1616
#include "clang/Basic/TargetOptions.h"
17-
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
17+
#include "clang/CodeGen/ObjectFilePCHContainerWriter.h"
1818
#include "clang/Config/config.h"
1919
#include "clang/Driver/DriverDiagnostic.h"
2020
#include "clang/Driver/Options.h"
@@ -25,6 +25,7 @@
2525
#include "clang/Frontend/TextDiagnosticPrinter.h"
2626
#include "clang/Frontend/Utils.h"
2727
#include "clang/FrontendTool/Utils.h"
28+
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
2829
#include "llvm/ADT/Statistic.h"
2930
#include "llvm/ADT/StringExtras.h"
3031
#include "llvm/Config/llvm-config.h"
@@ -44,6 +45,7 @@
4445
#include "llvm/Support/TargetSelect.h"
4546
#include "llvm/Support/TimeProfiler.h"
4647
#include "llvm/Support/Timer.h"
48+
#include "llvm/Support/VirtualFileSystem.h"
4749
#include "llvm/Support/raw_ostream.h"
4850
#include "llvm/Target/TargetMachine.h"
4951
#include "llvm/TargetParser/AArch64TargetParser.h"
@@ -263,7 +265,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
263265
CompilerInvocation::GetResourcesPath(Argv0, MainAddr);
264266

265267
// Create the actual diagnostics engine.
266-
Clang->createDiagnostics();
268+
Clang->createDiagnostics(*llvm::vfs::getRealFileSystem());
267269
if (!Clang->hasDiagnostics())
268270
return 1;
269271

@@ -281,6 +283,10 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
281283
// Execute the frontend actions.
282284
{
283285
llvm::TimeTraceScope TimeScope("ExecuteCompiler");
286+
bool TimePasses = Clang->getCodeGenOpts().TimePasses;
287+
if (TimePasses)
288+
Clang->createFrontendTimer();
289+
llvm::TimeRegion Timer(TimePasses ? &Clang->getFrontendTimer() : nullptr);
284290
Success = ExecuteCompilerInvocation(Clang.get());
285291
}
286292

src/zig_clang_cc1as_main.cpp

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ struct AssemblerInvocation {
9696
LLVM_PREFERRED_TYPE(bool)
9797
unsigned GenDwarfForAssembly : 1;
9898
LLVM_PREFERRED_TYPE(bool)
99-
unsigned RelaxELFRelocations : 1;
100-
LLVM_PREFERRED_TYPE(bool)
101-
unsigned SSE2AVX : 1;
102-
LLVM_PREFERRED_TYPE(bool)
10399
unsigned Dwarf64 : 1;
104100
unsigned DwarfVersion;
105101
std::string DwarfDebugFlags;
@@ -168,6 +164,13 @@ struct AssemblerInvocation {
168164

169165
LLVM_PREFERRED_TYPE(bool)
170166
unsigned Crel : 1;
167+
LLVM_PREFERRED_TYPE(bool)
168+
unsigned ImplicitMapsyms : 1;
169+
170+
LLVM_PREFERRED_TYPE(bool)
171+
unsigned X86RelaxRelocations : 1;
172+
LLVM_PREFERRED_TYPE(bool)
173+
unsigned X86Sse2Avx : 1;
171174

172175
/// The name of the relocation model to use.
173176
std::string RelocationModel;
@@ -199,7 +202,6 @@ struct AssemblerInvocation {
199202
ShowInst = 0;
200203
ShowEncoding = 0;
201204
RelaxAll = 0;
202-
SSE2AVX = 0;
203205
NoExecStack = 0;
204206
FatalWarnings = 0;
205207
NoWarn = 0;
@@ -211,6 +213,9 @@ struct AssemblerInvocation {
211213
EmitDwarfUnwind = EmitDwarfUnwindType::Default;
212214
EmitCompactUnwindNonCanonical = false;
213215
Crel = false;
216+
ImplicitMapsyms = 0;
217+
X86RelaxRelocations = 0;
218+
X86Sse2Avx = 0;
214219
}
215220

216221
static bool CreateFromArgs(AssemblerInvocation &Res,
@@ -290,8 +295,6 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
290295
.Default(llvm::DebugCompressionType::None);
291296
}
292297

293-
Opts.RelaxELFRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
294-
Opts.SSE2AVX = Args.hasArg(OPT_msse2avx);
295298
if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32))
296299
Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64);
297300
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
@@ -382,6 +385,9 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
382385
Opts.EmitCompactUnwindNonCanonical =
383386
Args.hasArg(OPT_femit_compact_unwind_non_canonical);
384387
Opts.Crel = Args.hasArg(OPT_crel);
388+
Opts.ImplicitMapsyms = Args.hasArg(OPT_mmapsyms_implicit);
389+
Opts.X86RelaxRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
390+
Opts.X86Sse2Avx = Args.hasArg(OPT_msse2avx);
385391

386392
Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file);
387393

@@ -440,8 +446,9 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
440446
MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical;
441447
MCOptions.MCSaveTempLabels = Opts.SaveTemporaryLabels;
442448
MCOptions.Crel = Opts.Crel;
443-
MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations;
444-
MCOptions.X86Sse2Avx = Opts.SSE2AVX;
449+
MCOptions.ImplicitMapSyms = Opts.ImplicitMapsyms;
450+
MCOptions.X86RelaxRelocations = Opts.X86RelaxRelocations;
451+
MCOptions.X86Sse2Avx = Opts.X86Sse2Avx;
445452
MCOptions.CompressDebugSections = Opts.CompressDebugSections;
446453
MCOptions.AsSecureLogFile = Opts.AsSecureLogFile;
447454

@@ -489,10 +496,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
489496
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
490497
std::unique_ptr<MCObjectFileInfo> MOFI(
491498
TheTarget->createMCObjectFileInfo(Ctx, PIC));
492-
if (Opts.DarwinTargetVariantTriple)
493-
MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
494-
if (!Opts.DarwinTargetVariantSDKVersion.empty())
495-
MOFI->setDarwinTargetVariantSDKVersion(Opts.DarwinTargetVariantSDKVersion);
496499
Ctx.setObjectFileInfo(MOFI.get());
497500

498501
if (Opts.GenDwarfForAssembly)
@@ -574,6 +577,13 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
574577
Str.reset(TheTarget->createMCObjectStreamer(
575578
T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
576579
Str.get()->initSections(Opts.NoExecStack, *STI);
580+
if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
581+
Triple *TVT = Opts.DarwinTargetVariantTriple
582+
? &*Opts.DarwinTargetVariantTriple
583+
: nullptr;
584+
Str->emitVersionForTarget(T, VersionTuple(), TVT,
585+
Opts.DarwinTargetVariantSDKVersion);
586+
}
577587
}
578588

579589
// When -fembed-bitcode is passed to clang_as, a 1-byte marker

src/zig_clang_driver.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "llvm/ADT/SmallString.h"
3030
#include "llvm/ADT/SmallVector.h"
3131
#include "llvm/ADT/StringSet.h"
32+
#include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
3233
#include "llvm/Option/ArgList.h"
3334
#include "llvm/Option/OptTable.h"
3435
#include "llvm/Option/Option.h"
@@ -46,12 +47,14 @@
4647
#include "llvm/Support/StringSaver.h"
4748
#include "llvm/Support/TargetSelect.h"
4849
#include "llvm/Support/Timer.h"
50+
#include "llvm/Support/VirtualFileSystem.h"
4951
#include "llvm/Support/raw_ostream.h"
5052
#include "llvm/TargetParser/Host.h"
5153
#include <memory>
5254
#include <optional>
5355
#include <set>
5456
#include <system_error>
57+
5558
using namespace clang;
5659
using namespace clang::driver;
5760
using namespace llvm::opt;
@@ -327,9 +330,11 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
327330
Diags.takeClient(), std::move(SerializedConsumer)));
328331
}
329332

330-
ProcessWarningOptions(Diags, *DiagOpts, /*ReportDiags=*/false);
333+
auto VFS = llvm::vfs::getRealFileSystem();
334+
ProcessWarningOptions(Diags, *DiagOpts, *VFS, /*ReportDiags=*/false);
331335

332-
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags);
336+
Driver TheDriver(Path, llvm::sys::getDefaultTargetTriple(), Diags,
337+
/*Title=*/"clang LLVM compiler", VFS);
333338
auto TargetAndMode = ToolChain::getTargetAndModeFromProgramName(ProgName);
334339
TheDriver.setTargetAndMode(TargetAndMode);
335340
// If -canonical-prefixes is set, GetExecutablePath will have resolved Path
@@ -345,10 +350,12 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
345350
if (!SetBackdoorDriverOutputsFromEnvVars(TheDriver))
346351
return 1;
347352

353+
auto ExecuteCC1WithContext =
354+
[&ToolContext](SmallVectorImpl<const char *> &ArgV) {
355+
return ExecuteCC1Tool(ArgV, ToolContext);
356+
};
348357
if (!UseNewCC1Process) {
349-
TheDriver.CC1Main = [ToolContext](SmallVectorImpl<const char *> &ArgV) {
350-
return ExecuteCC1Tool(ArgV, ToolContext);
351-
};
358+
TheDriver.CC1Main = ExecuteCC1WithContext;
352359
// Ensure the CC1Command actually catches cc1 crashes
353360
llvm::CrashRecoveryContext::Enable();
354361
}
@@ -427,7 +434,7 @@ static int clang_main(int Argc, char **Argv, const llvm::ToolContext &ToolContex
427434
if (!UseNewCC1Process && IsCrash) {
428435
// When crashing in -fintegrated-cc1 mode, bury the timer pointers, because
429436
// the internal linked list might point to already released stack frames.
430-
llvm::BuryPointer(llvm::TimerGroup::aquireDefaultGroup());
437+
llvm::BuryPointer(llvm::TimerGroup::acquireTimerGlobals());
431438
} else {
432439
// If any timers were active but haven't been destroyed yet, print their
433440
// results now. This happens in -disable-free mode.

0 commit comments

Comments
 (0)