From f2fc943fea8c47050d16f08472f7d2decd937863 Mon Sep 17 00:00:00 2001 From: rbramand Date: Tue, 10 Dec 2024 18:30:02 +0530 Subject: [PATCH] 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 2a7a7183351..5767c56ab71 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -753,6 +753,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()) @@ -785,16 +786,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);