1 Patch adapted to binutils 2.23.2 and extended to use
2 BR_COMPILER_PARANOID_UNSAFE_PATH by Thomas Petazzoni.
4 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
6 Upstream-Status: Inappropriate [distribution: codesourcery]
8 Patch originally created by Mark Hatle, forward-ported to
9 binutils 2.21 by Scott Garman.
11 purpose: warn for uses of system directories when cross linking
13 Code Merged from Sourcery G++ binutils 2.19 - 4.4-277
15 2008-07-02 Joseph Myers <joseph@codesourcery.com>
18 * ld.h (args_type): Add error_poison_system_directories.
19 * ld.texinfo (--error-poison-system-directories): Document.
20 * ldfile.c (ldfile_add_library_path): Check
21 command_line.error_poison_system_directories.
22 * ldmain.c (main): Initialize
23 command_line.error_poison_system_directories.
24 * lexsup.c (enum option_values): Add
25 OPTION_ERROR_POISON_SYSTEM_DIRECTORIES.
26 (ld_options): Add --error-poison-system-directories.
27 (parse_args): Handle new option.
29 2007-06-13 Joseph Myers <joseph@codesourcery.com>
32 * config.in: Regenerate.
33 * ld.h (args_type): Add poison_system_directories.
34 * ld.texinfo (--no-poison-system-directories): Document.
35 * ldfile.c (ldfile_add_library_path): Check
36 command_line.poison_system_directories.
37 * ldmain.c (main): Initialize
38 command_line.poison_system_directories.
39 * lexsup.c (enum option_values): Add
40 OPTION_NO_POISON_SYSTEM_DIRECTORIES.
41 (ld_options): Add --no-poison-system-directories.
42 (parse_args): Handle new option.
44 2007-04-20 Joseph Myers <joseph@codesourcery.com>
46 Merge from Sourcery G++ binutils 2.17:
48 2007-03-20 Joseph Myers <joseph@codesourcery.com>
49 Based on patch by Mark Hatle <mark.hatle@windriver.com>.
51 * configure.in (--enable-poison-system-directories): New option.
52 * configure, config.in: Regenerate.
53 * ldfile.c (ldfile_add_library_path): If
54 ENABLE_POISON_SYSTEM_DIRECTORIES defined, warn for use of /lib,
55 /usr/lib, /usr/local/lib or /usr/X11R6/lib.
57 Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
58 Signed-off-by: Scott Garman <scott.a.garman@intel.com>
61 ===================================================================
65 language is requested. */
68 +/* Define to warn for use of native system library directories */
69 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
71 /* Additional extension a shared object might have. */
72 #undef EXTRA_SHLIB_EXTENSION
75 ===================================================================
82 +enable_poison_system_directories
87 (and sometimes confusing) to the casual installer
88 --enable-targets alternative target configurations
89 --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes)
90 + --enable-poison-system-directories
91 + warn for use of native system library directories
92 --enable-gold[=ARG] build gold [ARG={default,yes,no}]
93 --enable-got=<type> GOT handling scheme (target, single, negative,
95 @@ -4339,7 +4342,18 @@
99 +# Check whether --enable-poison-system-directories was given.
100 +if test "${enable_poison_system_directories+set}" = set; then :
101 + enableval=$enable_poison_system_directories;
103 + enable_poison_system_directories=no
106 +if test "x${enable_poison_system_directories}" = "xyes"; then
108 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
112 # Check whether --enable-got was given.
113 if test "${enable_got+set}" = set; then :
114 Index: b/ld/configure.in
115 ===================================================================
116 --- a/ld/configure.in
117 +++ b/ld/configure.in
119 AC_SUBST(TARGET_SYSTEM_ROOT)
120 AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
122 +AC_ARG_ENABLE([poison-system-directories],
123 + AS_HELP_STRING([--enable-poison-system-directories],
124 + [warn for use of native system library directories]),,
125 + [enable_poison_system_directories=no])
126 +if test "x${enable_poison_system_directories}" = "xyes"; then
127 + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
129 + [Define to warn for use of native system library directories])
132 dnl Use --enable-gold to decide if this linker should be the default.
133 dnl "install_as_default" is set to false if gold is the default linker.
134 dnl "installed_linker" is the installed BFD linker name.
136 ===================================================================
140 new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL);
142 new_dirs->name = xstrdup (name);
144 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
145 + if (command_line.poison_system_directories
146 + && ((!strncmp (name, "/lib", 4))
147 + || (!strncmp (name, "/usr/lib", 8))
148 + || (!strncmp (name, "/usr/local/lib", 14))
149 + || (!strncmp (name, "/usr/X11R6/lib", 14))))
151 + if (command_line.error_poison_system_directories)
152 + einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
153 + "cross-compilation\n"), name);
155 + einfo (_("%P: warning: library search path \"%s\" is unsafe for "
156 + "cross-compilation\n"), name);
162 /* Try to open a BFD for a lang_input_statement. */
164 ===================================================================
168 /* If TRUE we'll just print the default output on stdout. */
169 bfd_boolean print_output_format;
171 + /* If TRUE (the default) warn for uses of system directories when
173 + bfd_boolean poison_system_directories;
175 + /* If TRUE (default FALSE) give an error for uses of system
176 + directories when cross linking instead of a warning. */
177 + bfd_boolean error_poison_system_directories;
179 /* Big or little endian as set on command line. */
180 enum endian_enum endian;
183 ===================================================================
187 command_line.warn_mismatch = TRUE;
188 command_line.warn_search_mismatch = TRUE;
189 command_line.check_section_addresses = -1;
190 + command_line.poison_system_directories = TRUE;
191 + command_line.error_poison_system_directories = FALSE;
193 /* We initialize DEMANGLING based on the environment variable
194 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
195 Index: b/ld/ld.texinfo
196 ===================================================================
199 @@ -2175,6 +2175,18 @@
201 Passing @code{none} for @var{style} disables the setting from any
202 @code{--build-id} options earlier on the command line.
204 +@kindex --no-poison-system-directories
205 +@item --no-poison-system-directories
206 +Do not warn for @option{-L} options using system directories such as
207 +@file{/usr/lib} when cross linking. This option is intended for use
208 +in chroot environments when such directories contain the correct
209 +libraries for the target system rather than the host.
211 +@kindex --error-poison-system-directories
212 +@item --error-poison-system-directories
213 +Give an error instead of a warning for @option{-L} options using
214 +system directories when cross linking.
219 ===================================================================
223 OPTION_IGNORE_UNRESOLVED_SYMBOL},
225 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
226 + { {"no-poison-system-directories", no_argument, NULL,
227 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
228 + '\0', NULL, N_("Do not warn for -L options using system directories"),
230 + { {"error-poison-system-directories", no_argument, NULL,
231 + + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
232 + '\0', NULL, N_("Give an error for -L options using system directories"),
236 #define OPTION_COUNT ARRAY_SIZE (ld_options)
239 char *default_dirlist = NULL;
241 + char *BR_paranoid_env;
242 struct option *longopts;
243 struct option *really_longopts;
245 @@ -1442,9 +1451,21 @@
246 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
250 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
251 + command_line.poison_system_directories = FALSE;
254 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
255 + command_line.error_poison_system_directories = TRUE;
260 + BR_paranoid_env = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH");
261 + if (BR_paranoid_env && strlen(BR_paranoid_env) > 0)
262 + command_line.error_poison_system_directories = TRUE;
268 ===================================================================
272 OPTION_DEFAULT_SCRIPT,
273 OPTION_PRINT_OUTPUT_FORMAT,
274 OPTION_IGNORE_UNRESOLVED_SYMBOL,
275 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
276 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
279 /* The initial parser states. */