@@ -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}
0 commit comments