2 * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
28 #endif /* STDC_HEADERS */
30 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
34 #endif /* HAVE_STRING_H */
37 #endif /* HAVE_STRINGS_H */
41 # include "compat/dlfcn.h"
50 # define LINE_MAX 2048
53 __dso_public int main(int argc, char *argv[]);
58 fprintf(stderr, "usage: load_symbols plugin.so symbols_file\n");
63 main(int argc, char *argv[])
66 const char *plugin_path;
67 const char *symbols_file;
68 char *cp, line[LINE_MAX];
70 int ntests = 0, errors = 0;
72 #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
73 setprogname(argc > 0 ? argv[0] : "check_symbols");
78 plugin_path = argv[1];
79 symbols_file = argv[2];
81 handle = dlopen(plugin_path, RTLD_LAZY|RTLD_GLOBAL);
83 fatalx_nodebug("unable to dlopen %s: %s", plugin_path, dlerror());
85 fp = fopen(symbols_file, "r");
87 fatal_nodebug("unable to open %s", symbols_file);
89 while (fgets(line, sizeof(line), fp) != NULL) {
91 if ((cp = strchr(line, '\n')) != NULL)
93 sym = dlsym(handle, line);
95 printf("%s: test %d: unable to resolve symbol %s: %s\n",
96 getprogname(), ntests, line, dlerror());
102 * Make sure unexported symbols are not available.
105 sym = dlsym(handle, "user_in_group");
107 printf("%s: test %d: able to resolve local symbol user_in_group\n",
108 getprogname(), ntests);
114 printf("%s: %d tests run, %d errors, %d%% success rate\n", getprogname(),
115 ntests, errors, (ntests - errors) * 100 / ntests);