Skip to content

ElfDeinit

Description

Release storage owned by an Elf. Frees the byte buffer through the data Buf’s carried allocator and tears down the section / symbol vectors. All three ElfOpen* constructors leave the parser as the sole owner of data, so this is unconditional. Safe to call on a zeroed struct.

Success

Returns to the caller. *self is zeroed.

Failure

Function cannot fail. NULL self is a no-op.

Usage example (Cross-references)

Usage examples (Cross-references)
                    return true;
                }
                ElfDeinit(out);
            }
        }
                    return true;
                }
                ElfDeinit(out);
            }
                    return true;
                }
                ElfDeinit(out);
            }
                    return true;
                }
                ElfDeinit(out);
            }
        }
        if (!VecPushBackR(&self->cache, entry)) {
            if (entry.has_sidecar)
                ElfDeinit(&entry.sidecar);
            ElfDeinit(&entry.elf);
            return NULL;
            if (entry.has_sidecar)
                ElfDeinit(&entry.sidecar);
            ElfDeinit(&entry.elf);
            return NULL;
        }
    #endif
            if (e->has_sidecar) {
                ElfDeinit(&e->sidecar);
            }
            ElfDeinit(&e->elf);
                ElfDeinit(&e->sidecar);
            }
            ElfDeinit(&e->elf);
        }
        VecDeinit(&self->cache);
    
    fail:
        ElfDeinit(out);
        return false;
    }
    }
    
    void ElfDeinit(Elf *self) {
        if (!self)
            return;
        ok = ok && VecLen(&elf.symbols) > 0;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool              ok   = text != NULL && text->size > 0 && (text->flags & 0x4); // SHF_EXECINSTR = 0x4
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.build_id != NULL && elf.build_id_size > 0 && elf.build_id_size <= 64;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && found_func;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
                     s1->vaddr != s1->offset; // distinct vaddr/offset survives decode
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        ok = ok && s == NULL;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = ElfFindSection(&elf, ".nosuchsection") == NULL && ElfFindSection(&elf, ".text") != NULL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             opened = ElfOpenFromMemoryCopy(&elf, bytes, len, ALLOCATOR_OF(&alloc));
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return !opened;
             elf.debuglink_crc == DEBUGLINK_CRC;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
             last->offset == STRTAB_OFF && last->size == STRTAB_SZ;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
                  t->size == TEXT_SIZE && (t->flags & 0x4) != 0;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool              ok  = sym != NULL && sym->info == SYMTAB_INFO && txt != NULL && txt->info == 0;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            // Names resolved through the in-range shstrtab.
            ok = ElfFindSection(&elf, ".shstrtab") != NULL && ElfFindSection(&elf, ".text") != NULL;
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            // Empty shstrtab => every section name decodes to "".
            ok = VecLen(&elf.sections) == N_SECTIONS;
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        if (ok) {
            ok = VecLen(&elf.sections) == N_SECTIONS;
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        bool              ok = VecLen(&elf.sections) == 2 && s1->name != NULL && s1->name[0] == '\0';
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool              ok = VecLen(&elf.sections) == 2 && s1->name != NULL && s1->name[0] == '\0';
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool              ok = VecLen(&elf.sections) == 2 && s1->name != NULL && ZstrCompare(s1->name, "XYZ") == 0;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            s != NULL && ZstrCompare(s->name, ".strtab") == 0 && sym != NULL && ZstrCompare(sym->name, ".symtab") == 0;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok = ok && ElfFindSection(&elf, ".no_such_section_xyz") == NULL;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && VecLen(&elf.sections) == elf.header.shnum;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok      = ok && VecLen(&elf.sections) == N_SECTIONS;
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             ok     = opened && elf.header.shnum == 1 && VecLen(&elf.sections) == 1;
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             opened = ElfOpenFromMemoryCopy(&elf, elf_blob, sizeof(elf_blob), ALLOCATOR_OF(&alloc));
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return opened;
        if (opened) {
            // Should not happen on real code; clean up and fail the test.
            ElfDeinit(&elf);
            DefaultAllocatorDeinit(&alloc);
            return false;
        bool             ok     = opened && elf.header.machine == ELF_MACHINE_HOST && VecLen(&elf.sections) > 0;
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = VecLen(&elf.symbols) == 5;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool ok = a->name && ZstrCompare(a->name, "alpha") == 0 && b->name && ZstrCompare(b->name, "beta") == 0 &&
                  l->name && ZstrCompare(l->name, "local") == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool             ok = a->value == SF_ALPHA_VADDR && a->size == SF_ALPHA_SIZE && a->type == ELF_SYMBOL_TYPE_FUNC &&
                  a->bind == ELF_SYMBOL_BIND_GLOBAL && a->section_index == SF_SEC_TEXT;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            ok                 = d->name && ZstrCompare(d->name, "dyn_sym") == 0 && d->value == SF_DYN_VADDR;
        }
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = ElfOpenFromMemoryCopy(&elf, sym_blob, sizeof(sym_blob), ALLOCATOR_OF(&alloc));
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return !opened; // must be rejected
        ok = ok && (s == NULL || ZstrCompare(s->name, "alpha") != 0);
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const ElfSymbol *miss = ElfResolveAddress(&elf, SF_BETA_VADDR + 1);
        bool             ok   = hit && hit->name && ZstrCompare(hit->name, "beta") == 0 && miss == NULL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const ElfSymbol *s  = ElfResolveAddress(&elf, SF_BETA_VADDR);
        bool             ok = s && s->name && ZstrCompare(s->name, "beta") == 0 && s->bind == ELF_SYMBOL_BIND_GLOBAL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        const ElfSymbol *s  = ElfResolveAddress(&elf, SF_ALPHA_VADDR + 4);
        bool             ok = s && s->name && ZstrCompare(s->name, "alpha") == 0 && s->bind == ELF_SYMBOL_BIND_GLOBAL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool ok =
            elf.build_id != NULL && elf.build_id_size == sizeof(desc) && MemCompare(elf.build_id, desc, sizeof(desc)) == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.build_id != NULL && elf.build_id_size == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.build_id == NULL && elf.build_id_size == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.build_id == NULL && elf.build_id_size == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.build_id == NULL && elf.build_id_size == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool ok = elf.debuglink_name != NULL && ZstrCompare(elf.debuglink_name, "abc.debug") == 0 &&
                  elf.debuglink_crc == 0x0a0b0c0du;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.debuglink_name == NULL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.debuglink_name == NULL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.debuglink_name == NULL;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = ElfOpenFromMemoryCopy(&elf, blob, sizeof(blob), ALLOCATOR_OF(&alloc));
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        // Real code: range check on 128 fails -> rejected. Mutant: 42 passes,
        ok = ok && elf.debuglink_name != NULL && ZstrCompare(elf.debuglink_name, "foo.debug") == 0 &&
             elf.debuglink_crc == DEBUGLINK_CRC;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        // but we only assert build-id here.)
        bool ok = elf.build_id == NULL && elf.build_id_size == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
        bool ok = elf.debuglink_name == NULL && elf.debuglink_crc == 0;
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        bool opened = ElfOpenFromMemoryCopy(&elf, buf, sizeof(buf), ALLOCATOR_OF(&alloc));
        if (opened)
            ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return !opened; // real rejects an out-of-range symtab link
        }
    
        ElfDeinit(&stripped);
        DefaultAllocatorDeinit(&alloc);
        return ok && sym_missing_or_unnamed;
            DwarfCfiDeinit(&cfi);
        }
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            DwarfCfiDeinit(&cfi);
        }
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            DwarfCfiDeinit(&cfi);
        }
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            DwarfCfiDeinit(&cfi);
        }
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
                DwarfCfiDeinit(&cfi);
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
                DwarfCfiDeinit(&cfi);
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
                DwarfCfiDeinit(&cfi);
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
                DwarfCfiDeinit(&cfi);
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
                DwarfCfiDeinit(&cfi);
            }
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        ElfDeinit(&elf);
        SymbolResolverDeinit(&res);
        DefaultAllocatorDeinit(&alloc);
        }
    
        ElfDeinit(&elf);
        SymbolResolverDeinit(&res);
        DefaultAllocatorDeinit(&alloc);
        }
    
        ElfDeinit(&elf);
        SymbolResolverDeinit(&res);
        DefaultAllocatorDeinit(&alloc);
        }
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        fx->built = DwarfLinesBuildFromElf(&fx->lines, &fx->elf, base);
        if (!fx->built) {
            ElfDeinit(&fx->elf);
            DefaultAllocatorDeinit(&fx->alloc);
            return false;
    static void lines_fixture_close(LinesFixture *fx) {
        DwarfLinesDeinit(&fx->lines);
        ElfDeinit(&fx->elf);
        DefaultAllocatorDeinit(&fx->alloc);
    }
    
        bool built = DwarfLinesBuildFromElf(lines, &elf, base);
        ElfDeinit(&elf);
        return built;
    }
        }
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        bool built = DwarfLinesBuildFromElf(lines, &elf, base);
        ElfDeinit(&elf);
        return built;
    }
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        // not; close the ELF either way (lines_from_debug_line opens it before
        // building).
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        }
    
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
        ok         = ok && (after == before);
    
        ElfDeinit(&elf);
        DebugAllocatorDeinit(&dbg);
        return ok;
        ok         = ok && (after == before);
    
        ElfDeinit(&elf);
        DebugAllocatorDeinit(&dbg);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            ok = false;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        } else {
            ElfDeinit(&elf);
            ElfDeinit(&elf);
        } else {
            ElfDeinit(&elf);
        }
    
        DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
        DefaultAllocatorDeinit(&alloc);
        return ok;
            ok = ok && e && e->file == NULL;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            ok = ok && e && e->dir == NULL;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            ok       = ok && first_real_row_address(&lines, &addr) && addr == (u64)-1;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            ok       = ok && first_real_row_address(&lines, &addr) && addr == (u64)-1;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            ok       = ok && first_real_row_address(&lines, &addr) && addr == (u64)-1;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
            ok       = ok && first_real_row_address(&lines, &addr) && addr == (u64)-1;
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        if (built) {
            DwarfLinesDeinit(&lines);
            ElfDeinit(&elf);
        } else {
            ElfDeinit(&elf);
            ElfDeinit(&elf);
        } else {
            ElfDeinit(&elf);
        }
        DefaultAllocatorDeinit(&alloc);
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
    
        bool ok = !built && (DebugAllocatorLiveCount(&dbg) == 0);
        if (built)
            DwarfLinesDeinit(&lines);
        ElfDeinit(&elf);
    
        bool ok = !built && (DebugAllocatorLiveCount(&dbg) == 0);
Last updated on