6a3bf6be87b13e17090a6b9dfb7fc6922b4f9623
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / binutils / 2.24 / 600-poison-system-directories.patch
1 Patch adapted to binutils 2.23.2 and extended to use
2 BR_COMPILER_PARANOID_UNSAFE_PATH by Thomas Petazzoni.
3
4 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
5
6 Upstream-Status: Inappropriate [distribution: codesourcery]
7
8 Patch originally created by Mark Hatle, forward-ported to
9 binutils 2.21 by Scott Garman.
10
11 purpose:  warn for uses of system directories when cross linking
12
13 Code Merged from Sourcery G++ binutils 2.19 - 4.4-277
14
15 2008-07-02  Joseph Myers  <joseph@codesourcery.com>
16
17     ld/
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.
28
29 2007-06-13  Joseph Myers  <joseph@codesourcery.com>
30
31     ld/
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.
43
44 2007-04-20  Joseph Myers  <joseph@codesourcery.com>
45
46     Merge from Sourcery G++ binutils 2.17:
47
48     2007-03-20  Joseph Myers  <joseph@codesourcery.com>
49     Based on patch by Mark Hatle <mark.hatle@windriver.com>.
50     ld/
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.
56
57 Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
58 Signed-off-by: Scott Garman <scott.a.garman@intel.com>
59
60 Index: b/ld/config.in
61 ===================================================================
62 --- a/ld/config.in
63 +++ b/ld/config.in
64 @@ -11,6 +11,9 @@
65     language is requested. */
66  #undef ENABLE_NLS
67  
68 +/* Define to warn for use of native system library directories */
69 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
70 +
71  /* Additional extension a shared object might have. */
72  #undef EXTRA_SHLIB_EXTENSION
73  
74 Index: b/ld/configure
75 ===================================================================
76 --- a/ld/configure
77 +++ b/ld/configure
78 @@ -774,6 +774,7 @@
79  enable_targets
80  enable_64_bit_bfd
81  with_sysroot
82 +enable_poison_system_directories
83  enable_gold
84  enable_got
85  enable_werror
86 @@ -1429,6 +1430,8 @@
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,
94                            multigot)
95 @@ -4339,7 +4342,18 @@
96  fi
97  
98  
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;
102 +else
103 +  enable_poison_system_directories=no
104 +fi
105 +
106 +if test "x${enable_poison_system_directories}" = "xyes"; then
107  
108 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
109 +
110 +fi
111  
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
118 @@ -87,6 +87,16 @@
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 Index: b/ld/ldfile.c
136 ===================================================================
137 --- a/ld/ldfile.c
138 +++ b/ld/ldfile.c
139 @@ -116,6 +116,23 @@
140      new_dirs->name = concat (ld_sysroot, name + 1, (const char *) NULL);
141    else
142      new_dirs->name = xstrdup (name);
143 +
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))))
150 +   {
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);
154 +     else
155 +       einfo (_("%P: warning: library search path \"%s\" is unsafe for "
156 +            "cross-compilation\n"), name);
157 +   }
158 +#endif
159 +
160  }
161  
162  /* Try to open a BFD for a lang_input_statement.  */
163 Index: b/ld/ld.h
164 ===================================================================
165 --- a/ld/ld.h
166 +++ b/ld/ld.h
167 @@ -180,6 +180,14 @@
168    /* If TRUE we'll just print the default output on stdout.  */
169    bfd_boolean print_output_format;
170  
171 +  /* If TRUE (the default) warn for uses of system directories when
172 +     cross linking.  */
173 +  bfd_boolean poison_system_directories;
174 +
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;
178 +
179    /* Big or little endian as set on command line.  */
180    enum endian_enum endian;
181  
182 Index: b/ld/ldmain.c
183 ===================================================================
184 --- a/ld/ldmain.c
185 +++ b/ld/ldmain.c
186 @@ -266,6 +266,8 @@
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;
192  
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 ===================================================================
197 --- a/ld/ld.texinfo
198 +++ b/ld/ld.texinfo
199 @@ -2175,6 +2175,18 @@
200  
201  Passing @code{none} for @var{style} disables the setting from any
202  @code{--build-id} options earlier on the command line.
203 +
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.
210 +
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.
215  @end table
216  
217  @c man end
218 Index: b/ld/lexsup.c
219 ===================================================================
220 --- a/ld/lexsup.c
221 +++ b/ld/lexsup.c
222 @@ -507,6 +507,14 @@
223      OPTION_IGNORE_UNRESOLVED_SYMBOL},
224      '\0', N_("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"),
229 +    TWO_DASHES },
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"),
233 +    TWO_DASHES },
234  };
235  
236  #define OPTION_COUNT ARRAY_SIZE (ld_options)
237 @@ -519,6 +527,7 @@
238    int ingroup = 0;
239    char *default_dirlist = NULL;
240    char *shortopts;
241 +  char *BR_paranoid_env;
242    struct option *longopts;
243    struct option *really_longopts;
244    int last_optind;
245 @@ -1442,9 +1451,21 @@
246                einfo (_("%P%X: --hash-size needs a numeric argument\n"));
247            }
248            break;
249 +
250 +   case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
251 +     command_line.poison_system_directories = FALSE;
252 +     break;
253 +
254 +   case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
255 +     command_line.error_poison_system_directories = TRUE;
256 +     break;
257         }
258      }
259  
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;
263 +
264    while (ingroup)
265      {
266        lang_leave_group ();
267 Index: b/ld/ldlex.h
268 ===================================================================
269 --- a/ld/ldlex.h
270 +++ b/ld/ldlex.h
271 @@ -138,6 +138,8 @@
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,
277  };
278  
279  /* The initial parser states.  */