From b3f30028b340ca2b999d33e6594b7c58962d74f7 Mon Sep 17 00:00:00 2001 From: "chenwen@espressif.com" Date: Thu, 19 Dec 2024 10:34:42 +0800 Subject: [PATCH] fix(elf_loader): Fixed the issue of getting wrong symbol type --- components/elf_loader/CHANGELOG.md | 1 + components/elf_loader/src/arch/esp_elf_riscv.c | 4 ++-- components/elf_loader/src/arch/esp_elf_xtensa.c | 4 ++-- components/elf_loader/src/esp_elf.c | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/elf_loader/CHANGELOG.md b/components/elf_loader/CHANGELOG.md index d558aa002..3a0651b8c 100644 --- a/components/elf_loader/CHANGELOG.md +++ b/components/elf_loader/CHANGELOG.md @@ -4,6 +4,7 @@ * Added support for the following RISC-V chips: ESP32-P4 and ESP32-C6 * Added support for linking other components to ELF file +* Fixed the issue of getting wrong symbol type ## v0.1.0 - 2023-08-14 diff --git a/components/elf_loader/src/arch/esp_elf_riscv.c b/components/elf_loader/src/arch/esp_elf_riscv.c index 93d25b27d..ad52e0fb4 100644 --- a/components/elf_loader/src/arch/esp_elf_riscv.c +++ b/components/elf_loader/src/arch/esp_elf_riscv.c @@ -86,8 +86,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela, assert(elf && rela); where = (uint32_t *)((uint8_t *)elf->psegment + rela->offset + elf->svaddr); - ESP_LOGD(TAG, "where=%p addr=0x%x offset=0x%x", - where, (int)elf->psegment, (int)rela->offset); + ESP_LOGD(TAG, "type: %d, where=%p addr=0x%x offset=0x%x", + ELF_R_TYPE(rela->info), where, (int)elf->psegment, (int)rela->offset); /* Do relocation based on relocation type */ diff --git a/components/elf_loader/src/arch/esp_elf_xtensa.c b/components/elf_loader/src/arch/esp_elf_xtensa.c index 09e8cdf89..0e0b03ddf 100644 --- a/components/elf_loader/src/arch/esp_elf_xtensa.c +++ b/components/elf_loader/src/arch/esp_elf_xtensa.c @@ -82,8 +82,8 @@ int esp_elf_arch_relocate(esp_elf_t *elf, const elf32_rela_t *rela, where = (uint32_t *)esp_elf_map_sym(elf, rela->offset); - ESP_LOGD(TAG, "where=%p addr=0x%x offset=0x%x\n", - where, (int)addr, (int)rela->offset); + ESP_LOGD(TAG, "type: %d, where=%p addr=0x%x offset=0x%x\n", + ELF_R_TYPE(rela->info), where, (int)addr, (int)rela->offset); switch (ELF_R_TYPE(rela->info)) { case R_XTENSA_RELATIVE: diff --git a/components/elf_loader/src/esp_elf.c b/components/elf_loader/src/esp_elf.c index 4c6fe8383..385cefa33 100644 --- a/components/elf_loader/src/esp_elf.c +++ b/components/elf_loader/src/esp_elf.c @@ -410,8 +410,8 @@ int esp_elf_relocate(esp_elf_t *elf, const uint8_t *pbuf) const elf32_sym_t *sym = &symtab[ELF_R_SYM(rela_buf.info)]; - type = ELF_R_TYPE(rela->info); - if (type == STT_COMMON || type == STT_OBJECT) { + type = ELF_R_TYPE(rela_buf.info); + if (type == STT_COMMON || type == STT_OBJECT || type == STT_SECTION) { const char *comm_name = strtab + sym->name; if (comm_name[0]) {