Linker: add support for symbols with local binding

This commits add support for relocating
symbols with local binding and of functional type
(STB_LOCAL, STT_FUNC).

Related-To: NEO-7299
Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2022-09-06 00:10:18 +00:00
committed by Compute-Runtime-Automation
parent 824c781ab5
commit 710c8cf5ef
10 changed files with 272 additions and 35 deletions

View File

@ -100,7 +100,8 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
auto &kernHeapInfo = kernelInfo->heapInfo;
const char *originalIsa = reinterpret_cast<const char *>(kernHeapInfo.pKernelHeap);
patchedIsaTempStorage.push_back(std::vector<char>(originalIsa, originalIsa + kernHeapInfo.KernelHeapSize));
isaSegmentsForPatching.push_back(Linker::PatchableSegment{patchedIsaTempStorage.rbegin()->data(), kernHeapInfo.KernelHeapSize});
DEBUG_BREAK_IF(nullptr == kernelInfo->getGraphicsAllocation());
isaSegmentsForPatching.push_back(Linker::PatchableSegment{patchedIsaTempStorage.rbegin()->data(), static_cast<uintptr_t>(kernelInfo->getGraphicsAllocation()->getGpuAddressToPatch()), kernHeapInfo.KernelHeapSize, kernelInfo->kernelDescriptor.kernelMetadata.kernelName});
kernelDescriptors.push_back(&kernelInfo->kernelDescriptor);
}
}
@ -123,9 +124,6 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
} else if (linkerInput->getTraits().requiresPatchingOfInstructionSegments) {
for (auto kernelId = 0u; kernelId < kernelInfoArray.size(); kernelId++) {
const auto &kernelInfo = kernelInfoArray[kernelId];
if (nullptr == kernelInfo->getGraphicsAllocation()) {
continue;
}
auto &kernHeapInfo = kernelInfo->heapInfo;
auto segmentId = &kernelInfo - &kernelInfoArray[0];
auto &hwInfo = pDevice->getHardwareInfo();

View File

@ -1319,6 +1319,9 @@ TEST_F(KernelDataTest, givenRelocationTablePatchTokenThenLinkerInputIsCreated) {
token.Token = PATCH_TOKEN_PROGRAM_RELOCATION_TABLE;
token.Size = static_cast<uint32_t>(sizeof(SPatchFunctionTableInfo));
token.NumEntries = 0;
kernelHeapSize = 0x100; //force creating kernel allocation for ISA
auto kernelHeapData = std::make_unique<char[]>(kernelHeapSize);
pKernelHeap = kernelHeapData.get();
pPatchList = &token;
patchListSize = token.Size;

View File

@ -586,6 +586,7 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
kernelHeap.resize(32, 7);
kernelInfo.heapInfo.pKernelHeap = kernelHeap.data();
kernelInfo.heapInfo.KernelHeapSize = static_cast<uint32_t>(kernelHeap.size());
kernelInfo.createKernelAllocation(device->getDevice(), false);
program.getKernelInfoArray(rootDeviceIndex).push_back(&kernelInfo);
program.setLinkerInput(rootDeviceIndex, std::move(linkerInput));
@ -600,6 +601,7 @@ TEST(ProgramLinkBinaryTest, whenLinkerUnresolvedExternalThenLinkFailedAndBuildLo
expectedUnresolvedExternals.push_back(Linker::UnresolvedExternal{relocation, 0, false});
auto expectedError = constructLinkerErrorMessage(expectedUnresolvedExternals, std::vector<std::string>{"kernel : " + kernelInfo.kernelDescriptor.kernelMetadata.kernelName});
EXPECT_TRUE(hasSubstr(buildLog, expectedError));
device->getMemoryManager()->freeGraphicsMemory(kernelInfo.getGraphicsAllocation());
}
TEST_F(ProgramDataTest, whenLinkerInputValidThenIsaIsProperlyPatched) {