]>
Commit | Line | Data |
---|---|---|
063f9ba2 AZ |
1 | /* Check if DT_AUDIT a module with la_plt{enter,exit} call la_symbind |
2 | for lazy resolution. | |
6d7e8eda | 3 | Copyright (C) 2021-2023 Free Software Foundation, Inc. |
063f9ba2 AZ |
4 | This file is part of the GNU C Library. |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with the GNU C Library; if not, see | |
18 | <https://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include <getopt.h> | |
21 | #include <support/capture_subprocess.h> | |
22 | #include <support/check.h> | |
23 | #include <support/xstdio.h> | |
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
26 | #include <stdbool.h> | |
27 | ||
28 | static int restart; | |
29 | #define CMDLINE_OPTIONS \ | |
30 | { "restart", no_argument, &restart, 1 }, | |
31 | ||
32 | int tst_audit18bmod1_func (void); | |
33 | ||
34 | static int | |
35 | handle_restart (void) | |
36 | { | |
37 | TEST_COMPARE (tst_audit18bmod1_func (), 10); | |
38 | return 0; | |
39 | } | |
40 | ||
41 | static inline bool | |
42 | startswith (const char *str, const char *pre) | |
43 | { | |
44 | size_t lenpre = strlen (pre); | |
45 | size_t lenstr = strlen (str); | |
46 | return lenstr < lenpre ? false : memcmp (pre, str, lenpre) == 0; | |
47 | } | |
48 | ||
49 | static int | |
50 | do_test (int argc, char *argv[]) | |
51 | { | |
52 | /* We must have either: | |
53 | - One our fource parameters left if called initially: | |
54 | + path to ld.so optional | |
55 | + "--library-path" optional | |
56 | + the library path optional | |
57 | + the application name */ | |
58 | ||
59 | if (restart) | |
60 | return handle_restart (); | |
61 | ||
62 | char *spargv[9]; | |
63 | int i = 0; | |
64 | for (; i < argc - 1; i++) | |
65 | spargv[i] = argv[i + 1]; | |
66 | spargv[i++] = (char *) "--direct"; | |
67 | spargv[i++] = (char *) "--restart"; | |
68 | spargv[i] = NULL; | |
69 | ||
70 | setenv ("LD_AUDIT", "tst-auditmod18b.so", 0); | |
71 | struct support_capture_subprocess result | |
72 | = support_capture_subprogram (spargv[0], spargv); | |
73 | support_capture_subprocess_check (&result, "tst-audit18b", 0, sc_allow_stderr); | |
74 | ||
75 | bool find_symbind = false; | |
76 | ||
77 | FILE *out = fmemopen (result.err.buffer, result.err.length, "r"); | |
78 | TEST_VERIFY (out != NULL); | |
79 | char *buffer = NULL; | |
80 | size_t buffer_length = 0; | |
81 | while (xgetline (&buffer, &buffer_length, out)) | |
82 | if (startswith (buffer, "la_symbind: tst_audit18bmod1_func") == 0) | |
83 | find_symbind = true; | |
84 | ||
85 | TEST_COMPARE (find_symbind, true); | |
86 | ||
87 | free (buffer); | |
88 | xfclose (out); | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | #define TEST_FUNCTION_ARGV do_test | |
94 | #include <support/test-driver.c> |