4 #include <libelfu/libelfu.h>
7 static void modelToPhdrs(ElfuElf *me, Elf *e)
14 CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
18 if (!gelf_newphdr(e, i)) {
19 ELFU_WARNELF("gelf_newphdr");
24 CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
25 if (!gelf_update_phdr (e, i, &mp->phdr)) {
26 ELFU_WARNELF("gelf_update_phdr");
35 static void* modelToSection(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
42 scnOut = elf_newscn(e);
44 ELFU_WARNELF("elf_newscn");
51 ms->shdr.sh_link = elfu_mScnIndex(me, ms->linkptr);
54 ms->shdr.sh_info = elfu_mScnIndex(me, ms->infoptr);
56 if (!gelf_update_shdr(scnOut, &ms->shdr)) {
57 ELFU_WARNELF("gelf_update_shdr");
63 Elf_Data *dataOut = elf_newdata(scnOut);
65 ELFU_WARNELF("elf_newdata");
69 dataOut->d_buf = ms->databuf;
71 dataOut->d_type = ELF_T_BYTE;
72 dataOut->d_size = ms->shdr.sh_size;
73 dataOut->d_version = elf_version(EV_NONE);
83 void elfu_mToElf(ElfuElf *me, Elf *e)
86 elfu_mSymtabFlatten(me);
90 /* We control the ELF file's layout now. */
91 /* tired's libelf also offers ELF_F_LAYOUT_OVERLAP for overlapping sections,
92 * but we don't want that since we filtered it out in the reading stage
93 * already. It would be too mind-blowing to handle the dependencies between
94 * the PHDRs and sections then... */
95 elf_flagelf(e, ELF_C_SET, ELF_F_LAYOUT);
99 if (!gelf_newehdr(e, me->elfclass)) {
100 ELFU_WARNELF("gelf_newehdr");
104 me->ehdr.e_shstrndx = elfu_mScnIndex(me, me->shstrtab);
107 if (!gelf_update_ehdr(e, &me->ehdr)) {
108 ELFU_WARNELF("gelf_update_ehdr");
113 elfu_mScnForall(me, modelToSection, e, NULL);
120 elf_flagelf(e, ELF_C_SET, ELF_F_DIRTY);