2 #include <libelfu/libelfu.h>
6 * Returns the section that starts at the same point in the file as
7 * the segment AND is wholly contained in the memory image.
9 * If no section fits, NULL is returned.
11 Elf_Scn* elfu_eScnFirstInSegment(Elf *e, GElf_Phdr *phdr)
15 scn = elf_getscn(e, 1);
19 if (gelf_getshdr(scn, &shdr) != &shdr) {
23 if (shdr.sh_offset == phdr->p_offset
24 && PHDR_CONTAINS_SCN_IN_MEMORY(phdr, &shdr)) {
28 scn = elf_nextscn(e, scn);
37 * Returns the first section that is contained in the segment and
38 * ends as close to its memory image of as possible (the "last"
39 * section in the segment).
41 * If no section fits, NULL is returned.
43 Elf_Scn* elfu_eScnLastInSegment(Elf *e, GElf_Phdr *phdr)
49 scn = elf_getscn(e, 1);
53 if (gelf_getshdr(scn, &shdr) != &shdr) {
54 ELFU_WARNELF("gelf_getshdr");
58 if (PHDR_CONTAINS_SCN_IN_MEMORY(phdr, &shdr)) {
64 if (gelf_getshdr(last, &shdrOld) != &shdrOld) {
68 if (shdr.sh_offset + shdr.sh_size
69 > shdrOld.sh_offset + shdrOld.sh_size) {
70 // TODO: Check (leftover space in memory image) < (p_align)
76 scn = elf_nextscn(e, scn);