+#define SCNFILESIZE(shdr) ((shdr)->sh_type == SHT_NOBITS ? 0 : (shdr)->sh_size)
+
+
int elfu_gPhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr);
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
#endif
}
/* Section should not overlap with PHDRs. */
- if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
+ if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
ehdr.e_phoff, numPhdr * ehdr.e_phentsize)) {
ELFU_WARN("elfu_eCheck: Section %d overlaps with PHDR.\n", i);
goto ERROR;
}
/* Section should not overlap with SHDRs. */
- if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
+ if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
ehdr.e_shoff, numShdr * ehdr.e_shentsize)) {
ELFU_WARN("elfu_eCheck: Section %d overlaps with SHDRs.\n", i);
goto ERROR;
}
/* Sections must not overlap in file. */
- if (OVERLAPPING(shdrs[i].sh_offset, elfu_gScnSizeFile(&shdrs[i]),
- shdrs[j].sh_offset, elfu_gScnSizeFile(&shdrs[j]))) {
+ if (OVERLAPPING(shdrs[i].sh_offset, SCNFILESIZE(&shdrs[i]),
+ shdrs[j].sh_offset, SCNFILESIZE(&shdrs[j]))) {
ELFU_WARN("elfu_eCheck: Sections %d and %d overlap in file.\n", i, j);
goto ERROR;
}
+++ /dev/null
-#include <assert.h>
-#include <sys/types.h>
-#include <libelf/gelf.h>
-#include <libelfu/libelfu.h>
-
-
-
-size_t elfu_gScnSizeFile(const GElf_Shdr *shdr)
-{
- assert(shdr);
-
- return shdr->sh_type == SHT_NOBITS ? 0 : shdr->sh_size;
-}
/* Check for overlapping sections */
for (i = 0; i < numSecs - 1; i++) {
- if (sortedSecs[i]->shdr.sh_offset + elfu_gScnSizeFile(&sortedSecs[i]->shdr)
+ if (sortedSecs[i]->shdr.sh_offset + SCNFILESIZE(&sortedSecs[i]->shdr)
> sortedSecs[i+1]->shdr.sh_offset) {
ELFU_WARN("elfu_check: Found overlapping sections: %s and %s.\n",
elfu_mScnName(me, sortedSecs[i]),
/* Check for sections overlapping with PHDRs */
for (i = 0; i < numSecs; i++) {
if (isOverlapping(sortedSecs[i]->shdr.sh_offset,
- elfu_gScnSizeFile(&sortedSecs[i]->shdr),
+ SCNFILESIZE(&sortedSecs[i]->shdr),
me->ehdr.e_phoff,
me->ehdr.e_phentsize * me->ehdr.e_phnum)) {
ELFU_WARN("elfu_check: Found section overlapping with PHDRs: %s.\n",
// TODO: Error handling
} else {
- injOffset = lastScn->shdr.sh_offset + elfu_gScnSizeFile(&lastScn->shdr);
+ injOffset = lastScn->shdr.sh_offset + SCNFILESIZE(&lastScn->shdr);
ELFU_INFO("Expanding at offset 0x%jx...\n",
injOffset);
/* Recalculate injOffset in case we expanded a NOBITS section */
lastScn = elfu_mScnLastInSegment(me, injAnchor);
- injOffset = lastScn->shdr.sh_offset + elfu_gScnSizeFile(&lastScn->shdr);
+ injOffset = lastScn->shdr.sh_offset + SCNFILESIZE(&lastScn->shdr);
ELFU_INFO("Inserting %s at offset 0x%jx...\n",
elfu_mScnName(mrel, ms),
CIRCLEQ_FOREACH(ms, &me->scnList, elem) {
/* Get section size on disk - for NOBITS sections that is 0 bytes. */
- size_t size = elfu_gScnSizeFile(&ms->shdr);
+ size_t size = SCNFILESIZE(&ms->shdr);
if (((ms->shdr.sh_offset + size >= mp->phdr.p_offset)
&& (ms->shdr.sh_offset + size <= mp->phdr.p_offset + mp->phdr.p_filesz))) {