Skip to content

Commit

Permalink
Avoid using fallback version when versioned symbols are found.
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonmessmer committed Feb 2, 2023
1 parent 2ec718e commit 0af21b5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tools/elfdeps.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
Expand Down Expand Up @@ -46,7 +47,7 @@ static char *getLibtoolVer(const char *filename)
const char *so;
char dest[PATH_MAX];
int destsize = 0;
int found_digit, found_dot = 0;
int found_digit = 0, found_dot = 0;

destsize = readlink(filename, dest, PATH_MAX);
if (destsize > 0) {
Expand Down Expand Up @@ -101,14 +102,15 @@ static char *getLibtoolVerFromShLink(const char *filename)
void *dl_handle;
struct link_map *linkmap;
char *version = NULL;
ssize_t len;

close(pipefd[0]);
dl_handle = dlmopen(LM_ID_NEWLM, filename, RTLD_LAZY);
if (dl_handle == NULL) _exit(0);
if (dlinfo(dl_handle, RTLD_DI_LINKMAP, &linkmap) != -1) {
version = getLibtoolVer(linkmap->l_name);
}
write(pipefd[1], version, strlen(version));
len = write(pipefd[1], version, strlen(version));
close(pipefd[1]);
free(version);
dlclose(dl_handle);
Expand Down Expand Up @@ -190,6 +192,14 @@ static const char *mkmarker(GElf_Ehdr *ehdr)
return marker;
}

static int findSonameInDeps(ARGV_t deps, const char *soname)
{
for (ARGV_t dep = deps; *dep; dep++) {
if (strncmp(*dep, soname, strlen(soname)) == 0) return 1;
}
return 0;
}

static void addDep(ARGV_t *deps,
const char *soname, const char *ver, const char *marker,
const char *compare_op, const char *fallback_ver)
Expand Down Expand Up @@ -326,7 +336,10 @@ static void processDynamic(Elf_Scn *scn, GElf_Shdr *shdr, elfInfo *ei)
s = elf_strptr(ei->elf, shdr->sh_link, dyn->d_un.d_val);
if (s) {
char *libtool_ver = NULL;
if (libtool_version_fallback) {
// If soname matches an item already in the deps, then
// it had versioned symbols and doesn't require fallback.
if (libtool_version_fallback &&
!findSonameInDeps(ei->requires, s)) {
libtool_ver = getLibtoolVerFromShLink(s);
}
addDep(&ei->requires, s, NULL, ei->marker, ">=", libtool_ver);
Expand Down

0 comments on commit 0af21b5

Please sign in to comment.