feature: Adding support for empty .text section

If .text section is empty then ignore it.

Related-To: NEO-12229

Signed-off-by: Chodor, Jaroslaw <jaroslaw.chodor@intel.com>
This commit is contained in:
Chodor, Jaroslaw
2025-07-16 15:01:46 +00:00
committed by Compute-Runtime-Automation
parent 81f4b885f1
commit b612301b72
2 changed files with 23 additions and 1 deletions

View File

@@ -249,7 +249,9 @@ DecodeError extractZebinSections(NEO::Elf::Elf<numBits> &elf, ZebinSections<numB
if (sectionName.startsWith(Elf::SectionNames::textPrefix.data())) {
out.textKernelSections.push_back(&elfSectionHeader);
} else if (sectionName == Elf::SectionNames::text) {
out.textSections.push_back(&elfSectionHeader);
if (false == elfSectionHeader.data.empty()) {
out.textSections.push_back(&elfSectionHeader);
}
} else if (sectionName == Elf::SectionNames::dataConst) {
out.constDataSections.push_back(&elfSectionHeader);
} else if (sectionName == Elf::SectionNames::dataGlobalConst) {

View File

@@ -222,6 +222,26 @@ TEST(ExtractZebinSections, GivenKnownSectionsThenCapturesThemProperly) {
EXPECT_STREQ(NEO::Zebin::Elf::SectionNames::dataGlobalZeroInit.data(), strings + sections.globalZeroInitDataSections[0]->header->name);
}
TEST(ExtractZebinSections, GivenEmptyTextSectionThenIgnoresIt) {
NEO::Elf::ElfEncoder<> elfEncoder;
elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Zebin::Elf::SectionNames::text, ArrayRef<const uint8_t>{});
auto encodedElf = elfEncoder.encode();
std::string elferrors;
std::string elfwarnings;
auto decodedElf = NEO::Elf::decodeElf(encodedElf, elferrors, elfwarnings);
ZebinSections sections;
std::string errors;
std::string warnings;
auto decodeError = extractZebinSections(decodedElf, sections, errors, warnings);
EXPECT_EQ(NEO::DecodeError::success, decodeError);
EXPECT_TRUE(warnings.empty()) << warnings;
EXPECT_TRUE(errors.empty()) << errors;
EXPECT_EQ(0U, sections.textSections.size());
}
TEST(ExtractZebinSections, GivenMispelledConstDataSectionThenAllowItButEmitWarning) {
NEO::Elf::ElfEncoder<> elfEncoder;
elfEncoder.appendSection(NEO::Elf::SHT_PROGBITS, ".data.global_const", std::string{});