]>
Commit | Line | Data |
---|---|---|
9590a71a | 1 | /* Print usage information and help for ld.so. |
581c785b | 2 | Copyright (C) 1995-2022 Free Software Foundation, Inc. |
9590a71a FW |
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 | #include <dl-cache.h> | |
20 | #include <dl-main.h> | |
21 | #include <ldsodefs.h> | |
e0f1a58f | 22 | #include <unistd.h> |
542923d9 | 23 | #include "version.h" |
9590a71a | 24 | |
21181d1c | 25 | #include <dl-procinfo.h> |
647103ea FW |
26 | #include <dl-hwcaps.h> |
27 | ||
9590a71a | 28 | void |
e0f1a58f | 29 | _dl_usage (const char *argv0, const char *wrong_option) |
9590a71a | 30 | { |
e0f1a58f FW |
31 | if (wrong_option != NULL) |
32 | _dl_error_printf ("%s: unrecognized option '%s'\n", argv0, wrong_option); | |
33 | else | |
34 | _dl_error_printf ("%s: missing program name\n", argv0); | |
35 | _dl_error_printf ("Try '%s --help' for more information.\n", argv0); | |
36 | _exit (EXIT_FAILURE); | |
37 | } | |
38 | ||
542923d9 FW |
39 | void |
40 | _dl_version (void) | |
41 | { | |
42 | _dl_printf ("\ | |
43 | ld.so " PKGVERSION RELEASE " release version " VERSION ".\n\ | |
581c785b | 44 | Copyright (C) 2022 Free Software Foundation, Inc.\n\ |
542923d9 FW |
45 | This is free software; see the source for copying conditions.\n\ |
46 | There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\ | |
47 | PARTICULAR PURPOSE.\n\ | |
48 | "); | |
49 | _exit (EXIT_SUCCESS); | |
50 | } | |
51 | ||
10b39a51 FW |
52 | /* Print part of the library search path (from a single source). */ |
53 | static void | |
54 | print_search_path_for_help_1 (struct r_search_path_elem **list) | |
55 | { | |
56 | if (list == NULL || list == (void *) -1) | |
57 | /* Path is missing or marked as inactive. */ | |
58 | return; | |
59 | ||
60 | for (; *list != NULL; ++list) | |
61 | { | |
62 | _dl_write (STDOUT_FILENO, " ", 2); | |
63 | const char *name = (*list)->dirname; | |
64 | size_t namelen = (*list)->dirnamelen; | |
65 | if (namelen == 0) | |
66 | { | |
67 | /* The empty string denotes the current directory. */ | |
68 | name = "."; | |
69 | namelen = 1; | |
70 | } | |
71 | else if (namelen > 1) | |
72 | /* Remove the trailing slash. */ | |
73 | --namelen; | |
74 | _dl_write (STDOUT_FILENO, name, namelen); | |
75 | _dl_printf (" (%s)\n", (*list)->what); | |
76 | } | |
77 | } | |
78 | ||
79 | /* Prints the library search path. See _dl_init_paths in dl-load.c | |
80 | how this information is populated. */ | |
81 | static void | |
82 | print_search_path_for_help (struct dl_main_state *state) | |
83 | { | |
84 | if (__rtld_search_dirs.dirs == NULL) | |
85 | /* The run-time search paths have not yet been initialized. */ | |
dad90d52 | 86 | call_init_paths (state); |
10b39a51 FW |
87 | |
88 | _dl_printf ("\nShared library search path:\n"); | |
89 | ||
90 | /* The print order should reflect the processing in | |
91 | _dl_map_object. */ | |
92 | ||
93 | struct link_map *map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; | |
94 | if (map != NULL) | |
95 | print_search_path_for_help_1 (map->l_rpath_dirs.dirs); | |
96 | ||
97 | print_search_path_for_help_1 (__rtld_env_path_list.dirs); | |
98 | ||
99 | if (map != NULL) | |
100 | print_search_path_for_help_1 (map->l_runpath_dirs.dirs); | |
101 | ||
102 | _dl_printf (" (libraries located via %s)\n", LD_SO_CACHE); | |
103 | ||
104 | print_search_path_for_help_1 (__rtld_search_dirs.dirs); | |
105 | } | |
106 | ||
647103ea FW |
107 | /* Helper function for printing flags associated with a HWCAP name. */ |
108 | static void | |
109 | print_hwcap_1 (bool *first, bool active, const char *label) | |
110 | { | |
111 | if (active) | |
112 | { | |
113 | if (*first) | |
114 | { | |
115 | _dl_printf (" ("); | |
116 | *first = false; | |
117 | } | |
118 | else | |
119 | _dl_printf (", "); | |
120 | _dl_printf ("%s", label); | |
121 | } | |
122 | } | |
123 | ||
124 | /* Called after a series of print_hwcap_1 calls to emit the line | |
125 | terminator. */ | |
126 | static void | |
127 | print_hwcap_1_finish (bool *first) | |
128 | { | |
129 | if (*first) | |
130 | _dl_printf ("\n"); | |
131 | else | |
132 | _dl_printf (")\n"); | |
133 | } | |
134 | ||
dad90d52 FW |
135 | /* Print the header for print_hwcaps_subdirectories. */ |
136 | static void | |
137 | print_hwcaps_subdirectories_header (bool *nothing_printed) | |
138 | { | |
139 | if (*nothing_printed) | |
140 | { | |
141 | _dl_printf ("\n\ | |
142 | Subdirectories of glibc-hwcaps directories, in priority order:\n"); | |
143 | *nothing_printed = false; | |
144 | } | |
145 | } | |
146 | ||
147 | /* Print the HWCAP name itself, indented. */ | |
148 | static void | |
149 | print_hwcaps_subdirectories_name (const struct dl_hwcaps_split *split) | |
150 | { | |
151 | _dl_write (STDOUT_FILENO, " ", 2); | |
152 | _dl_write (STDOUT_FILENO, split->segment, split->length); | |
153 | } | |
154 | ||
155 | /* Print the list of recognized glibc-hwcaps subdirectories. */ | |
156 | static void | |
157 | print_hwcaps_subdirectories (const struct dl_main_state *state) | |
158 | { | |
159 | bool nothing_printed = true; | |
160 | struct dl_hwcaps_split split; | |
161 | ||
162 | /* The prepended glibc-hwcaps subdirectories. */ | |
163 | _dl_hwcaps_split_init (&split, state->glibc_hwcaps_prepend); | |
164 | while (_dl_hwcaps_split (&split)) | |
165 | { | |
166 | print_hwcaps_subdirectories_header (¬hing_printed); | |
167 | print_hwcaps_subdirectories_name (&split); | |
168 | bool first = true; | |
169 | print_hwcap_1 (&first, true, "searched"); | |
170 | print_hwcap_1_finish (&first); | |
171 | } | |
172 | ||
173 | /* The built-in glibc-hwcaps subdirectories. Do the filtering | |
174 | manually, so that more precise diagnostics are possible. */ | |
175 | uint32_t mask = _dl_hwcaps_subdirs_active (); | |
176 | _dl_hwcaps_split_init (&split, _dl_hwcaps_subdirs); | |
177 | while (_dl_hwcaps_split (&split)) | |
178 | { | |
179 | print_hwcaps_subdirectories_header (¬hing_printed); | |
180 | print_hwcaps_subdirectories_name (&split); | |
181 | bool first = true; | |
182 | print_hwcap_1 (&first, mask & 1, "supported"); | |
183 | bool listed = _dl_hwcaps_contains (state->glibc_hwcaps_mask, | |
184 | split.segment, split.length); | |
185 | print_hwcap_1 (&first, !listed, "masked"); | |
186 | print_hwcap_1 (&first, (mask & 1) && listed, "searched"); | |
187 | print_hwcap_1_finish (&first); | |
188 | mask >>= 1; | |
189 | } | |
190 | ||
191 | if (nothing_printed) | |
192 | _dl_printf ("\n\ | |
193 | No subdirectories of glibc-hwcaps directories are searched.\n"); | |
194 | } | |
195 | ||
e0f1a58f FW |
196 | void |
197 | _dl_help (const char *argv0, struct dl_main_state *state) | |
198 | { | |
199 | _dl_printf ("\ | |
200 | Usage: %s [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\ | |
ca52c56a FW |
201 | You have invoked 'ld.so', the program interpreter for dynamically-linked\n\ |
202 | ELF programs. Usually, the program interpreter is invoked automatically\n\ | |
203 | when a dynamically-linked executable is started.\n\ | |
204 | \n\ | |
205 | You may invoke the program interpreter program directly from the command\n\ | |
206 | line to load and run an ELF executable file; this is like executing that\n\ | |
207 | file itself, but always uses the program interpreter you invoked,\n\ | |
208 | instead of the program interpreter specified in the executable file you\n\ | |
209 | run. Invoking the program interpreter directly provides access to\n\ | |
210 | additional diagnostics, and changing the dynamic linker behavior without\n\ | |
211 | setting environment variables (which would be inherited by subprocesses).\n\ | |
9590a71a FW |
212 | \n\ |
213 | --list list all dependencies and how they are resolved\n\ | |
214 | --verify verify that given object really is a dynamically linked\n\ | |
215 | object we can handle\n\ | |
216 | --inhibit-cache Do not use " LD_SO_CACHE "\n\ | |
217 | --library-path PATH use given PATH instead of content of the environment\n\ | |
218 | variable LD_LIBRARY_PATH\n\ | |
dad90d52 FW |
219 | --glibc-hwcaps-prepend LIST\n\ |
220 | search glibc-hwcaps subdirectories in LIST\n\ | |
221 | --glibc-hwcaps-mask LIST\n\ | |
222 | only search built-in subdirectories if in LIST\n\ | |
9590a71a FW |
223 | --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names\n\ |
224 | in LIST\n\ | |
225 | --audit LIST use objects named in LIST as auditors\n\ | |
226 | --preload LIST preload objects named in LIST\n\ | |
86f65dff L |
227 | --argv0 STRING set argv[0] to STRING before running\n" |
228 | #if HAVE_TUNABLES | |
229 | "\ | |
230 | --list-tunables list all tunables with minimum and maximum values\n" | |
231 | #endif | |
232 | "\ | |
851f32cf | 233 | --list-diagnostics list diagnostics information\n\ |
e0f1a58f | 234 | --help display this help and exit\n\ |
542923d9 | 235 | --version output version information and exit\n\ |
db03874d FW |
236 | \n\ |
237 | This program interpreter self-identifies as: " RTLD "\n\ | |
e0f1a58f FW |
238 | ", |
239 | argv0); | |
10b39a51 | 240 | print_search_path_for_help (state); |
dad90d52 | 241 | print_hwcaps_subdirectories (state); |
e0f1a58f | 242 | _exit (EXIT_SUCCESS); |
9590a71a | 243 | } |