ElfOpen
Description
Open and parse an ELF file from disk.
Parameters
| Name | Direction | Description |
|---|---|---|
out |
out | Populated on success. |
path |
in | Filesystem path. Prefer Str *; Zstr (NUL-terminated) accepted. |
alloc |
in | Allocator for the read-in byte buffer and the section / symbol vectors. Must outlive the Elf. |
Success
Returns true; out owns the read-in buffer and will free it on ElfDeinit.
Failure
Returns false; logs the failing step (open / read / magic / class / decoding). out is left zeroed.
Usage example (Cross-references)
Usage examples (Cross-references)
append_build_id_path(&path, main->build_id, main->build_id_size);
StrPushBackMany(&path, ".debug");
if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
if (sidecar_matches(main, out, /*by_build_id*/ true)) {
StrDeinit(&path); StrPushBackR(&path, '/');
StrPushBackMany(&path, main->debuglink_name);
if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
if (sidecar_matches(main, out, /*by_build_id*/ false)) {
StrDeinit(&path); StrPushBackMany(&path, "/.debug/");
StrPushBackMany(&path, main->debuglink_name);
if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
if (sidecar_matches(main, out, /*by_build_id*/ false)) {
StrDeinit(&path); StrPushBackR(&path, '/');
StrPushBackMany(&path, main->debuglink_name);
if (sys_path_exists(StrBegin(&path)) && ElfOpen(out, &path, alloc)) {
if (sidecar_matches(main, out, /*by_build_id*/ false)) {
StrDeinit(&path); MemSet(&entry, 0, sizeof(entry));
entry.path = path;
if (!ElfOpen(&entry.elf, path, self->allocator)) {
return NULL;
}- In
Elf.c:527:
bool elf_open(Elf *out, Zstr path, Allocator *alloc) {
if (!out || !path || !alloc) {
LOG_FATAL("ElfOpen: NULL argument (contract violation)");
}
Buf data = BufInit(alloc);- In
Elf.c:532:
if (FileReadAndClose(path, &data) < 0) {
BufDeinit(&data);
LOG_ERROR("ElfOpen: failed to read {}", path);
return false;
}- In
Elf.c:257:
Elf elf;
bool opened = ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc));
if (!opened) {
DefaultAllocatorDeinit(&alloc);- In
Elf.c:280:
Elf elf;
if (!ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:303:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
if (!ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:317:
Elf elf;
if (!ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1182:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
if (!ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Elf.c:1438:
DefaultAllocator alloc = DefaultAllocatorInit();
Elf elf;
bool opened = ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc));
bool ok = opened && elf.header.machine == ELF_MACHINE_HOST && VecLen(&elf.sections) > 0;
if (opened)- In
Stripped.c:62:
// (2) Open the stripped sibling.
Elf stripped;
if (!ElfOpen(&stripped, stripped_path_arg, base)) {
LOG_ERROR("stripped binary not openable: {}", stripped_path_arg);
DefaultAllocatorDeinit(&alloc);- In
Dwarf.c:24:
Elf elf;
if (!ElfOpen(&elf, "/proc/self/exe", ALLOCATOR_OF(&alloc))) {
DefaultAllocatorDeinit(&alloc);
return false;- In
Dwarf.c:63:
Elf elf;
if (!ElfOpen(&elf, r.module_path, base)) {
SymbolResolverDeinit(&res);
DefaultAllocatorDeinit(&alloc);- In
Dwarf.c:109:
Elf elf;
if (!ElfOpen(&elf, r.module_path, base)) {
SymbolResolverDeinit(&res);
DefaultAllocatorDeinit(&alloc);- In
Dwarf.c:172:
Elf elf;
if (!ElfOpen(&elf, r.module_path, base)) {
SymbolResolverDeinit(&res);
DefaultAllocatorDeinit(&alloc);
Last updated on