summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2013-01-03 12:11:26 +0200
committerPanu Matilainen <pmatilai@redhat.com>2013-01-29 08:12:04 +0200
commit0c87890cfd2258470d4a96cb3ae107f2f385feff (patch)
treefef35640fa8393a9b32222643f66d8dd27826d86 /tools
parentf48b9c0b83e1897637c4f8473a9559615cd4d76d (diff)
downloadrpm-0c87890cfd2258470d4a96cb3ae107f2f385feff.tar.gz
rpm-0c87890cfd2258470d4a96cb3ae107f2f385feff.tar.bz2
rpm-0c87890cfd2258470d4a96cb3ae107f2f385feff.zip
Consolidate elf dependency string generation to helper function
- Figure out the elf class marker early and handle the rest in helper to avoid copy-slop code. No functional changes. (cherry picked from commit e7489abd6672e8c980d2d1b2ab32b963e1ea83b2)
Diffstat (limited to 'tools')
-rw-r--r--tools/elfdeps.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/tools/elfdeps.c b/tools/elfdeps.c
index b52369895..e501f1764 100644
--- a/tools/elfdeps.c
+++ b/tools/elfdeps.c
@@ -19,12 +19,12 @@ typedef struct elfInfo_s {
Elf *elf;
int isDSO;
- int isElf64; /* is 64bit marker needed in dependencies */
int isExec; /* requires are only added to executables */
int gotDEBUG;
int gotHASH;
int gotGNUHASH;
int gotSONAME;
+ const char *marker; /* elf class marker or NULL */
ARGV_t requires;
ARGV_t provides;
@@ -35,6 +35,18 @@ static int skipPrivate(const char *s)
return (filter_private && rstreq(s, "GLIBC_PRIVATE"));
}
+static void addDep(ARGV_t *deps,
+ const char *soname, const char *ver, const char *marker)
+{
+ char *dep = NULL;
+ if (ver || marker) {
+ rasprintf(&dep,
+ "%s(%s)%s", soname, ver ? ver : "", marker ? marker : "");
+ }
+ argvAdd(deps, dep ? dep : soname);
+ free(dep);
+}
+
static void processVerDef(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
{
Elf_Data *data = NULL;
@@ -67,11 +79,7 @@ static void processVerDef(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
auxoffset += aux->vda_next;
continue;
} else if (soname && !soname_only && !skipPrivate(s)) {
- const char *marker = ei->isElf64 ? "(64bit)" : "";
- char *dep = NULL;
- rasprintf(&dep, "%s(%s)%s", soname, s, marker);
- argvAdd(&ei->provides, dep);
- rfree(dep);
+ addDep(&ei->provides, soname, s, ei->marker);
}
}
@@ -110,11 +118,7 @@ static void processVerNeed(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
break;
if (ei->isExec && soname && !soname_only && !skipPrivate(s)) {
- const char *marker = ei->isElf64 ? "(64bit)" : "";
- char *dep = NULL;
- rasprintf(&dep, "%s(%s)%s", soname, s, marker);
- argvAdd(&ei->requires, dep);
- rfree(dep);
+ addDep(&ei->requires, soname, s, ei->marker);
}
auxoffset += aux->vna_next;
}
@@ -163,10 +167,7 @@ static void processDynamic(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
}
if (s && deptype) {
- const char *marker = ei->isElf64 ? "()(64bit)" : "";
- char *dep = rstrscat(NULL, s, marker, NULL);
- argvAdd(deptype, dep);
- rfree(dep);
+ addDep(deptype, s, NULL, ei->marker);
}
}
}
@@ -221,9 +222,8 @@ static int processFile(const char *fn, int dtype)
if (ehdr->e_type == ET_DYN || ehdr->e_type == ET_EXEC) {
/* on alpha, everything is 64bit but we dont want the (64bit) markers */
#if !defined(__alpha__)
- ei->isElf64 = (ehdr->e_ident[EI_CLASS] == ELFCLASS64);
-#else
- ei->isElf64 = 0;
+ if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
+ ei->marker = "(64bit)";
#endif
ei->isDSO = (ehdr->e_type == ET_DYN);
ei->isExec = (st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH));
@@ -241,13 +241,8 @@ static int processFile(const char *fn, int dtype)
/* For DSO's, provide the basename of the file if DT_SONAME not found. */
if (ei->isDSO && !ei->gotDEBUG && !ei->gotSONAME) {
- const char *marker = ei->isElf64 ? "()(64bit)" : "";
const char *bn = strrchr(fn, '/');
- char *dep;
- bn = bn ? bn + 1 : fn;
- dep = rstrscat(NULL, bn, marker, NULL);
- argvAdd(&ei->provides, dep);
- rfree(dep);
+ addDep(&ei->provides, bn ? bn + 1 : fn, NULL, ei->marker);
}
rc = 0;