[PATCH] D70350: [DWARF] Allow cross-CU references of subprogram definitions
Vedant Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 2 17:02:06 PST 2019
vsk added a comment.
This is the problem: https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp#L954.
When llvm emits call site info, it creates the callee DIE if one doesn't exist. In an LTO build this only happens in CUs where a definition DISubprogram for the callee is available [1]. The issue with this is that the definition DIE is attached to the wrong parent/context DIE. The following assert catches the problem:
DIE *DwarfUnit::getOrCreateContextDIE(const DIScope *Context) {
- if (!Context || isa<DIFile>(Context))
+ if (!Context || isa<DIFile>(Context)) {
+ assert((!Context || CUNode->getFile() == Context) &&
+ "Can't find a suitable context DIE");
return &getUnitDie();
+ }
Once the definition is created, we do things like attach low/high pc ranges and/or inlined subroutines to it, assuming that it's nested within the correct CU when it's not. While this is a pre-existing issue, this patch surfaced the verifier failures because subprogram definitions were not shared pre-patch.
Some possible solutions:
1. Lazily get or create the //correct// context CU for definition subprograms, so that the definitions can be constructed properly. Not sure if it'd be a layering issue to call `DwarfDebug::getOrCreateDwarfCompileUnit` from within `DwarfCompileUnit`.
2. When a DIE for a subprogram is unavailable, insist on creating a fresh //declaration// DIE nested within the caller's CU (even if we have a definition DISubprogram at hand). Compared to (1) we'd emit a little extra debug info.
3. Maintain a list of unfinished call sites (pairs of `{DIE *, DISubprogram *}`) in DwarfDebug. Set DW_AT_call_origin within the unfinished call sites after all subprogram definition DIEs have been created.
Please let me know if you have alternate/preferred approaches. I think I'll try (3) tomorrow.
[1] When a //declaration// DIE for a callee is available, the call site info is emitted correctly today already. DIEs for declarations are created ahead of time in `DwarfDebug::getOrCreateDwarfCompileUnit`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70350/new/
https://reviews.llvm.org/D70350
More information about the llvm-commits
mailing list