llext: use elf_rela_t instead of elf_rel_t

elf_rela_t contains elf_rel_t exactly and contains an additional
field at the end. Therefore pointers of that type can be used for
both types, making the code generic.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
This commit is contained in:
Guennadi Liakhovetski 2023-09-22 15:40:26 +02:00 committed by Carles Cufí
parent bca88b4b3a
commit a9a82d557c
4 changed files with 18 additions and 4 deletions

View file

@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(elf, CONFIG_LLEXT_LOG_LEVEL);
* The relocation codes for arm are well documented
* https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#relocation
*/
void arch_elf_relocate(elf_rel_t *rel, uintptr_t opaddr, uintptr_t opval)
void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval)
{
elf_word reloc_type = ELF32_R_TYPE(rel->r_info);

View file

@ -306,6 +306,12 @@ struct elf32_rel {
elf32_word r_info;
};
struct elf32_rela {
elf32_addr r_offset;
elf32_word r_info;
elf32_word r_addend;
};
/**
* @brief Relocation symbol index from r_info
*
@ -330,6 +336,12 @@ struct elf64_rel {
elf64_xword r_info;
};
struct elf64_rela {
elf64_addr r_offset;
elf64_word r_info;
elf64_word r_addend;
};
/** @brief Relocation symbol from r_info
*
* @param i Value of r_info
@ -436,6 +448,7 @@ typedef elf64_half elf_half;
typedef elf64_xword elf_word;
/** Machine sized relocation struct */
typedef struct elf64_rel elf_rel_t;
typedef struct elf64_rela elf_rela_t;
/** Machine sized symbol struct */
typedef struct elf64_sym elf_sym_t;
/** Machine sized macro alias for obtaining a relocation symbol */
@ -461,6 +474,7 @@ typedef elf32_half elf_half;
typedef elf32_word elf_word;
/** Machine sized relocation struct */
typedef struct elf32_rel elf_rel_t;
typedef struct elf32_rela elf_rela_t;
/** Machine sized symbol struct */
typedef struct elf32_sym elf_sym_t;
/** Machine sized macro alias for obtaining a relocation symbol */

View file

@ -135,7 +135,7 @@ int llext_call_fn(struct llext *ext, const char *sym_name);
* @param[in] opaddr Address of operation to rewrite with relocation
* @param[in] opval Value of looked up symbol to relocate
*/
void arch_elf_relocate(elf_rel_t *rel, uintptr_t opaddr, uintptr_t opval);
void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval);
/**
* @}

View file

@ -403,7 +403,7 @@ out:
return ret;
}
__weak void arch_elf_relocate(elf_rel_t *rel, uintptr_t opaddr, uintptr_t opval)
__weak void arch_elf_relocate(elf_rela_t *rel, uintptr_t opaddr, uintptr_t opval)
{
}
@ -412,7 +412,7 @@ static int llext_link(struct llext_loader *ldr, struct llext *ext)
int ret = 0;
uintptr_t loc = 0;
elf_shdr_t shdr;
elf_rel_t rel;
elf_rela_t rel;
elf_sym_t sym;
size_t pos = ldr->hdr.e_shoff;
elf_word rel_cnt = 0;