[PATCH] D99850: [WIP/RFC] lld LTO drops variables in namespaces from .debug_names

Jan Kratochvil via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 3 17:59:58 PDT 2021


jankratochvil created this revision.
jankratochvil added reviewers: dblaikie, aprantl, labath.
jankratochvil added a project: LLVM.
Herald added subscribers: steven_wu, hiraditya, inglorion.
jankratochvil requested review of this revision.

Adding `-flto` will drop variable in namespace from `.debug_names`:

  echo 'namespace N { int varname; int func() { return varname; } } int main(){ N::func(); }'|clang++ -Wall -Werror -gdwarf-5 -gpubnames -fuse-ld=lld -flto -x c++ -;llvm-dwarfdump -debug-names

In `.debug_names` `N::func` is always present but `N::varname` is present only when `-flto` is not used.
Unfortunately I do not know much more what to do with it so posting it FYI.
The testcase should use *.ll format but then I could not make it use LLD LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99850

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/test/DebugInfo/Generic/debug-names-namespace-lto.test


Index: llvm/test/DebugInfo/Generic/debug-names-namespace-lto.test
===================================================================
--- /dev/null
+++ llvm/test/DebugInfo/Generic/debug-names-namespace-lto.test
@@ -0,0 +1,8 @@
+RUN: echo 'namespace N { int varname; } extern "C" void _start(){}' | clang++ -Wall -Werror -gdwarf-5 -gpubnames -fuse-ld=lld -nostdlib -o %t -flto -x c++ -
+RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
+
+CHECK: String: 0x{{[0-9a-f]*}} "varname"
+CHECK-NEXT: Entry
+CHECK-NEXT: Abbrev:
+CHECK-NEXT: Tag: DW_TAG_variable
+CHECK-NEXT: DW_IDX_die_offset: 0x{{[0-9a-f]*}}
Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -228,8 +228,11 @@
       continue;
 
     // Nothing to describe without address or constant.
+    // In LLD Global is nullptr and Expr->Elements=={}.
+#if 0 // It breaks llvm/test/DebugInfo/X86/unattached-global.ll
     if (!Global && (!Expr || !Expr->isConstant()))
       continue;
+#endif
 
     if (Global && Global->isThreadLocal() &&
         !Asm->getObjFileLowering().supportDebugThreadLocalLocation())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99850.335119.patch
Type: text/x-patch
Size: 1248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210404/0e5607a6/attachment.bin>


More information about the llvm-commits mailing list