From 439389ae19108f2ecb11c93a2f31a58768c18a8c Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Mon, 7 Mar 2022 12:50:37 +0000 Subject: [PATCH] Do not resolve external functions when none passed This commit adds check in Linker::resolveExternalFunctions checking if external functions are present before trying to resolve dependencies and adds default values for ExternalFunctionInfo. Signed-off-by: Krystian Chmielewski --- .../compiler_interface/external_functions.h | 8 ++++---- shared/source/compiler_interface/linker.cpp | 4 ++++ .../compiler_interface/linker_tests.cpp | 20 ++++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/shared/source/compiler_interface/external_functions.h b/shared/source/compiler_interface/external_functions.h index 74c717c37b..78d5f19243 100644 --- a/shared/source/compiler_interface/external_functions.h +++ b/shared/source/compiler_interface/external_functions.h @@ -22,10 +22,10 @@ enum ExternalFunctionResolveError : uint32_t { }; struct ExternalFunctionInfo { - std::string functionName; - uint8_t barrierCount; - uint16_t numGrfRequired; - uint8_t simdSize; + std::string functionName = ""; + uint8_t barrierCount = 0U; + uint16_t numGrfRequired = 0U; + uint8_t simdSize = 0U; }; struct ExternalFunctionUsageKernel { diff --git a/shared/source/compiler_interface/linker.cpp b/shared/source/compiler_interface/linker.cpp index 63e03cb8bb..1a4d997164 100644 --- a/shared/source/compiler_interface/linker.cpp +++ b/shared/source/compiler_interface/linker.cpp @@ -504,6 +504,10 @@ void Linker::applyDebugDataRelocations(const NEO::Elf::Elf &externalFunctions) { + if (externalFunctions.size() == 0U) { + return true; + } + ExternalFunctionInfosT externalFunctionsPtrs; FunctionDependenciesT functionDependenciesPtrs; KernelDependenciesT kernelDependenciesPtrs; diff --git a/shared/test/unit_test/compiler_interface/linker_tests.cpp b/shared/test/unit_test/compiler_interface/linker_tests.cpp index 25f996418c..8f0a2808e5 100644 --- a/shared/test/unit_test/compiler_interface/linker_tests.cpp +++ b/shared/test/unit_test/compiler_interface/linker_tests.cpp @@ -2357,10 +2357,28 @@ TEST(LinkerTests, givenDependencyOnMissingExternalFunctionWhenLinkingThenFail) { NEO::Linker::PatchableSegments patchableInstructionSegments; NEO::Linker::UnresolvedExternals unresolvedExternals; NEO::Linker::KernelDescriptorsT kernelDescriptors; - NEO::Linker::ExternalFunctionsT externalFunctions; + NEO::Linker::ExternalFunctionsT externalFunctions = {{"fun1", 0U, 128U, 8U}}; auto linkResult = linker.link( globalVar, globalConst, exportedFunc, {}, patchableGlobalVarSeg, patchableConstVarSeg, patchableInstructionSegments, unresolvedExternals, nullptr, nullptr, nullptr, kernelDescriptors, externalFunctions); EXPECT_EQ(LinkingStatus::Error, linkResult); } + +TEST(LinkerTests, givenDependencyOnMissingExternalFunctionAndNoExternalFunctionInfosWhenLinkingThenDoNotResolveDependenciesAndReturnSuccess) { + WhiteBox linkerInput; + linkerInput.extFunDependencies.push_back({"fun0", "fun1"}); + NEO::Linker linker(linkerInput); + NEO::Linker::SegmentInfo globalVar, globalConst, exportedFunc; + NEO::GraphicsAllocation *patchableGlobalVarSeg = nullptr; + NEO::GraphicsAllocation *patchableConstVarSeg = nullptr; + NEO::Linker::PatchableSegments patchableInstructionSegments; + NEO::Linker::UnresolvedExternals unresolvedExternals; + NEO::Linker::KernelDescriptorsT kernelDescriptors; + NEO::Linker::ExternalFunctionsT externalFunctions; + auto linkResult = linker.link( + globalVar, globalConst, exportedFunc, {}, + patchableGlobalVarSeg, patchableConstVarSeg, patchableInstructionSegments, + unresolvedExternals, nullptr, nullptr, nullptr, kernelDescriptors, externalFunctions); + EXPECT_EQ(LinkingStatus::LinkedFully, linkResult); +}