elf: Record whether paths come from LD_LIBRARY_PATH or --library-path
[platform/upstream/glibc.git] / elf / dl-main.h
1 /* Information collection during ld.so startup.
2    Copyright (C) 1995-2020 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.  */
40 struct 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.  */
63 enum rtld_mode
64   {
65     rtld_mode_normal, rtld_mode_list, rtld_mode_verify, rtld_mode_trace,
66   };
67
68 /* Aggregated state information extracted from environment variables
69    and the ld.so command line.  */
70 struct dl_main_state
71 {
72   struct audit_list audit_list;
73
74   /* The library search path.  */
75   const char *library_path;
76
77   /* Where library_path comes from.  LD_LIBRARY_PATH or --library-path.  */
78   const char *library_path_source;
79
80   /* The list preloaded objects from LD_PRELOAD.  */
81   const char *preloadlist;
82
83   /* The preload list passed as a command argument.  */
84   const char *preloadarg;
85
86   enum rtld_mode mode;
87
88   /* True if any of the debugging options is enabled.  */
89   bool any_debug;
90
91   /* True if information about versions has to be printed.  */
92   bool version_info;
93 };
94
95 /* Helper function to invoke _dl_init_paths with the right arguments
96    from *STATE.  */
97 static inline void
98 call_init_paths (const struct dl_main_state *state)
99 {
100   _dl_init_paths (state->library_path, state->library_path_source);
101 }
102
103 /* Print ld.so usage information and exit.  */
104 _Noreturn void _dl_usage (void) attribute_hidden;
105
106 #endif /* _DL_MAIN */