2 #include <libelf/gelf.h>
3 #include <libelfu/libelfu.h>
7 * Returns the first section beginning in the segment.
9 * Since sections have to be in the file in mapping order to load them
10 * as a continuous segment, we only have to search by start offset.
12 ElfuScn* elfu_mScnFirstInSegment(ElfuElf *me, ElfuPhdr *mp)
19 CIRCLEQ_FOREACH(ms, &me->scnList, elem) {
20 if ((ms->shdr.sh_offset >= mp->phdr.p_offset)
21 && (ms->shdr.sh_offset < mp->phdr.p_offset + mp->phdr.p_filesz)) {
32 * Returns the last section ending in the segment.
34 * Since sections have to be in the file in mapping order to load them
35 * as a continuous segment, we only have to search by end offset.
37 ElfuScn* elfu_mScnLastInSegment(ElfuElf *me, ElfuPhdr *mp)
45 CIRCLEQ_FOREACH(ms, &me->scnList, elem) {
46 /* Get section size on disk - for NOBITS sections that is 0 bytes. */
47 size_t size = SCNFILESIZE(&ms->shdr);
49 if (((ms->shdr.sh_offset + size >= mp->phdr.p_offset)
50 && (ms->shdr.sh_offset + size <= mp->phdr.p_offset + mp->phdr.p_filesz))) {