Skip to content

Commit a304bcb

Browse files
Implement symbol resolver
1 parent e507029 commit a304bcb

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

components/elf_loader/include/private/elf_symbol.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern "C" {
1313
#endif
1414

15-
#define ESP_ELFSYM_EXPORT(_sym) { #_sym, &_sym }
15+
#define ESP_ELFSYM_EXPORT(_sym) { #_sym, (void*)&_sym }
1616
#define ESP_ELFSYM_END { NULL, NULL }
1717

1818
/** @brief Function symbol description */
@@ -31,6 +31,24 @@ struct esp_elfsym {
3131
*/
3232
uintptr_t elf_find_sym(const char *sym_name);
3333

34+
35+
/**
36+
* @brief Resolves a symbol name (e.g. function name) to its address.
37+
*
38+
* @param sym_name - Symbol name
39+
* @return Symbol address if success or 0 if failed.
40+
*/
41+
typedef uintptr_t (*symbol_resolver)(const char *sym_name);
42+
43+
/**
44+
* @brief Override the internal symbol resolver.
45+
* The default resolver is based on static lists that are determined by KConfig.
46+
* This override allows for an arbitrary implementation.
47+
*
48+
* @param resolver the resolver function
49+
*/
50+
void elf_set_symbol_resolver(symbol_resolver resolver);
51+
3452
#ifdef __cplusplus
3553
}
3654
#endif

components/elf_loader/src/esp_elf.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@
1919

2020
#include "private/elf_symbol.h"
2121
#include "private/elf_platform.h"
22+
#include "esp_elf.h"
2223

2324
#define stype(_s, _t) ((_s)->type == (_t))
2425
#define sflags(_s, _f) (((_s)->flags & (_f)) == (_f))
2526
#define ADDR_OFFSET (0x400)
2627

28+
uintptr_t elf_find_sym_default(const char *sym_name);
29+
2730
static const char *TAG = "ELF";
31+
static symbol_resolver current_resolver = elf_find_sym_default;
32+
33+
/**
34+
* @brief Find symbol address by name.
35+
*
36+
* @param sym_name - Symbol name
37+
*
38+
* @return Symbol address if success or 0 if failed.
39+
*/
40+
uintptr_t elf_find_sym(const char *sym_name) {
41+
return current_resolver(sym_name);
42+
}
2843

2944
#if CONFIG_ELF_LOADER_BUS_ADDRESS_MIRROR
3045

@@ -306,6 +321,18 @@ static int esp_elf_load_segment(esp_elf_t *elf, const uint8_t *pbuf)
306321
}
307322
#endif
308323

324+
/**
325+
* @brief Override the internal symbol resolver.
326+
* The default resolver is based on static lists that are determined by KConfig.
327+
* This override allows for an arbitrary implementation.
328+
*
329+
* @param resolver the resolver function
330+
*/
331+
void elf_set_symbol_resolver(symbol_resolver resolver) {
332+
current_resolver = resolver;
333+
}
334+
335+
309336
/**
310337
* @brief Map symbol's address of ELF to physic space.
311338
*

components/elf_loader/src/esp_elf_symbol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const struct esp_elfsym g_esp_espidf_elfsyms[] = {
156156
*
157157
* @return Symbol address if success or 0 if failed.
158158
*/
159-
uintptr_t elf_find_sym(const char *sym_name)
159+
uintptr_t elf_find_sym_default(const char *sym_name)
160160
{
161161
const struct esp_elfsym *syms;
162162

0 commit comments

Comments
 (0)