AtlatestRepositorysigil-audio

sigil-audio / tree / testdl-search-probe.c

1/* dl-search-probe.c - links dl-search.c and reports which file a soname
2 * resolved to. Driven by test/dl-search-test.sh, compiled with the same
3 * -D configuration as the package: with SIGIL_DL_SEARCH_INTERPOSE=1 it
4 * calls plain dlopen (proving the interposition), with 0 it calls the
5 * named resolver the package's loader calls.
6 * usage: dl-search-probe <soname> exit 0 and print the path on success */
7#ifndef _GNU_SOURCE
8#define _GNU_SOURCE
9#endif
10#include <dlfcn.h>
11#include <link.h>
12#include <stdio.h>
14void *SIGIL_DL_SEARCH_OPEN(const char *name, int flags);
15const char *SIGIL_DL_SEARCH_SUMMARY(void);
17int main(int argc, char **argv)
19 if (argc != 2) { fprintf(stderr, "usage: %s <soname>\n", argv[0]); return 2; }
20#if SIGIL_DL_SEARCH_INTERPOSE
21 void *h = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL);
22#else
23 void *h = SIGIL_DL_SEARCH_OPEN(argv[1], RTLD_NOW | RTLD_LOCAL);
24#endif
25 if (!h) { printf("UNRESOLVED %s: %s\n", argv[1], dlerror()); return 1; }
26 struct link_map *lm = NULL;
27 if (dlinfo(h, RTLD_DI_LINKMAP, &lm) == 0 && lm) printf("RESOLVED %s -> %s\n", argv[1], lm->l_name);
28 else printf("RESOLVED %s\n", argv[1]);
29 (void)SIGIL_DL_SEARCH_SUMMARY;
30 return 0;