Skip to content

Commit

Permalink
Add changes to support 32 bit addend address in ELF patching
Browse files Browse the repository at this point in the history
Signed-off-by: rbramand <[email protected]>
  • Loading branch information
rbramand committed Dec 10, 2024
1 parent 42e5fb6 commit f2fc943
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ELFIO::Elf32_Rela>::get_r_sym(rela->r_info);
auto type = ELFIO::get_sym_and_type<ELFIO::Elf32_Rela>::get_r_type(rela->r_info);

auto dynsym_offset = symidx * sizeof(ELFIO::Elf32_Sym);
if (dynsym_offset >= dynsym->get_size())
Expand Down Expand Up @@ -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<patcher::symbol_type>(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<uint32_t>(sym->st_size) } :
patcher::patch_info{ offset, add_end_higher_28bit, 0 };
patcher::patch_info{ offset, add_end_addr, static_cast<uint32_t>(sym->st_size) } :
patcher::patch_info{ offset, add_end_addr, 0 };

auto key_string = generate_key_string(argnm, buf_type);

Expand Down

0 comments on commit f2fc943

Please sign in to comment.