From 1bf6431030f0f430d779bcf9e13d864673cb1299 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 18 Sep 2025 14:01:36 +0000 Subject: [PATCH] refactor: store special relocation names as string_view Signed-off-by: Mateusz Jablonski --- .../unit_tests/sources/module/test_module.cpp | 18 ++++++++--------- .../unit_test/program/program_data_tests.cpp | 4 ++-- shared/source/compiler_interface/linker.h | 4 ++-- shared/source/kernel/implicit_args_helper.h | 4 ++-- .../compiler_interface/linker_tests.cpp | 20 +++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/level_zero/core/test/unit_tests/sources/module/test_module.cpp b/level_zero/core/test/unit_tests/sources/module/test_module.cpp index 2d67953255..e851db8cc5 100644 --- a/level_zero/core/test/unit_tests/sources/module/test_module.cpp +++ b/level_zero/core/test/unit_tests/sources/module/test_module.cpp @@ -1906,7 +1906,7 @@ TEST_F(ModuleDynamicLinkTests, givenModuleWithInternalRelocationAndUnresolvedExt linkerInput->exportedFunctionsSegmentId = 0; 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 externalRelocationOffset = 0x20; @@ -1961,7 +1961,7 @@ HWTEST2_F(ModuleDynamicLinkTests, givenHeaplessAndModuleWithInternalRelocationAn linkerInput->traits.requiresPatchingOfInstructionSegments = true; linkerInput->exportedFunctionsSegmentId = 0; 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; constexpr auto externalSymbolName = "unresolved"; 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->exportedFunctionsSegmentId = 0; 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; constexpr auto externalSymbolName = "unresolved"; 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); auto linkerInput = std::make_unique<::WhiteBox>(); 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); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); @@ -4742,7 +4742,7 @@ TEST_F(ModuleTests, givenFullyLinkedModuleAndSlmSizeExceedingLocalMemorySizeWhen pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release()); auto linkerInput = std::make_unique<::WhiteBox>(); 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); auto status = pModule->linkBinary(); @@ -4784,7 +4784,7 @@ TEST_F(ModuleTests, givenFullyLinkedModuleWhenCreatingKernelThenDebugMsgOnPrivat pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo.release()); auto linkerInput = std::make_unique<::WhiteBox>(); 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); auto status = pModule->linkBinary(); @@ -4832,7 +4832,7 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationAndStackCallsWhenLinkingModuleThe pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); auto linkerInput = std::make_unique<::WhiteBox>(); 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); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); @@ -4863,7 +4863,7 @@ TEST_F(ModuleTests, givenImplicitArgsRelocationAndNoDebuggerOrStackCallsWhenLink pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); auto linkerInput = std::make_unique<::WhiteBox>(); 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); EXPECT_FALSE(kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs); @@ -4894,7 +4894,7 @@ TEST_F(ModuleTests, givenRequiredImplicitArgsInKernelAndNoDebuggerOrStackCallsWh pModule->translationUnit->programInfo.kernelInfos.push_back(kernelInfo); auto linkerInput = std::make_unique<::WhiteBox>(); 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); kernelInfo->kernelDescriptor.kernelAttributes.flags.requiresImplicitArgs = true; diff --git a/opencl/test/unit_test/program/program_data_tests.cpp b/opencl/test/unit_test/program/program_data_tests.cpp index 8529f973ec..5c3bbf2133 100644 --- a/opencl/test/unit_test/program/program_data_tests.cpp +++ b/opencl/test/unit_test/program/program_data_tests.cpp @@ -896,7 +896,7 @@ TEST_F(ProgramImplicitArgsTest, givenImplicitRelocationAndStackCallsThenKernelRe program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo); auto linkerInput = std::make_unique>(); - 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; program.setLinkerInput(rootDeviceIndex, std::move(linkerInput)); 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); auto linkerInput = std::make_unique>(); - 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; program.setLinkerInput(rootDeviceIndex, std::move(linkerInput)); auto ret = program.linkBinary(&device->getDevice(), nullptr, 0, nullptr, 0, {}, program.externalFunctions); diff --git a/shared/source/compiler_interface/linker.h b/shared/source/compiler_interface/linker.h index 14c289c5c4..127dfff396 100644 --- a/shared/source/compiler_interface/linker.h +++ b/shared/source/compiler_interface/linker.h @@ -193,8 +193,8 @@ struct LinkerInput : NEO::NonCopyableAndNonMovableClass { }; struct Linker { - inline static const std::string subDeviceID = "__SubDeviceID"; - inline static const std::string perThreadOff = "__INTEL_PER_THREAD_OFF"; + inline static constexpr std::string_view subDeviceID = "__SubDeviceID"; + inline static constexpr std::string_view perThreadOff = "__INTEL_PER_THREAD_OFF"; using RelocationInfo = LinkerInput::RelocationInfo; diff --git a/shared/source/kernel/implicit_args_helper.h b/shared/source/kernel/implicit_args_helper.h index e29eaf9b18..9a8d072b6c 100644 --- a/shared/source/kernel/implicit_args_helper.h +++ b/shared/source/kernel/implicit_args_helper.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include namespace NEO { @@ -20,7 +20,7 @@ namespace NEO { struct KernelDescriptor; 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 { std::array getDimensionOrderForLocalIds(const uint8_t *workgroupDimensionsOrder, std::optional> hwGenerationOfLocalIdsParams); diff --git a/shared/test/unit_test/compiler_interface/linker_tests.cpp b/shared/test/unit_test/compiler_interface/linker_tests.cpp index 4b87054500..a47efbcf17 100644 --- a/shared/test/unit_test/compiler_interface/linker_tests.cpp +++ b/shared/test/unit_test/compiler_interface/linker_tests.cpp @@ -807,11 +807,11 @@ TEST(LinkerInputTests, GivenNonFunctionRelocationInKernelRelocationsWhenParsingR for (auto nonFuncRelocationName : { implicitArgsRelocationSymbolName, - std::string(".str"), - std::string("globalVar"), + std::string_view(".str"), + std::string_view("globalVar"), Linker::perThreadOff, Linker::subDeviceID, - std::string("")}) { + std::string_view("")}) { NEO::LinkerInput::RelocationInfo relocInfo{}; relocInfo.symbolName = nonFuncRelocationName; @@ -1048,7 +1048,7 @@ HWTEST_F(LinkerTests, givenUnresolvedExternalSymbolsAndCrossThreadDataSmallerTha NEO::LinkerInput linkerInput{}; LinkerMock linker(linkerInput); 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 instructionSegment{}; instructionSegment.resize(kernelRelocOffset + 16); @@ -2250,7 +2250,7 @@ TEST_F(LinkerTests, givenImplicitArgRelocationAndStackCallsOrRequiredImplicitArg NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc.r_offset = 8; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; @@ -2324,7 +2324,7 @@ HWTEST_F(LinkerTests, givenImplicitArgRelocationAndImplicitArgsV1WhenLinkingThen NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc.r_offset = 8; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; @@ -2401,7 +2401,7 @@ HWTEST_F(LinkerTests, givenImplicitArgRelocationAndImplicitArgsWithUnknownVersio NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc.r_offset = 8; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; @@ -2455,7 +2455,7 @@ TEST_F(LinkerDebuggingSupportedTests, givenImplicitArgRelocationAndEnabledDebugg NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc.r_offset = 8; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; @@ -2563,7 +2563,7 @@ TEST_F(LinkerTests, givenImplicitArgRelocationWithoutStackCallsAndDisabledDebugg NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc.r_offset = 8; reloc.r_type = vISA::GenRelocType::R_SYM_ADDR_32; @@ -2663,7 +2663,7 @@ TEST_F(LinkerTests, givenMultipleImplicitArgsRelocationsWithinSingleKernelWhenLi NEO::LinkerInput linkerInput; vISA::GenRelocEntry reloc0 = {}; - std::string relocationName = implicitArgsRelocationSymbolName; + std::string relocationName{implicitArgsRelocationSymbolName}; memcpy_s(reloc0.r_symbol, 1024, relocationName.c_str(), relocationName.size()); reloc0.r_offset = 8; reloc0.r_type = vISA::GenRelocType::R_SYM_ADDR_32;