From ada36102ab34ce7937dfddd49d2f60f4ccd9e3db Mon Sep 17 00:00:00 2001 From: jbj Date: Tue, 15 Oct 2002 18:44:16 +0000 Subject: Replace libelf with elfutils. CVS patchset: 5778 CVS date: 2002/10/15 18:44:16 --- Makefile.am | 2 +- autogen.sh | 3 +- build/Makefile.am | 1 + build/rpmfc.c | 45 ++++++++++++++++-------- build/rpmfc.h | 56 ++++++++++++++--------------- build/tfr.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- configure.ac | 23 ++++-------- lib/depends.c | 18 +++++----- rpmdb/legacy.c | 3 -- rpmio/.cvsignore | 1 + tools/.cvsignore | 1 + zlib/.cvsignore | 1 + 12 files changed, 182 insertions(+), 75 deletions(-) diff --git a/Makefile.am b/Makefile.am index ed96028b7..67a869752 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ EXTRA_DIST = CHANGES CREDITS Doxyheader GROUPS README.amiga INSTALL \ po/*.in po/*.po po/rpm.pot \ rpm.magic rpmpopt-$(VERSION) rpmqv.c rpm.c -SUBDIRS = intl po @WITH_ZLIB_SUBDIR@ libelf @WITH_DB_SUBDIR@ popt beecrypt rpmio rpmdb lib build misc @WITH_PYTHON_SUBDIR@ tools scripts tests doc . +SUBDIRS = intl po @WITH_ZLIB_SUBDIR@ elfutils file @WITH_DB_SUBDIR@ popt beecrypt rpmio rpmdb lib build misc @WITH_PYTHON_SUBDIR@ tools scripts tests doc . INCLUDES = \ -I$(top_srcdir)/build \ diff --git a/autogen.sh b/autogen.sh index ab594f838..0adb4d500 100755 --- a/autogen.sh +++ b/autogen.sh @@ -23,7 +23,8 @@ recent versions of libtool/autoconf/automake. (echo "--- popt"; cd popt; ./autogen.sh --noconfigure "$@") (echo "--- zlib"; cd zlib; ./autogen.sh --noconfigure "$@") (echo "--- beecrypt"; cd beecrypt; ./autogen.sh --noconfigure "$@") -(echo "--- libelf"; cd libelf; ./autogen.sh --noconfigure "$@") +(echo "--- elfutils"; cd elfutils; ./autogen.sh --noconfigure "$@") +(echo "--- file"; cd file; ./autogen.sh --noconfigure "$@") echo "--- rpm" libtoolize --copy --force 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 #include + +#if HAVE_LIBELF_GELF_H + +#include + +#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); diff --git a/configure.ac b/configure.ac index 449e3d808..391e09cb6 100644 --- a/configure.ac +++ b/configure.ac @@ -51,7 +51,7 @@ AC_PROG_CXX AS=${AS-as} AC_SUBST(AS) if test "$ac_cv_prog_gcc" = yes; then - CFLAGS="$CFLAGS -D_GNU_SOURCE -D_REENTRANT -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wno-char-subscripts" + CFLAGS="$CFLAGS -D_GNU_SOURCE -D_REENTRANT -Wall" fi export CFLAGS @@ -367,23 +367,14 @@ WITH_LIBELF_SUBDIR= WITH_LIBELF_INCLUDE= WITH_LIBELF_LIB= WITH_LIBELF_ARCHIVE= -AC_CHECK_HEADER([libelf/gelf.h], [ - AC_DEFINE(HAVE_LIBELF_GELF_H, 1, [Define to 1 if you have the header file.]) - WITH_LIBELF_INCLUDE="-I/usr/include/libelf" - AC_CHECK_FUNC(gelf_getdyn, [], - AC_CHECK_LIB(elf, gelf_getdyn) - ) - WITH_LIBELF_LIB="-lelf" - ], [ - if test -d libelf ; then + if test -d elfutils/libelf ; then AC_DEFINE(HAVE_LIBELF_GELF_H, 1, [Define to 1 if you have the header file.]) AC_DEFINE(HAVE_LIBELF, 1, [Define to 1 if you have the `elf' library (-lelf).]) - WITH_LIBELF_SUBDIR=libelf - WITH_LIBELF_INCLUDE="-I\${top_srcdir}/${WITH_LIBELF_SUBDIR}/lib" - WITH_LIBELF_LIB="\${top_builddir}/${WITH_LIBELF_SUBDIR}/lib/libelf.la" - WITH_LIBELF_ARCHIVE="\${top_builddir}/${WITH_LIBELF_SUBDIR}/lib/.libs/libelf.a" + WITH_LIBELF_SUBDIR=elfutils/libelf + WITH_LIBELF_INCLUDE="-I\${top_srcdir}/${WITH_LIBELF_SUBDIR}" + WITH_LIBELF_LIB="\${top_builddir}/${WITH_LIBELF_SUBDIR}/libelf.la" + WITH_LIBELF_ARCHIVE="\${top_builddir}/${WITH_LIBELF_SUBDIR}/.libs/libelf.a" fi -]) AC_SUBST(WITH_LIBELF_SUBDIR) AC_SUBST(WITH_LIBELF_INCLUDE) AC_SUBST(WITH_LIBELF_LIB) @@ -1198,7 +1189,7 @@ dnl XXX this causes popt to depend on zlib et al dnl # XXX Propagate -lucb to popt ... dnl export LIBS INCPATH CONFIG_SITE -AC_CONFIG_SUBDIRS(popt beecrypt zlib libelf db3) +AC_CONFIG_SUBDIRS(popt beecrypt zlib elfutils file db3) AC_OUTPUT([ Doxyfile Makefile rpmrc macros platform rpmpopt rpm.spec rpmio/Makefile rpmdb/Makefile lib/Makefile build/Makefile diff --git a/lib/depends.c b/lib/depends.c index d44f96c39..6bb24dc30 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -250,17 +250,17 @@ uint_32 *mlmp, multiLibMask, oldMultiLibMask; /*@-boundsread@*/ { rpmdbMatchIterator mi; - Header h2; + Header oh; mi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, rpmteN(p), 0); - while((h2 = rpmdbNextIterator(mi)) != NULL) { - if (rpmVersionCompare(h, h2)) - xx = removePackage(ts, h2, rpmdbGetIteratorOffset(mi), pkgKey); + while((oh = rpmdbNextIterator(mi)) != NULL) { + if (rpmVersionCompare(h, oh)) + xx = removePackage(ts, oh, rpmdbGetIteratorOffset(mi), pkgKey); else { mlmp = NULL; oldMultiLibMask = 0; - if (hge(h2, RPMTAG_MULTILIBMASK, NULL, (void **) &mlmp, NULL)) + if (hge(oh, RPMTAG_MULTILIBMASK, NULL, (void **) &mlmp, NULL)) oldMultiLibMask = *mlmp; mlmp = NULL; multiLibMask = 0; @@ -291,21 +291,21 @@ uint_32 *mlmp, multiLibMask, oldMultiLibMask; continue; { rpmdbMatchIterator mi; - Header h2; + Header oh; mi = rpmtsInitIterator(ts, RPMTAG_PROVIDENAME, Name, 0); xx = rpmdbPruneIterator(mi, ts->removedPackages, ts->numRemovedPackages, 1); - while((h2 = rpmdbNextIterator(mi)) != NULL) { + while((oh = rpmdbNextIterator(mi)) != NULL) { /* * Rpm prior to 3.0.3 does not have versioned obsoletes. * If no obsoletes version info is available, match all names. */ if (rpmdsEVR(obsoletes) == NULL - || rpmdsAnyMatchesDep(h2, obsoletes, _rpmds_nopromote)) - xx = removePackage(ts, h2, rpmdbGetIteratorOffset(mi), pkgKey); + || rpmdsAnyMatchesDep(oh, obsoletes, _rpmds_nopromote)) + xx = removePackage(ts, oh, rpmdbGetIteratorOffset(mi), pkgKey); } mi = rpmdbFreeIterator(mi); } diff --git a/rpmdb/legacy.c b/rpmdb/legacy.c index 1aafd4454..3568de9e0 100644 --- a/rpmdb/legacy.c +++ b/rpmdb/legacy.c @@ -5,9 +5,6 @@ #include "system.h" #if HAVE_LIBELF_GELF_H -#define __LIBELF_INTERNAL__ 1 -# undef __P -# define __P(protos) protos #include diff --git a/rpmio/.cvsignore b/rpmio/.cvsignore index 80c7e73cc..1c294cb5e 100644 --- a/rpmio/.cvsignore +++ b/rpmio/.cvsignore @@ -12,6 +12,7 @@ tdir tficl tfts tglob +tinv tkey tring trpmio diff --git a/tools/.cvsignore b/tools/.cvsignore index fd8e2f235..561ba94c3 100644 --- a/tools/.cvsignore +++ b/tools/.cvsignore @@ -16,4 +16,5 @@ rpmlead rpmsort rpmsignature striptofile +tpkgid unstripfile diff --git a/zlib/.cvsignore b/zlib/.cvsignore index 9eed9011f..2343a9f15 100644 --- a/zlib/.cvsignore +++ b/zlib/.cvsignore @@ -5,6 +5,7 @@ Doxyfile Doxytags Makefile Makefile.in +aclocal.m4 apidocs autom4te-* config.cache -- cgit v1.2.3