diff --git a/libr/bin/format/elf/elf.c b/libr/bin/format/elf/elf.c index b5b5dc8320d8f..de46877cbeef4 100644 --- a/libr/bin/format/elf/elf.c +++ b/libr/bin/format/elf/elf.c @@ -991,9 +991,7 @@ static Sdb *store_versioninfo_gnu_verdef(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) } size_t shsize = shdr->sh_size; if (shdr->sh_size > bin->size) { - if (bin->verbose) { - eprintf ("Truncating shsize from %d to %d\n", (int)shdr->sh_size, (int)bin->size); - } + R_LOG_DEBUG ("Truncating shsize from %d to %d", (int)shdr->sh_size, (int)bin->size); if (bin->size > shdr->sh_offset) { shsize = bin->size - shdr->sh_offset; } else { @@ -1535,6 +1533,7 @@ static ut64 get_import_addr_loongarch(ELFOBJ *bin, RBinElfReloc *rel) { ut64 pos = COMPUTE_PLTGOT_POSITION(rel, got_addr, 0x2); return plt_addr + LOONGARCH_PLT_OFFSET + pos * LOONGARCH_PLT_ENTRY_SIZE; } + static ut64 get_import_addr_sparc(ELFOBJ *bin, RBinElfReloc *rel) { if (rel->type != R_SPARC_JMP_SLOT) { R_LOG_DEBUG ("Unknown sparc reloc type %d", rel->type); @@ -1686,7 +1685,7 @@ static ut64 get_import_addr(ELFOBJ *bin, int sym) { case EM_LOONGARCH: return get_import_addr_loongarch(bin, rel); default: - eprintf ("Unsupported relocs type %" PFMT64u " for arch %d\n", + R_LOG_WARN ("Unsupported relocs type %" PFMT64u " for arch %d", (ut64) rel->type, bin->ehdr.e_machine); return UT64_MAX; } @@ -1914,7 +1913,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { /* non-thumb entry points */ if (!memcmp (buf, "\x00\xb0\xa0\xe3\x00\xe0\xa0\xe3", 8)) { if (buf[0x40 + 2] == 0xff && buf[0x40 + 3] == 0xeb) { - // eprintf ("custom\n"); + // nothing to do } else if (!memcmp (buf + 0x28 + 2, "\xff\xeb", 2)) { return Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[0x34]) & ~1); } @@ -3998,6 +3997,7 @@ RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin, s ptr->bind = symbol->bind; ptr->type = symbol->type; ptr->is_imported = symbol->is_imported; + // ptr->is_internal = symbol->is_internal; ptr->paddr = paddr; ptr->vaddr = vaddr; ptr->size = symbol->size; @@ -4112,7 +4112,7 @@ typedef struct import_info_t { int nsym; } ImportInfo; -static RVector *_load_additional_imported_symbols (ELFOBJ *bin, ImportInfo *import_info) { +static RVector *_load_additional_imported_symbols(ELFOBJ *bin, ImportInfo *import_info) { // Elf_(fix_symbols) may find additional symbols, some of which could be // imported symbols. Let's reserve additional space for them. int nsym = import_info->nsym; @@ -4312,14 +4312,12 @@ static RVector /* */ *Elf_(_r_bin_elf_load_symbols_and_imports)( bool is_sht_null = false; bool is_vaddr = false; bool is_imported = false; + bool is_internal = false; if (type == R_BIN_ELF_IMPORT_SYMBOLS) { - if (memory.sym[k].st_value) { - toffset = memory.sym[k].st_value; - } else if ((toffset = get_import_addr (bin, k)) == -1) { - toffset = 0; - } + toffset = get_import_addr (bin, k); tsize = 16; - is_imported = memory.sym[k].st_shndx == STN_UNDEF; + is_imported = true; + is_internal = memory.sym[k].st_shndx != STN_UNDEF; } else { tsize = memory.sym[k].st_size; toffset = (ut64)memory.sym[k].st_value; @@ -4362,6 +4360,7 @@ static RVector /* */ *Elf_(_r_bin_elf_load_symbols_and_imports)( es->is_sht_null = is_sht_null; es->is_vaddr = is_vaddr; es->is_imported = is_imported; + es->is_internal = is_internal; if (type == R_BIN_ELF_IMPORT_SYMBOLS && is_imported) { import_ret_ctr++; } diff --git a/libr/bin/format/elf/elf.h b/libr/bin/format/elf/elf.h index 2fe19b28d8265..0b4ef65bf2b0b 100644 --- a/libr/bin/format/elf/elf.h +++ b/libr/bin/format/elf/elf.h @@ -58,6 +58,7 @@ typedef struct r_bin_elf_symbol_t { bool is_sht_null; bool is_vaddr; /* when true, offset is virtual address, otherwise it's physical */ bool is_imported; + bool is_internal; } RBinElfSymbol; typedef struct r_bin_elf_reloc_t { diff --git a/libr/bin/p/bin_elf.inc b/libr/bin/p/bin_elf.inc index 618f57711efc8..2954e0c7552ab 100644 --- a/libr/bin/p/bin_elf.inc +++ b/libr/bin/p/bin_elf.inc @@ -403,11 +403,13 @@ static RList* imports(RBinFile *bf) { RBinElfSymbol *import_symbol; r_vector_foreach (import_symbols, import_symbol) { + if (import_symbol->is_internal) { + continue; + } RBinImport *ptr = R_NEW0 (RBinImport); if (!ptr) { break; } - ptr->name = strdup (import_symbol->name); ptr->bind = import_symbol->bind; ptr->type = import_symbol->type;