]> code.ossystems Code Review - openembedded-core.git/blob
655cc375a9213ff344eb63c5c0fbbf42421b7fed
[openembedded-core.git] /
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
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    | 16 ++++++++++++++++
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     |  2 ++
62  ld/lexsup.c     | 16 ++++++++++++++++
63  9 files changed, 86 insertions(+)
64
65 --- a/ld/config.in
66 +++ b/ld/config.in
67 @@ -31,6 +31,9 @@
68     language is requested. */
69  #undef ENABLE_NLS
70  
71 +/* Define to warn for use of native system library directories */
72 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
73 +
74  /* Additional extension a shared object might have. */
75  #undef EXTRA_SHLIB_EXTENSION
76  
77 --- a/ld/configure
78 +++ b/ld/configure
79 @@ -827,6 +827,7 @@ with_lib_path
80  enable_targets
81  enable_64_bit_bfd
82  with_sysroot
83 +enable_poison_system_directories
84  enable_gold
85  enable_got
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,
95                            multigot)
96 @@ -16619,6 +16622,19 @@ fi
97  
98  
99  
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;
103 +else
104 +  enable_poison_system_directories=no
105 +fi
106 +
107 +if test "x${enable_poison_system_directories}" = "xyes"; then
108 +
109 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
110 +
111 +fi
112 +
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)
121  
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],
128 +       [1],
129 +       [Define to warn for use of native system library directories])
130 +fi
131 +
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.
135 --- a/ld/ld.h
136 +++ b/ld/ld.h
137 @@ -180,6 +180,14 @@ typedef struct
138       in the linker script.  */
139    bfd_boolean force_group_allocation;
140  
141 +  /* If TRUE (the default) warn for uses of system directories when
142 +     cross linking.  */
143 +  bfd_boolean poison_system_directories;
144 +
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;
148 +
149    /* Big or little endian as set on command line.  */
150    enum endian_enum endian;
151  
152 --- a/ld/ld.texi
153 +++ b/ld/ld.texi
154 @@ -2557,6 +2557,18 @@ string identifying the original linked f
155  
156  Passing @code{none} for @var{style} disables the setting from any
157  @code{--build-id} options earlier on the command line.
158 +
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.
165 +
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.
170  @end table
171  
172  @c man end
173 --- a/ld/ldfile.c
174 +++ b/ld/ldfile.c
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);
177    else
178      new_dirs->name = xstrdup (name);
179 +
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))))
186 +   {
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);
190 +     else
191 +       einfo (_("%P: warning: library search path \"%s\" is unsafe for "
192 +            "cross-compilation\n"), name);
193 +   }
194 +#endif
195 +
196  }
197  
198  /* Try to open a BFD for a lang_input_statement.  */
199 --- a/ld/ldlex.h
200 +++ b/ld/ldlex.h
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,
207  };
208  
209  /* The initial parser states.  */
210 --- a/ld/ldmain.c
211 +++ b/ld/ldmain.c
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;
218  
219    /* We initialize DEMANGLING based on the environment variable
220       COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
221 --- a/ld/lexsup.c
222 +++ b/ld/lexsup.c
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"),
226      TWO_DASHES },
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"),
230 +    TWO_DASHES },
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"),
234 +    TWO_DASHES },
235  };
236  
237  #define OPTION_COUNT ARRAY_SIZE (ld_options)
238 @@ -1590,6 +1598,13 @@ parse_args (unsigned argc, char **argv)
239  
240         case OPTION_PRINT_MAP_DISCARDED:
241           config.print_map_discarded = TRUE;
242 +
243 +       case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
244 +         command_line.poison_system_directories = FALSE;
245 +         break;
246 +
247 +       case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
248 +         command_line.error_poison_system_directories = TRUE;
249           break;
250         }
251      }