7 #include <libelfu/libelfu.h>
11 * Returns the section that starts at the same point in the file as
12 * the segment AND is wholly contained in the memory image.
14 * If no section fits, NULL is returned.
16 Elf_Scn* elfu_eScnFirstInSegment(Elf *e, GElf_Phdr *phdr)
20 scn = elf_getscn(e, 1);
24 if (gelf_getshdr(scn, &shdr) != &shdr) {
28 if (shdr.sh_offset == phdr->p_offset
29 && elfu_ePhdrContainsScn(phdr, &shdr)) {
33 scn = elf_nextscn(e, scn);
42 * Returns the first section that is contained in the segment and
43 * ends as close to its memory image of as possible (the "last"
44 * section in the segment).
46 * If no section fits, NULL is returned.
48 Elf_Scn* elfu_eScnLastInSegment(Elf *e, GElf_Phdr *phdr)
54 scn = elf_getscn(e, 1);
58 if (gelf_getshdr(scn, &shdr) != &shdr) {
59 fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
63 if (elfu_ePhdrContainsScn(phdr, &shdr)) {
69 if (gelf_getshdr(last, &shdrOld) != &shdrOld) {
73 if (shdr.sh_offset + shdr.sh_size
74 > shdrOld.sh_offset + shdrOld.sh_size) {
75 // TODO: Check (leftover space in memory image) < (p_align)
81 scn = elf_nextscn(e, scn);