]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
b267e516b37639e4c9636a5e98c9857a265a82ed
[thirdparty/openembedded/openembedded-core-contrib.git] /
1 From 26f6a7a397e62b5e974cf88f6d4d8ba9a3d51e3c Mon Sep 17 00:00:00 2001
2 From: Khem Raj <raj.khem@gmail.com>
3 Date: Fri, 15 Jan 2016 06:31:09 +0000
4 Subject: [PATCH] warn for uses of system directories when cross linking
5
6 2008-07-02 Joseph Myers <joseph@codesourcery.com>
7
8 ld/
9 * ld.h (args_type): Add error_poison_system_directories.
10 * ld.texinfo (--error-poison-system-directories): Document.
11 * ldfile.c (ldfile_add_library_path): Check
12 command_line.error_poison_system_directories.
13 * ldmain.c (main): Initialize
14 command_line.error_poison_system_directories.
15 * lexsup.c (enum option_values): Add
16 OPTION_ERROR_POISON_SYSTEM_DIRECTORIES.
17 (ld_options): Add --error-poison-system-directories.
18 (parse_args): Handle new option.
19
20 2007-06-13 Joseph Myers <joseph@codesourcery.com>
21
22 ld/
23 * config.in: Regenerate.
24 * ld.h (args_type): Add poison_system_directories.
25 * ld.texinfo (--no-poison-system-directories): Document.
26 * ldfile.c (ldfile_add_library_path): Check
27 command_line.poison_system_directories.
28 * ldmain.c (main): Initialize
29 command_line.poison_system_directories.
30 * lexsup.c (enum option_values): Add
31 OPTION_NO_POISON_SYSTEM_DIRECTORIES.
32 (ld_options): Add --no-poison-system-directories.
33 (parse_args): Handle new option.
34
35 2007-04-20 Joseph Myers <joseph@codesourcery.com>
36
37 Merge from Sourcery G++ binutils 2.17:
38
39 2007-03-20 Joseph Myers <joseph@codesourcery.com>
40 Based on patch by Mark Hatle <mark.hatle@windriver.com>.
41 ld/
42 * configure.in (--enable-poison-system-directories): New option.
43 * configure, config.in: Regenerate.
44 * ldfile.c (ldfile_add_library_path): If
45 ENABLE_POISON_SYSTEM_DIRECTORIES defined, warn for use of /lib,
46 /usr/lib, /usr/local/lib or /usr/X11R6/lib.
47
48 Upstream-Status: Pending
49
50 Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
51 Signed-off-by: Scott Garman <scott.a.garman@intel.com>
52 Signed-off-by: Khem Raj <raj.khem@gmail.com>
53 ---
54 ld/config.in | 3 +++
55 ld/configure | 16 ++++++++++++++++
56 ld/configure.ac | 10 ++++++++++
57 ld/ld.h | 8 ++++++++
58 ld/ld.texi | 12 ++++++++++++
59 ld/ldfile.c | 16 ++++++++++++++++
60 ld/ldlex.h | 2 ++
61 ld/ldmain.c | 6 ++++--
62 ld/lexsup.c | 15 +++++++++++++++
63 9 files changed, 86 insertions(+), 2 deletions(-)
64
65 diff --git a/ld/config.in b/ld/config.in
66 index f7c9da3d02a..e4fdbf6db5b 100644
67 --- a/ld/config.in
68 +++ b/ld/config.in
69 @@ -74,6 +74,9 @@
70 language is requested. */
71 #undef ENABLE_NLS
72
73 +/* Define to warn for use of native system library directories */
74 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
75 +
76 /* Additional extension a shared object might have. */
77 #undef EXTRA_SHLIB_EXTENSION
78
79 diff --git a/ld/configure b/ld/configure
80 index 1d89e3b0677..dd770216b61 100755
81 --- a/ld/configure
82 +++ b/ld/configure
83 @@ -844,6 +844,7 @@ with_lib_path
84 enable_targets
85 enable_64_bit_bfd
86 with_sysroot
87 +enable_poison_system_directories
88 enable_gold
89 enable_got
90 enable_compressed_debug_sections
91 @@ -1535,6 +1536,8 @@ Optional Features:
92 --enable-checking enable run-time checks
93 --enable-targets alternative target configurations
94 --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes)
95 + --enable-poison-system-directories
96 + warn for use of native system library directories
97 --enable-gold[=ARG] build gold [ARG={default,yes,no}]
98 --enable-got=<type> GOT handling scheme (target, single, negative,
99 multigot)
100 @@ -15566,6 +15569,19 @@ fi
101
102
103
104 +# Check whether --enable-poison-system-directories was given.
105 +if test "${enable_poison_system_directories+set}" = set; then :
106 + enableval=$enable_poison_system_directories;
107 +else
108 + enable_poison_system_directories=no
109 +fi
110 +
111 +if test "x${enable_poison_system_directories}" = "xyes"; then
112 +
113 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
114 +
115 +fi
116 +
117 # Check whether --enable-gold was given.
118 if test "${enable_gold+set}" = set; then :
119 enableval=$enable_gold; case "${enableval}" in
120 diff --git a/ld/configure.ac b/ld/configure.ac
121 index bdf51a062fa..3d370ff92ce 100644
122 --- a/ld/configure.ac
123 +++ b/ld/configure.ac
124 @@ -102,6 +102,16 @@ AC_SUBST(use_sysroot)
125 AC_SUBST(TARGET_SYSTEM_ROOT)
126 AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
127
128 +AC_ARG_ENABLE([poison-system-directories],
129 + AS_HELP_STRING([--enable-poison-system-directories],
130 + [warn for use of native system library directories]),,
131 + [enable_poison_system_directories=no])
132 +if test "x${enable_poison_system_directories}" = "xyes"; then
133 + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
134 + [1],
135 + [Define to warn for use of native system library directories])
136 +fi
137 +
138 dnl Use --enable-gold to decide if this linker should be the default.
139 dnl "install_as_default" is set to false if gold is the default linker.
140 dnl "installed_linker" is the installed BFD linker name.
141 diff --git a/ld/ld.h b/ld/ld.h
142 index 0dee944cf2a..83bd82d2a2e 100644
143 --- a/ld/ld.h
144 +++ b/ld/ld.h
145 @@ -166,6 +166,14 @@ typedef struct
146 in the linker script. */
147 bool force_group_allocation;
148
149 + /* If TRUE (the default) warn for uses of system directories when
150 + cross linking. */
151 + bool poison_system_directories;
152 +
153 + /* If TRUE (default FALSE) give an error for uses of system
154 + directories when cross linking instead of a warning. */
155 + bool error_poison_system_directories;
156 +
157 /* Big or little endian as set on command line. */
158 enum endian_enum endian;
159
160 diff --git a/ld/ld.texi b/ld/ld.texi
161 index 89e3913317a..178908edf32 100644
162 --- a/ld/ld.texi
163 +++ b/ld/ld.texi
164 @@ -3245,6 +3245,18 @@ creation of the metadata note, if one had been enabled by an earlier
165 occurrence of the --package-metadata option.
166 If the linker has been built with libjansson, then the JSON string
167 will be validated.
168 +
169 +@kindex --no-poison-system-directories
170 +@item --no-poison-system-directories
171 +Do not warn for @option{-L} options using system directories such as
172 +@file{/usr/lib} when cross linking. This option is intended for use
173 +in chroot environments when such directories contain the correct
174 +libraries for the target system rather than the host.
175 +
176 +@kindex --error-poison-system-directories
177 +@item --error-poison-system-directories
178 +Give an error instead of a warning for @option{-L} options using
179 +system directories when cross linking.
180 @end table
181
182 @c man end
183 diff --git a/ld/ldfile.c b/ld/ldfile.c
184 index 87be885d31a..86c8a5b267d 100644
185 --- a/ld/ldfile.c
186 +++ b/ld/ldfile.c
187 @@ -344,6 +344,22 @@ ldfile_add_library_path (const char *name, enum search_dir_source source)
188 search_tail_ptr = &new_dirs->next;
189 }
190
191 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
192 + if (command_line.poison_system_directories
193 + && ((!strncmp (name, "/lib", 4))
194 + || (!strncmp (name, "/usr/lib", 8))
195 + || (!strncmp (name, "/usr/local/lib", 14))
196 + || (!strncmp (name, "/usr/X11R6/lib", 14))))
197 + {
198 + if (command_line.error_poison_system_directories)
199 + einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
200 + "cross-compilation\n"), name);
201 + else
202 + einfo (_("%P: warning: library search path \"%s\" is unsafe for "
203 + "cross-compilation\n"), name);
204 + }
205 +#endif
206 +
207 return new_dirs;
208 }
209
210 diff --git a/ld/ldlex.h b/ld/ldlex.h
211 index defe3fcbbb9..aea75a25dc8 100644
212 --- a/ld/ldlex.h
213 +++ b/ld/ldlex.h
214 @@ -149,6 +149,8 @@ enum option_values
215 OPTION_PLUGIN_OPT,
216 OPTION_PLUGIN_SAVE_TEMPS,
217 #endif /* BFD_SUPPORTS_PLUGINS */
218 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
219 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
220 OPTION_DEFAULT_SCRIPT,
221 OPTION_PRINT_OUTPUT_FORMAT,
222 OPTION_PRINT_SYSROOT,
223 diff --git a/ld/ldmain.c b/ld/ldmain.c
224 index 2f500d73c58..8b1bf7ad6aa 100644
225 --- a/ld/ldmain.c
226 +++ b/ld/ldmain.c
227 @@ -348,6 +348,8 @@ main (int argc, char **argv)
228 command_line.warn_mismatch = true;
229 command_line.warn_search_mismatch = true;
230 command_line.check_section_addresses = -1;
231 + command_line.poison_system_directories = true;
232 + command_line.error_poison_system_directories = false;
233
234 /* We initialize DEMANGLING based on the environment variable
235 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
236 @@ -1489,7 +1491,7 @@ undefined_symbol (struct bfd_link_info *info,
237 argv[1] = "undefined-symbol";
238 argv[2] = (char *) name;
239 argv[3] = NULL;
240 -
241 +
242 if (verbose)
243 einfo (_("%P: About to run error handling script '%s' with arguments: '%s' '%s'\n"),
244 argv[0], argv[1], argv[2]);
245 @@ -1510,7 +1512,7 @@ undefined_symbol (struct bfd_link_info *info,
246 carry on to issue the normal error message. */
247 }
248 #endif /* SUPPORT_ERROR_HANDLING_SCRIPT */
249 -
250 +
251 if (section != NULL)
252 {
253 if (error_count < MAX_ERRORS_IN_A_ROW)
254 diff --git a/ld/lexsup.c b/ld/lexsup.c
255 index 4aa0124ce2f..65c90d48332 100644
256 --- a/ld/lexsup.c
257 +++ b/ld/lexsup.c
258 @@ -648,6 +648,14 @@ static const struct ld_option ld_options[] =
259 " <method> is: share-unconflicted (default),\n"
260 " share-duplicated"),
261 TWO_DASHES },
262 + { {"no-poison-system-directories", no_argument, NULL,
263 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
264 + '\0', NULL, N_("Do not warn for -L options using system directories"),
265 + TWO_DASHES },
266 + { {"error-poison-system-directories", no_argument, NULL,
267 + + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
268 + '\0', NULL, N_("Give an error for -L options using system directories"),
269 + TWO_DASHES },
270 };
271
272 #define OPTION_COUNT ARRAY_SIZE (ld_options)
273 @@ -1834,6 +1842,13 @@ parse_args (unsigned argc, char **argv)
274
275 case OPTION_PRINT_MAP_LOCALS:
276 config.print_map_locals = true;
277 +
278 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
279 + command_line.poison_system_directories = false;
280 + break;
281 +
282 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
283 + command_line.error_poison_system_directories = true;
284 break;
285
286 case OPTION_DEPENDENCY_FILE: