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

Function elf_writer_init

util/cbfstool/elfheaders.c:757–802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

755}
756
757struct elf_writer *elf_writer_init(const Elf64_Ehdr *ehdr)
758{
759 struct elf_writer *ew;
760 Elf64_Shdr shdr;
761 struct buffer empty_buffer;
762
763 if (!iself(ehdr))
764 return NULL;
765
766 ew = calloc(1, sizeof(*ew));
767
768 memcpy(&ew->ehdr, ehdr, sizeof(ew->ehdr));
769
770 ew->bit64 = ew->ehdr.e_ident[EI_CLASS] == ELFCLASS64;
771
772 /* Set the endinan ops. */
773 if (ew->ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
774 ew->xdr = &xdr_be;
775 else
776 ew->xdr = &xdr_le;
777
778 /* Reset count and offsets */
779 ew->ehdr.e_phoff = 0;
780 ew->ehdr.e_shoff = 0;
781 ew->ehdr.e_shnum = 0;
782 ew->ehdr.e_phnum = 0;
783
784 memset(&empty_buffer, 0, sizeof(empty_buffer));
785 memset(&shdr, 0, sizeof(shdr));
786
787 /* Add SHT_NULL section header. */
788 shdr.sh_type = SHT_NULL;
789 elf_writer_add_section(ew, &shdr, &empty_buffer, NULL);
790
791 /* Add section header string table and maintain reference to it. */
792 shdr.sh_type = SHT_STRTAB;
793 elf_writer_add_section(ew, &shdr, &empty_buffer, ".shstrtab");
794 ew->shstrtab_sec = last_section(ew);
795 ew->ehdr.e_shstrndx = section_index(ew, ew->shstrtab_sec);
796
797 /* Add a small string table and symbol table. */
798 strtab_init(ew, 4096);
799 symtab_init(ew, 100);
800
801 return ew;
802}
803
804/*
805 * Clean up any internal state represented by ew. Aftewards the elf_writer

Callers 4

write_elfFunction · 0.85
rmodule_stage_to_elfFunction · 0.85
cbfs_stage_make_elfFunction · 0.85
cbfs_payload_make_elfFunction · 0.85

Calls 9

elf_writer_add_sectionFunction · 0.85
last_sectionFunction · 0.85
section_indexFunction · 0.85
strtab_initFunction · 0.85
symtab_initFunction · 0.85
iselfFunction · 0.70
callocFunction · 0.50
memcpyFunction · 0.50
memsetFunction · 0.50

Tested by

no test coverage detected