Author: Prabhu Rajasekaran
Date: 2026-10-16T07:01:48Z
New Revision: 661ce2bed7a4e7a19679a99041c55fef53ce8c6b

URL: 
https://github.com/llvm/llvm-project/commit/661ce2bed7a4e7a19679a99041c55fef53ce8c6b
DIFF: 
https://github.com/llvm/llvm-project/commit/661ce2bed7a4e7a19679a99041c55fef53ce8c6b.diff

LOG: [CodeGen] Always emit CodeView compiler info for UEFI targets (#188383)

UEFI is based on the MSVC toolchain conventions. PR #142970 made Windows
targets always emit minimal CodeView compiler information (`S_OBJNAME`
and `S_COMPILE3`) even when debug info is otherwise disabled, matching
MSVC. Make UEFI targets behave the same way.

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/DebugInfo/CXX/coff.cpp
    clang/test/DebugInfo/Generic/version-coff.c
    llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/test/DebugInfo/COFF/uefi-nodebug.ll

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 00a82819681c14..4e0c8db06d05f6 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -628,10 +628,10 @@ CodeGenModule::CodeGenModule(ASTContext &C,
       CodeGenOpts.CoverageNotesFile.size() ||
       CodeGenOpts.CoverageDataFile.size())
     DebugInfo.reset(new CGDebugInfo(*this));
-  else if (getTriple().isOSWindows())
-    // On Windows targets, we want to emit compiler info even if debug info is
-    // otherwise disabled. Use a temporary CGDebugInfo instance to emit only
-    // basic compiler metadata.
+  else if (getTriple().isOSWindows() || getTriple().isUEFI())
+    // On Windows and UEFI targets, we want to emit compiler info even if debug
+    // info is otherwise disabled. Use a temporary CGDebugInfo instance to emit
+    // only basic compiler metadata.
     CGDebugInfo(*this);
 
   Block.GlobalUniqueCount = 0;
@@ -1433,7 +1433,7 @@ void CodeGenModule::Release() {
                               "StrictVTablePointersRequirement",
                               llvm::MDNode::get(VMContext, Ops));
   }
-  if (getModuleDebugInfo() || getTriple().isOSWindows())
+  if (getModuleDebugInfo() || getTriple().isOSWindows() || 
getTriple().isUEFI())
     // We support a single version in the linked module. The LLVM
     // parser will drop debug info with a 
diff erent version number
     // (and warn about it, too).

diff  --git a/clang/test/DebugInfo/CXX/coff.cpp 
b/clang/test/DebugInfo/CXX/coff.cpp
index 2535c5cc7511f6..591c317d0e10d1 100644
--- a/clang/test/DebugInfo/CXX/coff.cpp
+++ b/clang/test/DebugInfo/CXX/coff.cpp
@@ -32,6 +32,37 @@
 // CHECK-NEXT:   ]
 // CHECK-NEXT: ]
 
+// UEFI targets follow the MSVC toolchain conventions and emit the same
+// minimal compiler info.
+
+// RUN: %clang --target=x86_64-unknown-uefi -S -emit-llvm %s -o - | FileCheck 
--check-prefix=IR %s
+
+// RUN: %clang --target=x86_64-unknown-uefi -c %s -o %t.uefi.o
+// RUN: llvm-readobj --codeview %t.uefi.o | FileCheck --check-prefix=UEFI %s
+// UEFI:      CodeViewDebugInfo [
+// UEFI-NEXT:   Section: .debug$S ({{[0-9]+}})
+// UEFI-NEXT:   Magic: 0x4
+// UEFI-NEXT:   Subsection [
+// UEFI-NEXT:     SubSectionType: Symbols (0xF1)
+// UEFI-NEXT:     SubSectionSize:
+// UEFI-NEXT:     ObjNameSym {
+// UEFI-NEXT:       Kind: S_OBJNAME (0x1101)
+// UEFI-NEXT:       Signature: 0x0
+// UEFI-NEXT:       ObjectName:
+// UEFI-NEXT:     }
+// UEFI-NEXT:     Compile3Sym {
+// UEFI-NEXT:       Kind: S_COMPILE3 (0x113C)
+// UEFI-NEXT:       Language: Cpp (0x1)
+// UEFI-NEXT:       Flags [ (0x0)
+// UEFI-NEXT:       ]
+// UEFI-NEXT:       Machine: X64 (0xD0)
+// UEFI-NEXT:       FrontendVersion:
+// UEFI-NEXT:       BackendVersion:
+// UEFI-NEXT:       VersionName: {{.*}}clang version
+// UEFI-NEXT:     }
+// UEFI-NEXT:   ]
+// UEFI-NEXT: ]
+
 int main() {
   return 0;
 }

diff  --git a/clang/test/DebugInfo/Generic/version-coff.c 
b/clang/test/DebugInfo/Generic/version-coff.c
index 6497a58292362d..beddab75091d9b 100644
--- a/clang/test/DebugInfo/Generic/version-coff.c
+++ b/clang/test/DebugInfo/Generic/version-coff.c
@@ -1,6 +1,8 @@
 // REQUIRES: x86-registered-target
 // RUN: %clang --target=x86_64-windows -g -S -emit-llvm -o - %s | FileCheck %s
 // RUN: %clang --target=x86_64-windows -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang --target=x86_64-unknown-uefi -g -S -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang --target=x86_64-unknown-uefi -S -emit-llvm -o - %s | FileCheck 
%s
 int main (void) {
   return 0;
 }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp 
b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2f699d29725040..cbb339b2f7c629 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -627,9 +627,10 @@ bool AsmPrinter::doInitialization(Module &M) {
 
   if (MAI.doesSupportDebugInformation()) {
     bool EmitCodeView = M.getCodeViewFlag();
-    // On Windows targets, emit minimal CodeView compiler info even when debug
-    // info is disabled.
-    if ((Target.isOSWindows() || (Target.isUEFI() && EmitCodeView)) &&
+    // On Windows and UEFI targets, emit minimal CodeView compiler info even
+    // when debug info is disabled. UEFI follows the MSVC toolchain
+    // conventions, so it is treated the same way as Windows here.
+    if ((Target.isOSWindows() || Target.isUEFI()) &&
         M.getNamedMetadata("llvm.dbg.cu"))
       Handlers.push_back(std::make_unique<CodeViewDebug>(this));
     if (!EmitCodeView || M.getDwarfVersion()) {

diff  --git a/llvm/test/DebugInfo/COFF/uefi-nodebug.ll 
b/llvm/test/DebugInfo/COFF/uefi-nodebug.ll
index 92e5fd6b5796bb..faf2781c508196 100644
--- a/llvm/test/DebugInfo/COFF/uefi-nodebug.ll
+++ b/llvm/test/DebugInfo/COFF/uefi-nodebug.ll
@@ -1,8 +1,31 @@
 ; RUN: llc -filetype=obj -o - < %s | llvm-readobj --codeview - | FileCheck %s
-; Check that compiler info is not emitted when CodeView flag is not specified
+; Check that only basic compiler info is emitted for UEFI targets with
+; emissionKind NoDebug, matching the behavior of Windows targets.
 
 ; CHECK-NOT:  CodeViewTypes
-; CHECK-NOT:  CodeViewDebugInfo
+; CHECK:      CodeViewDebugInfo [
+; CHECK-NEXT:   Section: .debug$S (4)
+; CHECK-NEXT:   Magic: 0x4
+; CHECK-NEXT:   Subsection [
+; CHECK-NEXT:     SubSectionType: Symbols (0xF1)
+; CHECK-NEXT:     SubSectionSize: 0x2C
+; CHECK-NEXT:     ObjNameSym {
+; CHECK-NEXT:       Kind: S_OBJNAME (0x1101)
+; CHECK-NEXT:       Signature: 0x0
+; CHECK-NEXT:       ObjectName:
+; CHECK-NEXT:     }
+; CHECK-NEXT:     Compile3Sym {
+; CHECK-NEXT:       Kind: S_COMPILE3 (0x113C)
+; CHECK-NEXT:       Language: C (0x0)
+; CHECK-NEXT:       Flags [ (0x0)
+; CHECK-NEXT:       ]
+; CHECK-NEXT:       Machine: X64 (0xD0)
+; CHECK-NEXT:       FrontendVersion:
+; CHECK-NEXT:       BackendVersion:
+; CHECK-NEXT:       VersionName: clang
+; CHECK-NEXT:     }
+; CHECK-NEXT:   ]
+; CHECK-NEXT: ]
 
 source_filename = "empty"
 target datalayout = 
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to