1/* Information collection during ld.so startup.
2 Copyright (C) 1995-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#ifndef _DL_MAIN
20#define _DL_MAIN
21
22#include <ldsodefs.h>
23#include <limits.h>
24#include <stdlib.h>
25
26/* Length limits for names and paths, to protect the dynamic linker,
27 particularly when __libc_enable_secure is active. */
28#ifdef NAME_MAX
29# define SECURE_NAME_LIMIT NAME_MAX
30#else
31# define SECURE_NAME_LIMIT 255
32#endif
33#ifdef PATH_MAX
34# define SECURE_PATH_LIMIT PATH_MAX
35#else
36# define SECURE_PATH_LIMIT 1024
37#endif
38
39/* Strings containing colon-separated lists of audit modules. */
40struct audit_list
41{
42 /* Array of strings containing colon-separated path lists. Each
43 audit module needs its own namespace, so pre-allocate the largest
44 possible list. */
45 const char *audit_strings[DL_NNS];
46
47 /* Number of entries added to audit_strings. */
48 size_t length;
49
50 /* Index into the audit_strings array (for the iteration phase). */
51 size_t current_index;
52
53 /* Tail of audit_strings[current_index] which still needs
54 processing. */
55 const char *current_tail;
56
57 /* Scratch buffer for returning a name which is part of the strings
58 in audit_strings. */
59 char fname[SECURE_NAME_LIMIT];
60};
61
62/* This is a list of all the modes the dynamic loader can be in. */
63enum rtld_mode
64 {
65 rtld_mode_normal, rtld_mode_list, rtld_mode_verify, rtld_mode_trace,
66 rtld_mode_list_tunables, rtld_mode_list_diagnostics, rtld_mode_help,
67 };
68
69/* Aggregated state information extracted from environment variables
70 and the ld.so command line. */
71struct dl_main_state
72{
73 struct audit_list audit_list;
74
75 /* The library search path. */
76 const char *library_path;
77
78 /* Where library_path comes from. LD_LIBRARY_PATH or --library-path. */
79 const char *library_path_source;
80
81 /* The list preloaded objects from LD_PRELOAD. */
82 const char *preloadlist;
83
84 /* The preload list passed as a command argument. */
85 const char *preloadarg;
86
87 /* Additional glibc-hwcaps subdirectories to search first.
88 Colon-separated list. */
89 const char *glibc_hwcaps_prepend;
90
91 /* Mask for the internal glibc-hwcaps subdirectories.
92 Colon-separated list. */
93 const char *glibc_hwcaps_mask;
94
95 enum rtld_mode mode;
96
97 /* True if any of the debugging options is enabled. */
98 bool any_debug;
99
100 /* True if information about versions has to be printed. */
101 bool version_info;
102};
103
104/* Helper function to invoke _dl_init_paths with the right arguments
105 from *STATE. */
106static inline void
107call_init_paths (const struct dl_main_state *state)
108{
109 _dl_init_paths (library_path: state->library_path, source: state->library_path_source,
110 glibc_hwcaps_prepend: state->glibc_hwcaps_prepend, glibc_hwcaps_mask: state->glibc_hwcaps_mask);
111}
112
113/* Print ld.so usage information and exit. */
114_Noreturn void _dl_usage (const char *argv0, const char *wrong_option)
115 attribute_hidden;
116
117/* Print ld.so version information and exit. */
118_Noreturn void _dl_version (void) attribute_hidden;
119
120/* Print ld.so --help output and exit. */
121_Noreturn void _dl_help (const char *argv0, struct dl_main_state *state)
122 attribute_hidden;
123
124/* Print a diagnostics dump. */
125_Noreturn void _dl_print_diagnostics (char **environ) attribute_hidden;
126
127#endif /* _DL_MAIN */
128

source code of glibc/elf/dl-main.h