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 @@ -4336,7 +4339,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 = xstrdup (name);
141 new_dirs->sysrooted = is_sysrooted_pathname (name, FALSE);
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);
161 /* Try to open a BFD for a lang_input_statement. */
163 ===================================================================
167 /* If TRUE we'll just print the default output on stdout. */
168 bfd_boolean print_output_format;
170 + /* If TRUE (the default) warn for uses of system directories when
172 + bfd_boolean poison_system_directories;
174 + /* If TRUE (default FALSE) give an error for uses of system
175 + directories when cross linking instead of a warning. */
176 + bfd_boolean error_poison_system_directories;
178 /* Big or little endian as set on command line. */
179 enum endian_enum endian;
182 ===================================================================
186 command_line.warn_search_mismatch = TRUE;
187 command_line.check_section_addresses = -1;
188 command_line.disable_target_specific_optimizations = -1;
189 + command_line.poison_system_directories = TRUE;
190 + command_line.error_poison_system_directories = FALSE;
192 /* We initialize DEMANGLING based on the environment variable
193 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
194 Index: b/ld/ld.texinfo
195 ===================================================================
198 @@ -2147,6 +2147,18 @@
200 Passing @code{none} for @var{style} disables the setting from any
201 @code{--build-id} options earlier on the command line.
203 +@kindex --no-poison-system-directories
204 +@item --no-poison-system-directories
205 +Do not warn for @option{-L} options using system directories such as
206 +@file{/usr/lib} when cross linking. This option is intended for use
207 +in chroot environments when such directories contain the correct
208 +libraries for the target system rather than the host.
210 +@kindex --error-poison-system-directories
211 +@item --error-poison-system-directories
212 +Give an error instead of a warning for @option{-L} options using
213 +system directories when cross linking.
218 ===================================================================
222 #endif /* ENABLE_PLUGINS */
223 OPTION_DEFAULT_SCRIPT,
224 OPTION_PRINT_OUTPUT_FORMAT,
225 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
226 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
229 /* The long options. This structure is used for both the option
232 { {"wrap", required_argument, NULL, OPTION_WRAP},
233 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
234 + { {"no-poison-system-directories", no_argument, NULL,
235 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
236 + '\0', NULL, N_("Do not warn for -L options using system directories"),
238 + { {"error-poison-system-directories", no_argument, NULL,
239 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
240 + '\0', NULL, N_("Give an error for -L options using system directories"),
244 #define OPTION_COUNT ARRAY_SIZE (ld_options)
247 char *default_dirlist = NULL;
249 + char *BR_paranoid_env;
250 struct option *longopts;
251 struct option *really_longopts;
253 @@ -1541,9 +1552,21 @@
254 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
258 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
259 + command_line.poison_system_directories = FALSE;
262 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
263 + command_line.error_poison_system_directories = TRUE;
268 + BR_paranoid_env = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH");
269 + if (BR_paranoid_env && strlen(BR_paranoid_env) > 0)
270 + command_line.error_poison_system_directories = TRUE;