]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/blob
86ff7fdaa02c2baa643fef6c89fa2c19d528c7ea
[thirdparty/openembedded/openembedded-core-contrib.git] /
1 From 05dcd732a4b91ecd77f37fabd8a1a14209467816 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 | 20 ++++++++++++++++++--
56 ld/configure.ac | 10 ++++++++++
57 ld/ld.h | 8 ++++++++
58 ld/ld.texi | 12 ++++++++++++
59 ld/ldfile.c | 17 +++++++++++++++++
60 ld/ldlex.h | 2 ++
61 ld/ldmain.c | 6 ++++--
62 ld/lexsup.c | 15 +++++++++++++++
63 9 files changed, 89 insertions(+), 4 deletions(-)
64
65 diff --git a/ld/config.in b/ld/config.in
66 index 37812241bd9..be89571196c 100644
67 --- a/ld/config.in
68 +++ b/ld/config.in
69 @@ -78,6 +78,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 4afc58566fc..ca3d58ff618 100755
81 --- a/ld/configure
82 +++ b/ld/configure
83 @@ -841,6 +841,7 @@ enable_checking
84 with_lib_path
85 enable_targets
86 with_sysroot
87 +enable_poison_system_directories
88 enable_gold
89 enable_got
90 enable_compressed_debug_sections
91 @@ -1533,6 +1534,8 @@ Optional Features:
92 --disable-largefile omit support for large files
93 --enable-checking enable run-time checks
94 --enable-targets alternative target configurations
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 @@ -11514,7 +11517,7 @@ else
101 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
102 lt_status=$lt_dlunknown
103 cat > conftest.$ac_ext <<_LT_EOF
104 -#line 11517 "configure"
105 +#line 11520 "configure"
106 #include "confdefs.h"
107
108 #if HAVE_DLFCN_H
109 @@ -11620,7 +11623,7 @@ else
110 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
111 lt_status=$lt_dlunknown
112 cat > conftest.$ac_ext <<_LT_EOF
113 -#line 11623 "configure"
114 +#line 11626 "configure"
115 #include "confdefs.h"
116
117 #if HAVE_DLFCN_H
118 @@ -15367,6 +15370,19 @@ fi
119
120
121
122 +# Check whether --enable-poison-system-directories was given.
123 +if test "${enable_poison_system_directories+set}" = set; then :
124 + enableval=$enable_poison_system_directories;
125 +else
126 + enable_poison_system_directories=no
127 +fi
128 +
129 +if test "x${enable_poison_system_directories}" = "xyes"; then
130 +
131 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
132 +
133 +fi
134 +
135 # Check whether --enable-gold was given.
136 if test "${enable_gold+set}" = set; then :
137 enableval=$enable_gold; case "${enableval}" in
138 diff --git a/ld/configure.ac b/ld/configure.ac
139 index 3ee84958b1c..99ea84513da 100644
140 --- a/ld/configure.ac
141 +++ b/ld/configure.ac
142 @@ -115,6 +115,16 @@ AC_SUBST(use_sysroot)
143 AC_SUBST(TARGET_SYSTEM_ROOT)
144 AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
145
146 +AC_ARG_ENABLE([poison-system-directories],
147 + AS_HELP_STRING([--enable-poison-system-directories],
148 + [warn for use of native system library directories]),,
149 + [enable_poison_system_directories=no])
150 +if test "x${enable_poison_system_directories}" = "xyes"; then
151 + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
152 + [1],
153 + [Define to warn for use of native system library directories])
154 +fi
155 +
156 dnl Use --enable-gold to decide if this linker should be the default.
157 dnl "install_as_default" is set to false if gold is the default linker.
158 dnl "installed_linker" is the installed BFD linker name.
159 diff --git a/ld/ld.h b/ld/ld.h
160 index c8688153bd4..0b16caf347a 100644
161 --- a/ld/ld.h
162 +++ b/ld/ld.h
163 @@ -166,6 +166,14 @@ typedef struct
164 in the linker script. */
165 bool force_group_allocation;
166
167 + /* If TRUE (the default) warn for uses of system directories when
168 + cross linking. */
169 + bool poison_system_directories;
170 +
171 + /* If TRUE (default FALSE) give an error for uses of system
172 + directories when cross linking instead of a warning. */
173 + bool error_poison_system_directories;
174 +
175 /* Big or little endian as set on command line. */
176 enum endian_enum endian;
177
178 diff --git a/ld/ld.texi b/ld/ld.texi
179 index 413335ad765..7bea7fd7e1f 100644
180 --- a/ld/ld.texi
181 +++ b/ld/ld.texi
182 @@ -3350,6 +3350,18 @@ creation of the metadata note, if one had been enabled by an earlier
183 occurrence of the --package-metadata option.
184 If the linker has been built with libjansson, then the JSON string
185 will be validated.
186 +
187 +@kindex --no-poison-system-directories
188 +@item --no-poison-system-directories
189 +Do not warn for @option{-L} options using system directories such as
190 +@file{/usr/lib} when cross linking. This option is intended for use
191 +in chroot environments when such directories contain the correct
192 +libraries for the target system rather than the host.
193 +
194 +@kindex --error-poison-system-directories
195 +@item --error-poison-system-directories
196 +Give an error instead of a warning for @option{-L} options using
197 +system directories when cross linking.
198 @end table
199
200 @c man end
201 diff --git a/ld/ldfile.c b/ld/ldfile.c
202 index 75fd360d5e3..5a825c52bd3 100644
203 --- a/ld/ldfile.c
204 +++ b/ld/ldfile.c
205 @@ -328,6 +328,23 @@ ldfile_add_library_path (const char *name, bool cmdline)
206 new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
207 else
208 new_dirs->name = xstrdup (name);
209 +
210 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
211 + if (command_line.poison_system_directories
212 + && ((!strncmp (name, "/lib", 4))
213 + || (!strncmp (name, "/usr/lib", 8))
214 + || (!strncmp (name, "/usr/local/lib", 14))
215 + || (!strncmp (name, "/usr/X11R6/lib", 14))))
216 + {
217 + if (command_line.error_poison_system_directories)
218 + einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
219 + "cross-compilation\n"), name);
220 + else
221 + einfo (_("%P: warning: library search path \"%s\" is unsafe for "
222 + "cross-compilation\n"), name);
223 + }
224 +#endif
225 +
226 }
227
228 static void
229 diff --git a/ld/ldlex.h b/ld/ldlex.h
230 index 815da76a4c0..53fabed4ba2 100644
231 --- a/ld/ldlex.h
232 +++ b/ld/ldlex.h
233 @@ -151,6 +151,8 @@ enum option_values
234 OPTION_PLUGIN_OPT,
235 OPTION_PLUGIN_SAVE_TEMPS,
236 #endif /* BFD_SUPPORTS_PLUGINS */
237 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
238 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
239 OPTION_DEFAULT_SCRIPT,
240 OPTION_PRINT_OUTPUT_FORMAT,
241 OPTION_PRINT_SYSROOT,
242 diff --git a/ld/ldmain.c b/ld/ldmain.c
243 index 7878bd3922f..c9293a3cf41 100644
244 --- a/ld/ldmain.c
245 +++ b/ld/ldmain.c
246 @@ -672,6 +672,8 @@ main (int argc, char **argv)
247 command_line.warn_mismatch = true;
248 command_line.warn_search_mismatch = true;
249 command_line.check_section_addresses = -1;
250 + command_line.poison_system_directories = true;
251 + command_line.error_poison_system_directories = false;
252
253 /* We initialize DEMANGLING based on the environment variable
254 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
255 @@ -1876,7 +1878,7 @@ undefined_symbol (struct bfd_link_info *info,
256 argv[1] = "undefined-symbol";
257 argv[2] = (char *) name;
258 argv[3] = NULL;
259 -
260 +
261 if (verbose)
262 einfo (_("%P: About to run error handling script '%s' with arguments: '%s' '%s'\n"),
263 argv[0], argv[1], argv[2]);
264 @@ -1897,7 +1899,7 @@ undefined_symbol (struct bfd_link_info *info,
265 carry on to issue the normal error message. */
266 }
267 #endif /* SUPPORT_ERROR_HANDLING_SCRIPT */
268 -
269 +
270 if (section != NULL)
271 {
272 if (error_count < MAX_ERRORS_IN_A_ROW)
273 diff --git a/ld/lexsup.c b/ld/lexsup.c
274 index bde20465835..95ab1b7c200 100644
275 --- a/ld/lexsup.c
276 +++ b/ld/lexsup.c
277 @@ -652,6 +652,14 @@ static const struct ld_option ld_options[] =
278 " <method> is: share-unconflicted (default),\n"
279 " share-duplicated"),
280 TWO_DASHES },
281 + { {"no-poison-system-directories", no_argument, NULL,
282 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
283 + '\0', NULL, N_("Do not warn for -L options using system directories"),
284 + TWO_DASHES },
285 + { {"error-poison-system-directories", no_argument, NULL,
286 + + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
287 + '\0', NULL, N_("Give an error for -L options using system directories"),
288 + TWO_DASHES },
289 };
290
291 #define OPTION_COUNT ARRAY_SIZE (ld_options)
292 @@ -1849,6 +1857,13 @@ parse_args (unsigned argc, char **argv)
293
294 case OPTION_PRINT_MAP_LOCALS:
295 config.print_map_locals = true;
296 +
297 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
298 + command_line.poison_system_directories = false;
299 + break;
300 +
301 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
302 + command_line.error_poison_system_directories = true;
303 break;
304
305 case OPTION_DEPENDENCY_FILE: