xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/check-weak.c (revision 8a2b682e57a046b828f37bcde1776f131ef4629f)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2019, Joyent, Inc.
14  */
15 
16 /*
17  * Check that we properly handle weak symbols.
18  */
19 
20 #include "check-common.h"
21 
22 
23 static check_function_test_t functions[] = {
24 	{ "mumble", "int", 0, 0, NULL },
25 	{ "_mumble", "int", 0, 0, NULL },
26 	{ NULL }
27 };
28 
29 static check_symbol_t check_syms[] = {
30 	{ "strong", "int" },
31 	{ "_strong", "int" },
32 	{ NULL }
33 };
34 
35 int
36 main(int argc, char *argv[])
37 {
38 	int i, ret = 0;
39 
40 	if (argc < 2) {
41 		errx(EXIT_FAILURE, "missing test files");
42 	}
43 
44 	for (i = 1; i < argc; i++) {
45 		ctf_file_t *fp;
46 		uint_t j;
47 
48 		if ((fp = ctf_open(argv[i], &ret)) == NULL) {
49 			warnx("failed to open %s: %s", argv[i],
50 			    ctf_errmsg(ret));
51 			ret = EXIT_FAILURE;
52 			continue;
53 		}
54 
55 		if (!ctftest_check_symbols(fp, check_syms))
56 			ret = EXIT_FAILURE;
57 
58 		for (j = 0; functions[j].cft_name != NULL; j++) {
59 			if (!ctftest_check_function(functions[j].cft_name, fp,
60 			    functions[j].cft_rtype, functions[j].cft_nargs,
61 			    functions[j].cft_flags, functions[j].cft_args)) {
62 				ret = EXIT_FAILURE;
63 			}
64 		}
65 
66 		ctf_close(fp);
67 	}
68 
69 	return (ret);
70 }
71