@@ -663,63 +663,68 @@ void ZEBinaryBuilder::addElfSections(void* elfBin, size_t debugDataSize)
663
663
{
664
664
// Get section header to filter some section types.
665
665
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 )
673
667
{
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)
679
674
{
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" );
682
678
683
- for ( uint64_t i = 0 ; i < relocEntryNum; i++ )
679
+ if (entrySize == 64 )
684
680
{
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;
688
683
689
- if ((relocEntry. r_info >> 32 ) < symtabEntryNum) // index
684
+ for ( uint64_t i = 0 ; i < relocEntryNum; i++)
690
685
{
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
+ }
710
712
}
711
713
}
714
+ else // entrySize == 32
715
+ {
716
+ IGC_ASSERT_MESSAGE (false , " ELF 64-bit entry size supported only" );
717
+ }
712
718
}
713
- else // entrySize == 32
719
+ else if ( const char * sectionName = elfReader-> GetSectionName (elfSectionIdx))
714
720
{
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
+ }
716
726
}
717
727
}
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
- }
723
728
}
724
729
}
725
730
}
0 commit comments