From 6e4cbafe0876ff14ff03a14ab80951167ef67e06 Mon Sep 17 00:00:00 2001 From: norly Date: Sat, 23 Feb 2013 15:59:12 +0000 Subject: [PATCH] Clean up ELF-related files and functions --- include/libelfu/elfops.h | 13 ++++++------- include/libelfu/generic.h | 9 +++++++++ include/libelfu/libelfu.h | 1 + ...t-contains-section.c => phdr-contains-section.c} | 2 +- src/elfops/{phdr.c => phdr-fixup-selfref.c} | 2 +- src/elfops/section-by-name.c | 2 +- src/elfops/section-in-segment.c | 8 ++++---- src/elfops/section-name.c | 2 +- src/{elfops => generic}/scnSize.c | 2 +- src/model/check.c | 4 ++-- src/printing/sections.c | 4 ++-- src/printing/segments.c | 4 ++-- 12 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 include/libelfu/generic.h rename src/elfops/{segment-contains-section.c => phdr-contains-section.c} (83%) rename src/elfops/{phdr.c => phdr-fixup-selfref.c} (96%) rename src/{elfops => generic}/scnSize.c (78%) diff --git a/include/libelfu/elfops.h b/include/libelfu/elfops.h index a57069d..25575a1 100644 --- a/include/libelfu/elfops.h +++ b/include/libelfu/elfops.h @@ -6,15 +6,14 @@ #include -size_t elfu_scnSizeFile(const GElf_Shdr *shdr); -char* elfu_sectionName(Elf *e, Elf_Scn *scn); -Elf_Scn* elfu_sectionByName(Elf *e, char *name); + char* elfu_eScnName(Elf *e, Elf_Scn *scn); +Elf_Scn* elfu_eScnByName(Elf *e, char *name); -int elfu_segmentContainsSection(GElf_Phdr *phdr, GElf_Shdr *shdr); -Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr); -Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr); + int elfu_ePhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr); +Elf_Scn* elfu_eScnFirstInSegment(Elf *e, GElf_Phdr *phdr); +Elf_Scn* elfu_eScnLastInSegment(Elf *e, GElf_Phdr *phdr); -void elfu_fixupPhdrSelfRef(Elf *e); +void elfu_ePhdrFixupSelfRef(Elf *e); #endif diff --git a/include/libelfu/generic.h b/include/libelfu/generic.h new file mode 100644 index 0000000..9d9aefb --- /dev/null +++ b/include/libelfu/generic.h @@ -0,0 +1,9 @@ +#ifndef __LIBELFU_GENERIC_H__ +#define __LIBELFU_GENERIC_H__ + +#include + + +size_t elfu_gScnSizeFile(const GElf_Shdr *shdr); + +#endif diff --git a/include/libelfu/libelfu.h b/include/libelfu/libelfu.h index 961235f..3c62aad 100644 --- a/include/libelfu/libelfu.h +++ b/include/libelfu/libelfu.h @@ -4,6 +4,7 @@ #include +#include #include #include diff --git a/src/elfops/segment-contains-section.c b/src/elfops/phdr-contains-section.c similarity index 83% rename from src/elfops/segment-contains-section.c rename to src/elfops/phdr-contains-section.c index 298cf72..6b57019 100644 --- a/src/elfops/segment-contains-section.c +++ b/src/elfops/phdr-contains-section.c @@ -4,7 +4,7 @@ #include -int elfu_segmentContainsSection(GElf_Phdr *phdr, GElf_Shdr *shdr) +int elfu_ePhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr) { size_t secStart = shdr->sh_offset; size_t secEnd = shdr->sh_offset + shdr->sh_size; diff --git a/src/elfops/phdr.c b/src/elfops/phdr-fixup-selfref.c similarity index 96% rename from src/elfops/phdr.c rename to src/elfops/phdr-fixup-selfref.c index ccdc021..e79f584 100644 --- a/src/elfops/phdr.c +++ b/src/elfops/phdr-fixup-selfref.c @@ -3,7 +3,7 @@ #include #include -void elfu_fixupPhdrSelfRef(Elf *e) +void elfu_ePhdrFixupSelfRef(Elf *e) { GElf_Ehdr ehdr; size_t i, n; diff --git a/src/elfops/section-by-name.c b/src/elfops/section-by-name.c index 1697140..3352b14 100644 --- a/src/elfops/section-by-name.c +++ b/src/elfops/section-by-name.c @@ -6,7 +6,7 @@ #include -Elf_Scn* elfu_sectionByName(Elf *e, char *name) +Elf_Scn* elfu_eScnByName(Elf *e, char *name) { size_t shstrndx; Elf_Scn *scn; diff --git a/src/elfops/section-in-segment.c b/src/elfops/section-in-segment.c index e12720f..cb62514 100644 --- a/src/elfops/section-in-segment.c +++ b/src/elfops/section-in-segment.c @@ -13,7 +13,7 @@ * * If no section fits, NULL is returned. */ -Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr) +Elf_Scn* elfu_eScnFirstInSegment(Elf *e, GElf_Phdr *phdr) { Elf_Scn *scn; @@ -26,7 +26,7 @@ Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr) } if (shdr.sh_offset == phdr->p_offset - && elfu_segmentContainsSection(phdr, &shdr)) { + && elfu_ePhdrContainsScn(phdr, &shdr)) { return scn; } @@ -45,7 +45,7 @@ Elf_Scn* elfu_firstSectionInSegment(Elf *e, GElf_Phdr *phdr) * * If no section fits, NULL is returned. */ -Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr) +Elf_Scn* elfu_eScnLastInSegment(Elf *e, GElf_Phdr *phdr) { Elf_Scn *last = NULL; Elf_Scn *scn; @@ -60,7 +60,7 @@ Elf_Scn* elfu_lastSectionInSegment(Elf *e, GElf_Phdr *phdr) continue; } - if (elfu_segmentContainsSection(phdr, &shdr)) { + if (elfu_ePhdrContainsScn(phdr, &shdr)) { if (!last) { last = scn; } else { diff --git a/src/elfops/section-name.c b/src/elfops/section-name.c index 1365eb6..e77efee 100644 --- a/src/elfops/section-name.c +++ b/src/elfops/section-name.c @@ -6,7 +6,7 @@ #include -char* elfu_sectionName(Elf *e, Elf_Scn *scn) +char* elfu_eScnName(Elf *e, Elf_Scn *scn) { size_t shstrndx; GElf_Shdr shdr; diff --git a/src/elfops/scnSize.c b/src/generic/scnSize.c similarity index 78% rename from src/elfops/scnSize.c rename to src/generic/scnSize.c index 2c65ca1..e4cf1c1 100644 --- a/src/elfops/scnSize.c +++ b/src/generic/scnSize.c @@ -5,7 +5,7 @@ -size_t elfu_scnSizeFile(const GElf_Shdr *shdr) +size_t elfu_gScnSizeFile(const GElf_Shdr *shdr) { assert(shdr); diff --git a/src/model/check.c b/src/model/check.c index cd45f2d..dd5e8eb 100644 --- a/src/model/check.c +++ b/src/model/check.c @@ -69,7 +69,7 @@ int elfu_modelCheck(ElfuElf *me) /* Check for overlapping sections */ for (i = 0; i < numSecs - 1; i++) { - if (sortedSecs[i]->shdr.sh_offset + elfu_scnSizeFile(&sortedSecs[i]->shdr) + if (sortedSecs[i]->shdr.sh_offset + elfu_gScnSizeFile(&sortedSecs[i]->shdr) > sortedSecs[i+1]->shdr.sh_offset) { fprintf(stderr, "elfu_check: Found overlapping sections: %s and %s.\n", elfu_modelScnName(me, sortedSecs[i]), @@ -90,7 +90,7 @@ int elfu_modelCheck(ElfuElf *me) /* Check for sections overlapping with PHDRs */ for (i = 0; i < numSecs; i++) { if (isOverlapping(sortedSecs[i]->shdr.sh_offset, - elfu_scnSizeFile(&sortedSecs[i]->shdr), + elfu_gScnSizeFile(&sortedSecs[i]->shdr), me->ehdr.e_phoff, me->ehdr.e_phentsize * me->ehdr.e_phnum)) { fprintf(stderr, "elfu_check: Found section overlapping with PHDRs: %s.\n", diff --git a/src/printing/sections.c b/src/printing/sections.c index be7a907..e06f3b7 100644 --- a/src/printing/sections.c +++ b/src/printing/sections.c @@ -31,7 +31,7 @@ void printSegmentsWithSection(Elf *e, Elf_Scn *scn) continue; } - if (elfu_segmentContainsSection(&phdr, &shdr)) { + if (elfu_ePhdrContainsScn(&phdr, &shdr)) { printf(" %d %s\n", i, segmentTypeStr(phdr.p_type)); } } @@ -42,7 +42,7 @@ void printSection(Elf *e, Elf_Scn *scn) { printf(" %jd: %s\n", (uintmax_t) elf_ndxscn(scn), - elfu_sectionName(e, scn)); + elfu_eScnName(e, scn)); } diff --git a/src/printing/segments.c b/src/printing/segments.c index 1f431d6..74eeb83 100644 --- a/src/printing/segments.c +++ b/src/printing/segments.c @@ -33,8 +33,8 @@ void printSectionsInSegment(Elf *e, GElf_Phdr *phdr) continue; } - if (elfu_segmentContainsSection(phdr, &shdr)) { - printf(" %10u %s\n", elf_ndxscn(scn), elfu_sectionName(e, scn)); + if (elfu_ePhdrContainsScn(phdr, &shdr)) { + printf(" %10u %s\n", elf_ndxscn(scn), elfu_eScnName(e, scn)); } scn = elf_nextscn(e, scn); -- 2.30.2