1 From 99e1565b9d2b929d4ee4e9da6f63766b22b23fc3 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 @@ -829,6 +829,7 @@ with_lib_path
83 +enable_poison_system_directories
86 enable_compressed_debug_sections
87 @@ -1498,6 +1499,8 @@ Optional Features:
88 --enable-checking enable run-time checks
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 @@ -15215,6 +15218,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 @@ -106,6 +106,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 @@ -162,6 +162,14 @@ typedef struct
138 in the linker script. */
139 bool force_group_allocation;
141 + /* If TRUE (the default) warn for uses of system directories when
143 + bool 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 + bool error_poison_system_directories;
149 /* Big or little endian as set on command line. */
150 enum endian_enum endian;
154 @@ -2863,6 +2863,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 @@ -117,6 +117,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 @@ -163,6 +163,8 @@ enum option_values
202 OPTION_CTF_VARIABLES,
203 OPTION_NO_CTF_VARIABLES,
204 OPTION_CTF_SHARE_TYPES,
205 + OPTION_NO_POISON_SYSTEM_DIRECTORIES,
206 + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES,
209 /* The initial parser states. */
212 @@ -321,6 +321,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
221 @@ -1444,7 +1446,7 @@ undefined_symbol (struct bfd_link_info *
222 argv[1] = "undefined-symbol";
223 argv[2] = (char *) name;
228 einfo (_("%P: About to run error handling script '%s' with arguments: '%s' '%s'\n"),
229 argv[0], argv[1], argv[2]);
230 @@ -1465,7 +1467,7 @@ undefined_symbol (struct bfd_link_info *
231 carry on to issue the normal error message. */
233 #endif /* SUPPORT_ERROR_HANDLING_SCRIPT */
238 if (error_count < MAX_ERRORS_IN_A_ROW)
241 @@ -595,6 +595,14 @@ static const struct ld_option ld_options
242 " <method> is: share-unconflicted (default),\n"
243 " share-duplicated"),
245 + { {"no-poison-system-directories", no_argument, NULL,
246 + OPTION_NO_POISON_SYSTEM_DIRECTORIES},
247 + '\0', NULL, N_("Do not warn for -L options using system directories"),
249 + { {"error-poison-system-directories", no_argument, NULL,
250 + + OPTION_ERROR_POISON_SYSTEM_DIRECTORIES},
251 + '\0', NULL, N_("Give an error for -L options using system directories"),
255 #define OPTION_COUNT ARRAY_SIZE (ld_options)
256 @@ -1686,6 +1694,14 @@ parse_args (unsigned argc, char **argv)
257 config.print_map_discarded = true;
260 + case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
261 + command_line.poison_system_directories = false;
264 + case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
265 + command_line.error_poison_system_directories = true;
268 case OPTION_DEPENDENCY_FILE:
269 config.dependency_file = optarg;