[PATCH] D113465: [llvm-dwarfdump] Implementation of an add-on for handling LTO cases with CCU referencing

Dimitrije Milošević via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 00:09:36 PST 2021


dmilosevic141 created this revision.
dmilosevic141 added a reviewer: djtodoro.
Herald added subscribers: ormris, cmtice, steven_wu, hiraditya, inglorion.
Herald added a reviewer: jhenderson.
dmilosevic141 requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.

With link-time optimizations enabled, resulting //DWARF// may end up containing cross-compile-unit references (through the //DW_AT_abstract_origin// attribute).
Consider the following example:

  // sum.c
  __attribute__((always_inline)) int sum(int a, int b)
  {
       return a + b;
  }
  // main.c
  extern int sum(int, int);
  int main()
  {
       int a = 5, b = 10, c = sum(a, b);
       return 0;
  }

Compiled as follows:

  $ clang -g -flto -fuse-ld=lld main.c sum.c -o main

Results in the following //DWARF//:

  -- sum.c compile unit: abstract instance tree
  ...
  0x000000b0:   DW_TAG_subprogram
                  DW_AT_name	("sum")
                  DW_AT_decl_file	("sum.c")
                  DW_AT_decl_line	(1)
                  DW_AT_prototyped	(true)
                  DW_AT_type	(0x000000d3 "int")
                  DW_AT_external	(true)
                  DW_AT_inline	(DW_INL_inlined)
  
  0x000000bc:     DW_TAG_formal_parameter
                    DW_AT_name	("a")
                    DW_AT_decl_file	("sum.c")
                    DW_AT_decl_line	(1)
                    DW_AT_type	(0x000000d3 "int")
  
  0x000000c7:     DW_TAG_formal_parameter
                    DW_AT_name	("b")
                    DW_AT_decl_file	("sum.c")
                    DW_AT_decl_line	(1)
                    DW_AT_type	(0x000000d3 "int")
  ...
  -- main.c compile unit: concrete inlined instance tree
  ...
  0x0000006d:     DW_TAG_inlined_subroutine
                    DW_AT_abstract_origin	(0x00000000000000b0 "sum")
                    DW_AT_low_pc	(0x00000000002016ef)
                    DW_AT_high_pc	(0x00000000002016f1)
                    DW_AT_call_file	("main.c")
                    DW_AT_call_line	(5)
                    DW_AT_call_column	(0x19)
  
  0x00000081:       DW_TAG_formal_parameter
                      DW_AT_location	(DW_OP_reg0 RAX)
                      DW_AT_abstract_origin	(0x00000000000000bc "a")
  
  0x00000088:       DW_TAG_formal_parameter
                      DW_AT_location	(DW_OP_reg2 RCX)
                      DW_AT_abstract_origin	(0x00000000000000c7 "b")
  ...

Note that each entry within the concrete inlined instance tree in the //main.c// compile unit has a //DW_AT_abstract_origin// attribute which refers to a corresponding entry within the abstract instance tree in the //sum.c// compile unit.
//llvm-dwarfdump// (its //--statistics// option, to be precise) did not properly report //DW_TAG_formal_parameter//s///DW_TAG_variable//s which had 0% location coverage, mainly because information about abstract instance trees and their parameters/variables was stored locally - just for the compile unit being currently processed, rather than globally - for all compile units.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113465

Files:
  llvm/test/tools/llvm-dwarfdump/X86/LTO_CCU_zero_loc_cov.ll
  llvm/tools/llvm-dwarfdump/Statistics.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113465.385706.patch
Type: text/x-patch
Size: 19325 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211109/01f24ee8/attachment.bin>


More information about the llvm-commits mailing list