[llvm] [llc] Initialize TargetLoweringObjectFile in the NewPM CodeGen path (PR #218750)
Alex MacLean via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 11:56:15 PDT 2026
https://github.com/AlexMaclean created https://github.com/llvm/llvm-project/pull/218750
Initialize the `TargetLoweringObjectFile` before building the NewPM codegen pipeline, matching what the legacy path already does in `llc.cpp`.
https://github.com/llvm/llvm-project/blob/207362dd503979f3d74a1ebef0cfbdcf6e7be4c5/llvm/tools/llc/llc.cpp#L861-L862
In the NewPM path the TLOF is only initialized by `AsmPrinter::doInitialization`, reached through the pass added by `addAsmPrinterBegin`. `CodeGenPassBuilder::buildPipeline` only adds that pass when `willCompleteCodeGenPipeline()` is true, so under `-stop-after` or `-stop-before` the TLOF keeps a null `Mangler` and a null `MCContext`. Targets that need a mangled name or a symbol during ISel then crash.
>From 207362dd503979f3d74a1ebef0cfbdcf6e7be4c5 Mon Sep 17 00:00:00 2001
From: Alex Maclean <amaclean at nvidia.com>
Date: Tue, 25 Aug 2026 11:50:58 -0700
Subject: [PATCH] [llc] Initialize TargetLoweringObjectFile in the NewPM
CodeGen path
---
llvm/tools/llc/NewPMDriver.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index cc13f2f545549..a44a36e4c9af8 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -43,6 +43,7 @@
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Target/CGPassBuilderOption.h"
+#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
@@ -118,6 +119,8 @@ int llvm::compileModuleWithNewPM(
MachineModuleInfo MMI(Target.get());
+ Target->getObjFileLowering()->Initialize(MMI.getContext(), *Target);
+
PassInstrumentationCallbacks PIC;
StandardInstrumentations SI(Context, Opt.DebugPM,
VK == VerifierKind::EachPass);
More information about the llvm-commits
mailing list