1 From 8ee1a4986ea35bd1e8ab867c5639d5fdbd944d9f 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
6 2008-07-02 Joseph Myers <joseph@codesourcery.com>
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.
20 2007-06-13 Joseph Myers <joseph@codesourcery.com>
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.
35 2007-04-20 Joseph Myers <joseph@codesourcery.com>
37 Merge from Sourcery G++ binutils 2.17:
39 2007-03-20 Joseph Myers <joseph@codesourcery.com>
40 Based on patch by Mark Hatle <mark.hatle@windriver.com>.
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.
48 Upstream-Status: Pending
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>
55 ld/configure | 16 ++++++++++++++++
56 ld/configure.ac | 10 ++++++++++
58 ld/ld.texi | 12 ++++++++++++
59 ld/ldfile.c | 17 +++++++++++++++++
62 ld/lexsup.c | 16 ++++++++++++++++
63 9 files changed, 86 insertions(+)
68 language is requested. */
71 +/* Define to warn for use of native system library directories */
72 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
74 /* Additional extension a shared object might have. */
75 #undef EXTRA_SHLIB_EXTENSION
79 @@ -827,6 +827,7 @@ with_lib_path
83 +enable_poison_system_directories
86 enable_compressed_debug_sections
87 @@ -1491,6 +1492,8 @@ Optional Features:
88 --disable-largefile omit support for large files
89 --enable-targets alternative target configurations
90 --enable-64-bit-bfd 64-bit support (on hosts with narrower word sizes)
91 + --enable-poison-system-directories
92 + warn for use of native system library directories
93 --enable-gold[=ARG] build gold [ARG={default,yes,no}]
94 --enable-got=<type> GOT handling scheme (target, single, negative,
96 @@ -16619,6 +16622,19 @@ fi
100 +# Check whether --enable-poison-system-directories was given.
101 +if test "${enable_poison_system_directories+set}" = set; then :
102 + enableval=$enable_poison_system_directories;
104 + enable_poison_system_directories=no
107 +if test "x${enable_poison_system_directories}" = "xyes"; then
109 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
113 # Check whether --enable-gold was given.
114 if test "${enable_gold+set}" = set; then :
115 enableval=$enable_gold; case "${enableval}" in
116 --- a/ld/configure.ac
117 +++ b/ld/configure.ac
118 @@ -94,6 +94,16 @@ AC_SUBST(use_sysroot)
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.
137 @@ -180,6 +180,14 @@ typedef struct
138 in the linker script. */
139 bfd_boolean force_group_allocation;
141 + /* If TRUE (the default) warn for uses of system directories when
143 + bfd_boolean poison_system_directories;
145 + /* If TRUE (default FALSE) give an error for uses of system
146 + directories when cross linking instead of a warning. */
147 + bfd_boolean error_poison_system_directories;
149 /* Big or little endian as set on command line. */
150 enum endian_enum endian;
154 @@ -2557,6 +2557,18 @@ string identifying the original linked f
156 Passing @code{none} for @var{style} disables the setting from any
157 @code{--build-id} options earlier on the command line.
159 +@kindex --no-poison-system-directories
160 +@item --no-poison-system-directories
161 +Do not warn for @option{-L} options using system directories such as
162 +@file{/usr/lib} when cross linking. This option is intended for use
163 +in chroot environments when such directories contain the correct
164 +libraries for the target system rather than the host.
166 +@kindex --error-poison-system-directories
167 +@item --error-poison-system-directories
168 +Give an error instead of a warning for @option{-L} options using
169 +system directories when cross linking.
175 @@ -116,6 +116,23 @@ ldfile_add_library_path (const char *nam
176 new_dirs->name = concat (ld_sysroot, name + strlen ("$SYSROOT"), (const char *) NULL);
178 new_dirs->name = xstrdup (name);
180 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
181 + if (command_line.poison_system_directories
182 + && ((!strncmp (name, "/lib", 4))
183 + || (!strncmp (name, "/usr/lib", 8))
184 + || (!strncmp (name, "/usr/local/lib", 14))
185 + || (!strncmp (name, "/usr/X11R6/lib", 14))))
187 + if (command_line.error_poison_system_directories)
188 + einfo (_("%X%P: error: library search path \"%s\" is unsafe for "
189 + "cross-compilation\n"), name);
191 + einfo (_("%P: warning: library search path \"%s\" is unsafe for "
192 + "cross-compilation\n"), name);
198 /* Try to open a BFD for a lang_input_statement. */
201 @@ -150,6 +150,8 @@ enum option_values
202 OPTION_FORCE_GROUP_ALLOCATION,
203 OPTION_PRINT_MAP_DISCARDED,
204 OPTION_NO_PRINT_MAP_DISCARDED,
205 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
206 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
209 /* The initial parser states. */
212 @@ -270,6 +270,8 @@ main (int argc, char **argv)
213 command_line.warn_mismatch = TRUE;
214 command_line.warn_search_mismatch = TRUE;
215 command_line.check_section_addresses = -1;
216 + command_line.poison_system_directories = TRUE;
217 + command_line.error_poison_system_directories = FALSE;
219 /* We initialize DEMANGLING based on the environment variable
220 COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
223 @@ -549,6 +549,14 @@ static const struct ld_option ld_options
224 { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISCARDED},
225 '\0', NULL, N_("Do not show discarded sections in map file output"),
227 + { {"no-poison-system-directories", no_argument, NULL,
228 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
229 + '\0', NULL, N_("Do not warn for -L options using system directories"),
231 + { {"error-poison-system-directories", no_argument, NULL,
232 + + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
233 + '\0', NULL, N_("Give an error for -L options using system directories"),
237 #define OPTION_COUNT ARRAY_SIZE (ld_options)
238 @@ -1590,6 +1598,13 @@ parse_args (unsigned argc, char **argv)
240 case OPTION_PRINT_MAP_DISCARDED:
241 config.print_map_discarded = TRUE;
243 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
244 + command_line.poison_system_directories = FALSE;
247 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
248 + command_line.error_poison_system_directories = TRUE;