diff options
author | jbj <devnull@localhost> | 2002-10-15 18:44:16 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2002-10-15 18:44:16 +0000 |
commit | ada36102ab34ce7937dfddd49d2f60f4ccd9e3db (patch) | |
tree | 8b726c5c1a8e237bb7200591e26e280411766176 /build | |
parent | 8da8b70df8dbf3c83ae5c45c861f00856e35631a (diff) | |
download | rpm-ada36102ab34ce7937dfddd49d2f60f4ccd9e3db.tar.gz rpm-ada36102ab34ce7937dfddd49d2f60f4ccd9e3db.tar.bz2 rpm-ada36102ab34ce7937dfddd49d2f60f4ccd9e3db.zip |
Replace libelf with elfutils.
CVS patchset: 5778
CVS date: 2002/10/15 18:44:16
Diffstat (limited to 'build')
-rw-r--r-- | build/Makefile.am | 1 | ||||
-rw-r--r-- | build/rpmfc.c | 45 | ||||
-rw-r--r-- | build/rpmfc.h | 56 | ||||
-rw-r--r-- | build/tfr.c | 103 |
4 files changed, 160 insertions, 45 deletions
diff --git a/build/Makefile.am b/build/Makefile.am index fd6b6dab9..fea1ba21b 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -8,6 +8,7 @@ INCLUDES = -I. \ -I$(top_srcdir)/rpmdb \ -I$(top_srcdir)/rpmio \ -I$(top_srcdir)/popt \ + @WITH_LIBELF_INCLUDE@ \ @INCPATH@ LIBS = diff --git a/build/rpmfc.c b/build/rpmfc.c index 79aaf9789..c9d02c53a 100644 --- a/build/rpmfc.c +++ b/build/rpmfc.c @@ -10,7 +10,7 @@ /** */ /*@unchecked@*/ /*@observer@*/ -static struct fclassTokens_s fclassTokens[] = { +static struct rpmfcTokens_s rpmfcTokens[] = { { "directory", RPMFC_DIRECTORY|RPMFC_INCLUDE }, { " shared object", RPMFC_LIBRARY }, @@ -92,12 +92,12 @@ static struct fclassTokens_s fclassTokens[] = { static int fcolorIgnore = (RPMFC_ELF32|RPMFC_ELF64|RPMFC_DIRECTORY|RPMFC_LIBRARY|RPMFC_ARCHIVE|RPMFC_FONT|RPMFC_SCRIPT|RPMFC_IMAGE|RPMFC_WHITE); -int fclassColoring(const char * fmstr) +int rpmfcColoring(const char * fmstr) { - fclassToken fct; + rpmfcToken fct; int fcolor = RPMFC_BLACK; - for (fct = fclassTokens; fct->token != NULL; fct++) { + for (fct = rpmfcTokens; fct->token != NULL; fct++) { if (strstr(fmstr, fct->token) == NULL) continue; fcolor |= fct->colors; @@ -107,7 +107,7 @@ int fclassColoring(const char * fmstr) return fcolor; } -void fclassPrint(const char * msg, FCLASS_t fc, FILE * fp) +void rpmfcPrint(const char * msg, rpmfc fc, FILE * fp) { int ac = 0; int fcolor; @@ -142,7 +142,7 @@ void fclassPrint(const char * msg, FCLASS_t fc, FILE * fp) } } -FCLASS_t fclassFree(FCLASS_t fc) +rpmfc rpmfcFree(rpmfc fc) { if (fc) { fc->fn = argvFree(fc->fn); @@ -154,15 +154,25 @@ FCLASS_t fclassFree(FCLASS_t fc) return NULL; } -FCLASS_t fclassNew(void) +rpmfc rpmfcNew(void) { - FCLASS_t fc = xcalloc(1, sizeof(*fc)); + rpmfc fc = xcalloc(1, sizeof(*fc)); return fc; } -int fclassClassify(FCLASS_t *fcp, ARGV_t argv) +static int rpmfcELF(rpmfc fc) { - FCLASS_t fc; + return 0; +} + +static int rpmfcSCRIPT(rpmfc fc) +{ + return 0; +} + +int rpmfcClassify(rpmfc *fcp, ARGV_t argv) +{ + rpmfc fc; char buf[BUFSIZ]; ARGV_t dav; const char * s, * se; @@ -176,7 +186,7 @@ int fclassClassify(FCLASS_t *fcp, ARGV_t argv) return 0; if (*fcp == NULL) - *fcp = fclassNew(); + *fcp = rpmfcNew(); fc = *fcp; /* Set up the file class dictionary. */ @@ -199,7 +209,7 @@ int fclassClassify(FCLASS_t *fcp, ARGV_t argv) if (*se == '\0') return -1; - fcolor = fclassColoring(se); + fcolor = rpmfcColoring(se); if (fcolor == RPMFC_WHITE || !(fcolor & RPMFC_INCLUDE)) continue; @@ -243,7 +253,14 @@ int fclassClassify(FCLASS_t *fcp, ARGV_t argv) fwhite++; } - xx = argiAdd(&fc->fcolor, fc->ix, fclassColoring(se)); + fcolor = rpmfcColoring(se); + xx = argiAdd(&fc->fcolor, fc->ix, fcolor); + + if (fcolor & RPMFC_ELF) { + xx = rpmfcELF(fc); + } else if (fcolor & RPMFC_SCRIPT) { + xx = rpmfcSCRIPT(fc); + } fc->ix++; } @@ -251,7 +268,7 @@ int fclassClassify(FCLASS_t *fcp, ARGV_t argv) /*@-modfilesys@*/ sprintf(buf, "final: files %d dict[%d] %d%%", argvCount(fc->fn), argvCount(fc->dict), ((100 * fknown)/fc->ix)); -fclassPrint(buf, fc, NULL); +rpmfcPrint(buf, fc, NULL); /*@=modfilesys@*/ return 0; diff --git a/build/rpmfc.h b/build/rpmfc.h index b92c25f0f..3f68cc7dc 100644 --- a/build/rpmfc.h +++ b/build/rpmfc.h @@ -1,9 +1,9 @@ #ifndef _H_RPMFC_ #define _H_RPMFC_ -typedef struct fclass_s * FCLASS_t; +typedef struct rpmfc_s * rpmfc; -struct fclass_s { +struct rpmfc_s { ARGV_t av; /*!< file(1) output lines */ int ac; /*!< no. of lines */ int ix; /*!< current lineno */ @@ -18,25 +18,25 @@ enum FCOLOR_e { RPMFC_BLACK = 0, RPMFC_ELF32 = (1 << 0), RPMFC_ELF64 = (1 << 1), - - RPMFC_EXECUTABLE = (1 << 2), - RPMFC_SCRIPT = (1 << 3), - RPMFC_TEXT = (1 << 4), - RPMFC_DOCUMENT = (1 << 5), - - RPMFC_DIRECTORY = (1 << 8), - RPMFC_SYMLINK = (1 << 9), - RPMFC_DEVICE = (1 << 10), - - RPMFC_STATIC = (1 << 16), - RPMFC_NOTSTRIPPED = (1 << 17), - RPMFC_COMPRESSED = (1 << 18), - - RPMFC_LIBRARY = (1 << 24), - RPMFC_ARCHIVE = (1 << 25), - RPMFC_FONT = (1 << 26), - RPMFC_IMAGE = (1 << 27), - RPMFC_MANPAGE = (1 << 28), +#define RPMFC_ELF (RPMFC_ELF32|RPMFC_ELF64) + + RPMFC_EXECUTABLE = (1 << 8), + RPMFC_SCRIPT = (1 << 9), + RPMFC_TEXT = (1 << 10), + RPMFC_DATA = (1 << 11), /* XXX unused */ + RPMFC_DOCUMENT = (1 << 12), + RPMFC_STATIC = (1 << 13), + RPMFC_NOTSTRIPPED = (1 << 14), + RPMFC_COMPRESSED = (1 << 15), + + RPMFC_DIRECTORY = (1 << 16), + RPMFC_SYMLINK = (1 << 17), + RPMFC_DEVICE = (1 << 18), + RPMFC_LIBRARY = (1 << 19), + RPMFC_ARCHIVE = (1 << 20), + RPMFC_FONT = (1 << 21), + RPMFC_IMAGE = (1 << 22), + RPMFC_MANPAGE = (1 << 23), RPMFC_WHITE = (1 << 29), RPMFC_INCLUDE = (1 << 30), @@ -44,13 +44,13 @@ enum FCOLOR_e { }; typedef enum FCOLOR_e FCOLOR_t; -struct fclassTokens_s { +struct rpmfcTokens_s { /*@observer@*/ const char * token; int colors; }; -typedef struct fclassTokens_s * fclassToken; +typedef struct rpmfcTokens_s * rpmfcToken; #ifdef __cplusplus extern "C" { @@ -58,28 +58,28 @@ extern "C" { /** */ -int fclassColoring(const char * fmstr) +int rpmfcColoring(const char * fmstr) /*@*/; /** */ -void fclassPrint(const char * msg, FCLASS_t fc, FILE * fp) +void rpmfcPrint(const char * msg, rpmfc fc, FILE * fp) /*@globals fileSystem @*/ /*@modifies *fp, fileSystem @*/; /** */ /*@null@*/ -FCLASS_t fclassFree(/*@only@*/ /*@null@*/ FCLASS_t fc) +rpmfc rpmfcFree(/*@only@*/ /*@null@*/ rpmfc fc) /*@modifies fc @*/; /** */ -FCLASS_t fclassNew(void) +rpmfc rpmfcNew(void) /*@*/; /** */ -int fclassClassify(/*@out@*/ FCLASS_t *fcp, ARGV_t argv) +int rpmfcClassify(/*@out@*/ rpmfc *fcp, ARGV_t argv) /*@modifies *fcp @*/; #ifdef __cplusplus diff --git a/build/tfr.c b/build/tfr.c index 66726c214..fbf9d3eca 100644 --- a/build/tfr.c +++ b/build/tfr.c @@ -4,8 +4,96 @@ #include <argv.h> #include <rpmfc.h> + +#if HAVE_LIBELF_GELF_H + +#include <libelf/gelf.h> + +#if !defined(DT_GNU_PRELINKED) +#define DT_GNU_PRELINKED 0x6ffffdf5 +#endif +#if !defined(DT_GNU_LIBLIST) +#define DT_GNU_LIBLIST 0x6ffffef9 +#endif + +#endif + #include "debug.h" +static int rpmfcELF(rpmfc fc) +{ +#if HAVE_LIBELF_GELF_H && HAVE_LIBELF + const char * fn = fc->fn[fc->ix];; + Elf *elf = NULL; + Elf_Scn *scn = NULL; + Elf_Data *data = NULL; + GElf_Ehdr ehdr; + GElf_Shdr shdr; + GElf_Dyn dyn; + int bingo; + int fdno; + +size_t ndxscn[16]; +const char * sn; + +memset(ndxscn, 0, sizeof(ndxscn)); +fprintf(stderr, "*** %s\n", fn); + fdno = open(fn, O_RDONLY); + if (fdno < 0) + return fdno; + + (void) elf_version(EV_CURRENT); + + if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL + || elf_kind(elf) != ELF_K_ELF + || gelf_getehdr(elf, &ehdr) == NULL + || !(ehdr.e_type == ET_DYN || ehdr.e_type == ET_EXEC)) + goto exit; + + bingo = 0; + /*@-branchstate -uniondef @*/ + while (!bingo && (scn = elf_nextscn(elf, scn)) != NULL) { + (void) gelf_getshdr(scn, &shdr); +fprintf(stderr, "\tsection %s\n", elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name)); + if (shdr.sh_type >= 0 && shdr.sh_type < 16) + ndxscn[shdr.sh_type] = elf_ndxscn(scn); + switch (shdr.sh_type) { + default: + continue; + /*@switchbreak@*/ break; + case SHT_GNU_verneed: + /*@switchbreak@*/ break; + case SHT_DYNAMIC: + while (!bingo && (data = elf_getdata (scn, data)) != NULL) { + int maxndx = data->d_size / shdr.sh_entsize; + int ndx; + + for (ndx = 0; ndx < maxndx; ++ndx) { + (void) gelf_getdyn (data, ndx, &dyn); + switch (dyn.d_tag) { + default: + /*@innercontinue@*/ continue; + /*@notreached@*/ break; + case DT_NEEDED: +sn = elf_strptr(elf, ndxscn[SHT_STRTAB], dyn.d_un.d_val); +fprintf(stderr, "\t\tneeded %s\n", sn); + /*@switchbreak@*/ break; + } + } + } + /*@switchbreak@*/ break; + } + } + /*@=branchstate =uniondef @*/ + +exit: + if (elf) (void) elf_end(elf); + return 0; +#else + return -1; +#endif +} + static struct poptOption optionsTable[] = { { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0, @@ -26,11 +114,12 @@ main(int argc, char *const argv[]) int pac = 0; ARGV_t xav; ARGV_t av = NULL; - FCLASS_t fc; + rpmfc fc; int ac = 0; const char * s; int ec = 1; int xx; +int fcolor; optCon = rpmcliInit(argc, argv, optionsTable); if (optCon == NULL) @@ -65,8 +154,16 @@ main(int argc, char *const argv[]) xx = argvSort(xav, argvCmp); fc = NULL; - xx = fclassClassify(&fc, xav); - fc = fclassFree(fc); + xx = rpmfcClassify(&fc, xav); + + for (fc->ix = 0; fc->fn[fc->ix] != NULL; fc->ix++) { + fcolor = fc->fcolor->vals[fc->ix]; + if (fcolor & RPMFC_ELF) { + xx = rpmfcELF(fc); + continue; + } + } + fc = rpmfcFree(fc); xav = argvFree(xav); |