1 /* Check LD_AUDIT and LD_BIND_NOW.
2 Copyright (C) 2022 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/>. */
25 #include <support/capture_subprocess.h>
26 #include <support/check.h>
27 #include <support/xstdio.h>
28 #include <support/support.h>
32 #define CMDLINE_OPTIONS \
33 { "restart", no_argument, &restart, 1 },
35 void tst_audit25mod1_func1 (void);
36 void tst_audit25mod1_func2 (void);
37 void tst_audit25mod2_func1 (void);
38 void tst_audit25mod2_func2 (void);
43 tst_audit25mod1_func1 ();
44 tst_audit25mod1_func2 ();
45 tst_audit25mod2_func1 ();
46 tst_audit25mod2_func2 ();
52 do_test (int argc
, char *argv
[])
54 /* We must have either:
55 - One or four parameters left if called initially:
56 + path to ld.so optional
57 + "--library-path" optional
58 + the library path optional
59 + the application name */
62 return handle_restart ();
64 setenv ("LD_AUDIT", "tst-auditmod25.so", 0);
68 for (; i
< argc
- 1; i
++)
69 spargv
[i
] = argv
[i
+ 1];
70 spargv
[i
++] = (char *) "--direct";
71 spargv
[i
++] = (char *) "--restart";
75 struct support_capture_subprocess result
76 = support_capture_subprogram (spargv
[0], spargv
);
77 support_capture_subprocess_check (&result
, "tst-audit25a", 0,
80 /* tst-audit25a and tst-audit25mod1 are built with -Wl,-z,now, but
81 tst-audit25mod2 is built with -Wl,-z,lazy. So only
82 tst_audit25mod4_func1 (called by tst_audit25mod2_func1) should not
83 have LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. */
84 TEST_COMPARE_STRING (result
.err
.buffer
,
85 "la_symbind: tst_audit25mod3_func1 1\n"
86 "la_symbind: tst_audit25mod1_func1 1\n"
87 "la_symbind: tst_audit25mod2_func1 1\n"
88 "la_symbind: tst_audit25mod1_func2 1\n"
89 "la_symbind: tst_audit25mod2_func2 1\n"
90 "la_symbind: tst_audit25mod4_func1 0\n");
92 support_capture_subprocess_free (&result
);
96 setenv ("LD_BIND_NOW", "1", 0);
97 struct support_capture_subprocess result
98 = support_capture_subprogram (spargv
[0], spargv
);
99 support_capture_subprocess_check (&result
, "tst-audit25a", 0,
102 /* With LD_BIND_NOW all symbols are expected to have
103 LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT. Also the resolution
104 order is done in breadth-first order. */
105 TEST_COMPARE_STRING (result
.err
.buffer
,
106 "la_symbind: tst_audit25mod4_func1 1\n"
107 "la_symbind: tst_audit25mod3_func1 1\n"
108 "la_symbind: tst_audit25mod1_func1 1\n"
109 "la_symbind: tst_audit25mod2_func1 1\n"
110 "la_symbind: tst_audit25mod1_func2 1\n"
111 "la_symbind: tst_audit25mod2_func2 1\n");
113 support_capture_subprocess_free (&result
);
119 #define TEST_FUNCTION_ARGV do_test
120 #include <support/test-driver.c>