AtlatestRepositorysigil-audio
sigil-audio / tree / testdl-search-probe.c
1
/* dl-search-probe.c - links dl-search.c and reports which file a soname2
* resolved to. Driven by test/dl-search-test.sh, compiled with the same3
* -D configuration as the package: with SIGIL_DL_SEARCH_INTERPOSE=1 it4
* calls plain dlopen (proving the interposition), with 0 it calls the5
* named resolver the package's loader calls.6
* usage: dl-search-probe <soname> exit 0 and print the path on success */7
#ifndef _GNU_SOURCE8
#define _GNU_SOURCE9
#endif10
#include <dlfcn.h>11
#include <link.h>12
#include <stdio.h>14
void *SIGIL_DL_SEARCH_OPEN(const char *name, int flags);15
const char *SIGIL_DL_SEARCH_SUMMARY(void);17
int main(int argc, char **argv)18
{19
if (argc != 2) { fprintf(stderr, "usage: %s <soname>\n", argv[0]); return 2; }20
#if SIGIL_DL_SEARCH_INTERPOSE21
void *h = dlopen(argv[1], RTLD_NOW | RTLD_LOCAL);22
#else23
void *h = SIGIL_DL_SEARCH_OPEN(argv[1], RTLD_NOW | RTLD_LOCAL);24
#endif25
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;31
}