diff options
author | norly <ny-git@enpas.org> | 2013-06-17 23:34:30 +0100 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2013-06-17 23:39:12 +0100 |
commit | f88e1ad7d9db8a41abecc795200f21138af65c74 (patch) | |
tree | dc17e6153ae6ee4678b39f365f8c9d9b28bdde43 /src/elfops | |
parent | 150d0c42d423fe49304d648e2c19ff08f6c2e0ad (diff) |
C90 compliance, except variadic macros and TODOs
Also removed a lot of dead code from the early days.
Diffstat (limited to 'src/elfops')
-rw-r--r-- | src/elfops/phdr-fixup-selfref.c | 39 | ||||
-rw-r--r-- | src/elfops/section-by-name.c | 35 | ||||
-rw-r--r-- | src/elfops/section-in-segment.c | 80 | ||||
-rw-r--r-- | src/elfops/section-name.c | 20 |
4 files changed, 0 insertions, 174 deletions
diff --git a/src/elfops/phdr-fixup-selfref.c b/src/elfops/phdr-fixup-selfref.c deleted file mode 100644 index c961ceb..0000000 --- a/src/elfops/phdr-fixup-selfref.c +++ /dev/null @@ -1,39 +0,0 @@ -#include <libelfu/libelfu.h> - - -void elfu_ePhdrFixupSelfRef(Elf *e) -{ - GElf_Ehdr ehdr; - size_t i, n; - - if (!gelf_getehdr(e, &ehdr)) { - ELFU_WARNELF("gelf_getehdr"); - return; - } - - if (elf_getphdrnum(e, &n)) { - ELFU_WARNELF("elf_getphdrnum"); - } - - for (i = 0; i < n; i++) { - GElf_Phdr phdr; - - if (gelf_getphdr(e, i, &phdr) != &phdr) { - ELFU_WARN("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)) { - ELFU_WARNELF("gelf_update_ehdr"); - } - } - } - - /* Tell libelf that phdrs have changed */ - elf_flagphdr(e, ELF_C_SET, ELF_F_DIRTY); -} diff --git a/src/elfops/section-by-name.c b/src/elfops/section-by-name.c deleted file mode 100644 index 8bb93a3..0000000 --- a/src/elfops/section-by-name.c +++ /dev/null @@ -1,35 +0,0 @@ -#include <string.h> -#include <libelfu/libelfu.h> - - -Elf_Scn* elfu_eScnByName(Elf *e, char *name) -{ - size_t shstrndx; - Elf_Scn *scn; - - if (elf_getshdrstrndx(e, &shstrndx) != 0) { - return NULL; - } - - scn = elf_getscn(e, 1); - while (scn) { - GElf_Shdr shdr; - char *curname; - - if (gelf_getshdr(scn, &shdr) != &shdr) { - return NULL; - } - - /* elf_strptr returns NULL if there was an error */ - curname = elf_strptr(e, shstrndx, shdr.sh_name); - - /* strcmp... but we really have no bounds on the lengths here */ - if (!strcmp(curname, name)) { - return scn; - } - - scn = elf_nextscn(e, scn); - } - - return NULL; -} diff --git a/src/elfops/section-in-segment.c b/src/elfops/section-in-segment.c deleted file mode 100644 index 7e6206b..0000000 --- a/src/elfops/section-in-segment.c +++ /dev/null @@ -1,80 +0,0 @@ -#include <stdlib.h> -#include <libelfu/libelfu.h> - - -/* - * Returns the section that starts at the same point in the file as - * the segment AND is wholly contained in the memory image. - * - * If no section fits, NULL is returned. - */ -Elf_Scn* elfu_eScnFirstInSegment(Elf *e, GElf_Phdr *phdr) -{ - Elf_Scn *scn; - - scn = elf_getscn(e, 1); - while (scn) { - GElf_Shdr shdr; - - if (gelf_getshdr(scn, &shdr) != &shdr) { - return NULL; - } - - if (shdr.sh_offset == phdr->p_offset - && PHDR_CONTAINS_SCN_IN_MEMORY(phdr, &shdr)) { - return scn; - } - - scn = elf_nextscn(e, scn); - } - - return NULL; -} - - - -/* - * Returns the first section that is contained in the segment and - * ends as close to its memory image of as possible (the "last" - * section in the segment). - * - * If no section fits, NULL is returned. - */ -Elf_Scn* elfu_eScnLastInSegment(Elf *e, GElf_Phdr *phdr) -{ - Elf_Scn *last = NULL; - Elf_Scn *scn; - - - scn = elf_getscn(e, 1); - while (scn) { - GElf_Shdr shdr; - - if (gelf_getshdr(scn, &shdr) != &shdr) { - ELFU_WARNELF("gelf_getshdr"); - continue; - } - - if (PHDR_CONTAINS_SCN_IN_MEMORY(phdr, &shdr)) { - if (!last) { - last = scn; - } else { - GElf_Shdr shdrOld; - - if (gelf_getshdr(last, &shdrOld) != &shdrOld) { - continue; - } - - if (shdr.sh_offset + shdr.sh_size - > shdrOld.sh_offset + shdrOld.sh_size) { - // TODO: Check (leftover space in memory image) < (p_align) - last = scn; - } - } - } - - scn = elf_nextscn(e, scn); - } - - return last; -} diff --git a/src/elfops/section-name.c b/src/elfops/section-name.c deleted file mode 100644 index 4832db9..0000000 --- a/src/elfops/section-name.c +++ /dev/null @@ -1,20 +0,0 @@ -#include <stdlib.h> -#include <libelfu/libelfu.h> - - -char* elfu_eScnName(Elf *e, Elf_Scn *scn) -{ - size_t shstrndx; - GElf_Shdr shdr; - - if (elf_getshdrstrndx(e, &shstrndx) != 0) { - return NULL; - } - - if (gelf_getshdr(scn, &shdr) != &shdr) { - return NULL; - } - - /* elf_strptr returns NULL if there was an error */ - return elf_strptr(e, shstrndx, shdr.sh_name); -} |