Skip to content

ElfSection

Description

Decoded section header. name is borrowed from the file’s .shstrtab and stays valid until ElfFileDeinit.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        const ElfSection *text = ElfFileFindSection(&elf, ".text");
        bool              ok   = text != NULL && text->size > 0 && (text->flags & 0x4); // SHF_EXECINSTR = 0x4
        out->string_pool = StrInit(alloc);
    
        const ElfSection *line_section = ElfFileFindSection(elf, ".debug_line");
        if (!line_section || line_section->size == 0) {
            // No debug info — empty result is still success.
            StrReadFmt(cursor, FMT_SHDR64_LE, name, type, flags, addr, offset, size_, link, info, addralign, entsize);
    
            ElfSection s;
            s.name       = elf_str_at(self, shstr_off, shstr_size, name);
            s.type       = type;
    // ---------------------------------------------------------------------------
    
    static bool elf_decode_symbol_table(ElfFile *self, const ElfSection *symtab, ElfSymbols *out) {
        if (!symtab || symtab->size == 0) {
            return true;
            return false;
        }
        const ElfSection *strtab = &self->sections.data[strtab_idx];
        if (!elf_range_ok(self, strtab->offset, strtab->size)) {
            LOG_ERROR("ElfFile: strtab out of range");
    
    static bool elf_decode_symbols(ElfFile *self) {
        const ElfSection *symtab    = NULL;
        const ElfSection *dynsymtab = NULL;
    static bool elf_decode_symbols(ElfFile *self) {
        const ElfSection *symtab    = NULL;
        const ElfSection *dynsymtab = NULL;
    
        for (u64 i = 0; i < self->sections.length; ++i) {
    
        for (u64 i = 0; i < self->sections.length; ++i) {
            const ElfSection *s = &self->sections.data[i];
            if (s->type == ELF_SECTION_TYPE_SYMTAB) {
                symtab = s;
    }
    
    const ElfSection *ElfFileFindSection(const ElfFile *self, const char *name) {
        if (!self || !name)
            return NULL;
            return NULL;
        for (u64 i = 0; i < self->sections.length; ++i) {
            const ElfSection *s = &self->sections.data[i];
            if (s->name && ZstrCompare(s->name, name) == 0) {
                return s;
        u32         info;       // section-specific
        u64         entry_size; // for table-shaped sections
    } ElfSection;
    
    ///
    } ElfSymbol;
    
    typedef Vec(ElfSection) ElfSections;
    typedef Vec(ElfSymbol) ElfSymbols;
    /// Find a section by name (first match). Returns NULL if absent.
    ///
    const ElfSection *ElfFileFindSection(const ElfFile *self, const char *name);
    
    #endif // MISRA_PARSERS_ELF_H
Last updated on