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

Function write_phdrs

util/cbfstool/elfheaders.c:956–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

954}
955
956static void write_phdrs(struct elf_writer *ew, struct buffer *phdrs)
957{
958 Elf64_Half i;
959 Elf64_Phdr phdr;
960 size_t num_written = 0;
961 size_t num_needs_write = 0;
962
963 for (i = 0; i < ew->num_secs; i++) {
964 struct elf_writer_section *sec = &ew->sections[i];
965
966 if (!(sec->shdr.sh_flags & SHF_ALLOC))
967 continue;
968
969 if (!section_consecutive(ew, i)) {
970 /* Write out previously set phdr. */
971 if (num_needs_write != num_written) {
972 phdr_write(ew, phdrs, &phdr);
973 num_written++;
974 }
975 phdr.p_type = PT_LOAD;
976 phdr.p_offset = sec->shdr.sh_offset;
977 phdr.p_vaddr = sec->shdr.sh_addr;
978 phdr.p_paddr = sec->shdr.sh_addr;
979 phdr.p_filesz = buffer_size(&sec->content);
980 phdr.p_memsz = sec->shdr.sh_size;
981 phdr.p_flags = 0;
982 if (sec->shdr.sh_flags & SHF_EXECINSTR)
983 phdr.p_flags |= PF_X | PF_R;
984 if (sec->shdr.sh_flags & SHF_WRITE)
985 phdr.p_flags |= PF_W;
986 phdr.p_align = sec->shdr.sh_addralign;
987 num_needs_write++;
988
989 } else {
990 /* Accumulate file size and memsize. The assumption
991 * is that each section is either NOBITS or full
992 * (sh_size == file size). This is standard in that
993 * an ELF section doesn't have a file size component. */
994 if (sec->shdr.sh_flags & SHF_EXECINSTR)
995 phdr.p_flags |= PF_X | PF_R;
996 if (sec->shdr.sh_flags & SHF_WRITE)
997 phdr.p_flags |= PF_W;
998 phdr.p_filesz += buffer_size(&sec->content);
999 phdr.p_memsz += sec->shdr.sh_size;
1000 }
1001 }
1002
1003 /* Write out the last phdr. */
1004 if (num_needs_write != num_written) {
1005 phdr_write(ew, phdrs, &phdr);
1006 num_written++;
1007 }
1008 assert(num_written == ew->ehdr.e_phnum);
1009}
1010
1011static void fixup_symbol_table(struct elf_writer *ew)
1012{

Callers 1

elf_writer_serializeFunction · 0.85

Calls 3

section_consecutiveFunction · 0.85
phdr_writeFunction · 0.85
buffer_sizeFunction · 0.85

Tested by

no test coverage detected