[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
Sun Apr 4 15:28:10 PDT 2021


jankratochvil planned changes to this revision.
jankratochvil added a comment.

In D99850#2667839 <https://reviews.llvm.org/D99850#2667839>, @dblaikie wrote:

> Yeah, that looks like it breaks the unattached-global.ll because this causes a DW_AT_location to be added (probably with some kind of broken/empty expression) for a variable without a location/that's been optimized away.

I did not expect that but IMO `unattached-global.ll` is wrong (since its inception in D20147 <https://reviews.llvm.org/D20147>):

  !4 = !DIExpression(DW_OP_plus_uconst, 4)
                  DW_AT_location	(DW_OP_plus_uconst 0x4)

That is not a valid DWARF expression for `DW_TAG_variable`. There should be an empty DWARF expression (or completely missing `DW_AT_location`), right?

> How's the index behavior compare to GCC's debug_names behavior under similar circumstances? Or llvm's behavior with a static (file-local) variable that's similarly optimized away?

GCC cannot produce `.debug_names`. In GNU Toolchain `.debug_names` is produced by GDB. I wrote the GDB `.debug_names` producer+consumer but it took a year before it got accepted and then I could+did already switch to LLDB. GDB `.debug_names` format is correct but semantically it is wrong (it is now just a dump of GDB's internal `ManualDWARFIndex`). I planned to semantically fix it after the format producer+consumer gets accepted. For example one needs to fix `.debug_names` linkage name which is now in demangled form there, it should be mangled according to DWARF-5. Currently `.debug_names` is not in use, GDB is still using `.gdb_index` (which is also produced post-compilation by `gdb-add-index` and not by `GCC`. My less-priority plan is to make `.debug_names` format of LLVM+GDB compatible so that Linux OSes do not need to carry both `.gdb_index` and `.debug_names`.

LLVM does not produce `N::i` for an optimized-out variable:

  (set -ex;echo 'namespace N { const int i=42; } int main(void) { return N::i; }'|clang -g -gdwarf-5 -gpubnames -O2 -fuse-ld=lld -flto -x c++ -;llvm-dwarfdump -debug-info -debug-names)
        String: 0x0000002c "i"
          Tag: DW_TAG_variable
        String: 0x00000030 "N"
          Tag: DW_TAG_namespace

Which is correct because such variable has no linkage name. Unaware how `DW_IDX_parent` could be used for effective lookups, DWARF-5 spec does not describe it. This means `N::i` is missing in the index.

GDB does produce `N::i` but that is not mangled and therefore invalid according to the DWARF-5 spec:

  (set -ex;echo 'namespace N { const int i=42; } int main(void) { return N::i; }'|g++ -g -O2 -x c++ -;gdb-add-index -dwarf-5 ./a.out;llvm-dwarfdump -debug-info -debug-names)
        String: 0x00000067 "N::i" // invalid as it should have been mangled but then this variable does not have linkage name
          Tag: DW_TAG_variable
        String: 0x00000070 "N"
          Tag: DW_TAG_typedef // that should be DW_TAG_namespace but GDB IR is insufficient for that
  // missing entry for "i"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99850/new/

https://reviews.llvm.org/D99850



More information about the llvm-commits mailing list