Skip to content

Commit 439389a

Browse files
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 <[email protected]>
1 parent 0f54a57 commit 439389a

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

shared/source/compiler_interface/external_functions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ enum ExternalFunctionResolveError : uint32_t {
2222
};
2323

2424
struct ExternalFunctionInfo {
25-
std::string functionName;
26-
uint8_t barrierCount;
27-
uint16_t numGrfRequired;
28-
uint8_t simdSize;
25+
std::string functionName = "";
26+
uint8_t barrierCount = 0U;
27+
uint16_t numGrfRequired = 0U;
28+
uint8_t simdSize = 0U;
2929
};
3030

3131
struct ExternalFunctionUsageKernel {

shared/source/compiler_interface/linker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,10 @@ void Linker::applyDebugDataRelocations(const NEO::Elf::Elf<NEO::Elf::EI_CLASS_64
504504
}
505505

506506
bool Linker::resolveExternalFunctions(const KernelDescriptorsT &kernelDescriptors, std::vector<ExternalFunctionInfo> &externalFunctions) {
507+
if (externalFunctions.size() == 0U) {
508+
return true;
509+
}
510+
507511
ExternalFunctionInfosT externalFunctionsPtrs;
508512
FunctionDependenciesT functionDependenciesPtrs;
509513
KernelDependenciesT kernelDependenciesPtrs;

shared/test/unit_test/compiler_interface/linker_tests.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,10 +2357,28 @@ TEST(LinkerTests, givenDependencyOnMissingExternalFunctionWhenLinkingThenFail) {
23572357
NEO::Linker::PatchableSegments patchableInstructionSegments;
23582358
NEO::Linker::UnresolvedExternals unresolvedExternals;
23592359
NEO::Linker::KernelDescriptorsT kernelDescriptors;
2360-
NEO::Linker::ExternalFunctionsT externalFunctions;
2360+
NEO::Linker::ExternalFunctionsT externalFunctions = {{"fun1", 0U, 128U, 8U}};
23612361
auto linkResult = linker.link(
23622362
globalVar, globalConst, exportedFunc, {},
23632363
patchableGlobalVarSeg, patchableConstVarSeg, patchableInstructionSegments,
23642364
unresolvedExternals, nullptr, nullptr, nullptr, kernelDescriptors, externalFunctions);
23652365
EXPECT_EQ(LinkingStatus::Error, linkResult);
23662366
}
2367+
2368+
TEST(LinkerTests, givenDependencyOnMissingExternalFunctionAndNoExternalFunctionInfosWhenLinkingThenDoNotResolveDependenciesAndReturnSuccess) {
2369+
WhiteBox<NEO::LinkerInput> linkerInput;
2370+
linkerInput.extFunDependencies.push_back({"fun0", "fun1"});
2371+
NEO::Linker linker(linkerInput);
2372+
NEO::Linker::SegmentInfo globalVar, globalConst, exportedFunc;
2373+
NEO::GraphicsAllocation *patchableGlobalVarSeg = nullptr;
2374+
NEO::GraphicsAllocation *patchableConstVarSeg = nullptr;
2375+
NEO::Linker::PatchableSegments patchableInstructionSegments;
2376+
NEO::Linker::UnresolvedExternals unresolvedExternals;
2377+
NEO::Linker::KernelDescriptorsT kernelDescriptors;
2378+
NEO::Linker::ExternalFunctionsT externalFunctions;
2379+
auto linkResult = linker.link(
2380+
globalVar, globalConst, exportedFunc, {},
2381+
patchableGlobalVarSeg, patchableConstVarSeg, patchableInstructionSegments,
2382+
unresolvedExternals, nullptr, nullptr, nullptr, kernelDescriptors, externalFunctions);
2383+
EXPECT_EQ(LinkingStatus::LinkedFully, linkResult);
2384+
}

0 commit comments

Comments
 (0)