Commit 02a2d81b authored by Trifunovic, Konrad's avatar Trifunovic, Konrad Committed by Paige, Alexander

Revert “Insert Program Header Table in elf. Fix elf header to make it gdb

compliant. Added is_stmt for 1-step elf”

This reverts commit 3701f053

Change-Id: I822f45b239a8b2d399d1f658b29645d1cda2b9fb
parent 3701f053
......@@ -1456,7 +1456,6 @@ DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract)
return VariableDie;
}
bool addDecoration = false;
if (m_pModule->isDirectElfInput)
{
if (Loc.HasSurface())
......@@ -1476,8 +1475,6 @@ DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract)
buildPointer(DV, VariableDie, &Loc);
else
buildGeneral(DV, VariableDie, &Loc);
addDecoration = true;
}
else
{
......@@ -1543,29 +1540,23 @@ DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract)
// Now attach the location information to the DIE.
addBlock(VariableDie, dwarf::DW_AT_location, Block);
addDecoration = true;
}
DV.setDIE(VariableDie);
}
if (Loc.IsVectorized())
{
// Add description stating whether variable was vectorized in VISA
addString(VariableDie, dwarf::DW_AT_description, "vectorized");
uint16_t simdSize = m_pModule->GetSIMDSize();
addString(VariableDie, dwarf::DW_AT_description,
simdSize == 8 ? "simd8" : simdSize == 16 ? "simd16" : "???");
}
if (addDecoration)
{
if (Loc.IsVectorized())
{
// Add description stating whether variable was vectorized in VISA
addString(VariableDie, dwarf::DW_AT_description, "vectorized");
uint16_t simdSize = m_pModule->GetSIMDSize();
addString(VariableDie, dwarf::DW_AT_description,
simdSize == 8 ? "simd8" : simdSize == 16 ? "simd16" : "???");
if (Loc.IsInGlobalAddrSpace())
{
addString(VariableDie, dwarf::DW_AT_description, "global");
}
}
if (Loc.IsInGlobalAddrSpace())
{
addString(VariableDie, dwarf::DW_AT_description, "global");
}
DV.setDIE(VariableDie);
}
return VariableDie;
}
......
......@@ -593,31 +593,6 @@ namespace IGC
return &DISPToFunction;
}
bool isStmtExists(unsigned int line, llvm::DILocation* inlinedAt, bool add)
{
auto it = isStmtSet.find(line);
if (it == isStmtSet.end())
{
if (add)
{
std::vector<llvm::DILocation*> v = { inlinedAt };
isStmtSet.insert(std::make_pair(line, v));
}
return false;
}
for (auto& iat : (*it).second)
{
if (iat == inlinedAt)
return true;
}
if (add)
(*it).second.push_back(inlinedAt);
return false;
}
unsigned int lowPc = 0, highPc = 0;
DbgDecoder* getDecodedDbg() { return decodedDbg; }
......
......@@ -534,13 +534,8 @@ StreamEmitter::StreamEmitter(raw_pwrite_stream& outStream, const std::string& da
bool is64Bit = GetPointerSize() == 8;
uint8_t osABI = MCELFObjectTargetWriter::getOSABI(triple.getOS());
// Earlier eMachine was set to ELF::EM_X86_64 or ELF::EM_386
// This creates a problem for gdb so it is now set to 182
// which is an encoding reserved for Intel. It is not part of
// the enum so its value in inlined.
#define EM_INTEL_GEN 182
uint16_t eMachine = EM_INTEL_GEN;
bool hasRelocationAddend = is64Bit;
uint16_t eMachine = is64Bit ? ELF::EM_X86_64 : ELF::EM_386;
bool hasRelocationAddend = eMachine != ELF::EM_386;
std::unique_ptr<MCAsmBackend> pAsmBackend
= llvm::make_unique<VISAAsmBackend>(GetTargetTriple(), is64Bit);
std::unique_ptr<MCELFObjectTargetWriter> pTargetObjectWriter
......
......@@ -42,12 +42,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "llvm/IR/Module.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Verifier.h"
#include "llvm/MC/MCDwarf.h"
#if LLVM_VERSION_MAJOR == 4
#include "llvm/Support/ELF.h"
#elif LLVM_VERSION_MAJOR >= 7
#include "llvm/BinaryFormat/ELF.h"
#endif
#include "common/LLVMWarningsPop.hpp"
#include "Compiler/DebugInfo/DebugInfoUtils.hpp"
......@@ -244,7 +238,7 @@ void DebugEmitter::Finalize(void *&pBuffer, unsigned int &size, bool finalize)
}
void* genxISA = m_pVISAModule->m_pShader->ProgramOutput()->m_programBin;
DebugLoc prevSrcLoc = DebugLoc();
unsigned int prevSrcLine = 0;
unsigned int pc = prevLastGenOff;
for (auto item : GenISAToVISAIndex)
{
......@@ -287,17 +281,12 @@ void DebugEmitter::Finalize(void *&pBuffer, unsigned int &size, bool finalize)
auto scope = loc->getScope();
auto src = m_pDwarfDebug->getOrCreateSourceID(scope->getFilename(), scope->getDirectory(), m_pStreamEmitter->GetDwarfCompileUnitID());
if (loc != prevSrcLoc)
if (loc.getLine() != prevSrcLine)
{
unsigned int Flags = 0;
if (!m_pDwarfDebug->isStmtExists(loc.getLine(), loc.getInlinedAt(), true))
{
Flags |= DWARF2_FLAG_IS_STMT;
}
m_pStreamEmitter->EmitDwarfLocDirective(src, loc.getLine(), loc.getCol(), Flags, 0, 0, scope->getFilename());
m_pStreamEmitter->EmitDwarfLocDirective(src, loc.getLine(), loc.getCol(), 1, 0, 0, scope->getFilename());
}
prevSrcLoc = loc;
prevSrcLine = loc.getLine();
}
}
}
......@@ -353,83 +342,14 @@ void DebugEmitter::Finalize(void *&pBuffer, unsigned int &size, bool finalize)
m_pStreamEmitter->Finalize();
size = m_outStream.str().size();
// Add program header table to satisfy latest gdb
unsigned int is64Bit = (GetVISAModule()->GetModule()->getDataLayout().getPointerSize() == 8);
unsigned int phtSize = sizeof(llvm::ELF::Elf32_Phdr);
if (is64Bit)
phtSize = sizeof(llvm::ELF::Elf64_Phdr);
pBuffer = (char*)malloc((size + phtSize) * sizeof(char));
pBuffer = (char*)malloc(size * sizeof(char));
memcpy_s(pBuffer, size * sizeof(char), m_outStream.str().data(), size);
writeProgramHeaderTable(is64Bit, pBuffer, size);
setElfType(is64Bit, pBuffer);
size += phtSize;
// Reset all members and prepare for next beginModule() call.
Reset();
}
}
void DebugEmitter::setElfType(bool is64Bit, void* pBuffer)
{
// Set 1-step elf's e_type to ET_EXEC
if (!pBuffer)
return;
if (is64Bit)
{
void* etypeOff = ((char*)pBuffer) + (offsetof(llvm::ELF::Elf64_Ehdr, e_type));
*((llvm::ELF::Elf64_Half*)etypeOff) = llvm::ELF::ET_EXEC;
}
else
{
void* etypeOff = ((char*)pBuffer) + (offsetof(llvm::ELF::Elf32_Ehdr, e_type));
*((llvm::ELF::Elf32_Half*)etypeOff) = llvm::ELF::ET_EXEC;
}
}
void DebugEmitter::writeProgramHeaderTable(bool is64Bit, void* pBuffer, unsigned int size)
{
// Write program header table at end of elf
if (is64Bit)
{
llvm::ELF::Elf64_Phdr hdr;
hdr.p_type = llvm::ELF::PT_LOAD;
hdr.p_flags = 0;
hdr.p_offset = 0;
hdr.p_vaddr = 0;
hdr.p_paddr = 0;
hdr.p_filesz = size;
hdr.p_memsz = size;
hdr.p_align = 4;
void* phOffAddr = ((char*)pBuffer) + (offsetof(llvm::ELF::Elf64_Ehdr, e_phoff));
*(llvm::ELF::Elf64_Off*)(phOffAddr) = size;
((char*)pBuffer)[offsetof(llvm::ELF::Elf64_Ehdr, e_phentsize)] = sizeof(llvm::ELF::Elf64_Phdr);
((char*)pBuffer)[offsetof(llvm::ELF::Elf64_Ehdr, e_phnum)] = 1;
memcpy_s((char*)pBuffer + size, sizeof(llvm::ELF::Elf64_Phdr), &hdr, sizeof(hdr));
}
else
{
llvm::ELF::Elf32_Phdr hdr;
hdr.p_type = llvm::ELF::PT_LOAD;
hdr.p_offset = 0;
hdr.p_vaddr = 0;
hdr.p_paddr = 0;
hdr.p_filesz = size;
hdr.p_memsz = size;
hdr.p_flags = 0;
hdr.p_align = 4;
void* phOffAddr = ((char*)pBuffer) + (offsetof(llvm::ELF::Elf32_Ehdr, e_phoff));
*(llvm::ELF::Elf32_Off*)(phOffAddr) = size;
((char*)pBuffer)[offsetof(llvm::ELF::Elf32_Ehdr, e_phentsize)] = sizeof(llvm::ELF::Elf32_Phdr);
((char*)pBuffer)[offsetof(llvm::ELF::Elf32_Ehdr, e_phnum)] = 1;
memcpy_s((char*)pBuffer + size, sizeof(llvm::ELF::Elf32_Phdr), &hdr, sizeof(hdr));
}
}
void DebugEmitter::BeginInstruction(Instruction *pInst)
{
BeginEncodingMark();
......
......@@ -116,9 +116,6 @@ private:
std::vector<VISAModule*> toFree;
unsigned int lastGenOff = 0;
void writeProgramHeaderTable(bool is64Bit, void* pBuffer, unsigned int size);
void setElfType(bool is64Bit, void* pBuffer);
};
} // namespace IGC
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment