Enable relocation from instruction to data seg

Related-To: NEO-5833
Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
Krystian Chmielewski 2021-08-03 13:54:24 +00:00 committed by Compute-Runtime-Automation
parent c23a74e902
commit 34be220943
2 changed files with 26 additions and 16 deletions

View File

@ -136,7 +136,6 @@ bool LinkerInput::decodeRelocationTable(const void *data, uint32_t numEntries, u
void LinkerInput::addDataRelocationInfo(const RelocationInfo &relocationInfo) {
DEBUG_BREAK_IF((relocationInfo.relocationSegment != SegmentType::GlobalConstants) && (relocationInfo.relocationSegment != SegmentType::GlobalVariables));
DEBUG_BREAK_IF((relocationInfo.symbolSegment != SegmentType::GlobalConstants) && (relocationInfo.symbolSegment != SegmentType::GlobalVariables));
DEBUG_BREAK_IF(relocationInfo.type == LinkerInput::RelocationInfo::Type::AddressHigh);
this->traits.requiresPatchingOfGlobalVariablesBuffer |= (relocationInfo.relocationSegment == SegmentType::GlobalVariables);
this->traits.requiresPatchingOfGlobalConstantsBuffer |= (relocationInfo.relocationSegment == SegmentType::GlobalConstants);
@ -190,18 +189,13 @@ void LinkerInput::decodeElfSymbolTableAndRelocations(Elf::Elf<Elf::EI_CLASS_64>
} else if (nameRef.startsWith(NEO::Elf::SpecialSectionNames::data.data())) {
auto symbolSectionName = elf.getSectionName(reloc.symbolSectionIndex);
auto symbolSegment = getSegmentForSection(symbolSectionName);
if (symbolSegment == NEO::SegmentType::GlobalConstants || symbolSegment == NEO::SegmentType::GlobalVariables) {
relocationInfo.symbolSegment = symbolSegment;
auto relocationSegment = getSegmentForSection(nameRef);
if (relocationSegment == NEO::SegmentType::GlobalConstants || relocationSegment == NEO::SegmentType::GlobalVariables) {
if (symbolSegment != NEO::SegmentType::Unknown &&
(relocationSegment == NEO::SegmentType::GlobalConstants || relocationSegment == NEO::SegmentType::GlobalVariables)) {
relocationInfo.relocationSegment = relocationSegment;
this->addDataRelocationInfo(relocationInfo);
}
} else {
DEBUG_BREAK_IF(true);
}
}
}

View File

@ -604,11 +604,21 @@ TEST(LinkerInputTests, WhenDecodingElfGlobalDataRelocationsThenCorrectRelocation
reloc2.relocType = static_cast<uint32_t>(Elf::RELOCATION_X8664_TYPE::R_X8664_64);
reloc2.symbolName = "symbol2";
reloc2.symbolSectionIndex = 2;
reloc2.symbolTableIndex = 0;
reloc2.symbolTableIndex = 1;
reloc2.targetSectionIndex = 1;
elf64.relocations.emplace_back(reloc2);
NEO::Elf::Elf<NEO::Elf::EI_CLASS_64>::RelocationInfo reloc3;
reloc3.offset = 0;
reloc3.relocType = static_cast<uint32_t>(Elf::RELOCATION_X8664_TYPE::R_X8664_64);
reloc3.symbolName = "symbol3";
reloc3.symbolSectionIndex = 0;
reloc3.symbolTableIndex = 2;
reloc3.targetSectionIndex = 1;
elf64.relocations.emplace_back(reloc3);
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
nameToKernelId["abc"] = 0;
@ -616,7 +626,7 @@ TEST(LinkerInputTests, WhenDecodingElfGlobalDataRelocationsThenCorrectRelocation
linkerInput.decodeElfSymbolTableAndRelocations(elf64, nameToKernelId);
auto relocations = linkerInput.getDataRelocations();
ASSERT_EQ(2u, relocations.size());
ASSERT_EQ(3u, relocations.size());
EXPECT_EQ(64u, relocations[0].offset);
EXPECT_EQ(NEO::SegmentType::GlobalVariables, relocations[0].relocationSegment);
@ -629,6 +639,12 @@ TEST(LinkerInputTests, WhenDecodingElfGlobalDataRelocationsThenCorrectRelocation
EXPECT_EQ("symbol2", relocations[1].symbolName);
EXPECT_EQ(NEO::SegmentType::GlobalConstants, relocations[1].symbolSegment);
EXPECT_EQ(NEO::LinkerInput::RelocationInfo::Type::Address, relocations[1].type);
EXPECT_EQ(0u, relocations[2].offset);
EXPECT_EQ(NEO::SegmentType::GlobalVariables, relocations[2].relocationSegment);
EXPECT_EQ("symbol3", relocations[2].symbolName);
EXPECT_EQ(NEO::SegmentType::Instructions, relocations[2].symbolSegment);
EXPECT_EQ(NEO::LinkerInput::RelocationInfo::Type::Address, relocations[2].type);
}
TEST(LinkerInputTests, WhenDecodingElfConstantDataRelocationsThenCorrectRelocationsAreAdded) {
@ -719,14 +735,14 @@ TEST(LinkerInputTests, GivenUnsupportedDataSegmentWhenDecodingElfDataRelocationT
ASSERT_EQ(0u, relocations.size());
}
TEST(LinkerInputTests, GivenUnsupportedSymbolSegmentWhenDecodingElfDataRelocationThenNoRelocationsAreAddedAndDebugBreakIsCalled) {
TEST(LinkerInputTests, GivenUnsupportedSymbolSegmentWhenDecodingElfDataRelocationThenNoRelocationsAreAdded) {
NEO::LinkerInput linkerInput = {};
NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> header;
MockElf<NEO::Elf::EI_CLASS_64> elf64;
elf64.elfFileHeader = &header;
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
sectionNames[0] = ".unknown_section";
sectionNames[1] = ".data";
sectionNames[2] = ".data.const";