Skip to content

Commit ea5ab51

Browse files
piotrgkurekigcbot
authored andcommitted
Member initialization, asserts.
1 parent 5e7e7f7 commit ea5ab51

File tree

6 files changed

+68
-55
lines changed

6 files changed

+68
-55
lines changed

IGC/AdaptorOCL/CLElfLib/ElfReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const SElf64SectionHeader* CElfReader::GetSectionHeader(
247247
{
248248
pCurrentName = GetSectionName(i);
249249

250-
if (pSectionName && (strcmp(pSectionName, pCurrentName) == 0))
250+
if (pSectionName && pCurrentName && (strcmp(pSectionName, pCurrentName) == 0))
251251
{
252252
pSectionHeader = GetSectionHeader(i);
253253
break;

IGC/AdaptorOCL/OCL/sp/zebin_builder.cpp

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -663,63 +663,68 @@ void ZEBinaryBuilder::addElfSections(void* elfBin, size_t debugDataSize)
663663
{
664664
// Get section header to filter some section types.
665665
const SElf64SectionHeader* sectionHeader = elfReader->GetSectionHeader(elfSectionIdx);
666-
667-
if (sectionHeader->Type == ELF::SHT_REL)
668-
{
669-
IGC_ASSERT_MESSAGE(false, "ELF file relocation sections w/o addend not supported");
670-
continue;
671-
}
672-
else if (sectionHeader->Type == ELF::SHT_RELA)
666+
if (sectionHeader != nullptr)
673667
{
674-
int relocEntrySize = (entrySize == 64) ? sizeof(struct ELF::Elf64_Rela) : sizeof(struct ELF::Elf32_Rela);
675-
IGC_ASSERT_MESSAGE((secDataSize % relocEntrySize) == 0, "Incorrect relocation section size");
676-
IGC_ASSERT_MESSAGE((entrySize == 64) || (entrySize == 32), "Incorrect relocation entry size");
677-
678-
if (entrySize == 64)
668+
if (sectionHeader->Type == ELF::SHT_REL)
669+
{
670+
IGC_ASSERT_MESSAGE(false, "ELF file relocation sections w/o addend not supported");
671+
continue;
672+
}
673+
else if (sectionHeader->Type == ELF::SHT_RELA)
679674
{
680-
uint64_t relocEntryNum = secDataSize / relocEntrySize;
681-
struct ELF::Elf64_Rela relocEntry;
675+
int relocEntrySize = (entrySize == 64) ? sizeof(struct ELF::Elf64_Rela) : sizeof(struct ELF::Elf32_Rela);
676+
IGC_ASSERT_MESSAGE((secDataSize % relocEntrySize) == 0, "Incorrect relocation section size");
677+
IGC_ASSERT_MESSAGE((entrySize == 64) || (entrySize == 32), "Incorrect relocation entry size");
682678

683-
for (uint64_t i = 0; i < relocEntryNum; i++)
679+
if (entrySize == 64)
684680
{
685-
relocEntry = *(struct ELF::Elf64_Rela*)(secData + i * relocEntrySize);
686-
const uint32_t symtabEntrySize = sizeof(ELF::Elf64_Sym);
687-
uint64_t symtabEntryNum = symtabSectionHeader->DataSize / symtabEntrySize;
681+
uint64_t relocEntryNum = secDataSize / relocEntrySize;
682+
struct ELF::Elf64_Rela relocEntry;
688683

689-
if ((relocEntry.r_info >> 32) < symtabEntryNum) // index
684+
for (uint64_t i = 0; i < relocEntryNum; i++)
690685
{
691-
ELF::Elf64_Sym symtabEntry;
692-
char* symName = NULL;
693-
// To find a symbol name of relocation for adding to zeBinary, first we have to do
694-
// a lookup into .symtab then we have to find this name in .strtab.
695-
getElfSymbol(elfReader, relocEntry.r_info >> 32 /*index*/, symtabEntry, symName);
696-
697-
vISA::ZESymEntry zeSym(
698-
(vISA::GenSymType)symtabEntry.st_info,
699-
(uint32_t)symtabEntry.st_value,
700-
(uint32_t)symtabEntry.st_size,
701-
symName); // Symbol's name
702-
703-
// If .rela.foo is being processed then find zeBinary section ID of previously added .foo section
704-
ZEELFObjectBuilder::SectionID nonRelaSectionID =
705-
mBuilder.getSectionIDBySectionName(elfReader->GetSectionName(elfSectionIdx) + sizeof(".rela") - 1);
706-
707-
mBuilder.addSymbol(zeSym.s_name, zeSym.s_offset, zeSym.s_size, getSymbolElfBinding(zeSym),
708-
getSymbolElfType(zeSym), nonRelaSectionID);
709-
mBuilder.addRelocation(relocEntry.r_offset, zeSym.s_name, R_TYPE_ZEBIN::R_ZE_SYM_ADDR, nonRelaSectionID);
686+
relocEntry = *(struct ELF::Elf64_Rela*)(secData + i * relocEntrySize);
687+
const uint32_t symtabEntrySize = sizeof(ELF::Elf64_Sym);
688+
uint64_t symtabEntryNum = symtabSectionHeader->DataSize / symtabEntrySize;
689+
690+
if ((relocEntry.r_info >> 32) < symtabEntryNum) // index
691+
{
692+
ELF::Elf64_Sym symtabEntry;
693+
char* symName = NULL;
694+
// To find a symbol name of relocation for adding to zeBinary, first we have to do
695+
// a lookup into .symtab then we have to find this name in .strtab.
696+
getElfSymbol(elfReader, relocEntry.r_info >> 32 /*index*/, symtabEntry, symName);
697+
698+
vISA::ZESymEntry zeSym(
699+
(vISA::GenSymType)symtabEntry.st_info,
700+
(uint32_t)symtabEntry.st_value,
701+
(uint32_t)symtabEntry.st_size,
702+
symName); // Symbol's name
703+
704+
// If .rela.foo is being processed then find zeBinary section ID of previously added .foo section
705+
ZEELFObjectBuilder::SectionID nonRelaSectionID =
706+
mBuilder.getSectionIDBySectionName(elfReader->GetSectionName(elfSectionIdx) + sizeof(".rela") - 1);
707+
708+
mBuilder.addSymbol(zeSym.s_name, zeSym.s_offset, zeSym.s_size, getSymbolElfBinding(zeSym),
709+
getSymbolElfType(zeSym), nonRelaSectionID);
710+
mBuilder.addRelocation(relocEntry.r_offset, zeSym.s_name, R_TYPE_ZEBIN::R_ZE_SYM_ADDR, nonRelaSectionID);
711+
}
710712
}
711713
}
714+
else // entrySize == 32
715+
{
716+
IGC_ASSERT_MESSAGE(false, "ELF 64-bit entry size supported only");
717+
}
712718
}
713-
else // entrySize == 32
719+
else if (const char* sectionName = elfReader->GetSectionName(elfSectionIdx))
714720
{
715-
IGC_ASSERT_MESSAGE(false, "ELF 64-bit entry size supported only");
721+
if (memcmp(sectionName, ".text", sizeof(".text") - 1))
722+
{
723+
// Non-empty, non-relocation and non-text debug section to be copied from ELF to zeBinary.
724+
zeBinSectionID = mBuilder.addSectionDebug(sectionName, (uint8_t*)secData, secDataSize); // no padding, no alignment
725+
}
716726
}
717727
}
718-
else if (memcmp(elfReader->GetSectionName(elfSectionIdx), ".text", sizeof(".text") - 1))
719-
{
720-
// Non-empty, non-relocation and non-text debug section to be copied from ELF to zeBinary.
721-
zeBinSectionID = mBuilder.addSectionDebug(elfReader->GetSectionName(elfSectionIdx), (uint8_t*)secData, secDataSize); // no padding, no alignment
722-
}
723728
}
724729
}
725730
}

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,9 +3255,9 @@ namespace IGC
32553255

32563256
// As an heuristic we only match saturate if the instruction has one use
32573257
// to avoid duplicating expensive instructions and increasing reg pressure
3258-
// without improve code quality this may be refined in the future
3258+
// without improve code quality this may be refined in the future.
32593259
if (llvm::Instruction* sourceInst = llvm::cast<llvm::Instruction>(source);
3260-
sourceInst->hasOneUse() && SupportsSaturate(sourceInst))
3260+
sourceInst && sourceInst->hasOneUse() && SupportsSaturate(sourceInst))
32613261
{
32623262
if (llvm::BinaryOperator* binaryOpInst = llvm::dyn_cast<llvm::BinaryOperator>(source);
32633263
binaryOpInst && (binaryOpInst->getOpcode() == llvm::BinaryOperator::BinaryOps::Add) && isUnsigned)

IGC/Compiler/FixResourcePtr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ Value* FixResourcePtr::GetByteOffset(Instruction* eltPtr)
250250
IGC_ASSERT(eltPtr->getNumOperands() == 2);
251251
Value* ptrOp = eltPtr->getOperand(0);
252252
PointerType* ptrTy = dyn_cast<PointerType>(ptrOp->getType());
253+
IGC_ASSERT(ptrTy);
253254
Value* eltIdx = eltPtr->getOperand(1);
254255

255256
builder->SetInsertPoint(eltPtr);

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/GenericAddressDynamicResolution.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ void GenericAddressDynamicResolution::resolveGAS(Instruction& I, Value* pointerO
253253

254254
IRBuilder<> builder(&I);
255255
PointerType* pointerType = dyn_cast<PointerType>(pointerOperand->getType());
256+
IGC_ASSERT( pointerType != nullptr );
256257
ConstantInt* privateTag = builder.getInt64(1); // tag 001
257258
ConstantInt* localTag = builder.getInt64(2); // tag 010
258259

@@ -378,6 +379,7 @@ void GenericAddressDynamicResolution::resolveGASWithoutBranches(Instruction& I,
378379
{
379380
IRBuilder<> builder(&I);
380381
PointerType* pointerType = dyn_cast<PointerType>(pointerOperand->getType());
382+
IGC_ASSERT( pointerType != nullptr );
381383

382384
Value* nonLocalLoad = nullptr;
383385

@@ -418,10 +420,12 @@ bool GenericAddressDynamicResolution::visitIntrinsicCall(CallInst& I)
418420
IGC_ASSERT(I.getNumArgOperands() == 1);
419421
Value* arg = I.getArgOperand(0);
420422
PointerType* dstType = dyn_cast<PointerType>(I.getType());
423+
IGC_ASSERT( dstType != nullptr );
421424
const unsigned targetAS = cast<PointerType>(I.getType())->getAddressSpace();
422425

423426
IRBuilder<> builder(&I);
424427
PointerType* pointerType = dyn_cast<PointerType>(arg->getType());
428+
IGC_ASSERT( pointerType != nullptr );
425429
ConstantInt* globalTag = builder.getInt64(0); // tag 000/111
426430
ConstantInt* privateTag = builder.getInt64(1); // tag 001
427431
ConstantInt* localTag = builder.getInt64(2); // tag 010

IGC/DebugInfo/VISADebugEmitter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,17 @@ void DebugEmitter::prepareElfForZeBinary(bool is64Bit, char* pElfBuffer, size_t
492492
}
493493
}
494494

495-
// ELF binary header also must be updated to reflect offsets changes.
496-
if (pElf64Header->SectionHeadersOffset > pSectionHeader->DataOffset)
495+
if (pSectionHeader)
497496
{
498-
pElf64Header->SectionHeadersOffset += kernelNameWithDotSize;
499-
}
500-
if (pElf64Header->ProgramHeadersOffset > pSectionHeader->DataOffset)
501-
{
502-
pElf64Header->ProgramHeadersOffset += kernelNameWithDotSize;
497+
// ELF binary header also must be updated to reflect offsets changes.
498+
if (pElf64Header->SectionHeadersOffset > pSectionHeader->DataOffset)
499+
{
500+
pElf64Header->SectionHeadersOffset += kernelNameWithDotSize;
501+
}
502+
if (pElf64Header->ProgramHeadersOffset > pSectionHeader->DataOffset)
503+
{
504+
pElf64Header->ProgramHeadersOffset += kernelNameWithDotSize;
505+
}
503506
}
504507
}
505508
else

0 commit comments

Comments
 (0)