MCPcopy Create free account
hub / github.com/coreboot/coreboot / parse_elf

Function parse_elf

util/cbfstool/elfheaders.c:486–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

484}
485
486int parse_elf(const struct buffer *pinput, struct parsed_elf *pelf, int flags)
487{
488 struct xdr *xdr = &xdr_le;
489 int bit64 = 0;
490 struct buffer input;
491 Elf64_Ehdr *ehdr;
492
493 /* Zero out the parsed elf structure. */
494 memset(pelf, 0, sizeof(*pelf));
495
496 if (buffer_size(pinput) < sizeof(*ehdr)) {
497 DEBUG("The stage file is too short!\n");
498 return -1;
499 }
500
501 if (!iself(buffer_get(pinput))) {
502 DEBUG("The stage file is not in ELF format!\n");
503 return -1;
504 }
505
506 buffer_clone(&input, pinput);
507 ehdr = &pelf->ehdr;
508 elf_eident(&input, ehdr);
509 bit64 = ehdr->e_ident[EI_CLASS] == ELFCLASS64;
510 /* Assume LE unless we are sure otherwise.
511 * We're not going to take on the task of
512 * fully validating the ELF file. That way
513 * lies madness.
514 */
515 if (ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
516 xdr = &xdr_be;
517
518 elf_ehdr(&input, ehdr, xdr, bit64);
519
520 /* Relocation processing requires section header parsing. */
521 if (flags & ELF_PARSE_RELOC)
522 flags |= ELF_PARSE_SHDR;
523
524 /* String table processing requires section header parsing. */
525 if (flags & ELF_PARSE_STRTAB)
526 flags |= ELF_PARSE_SHDR;
527
528 /* Symbole table processing requires section header parsing. */
529 if (flags & ELF_PARSE_SYMTAB)
530 flags |= ELF_PARSE_SHDR;
531
532 if ((flags & ELF_PARSE_PHDR) && phdr_read(pinput, pelf, xdr, bit64))
533 goto fail;
534
535 if ((flags & ELF_PARSE_SHDR) && shdr_read(pinput, pelf, xdr, bit64))
536 goto fail;
537
538 if ((flags & ELF_PARSE_RELOC) && reloc_read(pinput, pelf, xdr, bit64))
539 goto fail;
540
541 if ((flags & ELF_PARSE_STRTAB) && strtab_read(pinput, pelf))
542 goto fail;
543

Callers 6

qualcomm_find_hash_mbnv7Function · 0.85
qualcomm_find_hashFunction · 0.85
rmodule_initFunction · 0.85
parse_elf_to_xip_ramFunction · 0.85
parse_elf_to_stageFunction · 0.85
elf_headersFunction · 0.85

Calls 13

buffer_sizeFunction · 0.85
buffer_getFunction · 0.85
buffer_cloneFunction · 0.85
elf_eidentFunction · 0.85
elf_ehdrFunction · 0.85
phdr_readFunction · 0.85
shdr_readFunction · 0.85
reloc_readFunction · 0.85
strtab_readFunction · 0.85
symtab_readFunction · 0.85
parsed_elf_destroyFunction · 0.85
iselfFunction · 0.70

Tested by

no test coverage detected