1 | /* Print usage information and help for ld.so. |
2 | Copyright (C) 1995-2024 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 | #include <dl-cache.h> |
20 | #include <dl-main.h> |
21 | #include <ldsodefs.h> |
22 | #include <unistd.h> |
23 | #include "version.h" |
24 | |
25 | #include <dl-procinfo.h> |
26 | #include <dl-hwcaps.h> |
27 | |
28 | void |
29 | _dl_usage (const char *argv0, const char *wrong_option) |
30 | { |
31 | if (wrong_option != NULL) |
32 | _dl_error_printf (fmt: "%s: unrecognized option '%s'\n" , argv0, wrong_option); |
33 | else |
34 | _dl_error_printf (fmt: "%s: missing program name\n" , argv0); |
35 | _dl_error_printf (fmt: "Try '%s --help' for more information.\n" , argv0); |
36 | _exit (EXIT_FAILURE); |
37 | } |
38 | |
39 | void |
40 | _dl_version (void) |
41 | { |
42 | _dl_printf (fmt: "\ |
43 | ld.so " PKGVERSION RELEASE " release version " VERSION ".\n\ |
44 | Copyright (C) 2024 Free Software Foundation, Inc.\n\ |
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 | |
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, buffer: " " , length: 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, buffer: name, length: namelen); |
75 | _dl_printf (fmt: " (%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. */ |
86 | call_init_paths (state); |
87 | |
88 | _dl_printf (fmt: "\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 (list: map->l_rpath_dirs.dirs); |
96 | |
97 | print_search_path_for_help_1 (list: __rtld_env_path_list.dirs); |
98 | |
99 | if (map != NULL) |
100 | print_search_path_for_help_1 (list: map->l_runpath_dirs.dirs); |
101 | |
102 | if (!GLRO(dl_inhibit_cache)) |
103 | _dl_printf (fmt: " (libraries located via %s)\n" , LD_SO_CACHE); |
104 | |
105 | print_search_path_for_help_1 (list: __rtld_search_dirs.dirs); |
106 | } |
107 | |
108 | /* Print the header for print_hwcaps_subdirectories. */ |
109 | static void |
110 | (bool *nothing_printed) |
111 | { |
112 | if (*nothing_printed) |
113 | { |
114 | _dl_printf (fmt: "\n\ |
115 | Subdirectories of glibc-hwcaps directories, in priority order:\n" ); |
116 | *nothing_printed = false; |
117 | } |
118 | } |
119 | |
120 | /* Print the HWCAP name itself, indented. */ |
121 | static void |
122 | print_hwcaps_subdirectories_name (const struct dl_hwcaps_split *split) |
123 | { |
124 | _dl_write (STDOUT_FILENO, buffer: " " , length: 2); |
125 | _dl_write (STDOUT_FILENO, buffer: split->segment, length: split->length); |
126 | } |
127 | |
128 | /* Print the list of recognized glibc-hwcaps subdirectories. */ |
129 | static void |
130 | print_hwcaps_subdirectories (const struct dl_main_state *state) |
131 | { |
132 | bool nothing_printed = true; |
133 | struct dl_hwcaps_split split; |
134 | |
135 | /* The prepended glibc-hwcaps subdirectories. */ |
136 | _dl_hwcaps_split_init (s: &split, subject: state->glibc_hwcaps_prepend); |
137 | while (_dl_hwcaps_split (s: &split)) |
138 | { |
139 | print_hwcaps_subdirectories_header (nothing_printed: ¬hing_printed); |
140 | print_hwcaps_subdirectories_name (split: &split); |
141 | _dl_printf (fmt: " (searched)\n" ); |
142 | } |
143 | |
144 | /* The built-in glibc-hwcaps subdirectories. Do the filtering |
145 | manually, so that more precise diagnostics are possible. */ |
146 | uint32_t mask = _dl_hwcaps_subdirs_active (); |
147 | _dl_hwcaps_split_init (s: &split, subject: _dl_hwcaps_subdirs); |
148 | while (_dl_hwcaps_split (s: &split)) |
149 | { |
150 | print_hwcaps_subdirectories_header (nothing_printed: ¬hing_printed); |
151 | print_hwcaps_subdirectories_name (split: &split); |
152 | bool listed = _dl_hwcaps_contains (hwcaps: state->glibc_hwcaps_mask, |
153 | name: split.segment, name_length: split.length); |
154 | if (mask & 1) |
155 | _dl_printf (fmt: " (supported, %s)\n" , listed ? "searched" : "masked" ); |
156 | else if (!listed) |
157 | _dl_printf (fmt: " (masked)\n" ); |
158 | else |
159 | _dl_printf (fmt: "\n" ); |
160 | mask >>= 1; |
161 | } |
162 | |
163 | if (nothing_printed) |
164 | _dl_printf (fmt: "\n\ |
165 | No subdirectories of glibc-hwcaps directories are searched.\n" ); |
166 | } |
167 | |
168 | void |
169 | _dl_help (const char *argv0, struct dl_main_state *state) |
170 | { |
171 | _dl_printf (fmt: "\ |
172 | Usage: %s [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...]\n\ |
173 | You have invoked 'ld.so', the program interpreter for dynamically-linked\n\ |
174 | ELF programs. Usually, the program interpreter is invoked automatically\n\ |
175 | when a dynamically-linked executable is started.\n\ |
176 | \n\ |
177 | You may invoke the program interpreter program directly from the command\n\ |
178 | line to load and run an ELF executable file; this is like executing that\n\ |
179 | file itself, but always uses the program interpreter you invoked,\n\ |
180 | instead of the program interpreter specified in the executable file you\n\ |
181 | run. Invoking the program interpreter directly provides access to\n\ |
182 | additional diagnostics, and changing the dynamic linker behavior without\n\ |
183 | setting environment variables (which would be inherited by subprocesses).\n\ |
184 | \n\ |
185 | --list list all dependencies and how they are resolved\n\ |
186 | --verify verify that given object really is a dynamically linked\n\ |
187 | object we can handle\n\ |
188 | --inhibit-cache Do not use " LD_SO_CACHE "\n\ |
189 | --library-path PATH use given PATH instead of content of the environment\n\ |
190 | variable LD_LIBRARY_PATH\n\ |
191 | --glibc-hwcaps-prepend LIST\n\ |
192 | search glibc-hwcaps subdirectories in LIST\n\ |
193 | --glibc-hwcaps-mask LIST\n\ |
194 | only search built-in subdirectories if in LIST\n\ |
195 | --inhibit-rpath LIST ignore RUNPATH and RPATH information in object names\n\ |
196 | in LIST\n\ |
197 | --audit LIST use objects named in LIST as auditors\n\ |
198 | --preload LIST preload objects named in LIST\n\ |
199 | --argv0 STRING set argv[0] to STRING before running\n\ |
200 | --list-tunables list all tunables with minimum and maximum values\n\ |
201 | --list-diagnostics list diagnostics information\n\ |
202 | --help display this help and exit\n\ |
203 | --version output version information and exit\n\ |
204 | \n\ |
205 | This program interpreter self-identifies as: " RTLD "\n\ |
206 | " , |
207 | argv0); |
208 | print_search_path_for_help (state); |
209 | print_hwcaps_subdirectories (state); |
210 | _exit (EXIT_SUCCESS); |
211 | } |
212 | |