diff options
| author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2024-04-23 09:31:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 09:31:20 +0100 |
| commit | 0e44ffe817ae0f544199be70f468975fcc3ab5c5 (patch) | |
| tree | 74667fc320ef4732f47c5a9d392e457cef53df28 /llvm/lib/CodeGen | |
| parent | 55fc5eb95fbd26ac0539089cfc4e287ad7a233c3 (diff) | |
| download | llvm-0e44ffe817ae0f544199be70f468975fcc3ab5c5.tar.gz llvm-0e44ffe817ae0f544199be70f468975fcc3ab5c5.tar.bz2 llvm-0e44ffe817ae0f544199be70f468975fcc3ab5c5.zip | |
[DWARF] Add option to add linkage_names to call_origin declaration refs (#89640)
If -mllvm -add-linkage-names-to-external-call-origins is true then add
DW_AT_linkage_name attributes to DW_TAG_subprogram DIEs referenced by
DW_AT_call_origin attributes that would otherwise be omitted.
A debugger may use DW_TAG_call_origin attributes to determine whether any
frames in a callstack are missing due to optimisations (e.g. tail calls).
For example, say a() calls b() tail-calls c(), and you stop in your debugger
in c():
The callstack looks like this:
c()
a()
Looking "up" from c(), call site information can be found in a(). This includes
a DW_AT_call_origin referencing b()'s subprogram DIE, which means the call at
this call site was to b(), not c() where we are currently stopped. This
indicates b()'s frame has been lost due to optimisation (or is misleading due
to ICF).
This patch makes it easier for a debugger to check whether the referenced
DIE describes the target function or not, for example by comparing the referenced
function name to the current frame.
There's already an option to apply DW_AT_linkage_name in a targeted manner:
-dwarf-linkage-names=Abstract, which limits adding DW_AT_linkage_names to
abstract subprogram DIEs (this is default for SCE tuning).
The new flag shouldn't affect non-SCE-tuned behaviour whether it is enabled
or not because the non-SCE-tuned behaviour is to always add linkage names to
subprogram DIEs.
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 14f2a363f9be..6022afbae574 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -32,6 +32,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbolWasm.h" #include "llvm/MC/MachineLocation.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" @@ -42,6 +43,20 @@ using namespace llvm; +/// Query value using AddLinkageNamesToDeclCallOriginsForTuning. +cl::opt<cl::boolOrDefault> AddLinkageNamesToDeclCallOrigins( + "add-linkage-names-to-declaration-call-origins", cl::Hidden, + cl::desc("Add DW_AT_linkage_name to function declaration DIEs " + "referenced by DW_AT_call_origin attributes. Enabled by default " + "for -gsce debugger tuning.")); + +static bool AddLinkageNamesToDeclCallOriginsForTuning(const DwarfDebug *DD) { + bool EnabledByDefault = DD->tuneForSCE(); + if (EnabledByDefault) + return AddLinkageNamesToDeclCallOrigins != cl::boolOrDefault::BOU_FALSE; + return AddLinkageNamesToDeclCallOrigins == cl::boolOrDefault::BOU_TRUE; +} + static dwarf::Tag GetCompileUnitType(UnitKind Kind, DwarfDebug *DW) { // According to DWARF Debugging Information Format Version 5, @@ -1260,6 +1275,12 @@ DIE &DwarfCompileUnit::constructCallSiteEntryDIE(DIE &ScopeDIE, } else { DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP); assert(CalleeDIE && "Could not create DIE for call site entry origin"); + if (AddLinkageNamesToDeclCallOriginsForTuning(DD) && + !CalleeSP->isDefinition() && + !CalleeDIE->findAttribute(dwarf::DW_AT_linkage_name)) { + addLinkageName(*CalleeDIE, CalleeSP->getLinkageName()); + } + addDIEEntry(CallSiteDIE, getDwarf5OrGNUAttr(dwarf::DW_AT_call_origin), *CalleeDIE); } |
