1 /* Check LD_AUDIT and LD_BIND_NOW.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <array_length.h>
26 #include <support/capture_subprocess.h>
27 #include <support/check.h>
28 #include <support/xstdio.h>
29 #include <support/support.h>
32 #include "tst-audit25.h"
35 #define CMDLINE_OPTIONS \
36 { "restart", no_argument, &restart, 1 },
38 void tst_audit25mod1_func1 (void);
39 void tst_audit25mod1_func2 (void);
40 void tst_audit25mod2_func1 (void);
41 void tst_audit25mod2_func2 (void);
46 tst_audit25mod1_func1 ();
47 tst_audit25mod1_func2 ();
48 tst_audit25mod2_func1 ();
49 tst_audit25mod2_func2 ();
55 do_test (int argc
, char *argv
[])
57 /* We must have either:
58 - One or four parameters left if called initially:
59 + path to ld.so optional
60 + "--library-path" optional
61 + the library path optional
62 + the application name */
65 return handle_restart ();
67 setenv ("LD_AUDIT", "tst-auditmod25.so", 0);
71 for (; i
< argc
- 1; i
++)
72 spargv
[i
] = argv
[i
+ 1];
73 spargv
[i
++] = (char *) "--direct";
74 spargv
[i
++] = (char *) "--restart";
78 struct support_capture_subprocess result
79 = support_capture_subprogram (spargv
[0], spargv
);
80 support_capture_subprocess_check (&result
, "tst-audit25a", 0,
83 /* tst-audit25a and tst-audit25mod1 are built with -Wl,-z,now, but
84 tst-audit25mod2 is built with -Wl,-z,lazy. So only
85 tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
86 have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
87 const char *expected
[] =
89 "la_symbind: tst_audit25mod3_func1 1\n",
90 "la_symbind: tst_audit25mod1_func1 1\n",
91 "la_symbind: tst_audit25mod2_func1 1\n",
92 "la_symbind: tst_audit25mod1_func2 1\n",
93 "la_symbind: tst_audit25mod2_func2 1\n",
94 "la_symbind: tst_audit25mod4_func1 0\n",
96 compare_output (result
.err
.buffer
, result
.err
.length
,
97 expected
, array_length(expected
));
99 support_capture_subprocess_free (&result
);
103 setenv ("LD_BIND_NOW", "1", 0);
104 struct support_capture_subprocess result
105 = support_capture_subprogram (spargv
[0], spargv
);
106 support_capture_subprocess_check (&result
, "tst-audit25a", 0,
109 /* With LD_BIND_NOW all symbols are expected to have
110 LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
111 order is done in breadth-first order. */
112 const char *expected
[] =
114 "la_symbind: tst_audit25mod4_func1 1\n",
115 "la_symbind: tst_audit25mod3_func1 1\n",
116 "la_symbind: tst_audit25mod1_func1 1\n",
117 "la_symbind: tst_audit25mod2_func1 1\n",
118 "la_symbind: tst_audit25mod1_func2 1\n",
119 "la_symbind: tst_audit25mod2_func2 1\n",
121 compare_output (result
.err
.buffer
, result
.err
.length
,
122 expected
, array_length(expected
));
124 support_capture_subprocess_free (&result
);
130 #define TEST_FUNCTION_ARGV do_test
131 #include <support/test-driver.c>