Simplify includes
[centaur.git] / src / elfops / phdr-fixup-selfref.c
1 #include <libelfu/libelfu.h>
2
3
4 void elfu_ePhdrFixupSelfRef(Elf *e)
5 {
6   GElf_Ehdr ehdr;
7   size_t i, n;
8
9   if (!gelf_getehdr(e, &ehdr)) {
10     ELFU_WARNELF("gelf_getehdr");
11     return;
12   }
13
14   if (elf_getphdrnum(e, &n)) {
15     ELFU_WARNELF("elf_getphdrnum");
16   }
17
18   for (i = 0; i < n; i++) {
19     GElf_Phdr phdr;
20
21     if (gelf_getphdr(e, i, &phdr) != &phdr) {
22       ELFU_WARN("gelf_getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
23       continue;
24     }
25
26     if (phdr.p_type == PT_PHDR) {
27       phdr.p_offset = ehdr.e_phoff;
28       phdr.p_filesz = elf32_fsize(ELF_T_PHDR, n, EV_CURRENT);
29       phdr.p_memsz = phdr.p_filesz;
30
31       if (!gelf_update_phdr (e, i, &phdr)) {
32         ELFU_WARNELF("gelf_update_ehdr");
33       }
34     }
35   }
36
37   /* Tell libelf that phdrs have changed */
38   elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
39 }