refactor: store special relocation names as string_view

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2025-09-18 14:01:36 +00:00
committed by Compute-Runtime-Automation
parent 700921cc10
commit 1bf6431030
5 changed files with 25 additions and 25 deletions

View File

@@ -1906,7 +1906,7 @@ TEST_F(ModuleDynamicLinkTests, givenModuleWithInternalRelocationAndUnresolvedExt
linkerInput->exportedFunctionsSegmentId = 0; linkerInput->exportedFunctionsSegmentId = 0;
uint32_t internalRelocationOffset = 0x10; uint32_t internalRelocationOffset = 0x10;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}});
uint32_t expectedInternalRelocationValue = ImplicitArgsTestHelper::getImplicitArgsSize(neoDevice->getGfxCoreHelper().getImplicitArgsVersion()); uint32_t expectedInternalRelocationValue = ImplicitArgsTestHelper::getImplicitArgsSize(neoDevice->getGfxCoreHelper().getImplicitArgsVersion());
uint32_t externalRelocationOffset = 0x20; uint32_t externalRelocationOffset = 0x20;
@@ -1961,7 +1961,7 @@ HWTEST2_F(ModuleDynamicLinkTests, givenHeaplessAndModuleWithInternalRelocationAn
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->exportedFunctionsSegmentId = 0; linkerInput->exportedFunctionsSegmentId = 0;
uint32_t internalRelocationOffset = 0x10; uint32_t internalRelocationOffset = 0x10;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}});
uint32_t externalRelocationOffset = 0x20; uint32_t externalRelocationOffset = 0x20;
constexpr auto externalSymbolName = "unresolved"; constexpr auto externalSymbolName = "unresolved";
linkerInput->textRelocations[0].push_back({externalSymbolName, externalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}); linkerInput->textRelocations[0].push_back({externalSymbolName, externalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions});
@@ -2008,7 +2008,7 @@ HWTEST2_F(ModuleDynamicLinkTests, givenHeaplessAndModuleWithInternalRelocationAn
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->exportedFunctionsSegmentId = 0; linkerInput->exportedFunctionsSegmentId = 0;
uint32_t internalRelocationOffset = 0x10; uint32_t internalRelocationOffset = 0x10;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), internalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}});
uint32_t externalRelocationOffset = 0x20; uint32_t externalRelocationOffset = 0x20;
constexpr auto externalSymbolName = "unresolved"; constexpr auto externalSymbolName = "unresolved";
linkerInput->textRelocations[0].push_back({externalSymbolName, externalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions}); linkerInput->textRelocations[0].push_back({externalSymbolName, externalRelocationOffset, LinkerInput::RelocationInfo::Type::address, SegmentType::instructions});
@@ -4698,7 +4698,7 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationWhenLinkingBuiltinModuleThenSegme
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
@@ -4742,7 +4742,7 @@ TEST_F(ModuleTests, givenFullyLinkedModuleAndSlmSizeExceedingLocalMemorySizeWhen
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release()); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release());
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
auto status = pModule->linkBinary(); auto status = pModule->linkBinary();
@@ -4784,7 +4784,7 @@ TEST_F(ModuleTests, givenFullyLinkedModuleWhenCreatingKernelThenDebugMsgOnPrivat
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release()); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release());
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
auto status = pModule->linkBinary(); auto status = pModule->linkBinary();
@@ -4832,7 +4832,7 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationAndStackCallsWhenLinkingModuleThe
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
@@ -4863,7 +4863,7 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationAndNoDebuggerOrStackCallsWhenLink
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs);
@@ -4894,7 +4894,7 @@ TEST_F(ModuleTests, givenRequiredImplicitArgsInKernelAndNoDebuggerOrStackCallsWh
pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>(); auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput); pModule->translationUnit->programInfo.linkerInput = std::move(linkerInput);
kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs = true; kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs = true;

View File

@@ -896,7 +896,7 @@ TEST_F(ProgramImplicitArgsTest, givenImplicitRelocationAndStackCallsThenKernelRe
program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo); program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo);
auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>(); auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>();
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
program.setLinkerInput(rootDeviceIndex, std::move(linkerInput)); program.setLinkerInput(rootDeviceIndex, std::move(linkerInput));
auto ret = program.linkBinary(&device->getDevice(), nullptr, 0, nullptr, 0, {}, program.externalFunctions); auto ret = program.linkBinary(&device->getDevice(), nullptr, 0, nullptr, 0, {}, program.externalFunctions);
@@ -922,7 +922,7 @@ TEST_F(ProgramImplicitArgsTest, givenImplicitRelocationAndNoStackCallsAndDisable
program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo); program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo);
auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>(); auto linkerInput = std::make_unique<WhiteBox<LinkerInput>>();
linkerInput->textRelocations.push_back({{implicitArgsRelocationSymbolName, 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}}); linkerInput->textRelocations.push_back({{std::string(implicitArgsRelocationSymbolName), 0x8, LinkerInput::RelocationInfo::Type::addressLow, SegmentType::instructions}});
linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->traits.requiresPatchingOfInstructionSegments = true;
program.setLinkerInput(rootDeviceIndex, std::move(linkerInput)); program.setLinkerInput(rootDeviceIndex, std::move(linkerInput));
auto ret = program.linkBinary(&device->getDevice(), nullptr, 0, nullptr, 0, {}, program.externalFunctions); auto ret = program.linkBinary(&device->getDevice(), nullptr, 0, nullptr, 0, {}, program.externalFunctions);

View File

@@ -193,8 +193,8 @@ struct LinkerInput : NEO::NonCopyableAndNonMovableClass {
}; };
struct Linker { struct Linker {
inline static const std::string subDeviceID = "__SubDeviceID"; inline static constexpr std::string_view subDeviceID = "__SubDeviceID";
inline static const std::string perThreadOff = "__INTEL_PER_THREAD_OFF"; inline static constexpr std::string_view perThreadOff = "__INTEL_PER_THREAD_OFF";
using RelocationInfo = LinkerInput::RelocationInfo; using RelocationInfo = LinkerInput::RelocationInfo;

View File

@@ -12,7 +12,7 @@
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include <string> #include <string_view>
#include <type_traits> #include <type_traits>
namespace NEO { namespace NEO {
@@ -20,7 +20,7 @@ namespace NEO {
struct KernelDescriptor; struct KernelDescriptor;
struct RootDeviceEnvironment; struct RootDeviceEnvironment;
inline const std::string implicitArgsRelocationSymbolName = "__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0"; inline constexpr std::string_view implicitArgsRelocationSymbolName = "__INTEL_PATCH_CROSS_THREAD_OFFSET_OFF_R0";
namespace ImplicitArgsHelper { namespace ImplicitArgsHelper {
std::array<uint8_t, 3> getDimensionOrderForLocalIds(const uint8_t *workgroupDimensionsOrder, std::optional<std::pair<bool /* localIdsGeneratedByRuntime */, uint32_t /* walkOrderForHwGenerationOfLocalIds */>> hwGenerationOfLocalIdsParams); std::array<uint8_t, 3> getDimensionOrderForLocalIds(const uint8_t *workgroupDimensionsOrder, std::optional<std::pair<bool /* localIdsGeneratedByRuntime */, uint32_t /* walkOrderForHwGenerationOfLocalIds */>> hwGenerationOfLocalIdsParams);

View File

@@ -807,11 +807,11 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR
for (auto nonFuncRelocationName : { for (auto nonFuncRelocationName : {
implicitArgsRelocationSymbolName, implicitArgsRelocationSymbolName,
std::string(".str"), std::string_view(".str"),
std::string("globalVar"), std::string_view("globalVar"),
Linker::perThreadOff, Linker::perThreadOff,
Linker::subDeviceID, Linker::subDeviceID,
std::string("")}) { std::string_view("")}) {
NEO::LinkerInput::RelocationInfo relocInfo{}; NEO::LinkerInput::RelocationInfo relocInfo{};
relocInfo.symbolName = nonFuncRelocationName; relocInfo.symbolName = nonFuncRelocationName;
@@ -1048,7 +1048,7 @@ HWTEST_F(LinkerTests, givenUnresolvedExternalSymbolsAndCrossThreadDataSmallerTha
NEO::LinkerInput linkerInput{}; NEO::LinkerInput linkerInput{};
LinkerMock linker(linkerInput); LinkerMock linker(linkerInput);
NEO::Linker::UnresolvedExternals unresolvedExternals{}; NEO::Linker::UnresolvedExternals unresolvedExternals{};
unresolvedExternals.push_back({{NEO::Linker::perThreadOff, kernelRelocOffset, NEO::Linker::RelocationInfo::Type::address16, NEO::SegmentType::instructions, ".text.kernel_func1"}, 0u, false}); unresolvedExternals.push_back({{std::string(NEO::Linker::perThreadOff), kernelRelocOffset, NEO::Linker::RelocationInfo::Type::address16, NEO::SegmentType::instructions, ".text.kernel_func1"}, 0u, false});
std::vector<char> instructionSegment{}; std::vector<char> instructionSegment{};
instructionSegment.resize(kernelRelocOffset + 16); instructionSegment.resize(kernelRelocOffset + 16);
@@ -2250,7 +2250,7 @@ TEST_F(LinkerTests, givenImplicitArgRelocationAndStackCallsOrRequiredImplicitArg
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc = {}; vISA::GenRelocEntry reloc = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc.r_offset = 8; reloc.r_offset = 8;
reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32;
@@ -2324,7 +2324,7 @@ HWTEST_F(LinkerTests, givenImplicitArgRelocationAndImplicitArgsV1WhenLinkingThen
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc = {}; vISA::GenRelocEntry reloc = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc.r_offset = 8; reloc.r_offset = 8;
reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32;
@@ -2401,7 +2401,7 @@ HWTEST_F(LinkerTests, givenImplicitArgRelocationAndImplicitArgsWithUnknownVersio
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc = {}; vISA::GenRelocEntry reloc = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc.r_offset = 8; reloc.r_offset = 8;
reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32;
@@ -2455,7 +2455,7 @@ TEST_F(LinkerDebuggingSupportedTests, givenImplicitArgRelocationAndEnabledDebugg
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc = {}; vISA::GenRelocEntry reloc = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc.r_offset = 8; reloc.r_offset = 8;
reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32;
@@ -2563,7 +2563,7 @@ TEST_F(LinkerTests, givenImplicitArgRelocationWithoutStackCallsAndDisabledDebugg
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc = {}; vISA::GenRelocEntry reloc = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc.r_offset = 8; reloc.r_offset = 8;
reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32;
@@ -2663,7 +2663,7 @@ TEST_F(LinkerTests, givenMultipleImplicitArgsRelocationsWithinSingleKernelWhenLi
NEO::LinkerInput linkerInput; NEO::LinkerInput linkerInput;
vISA::GenRelocEntry reloc0 = {}; vISA::GenRelocEntry reloc0 = {};
std::string relocationName = implicitArgsRelocationSymbolName; std::string relocationName{implicitArgsRelocationSymbolName};
memcpy_s(reloc0.r_symbol, 1024, relocationName.c_str(), relocationName.size()); memcpy_s(reloc0.r_symbol, 1024, relocationName.c_str(), relocationName.size());
reloc0.r_offset = 8; reloc0.r_offset = 8;
reloc0.r_type = vISA::GenRelocType::R_SYM_ADDR_32; reloc0.r_type = vISA::GenRelocType::R_SYM_ADDR_32;