b9ff8bee4a393767c0c649029cada4c38afe6d85
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / binutils / 2.22 / 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 @@ -4,6 +4,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 @@ -773,6 +773,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 @@ -1427,6 +1428,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 @@ -4336,7 +4339,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 @@ -70,6 +70,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 @@ -126,6 +126,22 @@
140        new_dirs->name = xstrdup (name);
141        new_dirs->sysrooted = is_sysrooted_pathname (name, FALSE);
142      }
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  /* Try to open a BFD for a lang_input_statement.  */
162 Index: b/ld/ld.h
163 ===================================================================
164 --- a/ld/ld.h
165 +++ b/ld/ld.h
166 @@ -203,6 +203,14 @@
167    /* If TRUE we'll just print the default output on stdout.  */
168    bfd_boolean print_output_format;
169  
170 +  /* If TRUE (the default) warn for uses of system directories when
171 +     cross linking.  */
172 +  bfd_boolean poison_system_directories;
173 +
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;
177 +
178    /* Big or little endian as set on command line.  */
179    enum endian_enum endian;
180  
181 Index: b/ld/ldmain.c
182 ===================================================================
183 --- a/ld/ldmain.c
184 +++ b/ld/ldmain.c
185 @@ -259,6 +259,8 @@
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;
191  
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 ===================================================================
196 --- a/ld/ld.texinfo
197 +++ b/ld/ld.texinfo
198 @@ -2147,6 +2147,18 @@
199  
200  Passing @code{none} for @var{style} disables the setting from any
201  @code{--build-id} options earlier on the command line.
202 +
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.
209 +
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.
214  @end table
215  
216  @c man end
217 Index: b/ld/lexsup.c
218 ===================================================================
219 --- a/ld/lexsup.c
220 +++ b/ld/lexsup.c
221 @@ -176,6 +176,8 @@
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,
227  };
228  
229  /* The long options.  This structure is used for both the option
230 @@ -612,6 +614,14 @@
231      TWO_DASHES },
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"),
237 +    TWO_DASHES },
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"),
241 +    TWO_DASHES },
242  };
243  
244  #define OPTION_COUNT ARRAY_SIZE (ld_options)
245 @@ -624,6 +634,7 @@
246    int ingroup = 0;
247    char *default_dirlist = NULL;
248    char *shortopts;
249 +  char *BR_paranoid_env;
250    struct option *longopts;
251    struct option *really_longopts;
252    int last_optind;
253 @@ -1541,9 +1552,21 @@
254                einfo (_("%P%X: --hash-size needs a numeric argument\n"));
255            }
256            break;
257 +
258 +   case OPTION_NO_POISON_SYSTEM_DIRECTORIES:
259 +     command_line.poison_system_directories = FALSE;
260 +     break;
261 +
262 +   case OPTION_ERROR_POISON_SYSTEM_DIRECTORIES:
263 +     command_line.error_poison_system_directories = TRUE;
264 +     break;
265         }
266      }
267  
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;
271 +
272    while (ingroup)
273      {
274        lang_leave_group ();