Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion components/elf_loader/include/private/elf_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
27 changes: 27 additions & 0 deletions components/elf_loader/src/esp_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion components/elf_loader/src/esp_elf_symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down