Skip to content

ElfSymbol

Description

Decoded symbol-table entry. name is borrowed from the file’s .strtab (for symbols) or .dynstr (for dynamic_symbols).

Usage example (Cross-references)

Usage examples (Cross-references)
        bool ok = false;
        for (u64 i = 0; i < elf.symbols.length; ++i) {
            const ElfSymbol *s = &elf.symbols.data[i];
            if (s->type == ELF_SYMBOL_TYPE_FUNC && s->size > 0 && s->name && s->name[0] != '\0') {
                ok = true;
    
        u64              file_relative = addr - load_base;
        const ElfSymbol *sym           = ElfFileResolveAddress(&cache_entry->elf, file_relative);
        if (sym && sym->name && sym->name[0]) {
            out->symbol_name  = sym->name;
            StrReadFmt(cursor, FMT_SYM64_LE, name, info, other, shndx, value, size_);
    
            ElfSymbol s;
            s.name          = elf_str_at(self, strtab->offset, strtab->size, name);
            s.bind          = (ElfSymbolBind)(info >> 4);
    // ---------------------------------------------------------------------------
    
    static const ElfSymbol *elf_search_symbols(const ElfSymbols *syms, u64 vaddr) {
        const ElfSymbol *best = NULL;
        for (u64 i = 0; i < syms->length; ++i) {
    
    static const ElfSymbol *elf_search_symbols(const ElfSymbols *syms, u64 vaddr) {
        const ElfSymbol *best = NULL;
        for (u64 i = 0; i < syms->length; ++i) {
            const ElfSymbol *s = &syms->data[i];
        const ElfSymbol *best = NULL;
        for (u64 i = 0; i < syms->length; ++i) {
            const ElfSymbol *s = &syms->data[i];
            if (s->size == 0) {
                // Some symbols (e.g. labels) have zero size — only match
    }
    
    const ElfSymbol *ElfFileResolveAddress(const ElfFile *self, u64 vaddr) {
        if (!self)
            return NULL;
        if (!self)
            return NULL;
        const ElfSymbol *hit = elf_search_symbols(&self->symbols, vaddr);
        if (hit)
            return hit;
        u64           value; // virtual address for ET_EXEC / ET_DYN
        u64           size;
    } ElfSymbol;
    
    typedef Vec(ElfSection) ElfSections;
    
    typedef Vec(ElfSection) ElfSections;
    typedef Vec(ElfSymbol) ElfSymbols;
    
    ///
    /// TAGS: Parser, ELF, Symbol
    ///
    const ElfSymbol *ElfFileResolveAddress(const ElfFile *self, u64 vaddr);
    
    ///
Last updated on