]> sbz's 6dev Repos - ctfdump/.git/commitdiff
sync with readdwarf(1)
authorMartin Pieuchot <mpi@openbsd.org>
Tue, 12 Apr 2016 17:03:47 +0000 (19:03 +0200)
committerMartin Pieuchot <mpi@openbsd.org>
Tue, 12 Apr 2016 17:03:47 +0000 (19:03 +0200)
ctfdump.c
elf.c

index 1cdb3a19a4bdb88374e24dafc42af106bdc1b1c0..3f3ebd6c2dd16ca34fa70ab4b02fca09d6e2c96e 100644 (file)
--- a/ctfdump.c
+++ b/ctfdump.c
@@ -68,8 +68,8 @@ int            iself(const char *, size_t);
 int             elf_getshstrtab(const char *, size_t, const char **, size_t *);
 int             elf_getsymtab(const char *, const char *, size_t,
                     const Elf_Sym **, size_t *);
-int             elf_getstrtab(const char *, const char *, size_t,
-                    const char **, size_t *);
+int             elf_getsection(const char *, const char *, const char *,
+                    size_t, const char **, size_t *);
 
 #ifdef ZLIB
 char           *decompress(const char *, size_t, off_t);
@@ -203,7 +203,7 @@ elf_dump(const char *p, size_t filesize, uint8_t flags)
                warnx("symbol table not found");
 
        /* Find string table location and size. */
-       if (elf_getstrtab(p, shstrtab, shstrtabsize, &strtab, &strtabsize))
+       if (elf_getsection(p, ELF_STRTAB, shstrtab, shstrtabsize, &strtab, &strtabsize))
                warnx("string table not found");
 
        /* Find CTF section and dump it. */
diff --git a/elf.c b/elf.c
index cf3df8a1d0f7948950a0e5d45f1ce8463a462534..7f2da180ff924d80cbc3225ce14509930a213dff 100644 (file)
--- a/elf.c
+++ b/elf.c
@@ -121,8 +121,8 @@ elf_getsymtab(const char *p, const char *shstrtab, size_t shstrtabsize,
 }
 
 int
-elf_getstrtab(const char *p, const char *shstrtab, size_t shstrtabsize,
-    const char **strtab, size_t *strtabsize)
+elf_getsection(const char *p, const char *sname, const char *shstrtab,
+    size_t shstrtabsize, const char **sdata, size_t *ssize)
 {
        Elf_Ehdr        *eh = (Elf_Ehdr *)p;
        Elf_Shdr        *sh;
@@ -131,19 +131,16 @@ elf_getstrtab(const char *p, const char *shstrtab, size_t shstrtabsize,
        for (i = 0; i < eh->e_shnum; i++) {
                sh = (Elf_Shdr *)(p + eh->e_shoff + i * eh->e_shentsize);
 
-               if (sh->sh_type != SHT_STRTAB)
-                       continue;
-
                if ((sh->sh_link >= eh->e_shnum) ||
                    (sh->sh_name >= shstrtabsize))
                        continue;
 
-               if (strncmp(shstrtab + sh->sh_name, ELF_STRTAB,
-                   strlen(ELF_STRTAB)) == 0) {
-                       if (strtab != NULL)
-                               *strtab = p + sh->sh_offset;
-                       if (strtabsize != NULL)
-                               *strtabsize = sh->sh_size;
+               if (strncmp(shstrtab + sh->sh_name, sname,
+                   strlen(sname)) == 0) {
+                       if (sdata != NULL)
+                               *sdata = p + sh->sh_offset;
+                       if (ssize != NULL)
+                               *ssize = sh->sh_size;
 
                        return 0;
                }