7 #include <libelfu/libelfu.h>
11 * Returns the first section that is contained in the segment and
12 * ends as close to its memory image of as possible (the "last"
13 * section in the segment).
15 * If no section fits, NULL is returned.
17 Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr)
23 scn = elf_getscn(e, 1);
27 if (gelf_getshdr(scn, &shdr) != &shdr) {
28 fprintf(stderr, "gelf_getshdr() failed: %s\n", elf_errmsg(-1));
32 if (elfu_segmentContainsSection(phdr, &shdr)) {
38 if (gelf_getshdr(last, &shdrOld) != &shdrOld) {
42 if (shdr.sh_offset + shdr.sh_size
43 > shdrOld.sh_offset + shdrOld.sh_size) {
44 // TODO: Check (leftover space in memory image) < (p_align)
50 scn = elf_nextscn(e, scn);