[llvm-branch-commits] [lld] 1363dfa - [CodeView] Avoid emitting empty debug globals subsection.
Amy Huang via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 25 16:18:03 PST 2020
Author: Amy Huang
Date: 2020-11-25T16:13:32-08:00
New Revision: 1363dfaf3105470e1724ed1f17c6d9c0713f442e
URL: https://github.com/llvm/llvm-project/commit/1363dfaf3105470e1724ed1f17c6d9c0713f442e
DIFF: https://github.com/llvm/llvm-project/commit/1363dfaf3105470e1724ed1f17c6d9c0713f442e.diff
LOG: [CodeView] Avoid emitting empty debug globals subsection.
In https://reviews.llvm.org/D89072 I added static const data members
to the debug subsection for globals. It skipped emitting an S_CONSTANT if it
didn't have a value, which meant the subsection could be empty.
This patch fixes the empty subsection issue.
Differential Revision: https://reviews.llvm.org/D92049
Added:
lld/test/COFF/empty-subsection.s
llvm/test/DebugInfo/COFF/empty-globals-subsection.ll
Modified:
lld/COFF/PDB.cpp
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Removed:
################################################################################
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index 5e65eca5b9fe..36526de7796c 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -500,6 +500,9 @@ void PDBLinker::mergeSymbolRecords(TpiSource *source,
cantFail(symData.readBytes(0, symData.getLength(), symsBuffer));
SmallVector<SymbolScope, 4> scopes;
+ if (symsBuffer.empty())
+ warn("empty symbols subsection in " + file->getName());
+
// Iterate every symbol to check if any need to be realigned, and if so, how
// much space we need to allocate for them.
bool needsRealignment = false;
diff --git a/lld/test/COFF/empty-subsection.s b/lld/test/COFF/empty-subsection.s
new file mode 100644
index 000000000000..e573d5b57bdd
--- /dev/null
+++ b/lld/test/COFF/empty-subsection.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
+# RUN: lld-link /entry:main /debug /out:%t.exe %t.obj 2>&1 | FileCheck %s
+
+# CHECK: warning: empty symbols subsection
+
+.globl main
+.Lfunc_begin0:
+main:
+ xorl %eax, %eax
+ retq
+.Lfunc_end0:
+
+.section .debug$S,"dr"
+ .p2align 2
+ .long 4 # Debug section magic
+ .long 241 # Symbol subsection for globals
+ .long .Ltmp5-.Ltmp4 # Subsection size
+.Ltmp4:
+.Ltmp5:
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index 4d618cf3d687..b15e750aaf85 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -2150,10 +2150,13 @@ void CodeViewDebug::collectMemberInfo(ClassInfo &Info,
if (!DDTy->getName().empty()) {
Info.Members.push_back({DDTy, 0});
- // Collect static const data members.
+ // Collect static const data members with values.
if ((DDTy->getFlags() & DINode::FlagStaticMember) ==
- DINode::FlagStaticMember)
- StaticConstMembers.push_back(DDTy);
+ DINode::FlagStaticMember) {
+ if (DDTy->getConstant() && (isa<ConstantInt>(DDTy->getConstant()) ||
+ isa<ConstantFP>(DDTy->getConstant())))
+ StaticConstMembers.push_back(DDTy);
+ }
return;
}
@@ -3134,7 +3137,7 @@ void CodeViewDebug::emitStaticConstMemberList() {
dyn_cast_or_null<ConstantFP>(DTy->getConstant()))
Value = APSInt(CFP->getValueAPF().bitcastToAPInt(), true);
else
- continue;
+ llvm_unreachable("cannot emit a constant without a value");
std::string QualifiedName = getFullyQualifiedName(Scope, DTy->getName());
diff --git a/llvm/test/DebugInfo/COFF/empty-globals-subsection.ll b/llvm/test/DebugInfo/COFF/empty-globals-subsection.ll
new file mode 100644
index 000000000000..b6f3c9a752d0
--- /dev/null
+++ b/llvm/test/DebugInfo/COFF/empty-globals-subsection.ll
@@ -0,0 +1,29 @@
+; RUN: llc < %s | FileCheck %s
+
+; The debug info contains a struct with a non-const static member.
+; Check that we don't emit a symbol subsection for globals.
+
+; CHECK-NOT: Symbol subsection for globals
+
+; ModuleID = 'a.cpp'
+source_filename = "a.cpp"
+target triple = "x86_64-pc-windows-msvc19.25.28614"
+
+define dso_local i32 @main() {
+entry:
+ ret i32 0
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!8, !9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
+!1 = !DIFile(filename: "a.cpp", directory: "C:/path/to/test", checksumkind: CSK_MD5, checksum: "a1dbf3aabea9e8f9d1be48f60287942f")
+!2 = !{}
+!3 = !{!4}
+!4 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 5, size: 32, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !5, identifier: ".?AU?$A at J@@")
+!5 = !{!6}
+!6 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !4, file: !1, line: 6, baseType: !7, size: 32, flags: DIFlagStaticMember)
+!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!8 = !{i32 2, !"CodeView", i32 1}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
More information about the llvm-branch-commits
mailing list