mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-21 01:04:57 +08:00
Create input for linker during zebin decoding
Remove code duplication. Parsing zebin elf for relocations and symbols is moved to decodeSingleDeviceBinary. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
a9bc4de8cf
commit
311b0b0020
@@ -11,23 +11,13 @@
|
||||
#include "shared/source/device_binary_format/elf/elf_encoder.h"
|
||||
#include "shared/source/device_binary_format/elf/zebin_elf.h"
|
||||
#include "shared/source/device_binary_format/zebin_decoder.h"
|
||||
#include "shared/source/program/kernel_info.h"
|
||||
#include "shared/source/program/program_info.h"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <>
|
||||
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> binary) {
|
||||
auto header = Elf::decodeElfFileHeader<Elf::EI_CLASS_64>(binary);
|
||||
if (nullptr == header) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return header->type == NEO::Elf::ET_REL ||
|
||||
header->type == NEO::Elf::ET_ZEBIN_EXE;
|
||||
}
|
||||
|
||||
template <>
|
||||
SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> archive, const ConstStringRef requestedProductAbbreviation, const TargetDevice &requestedTargetDevice,
|
||||
std::string &outErrReason, std::string &outWarning) {
|
||||
@@ -86,4 +76,29 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
void prepareLinkerInputForZebin(ProgramInfo &programInfo, Elf::Elf<Elf::EI_CLASS_64> &elf) {
|
||||
programInfo.prepareLinkerInputStorage();
|
||||
|
||||
LinkerInput::SectionNameToSegmentIdMap nameToKernelId;
|
||||
for (uint32_t id = 0; id < static_cast<uint32_t>(programInfo.kernelInfos.size()); id++) {
|
||||
nameToKernelId[programInfo.kernelInfos[id]->kernelDescriptor.kernelMetadata.kernelName] = id;
|
||||
}
|
||||
programInfo.linkerInput->decodeElfSymbolTableAndRelocations(elf, nameToKernelId);
|
||||
}
|
||||
|
||||
template <>
|
||||
DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) {
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_64>(src.deviceBinary, outErrReason, outWarning);
|
||||
if (nullptr == elf.elfFileHeader) {
|
||||
return DecodeError::InvalidBinary;
|
||||
}
|
||||
|
||||
dst.grfSize = src.targetDevice.grfSize;
|
||||
dst.minScratchSpaceSize = src.targetDevice.minScratchSpaceSize;
|
||||
auto decodeError = decodeZebin(dst, elf, outErrReason, outWarning);
|
||||
prepareLinkerInputForZebin(dst, elf);
|
||||
|
||||
return decodeError;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -26,6 +26,17 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
template <>
|
||||
bool isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>(const ArrayRef<const uint8_t> binary) {
|
||||
auto header = Elf::decodeElfFileHeader<Elf::EI_CLASS_64>(binary);
|
||||
if (nullptr == header) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return header->type == NEO::Elf::ET_REL ||
|
||||
header->type == NEO::Elf::ET_ZEBIN_EXE;
|
||||
}
|
||||
|
||||
bool validateTargetDevice(const Elf::Elf<Elf::EI_CLASS_64> &elf, const TargetDevice &targetDevice, std::string &outErrReason, std::string &outWarning) {
|
||||
GFXCORE_FAMILY gfxCore = IGFX_UNKNOWN_CORE;
|
||||
PRODUCT_FAMILY productFamily = IGFX_UNKNOWN;
|
||||
@@ -1427,13 +1438,7 @@ NEO::DecodeError populateKernelSourceAttributes(NEO::KernelDescriptor &dst, NEO:
|
||||
return DecodeError::Success;
|
||||
}
|
||||
|
||||
template <>
|
||||
DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) {
|
||||
auto elf = Elf::decodeElf<Elf::EI_CLASS_64>(src.deviceBinary, outErrReason, outWarning);
|
||||
if (nullptr == elf.elfFileHeader) {
|
||||
return DecodeError::InvalidBinary;
|
||||
}
|
||||
|
||||
NEO::DecodeError decodeZebin(ProgramInfo &dst, NEO::Elf::Elf<NEO::Elf::EI_CLASS_64> &elf, std::string &outErrReason, std::string &outWarning) {
|
||||
ZebinSections zebinSections;
|
||||
auto extractError = extractZebinSections(elf, zebinSections, outErrReason, outWarning);
|
||||
if (DecodeError::Success != extractError) {
|
||||
@@ -1445,10 +1450,6 @@ DecodeError decodeSingleDeviceBinary<NEO::DeviceBinaryFormat::Zebin>(ProgramInfo
|
||||
return extractError;
|
||||
}
|
||||
|
||||
dst.decodedElf = elf;
|
||||
dst.grfSize = src.targetDevice.grfSize;
|
||||
dst.minScratchSpaceSize = src.targetDevice.minScratchSpaceSize;
|
||||
|
||||
if (false == zebinSections.globalDataSections.empty()) {
|
||||
dst.globalVariables.initData = zebinSections.globalDataSections[0]->data.begin();
|
||||
dst.globalVariables.size = zebinSections.globalDataSections[0]->data.size();
|
||||
|
||||
@@ -121,4 +121,6 @@ NEO::DecodeError populateZeInfoVersion(NEO::Elf::ZebinKernelMetadata::Types::Ver
|
||||
NEO::DecodeError populateExternalFunctionsMetadata(NEO::ProgramInfo &dst, NEO::Yaml::YamlParser &yamlParser, const NEO::Yaml::Node &functionNd, std::string &outErrReason, std::string &outWarning);
|
||||
|
||||
NEO::DecodeError populateKernelSourceAttributes(NEO::KernelDescriptor &dst, NEO::Elf::ZebinKernelMetadata::Types::Kernel::Attributes::AttributesBaseT &attributes);
|
||||
|
||||
NEO::DecodeError decodeZebin(ProgramInfo &dst, NEO::Elf::Elf<NEO::Elf::EI_CLASS_64> &elf, std::string &outErrReason, std::string &outWarning);
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user