/* * Copyright (C) 2021-2023 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/device_binary_format/elf/elf_decoder.h" #include "shared/source/utilities/arrayref.h" #include #include #include #include namespace NEO { namespace Elf { enum RELOC_TYPE_ZEBIN : uint32_t; } class GraphicsAllocation; namespace Debug { struct Segments { struct Segment { uintptr_t address = std::numeric_limits::max(); size_t size = 0; }; using CPUSegment = Segment; using GPUSegment = Segment; using KernelNameIsaPairT = std::pair; using KernelNameToSegmentMap = std::unordered_map; GPUSegment varData; GPUSegment constData; CPUSegment stringData; KernelNameToSegmentMap nameToSegMap; Segments(); Segments(const GraphicsAllocation *globalVarAlloc, const GraphicsAllocation *globalConstAlloc, ArrayRef &globalStrings, std::vector &kernels); }; class DebugZebinCreator { public: using Elf = NEO::Elf::Elf; DebugZebinCreator() = delete; DebugZebinCreator(Elf &zebin, const Segments &segments) : segments(segments), zebin(zebin) {} void applyRelocations(); void createDebugZebin(); inline std::vector getDebugZebin() { return debugZebin; } protected: void applyRelocation(uintptr_t addr, uint64_t value, NEO::Elf::RELOC_TYPE_ZEBIN type); bool isRelocTypeSupported(NEO::Elf::RELOC_TYPE_ZEBIN type); const Segments::Segment *getSegmentByName(ConstStringRef sectionName); const Segments::Segment *getTextSegmentByName(ConstStringRef textSegmentName); bool isCpuSegment(ConstStringRef sectionName); const Segments &segments; const Elf &zebin; uint32_t symTabShndx = std::numeric_limits::max(); std::vector debugZebin; }; template void patchWithValue(uintptr_t addr, T value); std::vector createDebugZebin(ArrayRef zebin, const Segments &segmentData); } // namespace Debug } // namespace NEO