Add implementation of module dynamic link

Change-Id: I80c9ed1b5f6b0243e89515c393d89c4f86e5d83a
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-07-14 15:40:00 +02:00
committed by sys_ocldev
parent 9bced7da37
commit 92aef012d9
9 changed files with 170 additions and 34 deletions

View File

@@ -158,6 +158,21 @@ bool Linker::processRelocations(const SegmentInfo &globalVariables, const Segmen
uint32_t addressSizeInBytes(LinkerInput::RelocationInfo::Type relocationtype) {
return (relocationtype == LinkerInput::RelocationInfo::Type::Address) ? sizeof(uintptr_t) : sizeof(uint32_t);
}
void Linker::patchAddress(void *relocAddress, const Linker::RelocatedSymbol &symbol, const Linker::RelocationInfo &relocation) {
uint64_t gpuAddressAs64bit = static_cast<uint64_t>(symbol.gpuAddress);
switch (relocation.type) {
default:
UNRECOVERABLE_IF(RelocationInfo::Type::Address != relocation.type);
*reinterpret_cast<uintptr_t *>(relocAddress) = symbol.gpuAddress;
break;
case RelocationInfo::Type::AddressLow:
*reinterpret_cast<uint32_t *>(relocAddress) = static_cast<uint32_t>(gpuAddressAs64bit & 0xffffffff);
break;
case RelocationInfo::Type::AddressHigh:
*reinterpret_cast<uint32_t *>(relocAddress) = static_cast<uint32_t>((gpuAddressAs64bit >> 32) & 0xffffffff);
break;
}
}
void Linker::patchInstructionsSegments(const std::vector<PatchableSegment> &instructionsSegments, std::vector<UnresolvedExternal> &outUnresolvedExternals) {
if (false == data.getTraits().requiresPatchingOfInstructionSegments) {
@@ -184,19 +199,7 @@ void Linker::patchInstructionsSegments(const std::vector<PatchableSegment> &inst
continue;
}
uint64_t gpuAddressAs64bit = static_cast<uint64_t>(symbolIt->second.gpuAddress);
switch (relocation.type) {
default:
UNRECOVERABLE_IF(RelocationInfo::Type::Address != relocation.type);
*reinterpret_cast<uintptr_t *>(relocAddress) = symbolIt->second.gpuAddress;
break;
case RelocationInfo::Type::AddressLow:
*reinterpret_cast<uint32_t *>(relocAddress) = static_cast<uint32_t>(gpuAddressAs64bit & 0xffffffff);
break;
case RelocationInfo::Type::AddressHigh:
*reinterpret_cast<uint32_t *>(relocAddress) = static_cast<uint32_t>((gpuAddressAs64bit >> 32) & 0xffffffff);
break;
}
patchAddress(relocAddress, symbolIt->second, relocation);
}
}
}

View File

@@ -186,7 +186,7 @@ struct Linker {
}
return LinkingStatus::LinkedFully;
}
static void patchAddress(void *relocAddress, const RelocatedSymbol &symbol, const RelocationInfo &relocation);
RelocatedSymbolsMap extractRelocatedSymbols() {
return RelocatedSymbolsMap(std::move(relocatedSymbols));
}