2 #include <libelfu/libelfu.h>
6 static void modelToPhdrs(ElfuElf *me, Elf *e)
13 CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
17 if (!gelf_newphdr(e, i)) {
18 ELFU_WARNELF("gelf_newphdr");
23 CIRCLEQ_FOREACH(mp, &me->phdrList, elem) {
24 if (!gelf_update_phdr (e, i, &mp->phdr)) {
25 ELFU_WARNELF("gelf_update_phdr");
34 static int modelToSection(ElfuElf *me, ElfuScn *ms, void *aux1, void *aux2)
41 scnOut = elf_newscn(e);
43 ELFU_WARNELF("elf_newscn");
50 ms->shdr.sh_link = elfu_mScnIndex(me, ms->linkptr);
53 ms->shdr.sh_info = elfu_mScnIndex(me, ms->infoptr);
55 if (!gelf_update_shdr(scnOut, &ms->shdr)) {
56 ELFU_WARNELF("gelf_update_shdr");
62 Elf_Data *dataOut = elf_newdata(scnOut);
64 ELFU_WARNELF("elf_newdata");
67 dataOut->d_align = ms->data.d_align;
68 dataOut->d_buf = ms->data.d_buf;
69 dataOut->d_off = ms->data.d_off;
70 dataOut->d_type = ms->data.d_type;
71 dataOut->d_size = ms->data.d_size;
72 dataOut->d_version = ms->data.d_version;
82 void elfu_mToElf(ElfuElf *me, Elf *e)
84 /* We control the ELF file's layout now. */
85 /* tired's libelf also offers ELF_F_LAYOUT_OVERLAP for overlapping sections,
86 * but we don't want that since we filtered it out in the reading stage
87 * already. It would be too mind-blowing to handle the dependencies between
88 * the PHDRs and sections then... */
89 elf_flagelf(e, ELF_C_SET, ELF_F_LAYOUT);
93 if (!gelf_newehdr(e, me->elfclass)) {
94 ELFU_WARNELF("gelf_newehdr");
98 me->ehdr.e_shstrndx = elfu_mScnIndex(me, me->shstrtab);
101 if (!gelf_update_ehdr(e, &me->ehdr)) {
102 ELFU_WARNELF("gelf_update_ehdr");
107 elfu_mScnForall(me, modelToSection, e, NULL);
114 elf_flagelf(e, ELF_C_SET, ELF_F_DIRTY);