diff --git a/components/elf_loader/include/private/elf_symbol.h b/components/elf_loader/include/private/elf_symbol.h index f586152056..3b58e0210f 100644 --- a/components/elf_loader/include/private/elf_symbol.h +++ b/components/elf_loader/include/private/elf_symbol.h @@ -12,7 +12,7 @@ extern "C" { #endif -#define ESP_ELFSYM_EXPORT(_sym) { #_sym, &_sym } +#define ESP_ELFSYM_EXPORT(_sym) { #_sym, (void*)&_sym } #define ESP_ELFSYM_END { NULL, NULL } /** @brief Function symbol description */ @@ -31,6 +31,24 @@ struct esp_elfsym { */ uintptr_t elf_find_sym(const char *sym_name); + +/** + * @brief Resolves a symbol name (e.g. function name) to its address. + * + * @param sym_name - Symbol name + * @return Symbol address if success or 0 if failed. + */ +typedef uintptr_t (*symbol_resolver)(const char *sym_name); + +/** + * @brief Override the internal symbol resolver. + * The default resolver is based on static lists that are determined by KConfig. + * This override allows for an arbitrary implementation. + * + * @param resolver the resolver function + */ +void elf_set_symbol_resolver(symbol_resolver resolver); + #ifdef __cplusplus } #endif diff --git a/components/elf_loader/src/esp_elf.c b/components/elf_loader/src/esp_elf.c index 385cefa338..6139be3ce8 100644 --- a/components/elf_loader/src/esp_elf.c +++ b/components/elf_loader/src/esp_elf.c @@ -19,12 +19,27 @@ #include "private/elf_symbol.h" #include "private/elf_platform.h" +#include "esp_elf.h" #define stype(_s, _t) ((_s)->type == (_t)) #define sflags(_s, _f) (((_s)->flags & (_f)) == (_f)) #define ADDR_OFFSET (0x400) +uintptr_t elf_find_sym_default(const char *sym_name); + static const char *TAG = "ELF"; +static symbol_resolver current_resolver = elf_find_sym_default; + +/** + * @brief Find symbol address by name. + * + * @param sym_name - Symbol name + * + * @return Symbol address if success or 0 if failed. + */ +uintptr_t elf_find_sym(const char *sym_name) { + return current_resolver(sym_name); +} #if CONFIG_ELF_LOADER_BUS_ADDRESS_MIRROR @@ -306,6 +321,18 @@ static int esp_elf_load_segment(esp_elf_t *elf, const uint8_t *pbuf) } #endif +/** + * @brief Override the internal symbol resolver. + * The default resolver is based on static lists that are determined by KConfig. + * This override allows for an arbitrary implementation. + * + * @param resolver the resolver function + */ +void elf_set_symbol_resolver(symbol_resolver resolver) { + current_resolver = resolver; +} + + /** * @brief Map symbol's address of ELF to physic space. * diff --git a/components/elf_loader/src/esp_elf_symbol.c b/components/elf_loader/src/esp_elf_symbol.c index cbe22fc4fb..5bddcfd7ab 100644 --- a/components/elf_loader/src/esp_elf_symbol.c +++ b/components/elf_loader/src/esp_elf_symbol.c @@ -156,7 +156,7 @@ static const struct esp_elfsym g_esp_espidf_elfsyms[] = { * * @return Symbol address if success or 0 if failed. */ -uintptr_t elf_find_sym(const char *sym_name) +uintptr_t elf_find_sym_default(const char *sym_name) { const struct esp_elfsym *syms;