Skip to content

Commit e384dfe

Browse files
pratikasharigcbot
authored andcommitted
Add support to emit relocations in debug info.
1 parent 894cb2f commit e384dfe

File tree

9 files changed

+295
-121
lines changed

9 files changed

+295
-121
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ bool EmitPass::runOnFunction(llvm::Function& F)
577577
DebugOpts.EmitDebugRanges = IGC_IS_FLAG_ENABLED(EmitDebugRanges);
578578
DebugOpts.EmitDebugLoc = IGC_IS_FLAG_ENABLED(EmitDebugLoc);
579579
DebugOpts.EmitOffsetInDbgLoc = IGC_IS_FLAG_ENABLED(EmitOffsetInDbgLoc);
580+
DebugOpts.EnableRelocation = IGC_IS_FLAG_ENABLED(EnableRelocations);
580581
IF_DEBUG_INFO(m_pDebugEmitter = IDebugEmitter::Create();)
581582
IF_DEBUG_INFO(m_pDebugEmitter->Initialize(
582583
vMod, DebugOpts, DebugInfoData::hasDebugInfo(m_currShader));)

IGC/DebugInfo/DwarfCompileUnit.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4949
#endif
5050
#include "llvm/MC/MCSection.h"
5151
#include "llvm/MC/MachineLocation.h"
52+
#include "llvm/MC/MCSymbol.h"
53+
#include "llvm/MC/MCSymbolELF.h"
5254
#include "llvm/IR/GlobalValue.h"
5355
#include "llvm/IR/IntrinsicInst.h"
5456
#include "common/LLVMWarningsPop.hpp"
@@ -297,6 +299,16 @@ void CompileUnit::addLabelAddress(DIE* Die, dwarf::Attribute Attribute, MCSymbol
297299
}
298300
}
299301

302+
void CompileUnit::addLabelLoc(DIE* Die, dwarf::Attribute Attribute, MCSymbol* Label)
303+
{
304+
if (Label != NULL)
305+
{
306+
DD->addArangeLabel(SymbolCU(this, Label));
307+
DIEValue* Value = new (DIEValueAllocator)DIELabel(Label);
308+
Die->addValue(Attribute, dwarf::DW_FORM_sec_offset, Value);
309+
}
310+
}
311+
300312
/// addOpAddress - Add a dwarf op address data and value using the
301313
/// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
302314
///
@@ -2129,8 +2141,19 @@ IGC::DIE* CompileUnit::constructVariableDIE(DbgVariable& DV, bool isScopeAbstrac
21292141
if (DD->IsDirectElfInput())
21302142
{
21312143
// Copy over references ranges to DotLocDebugEntries
2132-
Offset = DD->CopyDebugLoc(Offset);
2133-
addUInt(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset, Offset);
2144+
if (EmitSettings.EnableRelocation)
2145+
{
2146+
// Retrieve correct location value based on Offset.
2147+
// Then attach label corresponding to this offset
2148+
// to DW_AT_location attribute.
2149+
auto LocLabel = DD->CopyDebugLoc(Offset);
2150+
addLabelLoc(VariableDie, dwarf::DW_AT_location, LocLabel);
2151+
}
2152+
else
2153+
{
2154+
Offset = DD->CopyDebugLocNoReloc(Offset);
2155+
addUInt(VariableDie, dwarf::DW_AT_location, dwarf::DW_FORM_sec_offset, Offset);
2156+
}
21342157
if (DV.getDecorations().size() > 0)
21352158
{
21362159
addString(VariableDie, dwarf::DW_AT_description, DV.getDecorations());
@@ -2760,7 +2783,11 @@ void CompileUnit::emitHeader(const MCSection* ASection, const MCSymbol* ASection
27602783
// Emit ("DWARF version number");
27612784
Asm->EmitInt16(DD->getDwarfVersion());
27622785
// Emit ("Offset Into Abbrev. Section");
2763-
Asm->EmitSectionOffset(Asm->GetTempSymbol(/*ASection->getLabelBeginName()*/".debug_abbrev_begin"), ASectionSym);
2786+
if (EmitSettings.EnableRelocation)
2787+
// Emit 4-byte offset since we're using DWARF4 32-bit format
2788+
Asm->EmitLabelReference(Asm->GetTempSymbol(/*ASection->getLabelBeginName()*/".debug_abbrev_begin"), 4);
2789+
else
2790+
Asm->EmitSectionOffset(Asm->GetTempSymbol(/*ASection->getLabelBeginName()*/".debug_abbrev_begin"), ASectionSym);
27642791
// Emit ("Address Size (in bytes)");
27652792
Asm->EmitInt8(Asm->GetPointerSize());
27662793
}

IGC/DebugInfo/DwarfCompileUnit.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ namespace IGC
195195
///
196196
void addLabelAddress(DIE* Die, llvm::dwarf::Attribute Attribute, llvm::MCSymbol* Label);
197197

198+
// addLabelLoc - Add dwarf label attribute data and value using DW_FORM_sec_offset.
199+
void addLabelLoc(DIE* Die, llvm::dwarf::Attribute Attribute, llvm::MCSymbol* Label);
200+
198201
/// addOpAddress - Add a dwarf op address data and value using the
199202
/// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
200203
///

0 commit comments

Comments
 (0)