From b23afcc956670b93606f0ef376bb9111b2d70aa9 Mon Sep 17 00:00:00 2001 From: rbramand Date: Tue, 10 Dec 2024 18:30:02 +0530 Subject: [PATCH 1/2] Add changes to support 32 bit addend address in ELF patching Signed-off-by: rbramand --- src/runtime_src/core/common/api/xrt_module.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index c2ccb38daf0..f44db0fa1f2 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -754,6 +754,7 @@ class module_elf : public module_impl auto end = begin + sec->get_size() / sizeof(const ELFIO::Elf32_Rela); for (auto rela = begin; rela != end; ++rela) { auto symidx = ELFIO::get_sym_and_type::get_r_sym(rela->r_info); + auto type = ELFIO::get_sym_and_type::get_r_type(rela->r_info); auto dynsym_offset = symidx * sizeof(ELFIO::Elf32_Sym); if (dynsym_offset >= dynsym->get_size()) @@ -786,16 +787,20 @@ class module_elf : public module_impl if (offset >= sec_size) throw std::runtime_error("Invalid offset " + std::to_string(offset)); + // rela addend have offset to base_bo_addr info along with schema + // rela addend 4-31 bits are used for base_bo_addr 0-27 bits and + // rela info type 4-7 bits are used for base_bo_addr 28-31 bits uint32_t add_end_higher_28bit = (rela->r_addend & addend_mask) >> addend_shift; - std::string argnm{ symname, symname + std::min(strlen(symname), dynstr->get_size()) }; + uint32_t add_end_addr = (((type >> 4) & 0xF) << 28) | add_end_higher_28bit; // NOLINT + std::string argnm{ symname, symname + std::min(strlen(symname), dynstr->get_size()) }; auto patch_scheme = static_cast(rela->r_addend & schema_mask); patcher::patch_info pi = patch_scheme == patcher::symbol_type::scalar_32bit_kind ? // st_size is is encoded using register value mask for scaler_32 // for other pacthing scheme it is encoded using size of dma - patcher::patch_info{ offset, add_end_higher_28bit, static_cast(sym->st_size) } : - patcher::patch_info{ offset, add_end_higher_28bit, 0 }; + patcher::patch_info{ offset, add_end_addr, static_cast(sym->st_size) } : + patcher::patch_info{ offset, add_end_addr, 0 }; auto key_string = generate_key_string(argnm, buf_type); From add8364eae64c486fb8e95ae0f9ab0c67a7b5618 Mon Sep 17 00:00:00 2001 From: rbramand Date: Wed, 11 Dec 2024 17:17:10 +0530 Subject: [PATCH 2/2] Made changes according to new spec Signed-off-by: rbramand --- .../core/common/api/xrt_module.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index f44db0fa1f2..98c73f0be5e 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -787,15 +787,20 @@ class module_elf : public module_impl if (offset >= sec_size) throw std::runtime_error("Invalid offset " + std::to_string(offset)); - // rela addend have offset to base_bo_addr info along with schema - // rela addend 4-31 bits are used for base_bo_addr 0-27 bits and - // rela info type 4-7 bits are used for base_bo_addr 28-31 bits - uint32_t add_end_higher_28bit = (rela->r_addend & addend_mask) >> addend_shift; - uint32_t add_end_addr = (((type >> 4) & 0xF) << 28) | add_end_higher_28bit; // NOLINT + patcher::symbol_type patch_scheme; + uint32_t add_end_addr; + auto abi_version = static_cast(elf.get_abi_version()); + if (abi_version != 1) { + add_end_addr = rela->r_addend; + patch_scheme = static_cast(type); + } + else { + // rela addend have offset to base_bo_addr info along with schema + add_end_addr = (rela->r_addend & addend_mask) >> addend_shift; + patch_scheme = static_cast(rela->r_addend & schema_mask); + } std::string argnm{ symname, symname + std::min(strlen(symname), dynstr->get_size()) }; - auto patch_scheme = static_cast(rela->r_addend & schema_mask); - patcher::patch_info pi = patch_scheme == patcher::symbol_type::scalar_32bit_kind ? // st_size is is encoded using register value mask for scaler_32 // for other pacthing scheme it is encoded using size of dma