Revert "fix: improve parsing relocations in external usage"

This reverts commit 65d883bc9d.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2025-09-27 04:39:48 +02:00
committed by Compute-Runtime-Automation
parent bf60c796bc
commit aaa9342141
5 changed files with 21 additions and 33 deletions

View File

@@ -232,7 +232,6 @@ bool LinkerInput::addSymbol(Elf::Elf<numBits> &elf, const SectionNameToSegmentId
auto symbolSectionName = elf.getSectionName(elfSymbol.shndx);
auto segment = getSegmentForSection(symbolSectionName);
if (segment == SegmentType::unknown) {
externalSymbols.push_back(symbolName);
return false;
}
@@ -312,9 +311,10 @@ void LinkerInput::parseRelocationForExtFuncUsage(const RelocationInfo &relocInfo
return true;
}
// ignore relocations for external symbols
if (std::ranges::find(externalSymbols, relocInfo.symbolName) != externalSymbols.end()) {
return true;
for (auto specialRelocationName : {implicitArgsRelocationSymbolName, Linker::perThreadOff, Linker::subDeviceID}) {
if (relocInfo.symbolName == specialRelocationName) {
return true;
}
}
return false;
};

View File

@@ -183,7 +183,6 @@ struct LinkerInput : NEO::NonCopyableAndNonMovableClass {
Traits traits;
SymbolMap symbols;
std::vector<std::string> externalSymbols;
std::vector<std::pair<std::string, SymbolInfo>> extFuncSymbols;
Relocations dataRelocations;
RelocationsPerInstSegment textRelocations;

View File

@@ -24,7 +24,6 @@ struct WhiteBox<NEO::LinkerInput> : NEO::LinkerInput {
using BaseClass::dataRelocations;
using BaseClass::exportedFunctionsSegmentId;
using BaseClass::externalSymbols;
using BaseClass::extFuncSymbols;
using BaseClass::extFunDependencies;
using BaseClass::kernelDependencies;

View File

@@ -57,7 +57,7 @@ struct MockElf : public NEO::Elf::Elf<numBits> {
relocations.emplace_back(reloc);
}
void setupSectionNames(std::unordered_map<uint32_t, std::string> map) {
void setupSecionNames(std::unordered_map<uint32_t, std::string> map) {
sectionNames = map;
overrideSectionNames = true;
}

View File

@@ -388,7 +388,7 @@ TEST(LinkerInputTests, GivenTwoGlobalSymbolsOfTypeFunctionEachPointingToDifferen
sectionNames[1] = ".data.const";
sectionNames[2] = ".text.hello";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0x1234000, 8, 0, Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -405,7 +405,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeObjectPointingToDataGlobalSectionW
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
sectionNames[1] = ".data.global";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0x20, 8, 1, Elf::STT_OBJECT, Elf::STB_GLOBAL);
@@ -428,7 +428,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeObjectPointingToDataConstSectionWh
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
sectionNames[1] = ".data.const";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0, 8, 1, Elf::STT_OBJECT, Elf::STB_GLOBAL);
@@ -452,7 +452,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeFuncPointingToFunctionsSectionWhen
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
sectionNames[1] = functionsSectionName.str();
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0, 32, 1, Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -479,7 +479,7 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeDifferentThantObjectOrFuncWhenDeco
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
sectionNames[1] = ".data.const";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0, 8, 0, Elf::STT_NOTYPE, Elf::STB_GLOBAL);
@@ -490,24 +490,21 @@ TEST(LinkerInputTests, GivenGlobalSymbolOfTypeDifferentThantObjectOrFuncWhenDeco
EXPECT_EQ(0U, linkerInput.getSymbols().size());
}
TEST(LinkerInputTests, GivenGlobalSymbolPointingToSectionDifferentThanInstructionsOrDataWhenDecodingElfThenItIsIgnoredAndAddedToExternalSymbols) {
TEST(LinkerInputTests, GivenGlobalSymbolPointingToSectionDifferentThanInstructionsOrDataWhenDecodingElfThenItIsIgnored) {
MockElf<NEO::Elf::EI_CLASS_64> elf64;
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ""; // UNDEF section
sectionNames[1] = ".text.abc";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
constexpr uint32_t externalSymbol = 3;
elf64.addSymbol(externalSymbol, 0, 8, 0, Elf::STT_OBJECT, Elf::STB_GLOBAL);
WhiteBox<NEO::LinkerInput> linkerInput;
elf64.addSymbol(0, 0, 8, 0, Elf::STT_OBJECT, Elf::STB_GLOBAL);
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId = {{"abc", 0}};
NEO::LinkerInput linkerInput = {};
linkerInput.decodeElfSymbolTableAndRelocations(elf64, nameToKernelId);
EXPECT_TRUE(linkerInput.isValid());
EXPECT_EQ(0U, linkerInput.getSymbols().size());
EXPECT_EQ(1U, linkerInput.externalSymbols.size());
EXPECT_EQ(std::to_string(externalSymbol), linkerInput.externalSymbols[0]);
}
TEST(LInkerInputTests, GivenSymbolPointingToInstructionSegmentAndInvalidInstructionSectionNameMappingWhenDecodingElfThenLinkerInputIsInvalid) {
@@ -516,7 +513,7 @@ TEST(LInkerInputTests, GivenSymbolPointingToInstructionSegmentAndInvalidInstruct
std::unordered_map<uint32_t, std::string> sectionNames;
sectionNames[0] = ".text.abc";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.overrideSymbolName = true;
elf64.addSymbol(0, 0, 8, 0, Elf::STT_FUNC, Elf::STB_GLOBAL);
@@ -535,7 +532,7 @@ TEST(LinkerInputTests, GivenInstructionRelocationAndInvalidInstructionSectionNam
sectionNames[0] = ".text.abc";
sectionNames[1] = ".data.const";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.addReloc(64, 0, Zebin::Elf::R_ZE_SYM_ADDR, 0, 0, "0");
elf64.overrideSymbolName = true;
@@ -551,7 +548,7 @@ TEST(LinkerInputTests, GivenRelocationWithSymbolIdOutOfBoundsOfSymbolTableWhenDe
MockElf<NEO::Elf::EI_CLASS_64> elf64;
std::unordered_map<uint32_t, std::string> sectionNames = {{0, ".text.abc"}};
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.addReloc(64, 0, Zebin::Elf::R_ZE_SYM_ADDR, 0, 2, "symbol");
@@ -567,7 +564,7 @@ TEST(LinkerInputTests, GivenRelocationToSectionDifferentThanDataOrInstructionsWh
std::unordered_map<uint32_t, std::string> sectionNames = {{0, ".text.abc"},
{1, "unknown.section"}};
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.addReloc(64, 0, Zebin::Elf::R_ZE_SYM_ADDR, 1, 2, "symbol");
NEO::LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
@@ -587,7 +584,7 @@ TEST(LinkerInputTests, GivenGlobalDataRelocationWithLocalSymbolPointingToConstDa
sectionNames[1] = ".data.const";
sectionNames[2] = ".data.global";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.addReloc(64, 10, Zebin::Elf::R_ZE_SYM_ADDR, 2, 0, "0");
elf64.overrideSymbolName = true;
@@ -620,7 +617,7 @@ TEST(LinkerInputTests, GivenInstructionRelocationWithLocalSymbolPointingToFuncti
sectionNames[0] = ".text.abc";
sectionNames[1] = functionsSectionName.str();
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
elf64.addReloc(64, 10, Zebin::Elf::R_ZE_SYM_ADDR, 0, 0, "0");
elf64.overrideSymbolName = true;
@@ -808,12 +805,6 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR
symbols.emplace("globalVar", symbol1);
symbols.emplace("fun", symbol2);
auto &externalSymbols = mockLinkerInput.externalSymbols;
externalSymbols.push_back(std::string(implicitArgsRelocationSymbolName));
externalSymbols.push_back(std::string(Linker::perThreadOff));
externalSymbols.push_back(std::string(Linker::subDeviceID));
for (auto nonFuncRelocationName : {
implicitArgsRelocationSymbolName,
std::string_view(".str"),
@@ -831,7 +822,6 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR
EXPECT_EQ(0u, mockLinkerInput.kernelDependencies.size());
}
}
HWTEST_F(LinkerTests, givenEmptyLinkerInputThenLinkerOutputIsEmpty) {
NEO::LinkerInput linkerInput;
NEO::Linker linker(linkerInput);
@@ -2150,7 +2140,7 @@ TEST_F(LinkerTests, GivenDebugDataWhenApplyingDebugDataRelocationsThenRelocation
sectionNames[4] = ".debug_line";
sectionNames[5] = ".data.const";
elf64.setupSectionNames(std::move(sectionNames));
elf64.setupSecionNames(std::move(sectionNames));
NEO::Elf::Elf<NEO::Elf::EI_CLASS_64>::RelocationInfo reloc0 = {};
reloc0.offset = 64;