From 29dfd585e8f8d87d978259919f74815493899f01 Mon Sep 17 00:00:00 2001 From: norly Date: Mon, 27 May 2013 03:18:00 +0100 Subject: [PATCH] Turn elfu_gScnSizeFile into a macro --- include/libelfu/generic.h | 4 +++- src/elfops/check.c | 8 ++++---- src/generic/scnSize.c | 13 ------------- src/model/check.c | 4 ++-- src/model/reladd.c | 4 ++-- src/model/section-in-segment.c | 2 +- 6 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 src/generic/scnSize.c diff --git a/include/libelfu/generic.h b/include/libelfu/generic.h index 09d2ffc..c74981a 100644 --- a/include/libelfu/generic.h +++ b/include/libelfu/generic.h @@ -17,8 +17,10 @@ +#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 diff --git a/src/elfops/check.c b/src/elfops/check.c index c7ebc7d..8aaa7b5 100644 --- a/src/elfops/check.c +++ b/src/elfops/check.c @@ -126,14 +126,14 @@ int elfu_eCheck(Elf *e) } /* 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; @@ -154,8 +154,8 @@ int elfu_eCheck(Elf *e) } /* 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; } diff --git a/src/generic/scnSize.c b/src/generic/scnSize.c deleted file mode 100644 index 43abb13..0000000 --- a/src/generic/scnSize.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - - - -size_t elfu_gScnSizeFile(const GElf_Shdr *shdr) -{ - assert(shdr); - - return shdr->sh_type == SHT_NOBITS ? 0 : shdr->sh_size; -} diff --git a/src/model/check.c b/src/model/check.c index 2c8c67e..4fb042c 100644 --- a/src/model/check.c +++ b/src/model/check.c @@ -68,7 +68,7 @@ int elfu_mCheck(ElfuElf *me) /* 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]), @@ -89,7 +89,7 @@ int elfu_mCheck(ElfuElf *me) /* 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", diff --git a/src/model/reladd.c b/src/model/reladd.c index 41d7cfb..549afcf 100644 --- a/src/model/reladd.c +++ b/src/model/reladd.c @@ -119,7 +119,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *ms) // 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); @@ -129,7 +129,7 @@ static ElfuScn* insertSection(ElfuElf *me, ElfuElf *mrel, ElfuScn *ms) /* 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), diff --git a/src/model/section-in-segment.c b/src/model/section-in-segment.c index ad7f037..0e513e2 100644 --- a/src/model/section-in-segment.c +++ b/src/model/section-in-segment.c @@ -44,7 +44,7 @@ ElfuScn* elfu_mScnLastInSegment(ElfuElf *me, ElfuPhdr *mp) 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))) { -- 2.30.2