1/* Check if DT_AUDIT a module with la_plt{enter,exit} call la_symbind
2 for lazy resolution.
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
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
28static int restart;
29#define CMDLINE_OPTIONS \
30 { "restart", no_argument, &restart, 1 },
31
32int tst_audit18bmod1_func (void);
33
34static int
35handle_restart (void)
36{
37 TEST_COMPARE (tst_audit18bmod1_func (), 10);
38 return 0;
39}
40
41static inline bool
42startswith (const char *str, const char *pre)
43{
44 size_t lenpre = strlen (s: pre);
45 size_t lenstr = strlen (s: str);
46 return lenstr < lenpre ? false : memcmp (s1: pre, s2: str, n: lenpre) == 0;
47}
48
49static int
50do_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 (name: "LD_AUDIT", value: "tst-auditmod18b.so", replace: 0);
71 struct support_capture_subprocess result
72 = support_capture_subprogram (file: spargv[0], argv: spargv);
73 support_capture_subprocess_check (&result, context: "tst-audit18b", status_or_signal: 0, allowed: sc_allow_stderr);
74
75 bool find_symbind = false;
76
77 FILE *out = fmemopen (s: result.err.buffer, len: result.err.length, modes: "r");
78 TEST_VERIFY (out != NULL);
79 char *buffer = NULL;
80 size_t buffer_length = 0;
81 while (xgetline (lineptr: &buffer, n: &buffer_length, stream: out))
82 if (startswith (str: buffer, pre: "la_symbind: tst_audit18bmod1_func") == 0)
83 find_symbind = true;
84
85 TEST_COMPARE (find_symbind, true);
86
87 free (ptr: buffer);
88 xfclose (out);
89
90 return 0;
91}
92
93#define TEST_FUNCTION_ARGV do_test
94#include <support/test-driver.c>
95

source code of glibc/elf/tst-audit19b.c