#include <libelfu/types.h>
-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
--- /dev/null
+#ifndef __LIBELFU_GENERIC_H__
+#define __LIBELFU_GENERIC_H__
+
+#include <gelf.h>
+
+
+size_t elfu_gScnSizeFile(const GElf_Shdr *shdr);
+
+#endif
#include <libelfu/types.h>
+#include <libelfu/generic.h>
#include <libelfu/elfops.h>
#include <libelfu/model.h>
--- /dev/null
+#include <libelf.h>
+#include <gelf.h>
+
+#include <libelfu/libelfu.h>
+
+
+int elfu_ePhdrContainsScn(GElf_Phdr *phdr, GElf_Shdr *shdr)
+{
+ size_t secStart = shdr->sh_offset;
+ size_t secEnd = shdr->sh_offset + shdr->sh_size;
+ size_t segStart = phdr->p_offset;
+ size_t segEnd = phdr->p_offset + phdr->p_memsz;
+
+ if (secStart < segStart || secEnd > segEnd) {
+ return 0;
+ }
+
+ return 1;
+}
--- /dev/null
+#include <stdio.h>
+
+#include <libelf.h>
+#include <gelf.h>
+
+void elfu_ePhdrFixupSelfRef(Elf *e)
+{
+ GElf_Ehdr ehdr;
+ size_t i, n;
+
+ if (!gelf_getehdr(e, &ehdr)) {
+ fprintf(stderr, "gelf_getehdr() failed: %s.", elf_errmsg(-1));
+ return;
+ }
+
+ if (elf_getphdrnum(e, &n)) {
+ fprintf(stderr, "elf_getphdrnum() failed: %s\n", elf_errmsg(-1));
+ }
+
+ for (i = 0; i < n; i++) {
+ GElf_Phdr phdr;
+
+ if (gelf_getphdr(e, i, &phdr) != &phdr) {
+ fprintf(stderr, "gelf_getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
+ continue;
+ }
+
+ if (phdr.p_type == PT_PHDR) {
+ phdr.p_offset = ehdr.e_phoff;
+ phdr.p_filesz = elf32_fsize(ELF_T_PHDR, n, EV_CURRENT);
+ phdr.p_memsz = phdr.p_filesz;
+
+ if (!gelf_update_phdr (e, i, &phdr)) {
+ fprintf(stderr, "gelf_update_ehdr() failed: %s\n", elf_errmsg(-1));
+ }
+ }
+ }
+
+ /* Tell libelf that phdrs have changed */
+ elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
+}
+++ /dev/null
-#include <stdio.h>
-
-#include <libelf.h>
-#include <gelf.h>
-
-void elfu_fixupPhdrSelfRef(Elf *e)
-{
- GElf_Ehdr ehdr;
- size_t i, n;
-
- if (!gelf_getehdr(e, &ehdr)) {
- fprintf(stderr, "gelf_getehdr() failed: %s.", elf_errmsg(-1));
- return;
- }
-
- if (elf_getphdrnum(e, &n)) {
- fprintf(stderr, "elf_getphdrnum() failed: %s\n", elf_errmsg(-1));
- }
-
- for (i = 0; i < n; i++) {
- GElf_Phdr phdr;
-
- if (gelf_getphdr(e, i, &phdr) != &phdr) {
- fprintf(stderr, "gelf_getphdr() failed for #%d: %s\n", i, elf_errmsg(-1));
- continue;
- }
-
- if (phdr.p_type == PT_PHDR) {
- phdr.p_offset = ehdr.e_phoff;
- phdr.p_filesz = elf32_fsize(ELF_T_PHDR, n, EV_CURRENT);
- phdr.p_memsz = phdr.p_filesz;
-
- if (!gelf_update_phdr (e, i, &phdr)) {
- fprintf(stderr, "gelf_update_ehdr() failed: %s\n", elf_errmsg(-1));
- }
- }
- }
-
- /* Tell libelf that phdrs have changed */
- elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY);
-}
+++ /dev/null
-#include <assert.h>
-#include <sys/types.h>
-#include <gelf.h>
-#include <libelfu/libelfu.h>
-
-
-
-size_t elfu_scnSizeFile(const GElf_Shdr *shdr)
-{
- assert(shdr);
-
- return shdr->sh_type == SHT_NOBITS ? 0 : shdr->sh_size;
-}
#include <libelfu/libelfu.h>
-Elf_Scn* elfu_sectionByName(Elf *e, char *name)
+Elf_Scn* elfu_eScnByName(Elf *e, char *name)
{
size_t shstrndx;
Elf_Scn *scn;
*
* 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;
}
if (shdr.sh_offset == phdr->p_offset
- && elfu_segmentContainsSection(phdr, &shdr)) {
+ && elfu_ePhdrContainsScn(phdr, &shdr)) {
return scn;
}
*
* 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;
continue;
}
- if (elfu_segmentContainsSection(phdr, &shdr)) {
+ if (elfu_ePhdrContainsScn(phdr, &shdr)) {
if (!last) {
last = scn;
} else {
#include <libelfu/libelfu.h>
-char* elfu_sectionName(Elf *e, Elf_Scn *scn)
+char* elfu_eScnName(Elf *e, Elf_Scn *scn)
{
size_t shstrndx;
GElf_Shdr shdr;
+++ /dev/null
-#include <libelf.h>
-#include <gelf.h>
-
-#include <libelfu/libelfu.h>
-
-
-int elfu_segmentContainsSection(GElf_Phdr *phdr, GElf_Shdr *shdr)
-{
- size_t secStart = shdr->sh_offset;
- size_t secEnd = shdr->sh_offset + shdr->sh_size;
- size_t segStart = phdr->p_offset;
- size_t segEnd = phdr->p_offset + phdr->p_memsz;
-
- if (secStart < segStart || secEnd > segEnd) {
- return 0;
- }
-
- return 1;
-}
--- /dev/null
+#include <assert.h>
+#include <sys/types.h>
+#include <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_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]),
/* 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",
continue;
}
- if (elfu_segmentContainsSection(&phdr, &shdr)) {
+ if (elfu_ePhdrContainsScn(&phdr, &shdr)) {
printf(" %d %s\n", i, segmentTypeStr(phdr.p_type));
}
}
{
printf(" %jd: %s\n",
(uintmax_t) elf_ndxscn(scn),
- elfu_sectionName(e, scn));
+ elfu_eScnName(e, scn));
}
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);