975f01fc72ebe0da776af9a153302b8a2ee667eb
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / gcc / 4.9.2 / 910-gcc-poison-system-directories.patch
1 From 160397ef3c3331099af028f1b8d3e085b07d88ad Mon Sep 17 00:00:00 2001
2 From: Khem Raj <raj.khem@gmail.com>
3 Date: Fri, 29 Mar 2013 08:59:00 +0400
4 Subject: [PATCH 16/35] gcc: poison-system-directories
5
6 Adapted to Buildroot and gcc 4.9.1 by Thomas Petazzoni, especially the
7 addition of the BR_COMPILER_PARANOID_UNSAFE_PATH environment variable.
8
9 Signed-off-by: Khem Raj <raj.khem@gmail.com>
10 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
11
12 Upstream-Status: Inappropriate [distribution: codesourcery]
13 ---
14  gcc/Makefile.in     |    2 +-
15  gcc/common.opt      |    4 ++++
16  gcc/config.in       |    6 ++++++
17  gcc/configure       |   20 ++++++++++++++++++--
18  gcc/configure.ac    |   10 ++++++++++
19  gcc/doc/invoke.texi |    9 +++++++++
20  gcc/gcc.c           |    2 ++
21  gcc/incpath.c       |   19 +++++++++++++++++++
22  8 files changed, 69 insertions(+), 3 deletions(-)
23
24 Index: b/gcc/common.opt
25 ===================================================================
26 --- a/gcc/common.opt
27 +++ b/gcc/common.opt
28 @@ -603,6 +603,10 @@
29  Common Var(pedantic) Warning
30  Issue warnings needed for strict compliance to the standard
31  
32 +Wpoison-system-directories
33 +Common Var(flag_poison_system_directories) Init(1) Warning
34 +Warn for -I and -L options using system directories if cross compiling
35 +
36  Wshadow
37  Common Var(warn_shadow) Warning
38  Warn when one local variable shadows another
39 Index: b/gcc/config.in
40 ===================================================================
41 --- a/gcc/config.in
42 +++ b/gcc/config.in
43 @@ -138,6 +138,12 @@
44  #endif
45  
46  
47 +/* Define to warn for use of native system header directories */
48 +#ifndef USED_FOR_TARGET
49 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
50 +#endif
51 +
52 +
53  /* Define if you want all operations on RTL (the basic data structure of the
54     optimizer and back end) to be checked for dynamic type safety at runtime.
55     This is quite expensive. */
56 Index: b/gcc/configure
57 ===================================================================
58 --- a/gcc/configure
59 +++ b/gcc/configure
60 @@ -929,6 +929,7 @@
61  enable_maintainer_mode
62  enable_link_mutex
63  enable_version_specific_runtime_libs
64 +enable_poison_system_directories
65  enable_plugin
66  enable_host_shared
67  enable_libquadmath_support
68 @@ -1657,6 +1658,8 @@
69    --enable-version-specific-runtime-libs
70                            specify that runtime libraries should be installed
71                            in a compiler-specific directory
72 +  --enable-poison-system-directories
73 +                          warn for use of native system header directories
74    --enable-plugin         enable plugin support
75    --enable-host-shared    build host code as shared libraries
76    --disable-libquadmath-support
77 @@ -27765,6 +27768,19 @@
78  fi
79  
80  
81 +# Check whether --enable-poison-system-directories was given.
82 +if test "${enable_poison_system_directories+set}" = set; then :
83 +  enableval=$enable_poison_system_directories;
84 +else
85 +  enable_poison_system_directories=no
86 +fi
87 +
88 +if test "x${enable_poison_system_directories}" = "xyes"; then
89 +
90 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
91 +
92 +fi
93 +
94  # Substitute configuration variables
95  
96  
97 Index: b/gcc/configure.ac
98 ===================================================================
99 --- a/gcc/configure.ac
100 +++ b/gcc/configure.ac
101 @@ -5411,6 +5411,16 @@
102                  [specify that runtime libraries should be
103                   installed in a compiler-specific directory])])
104  
105 +AC_ARG_ENABLE([poison-system-directories],
106 +             AS_HELP_STRING([--enable-poison-system-directories],
107 +                            [warn for use of native system header directories]),,
108 +             [enable_poison_system_directories=no])
109 +if test "x${enable_poison_system_directories}" = "xyes"; then
110 +  AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
111 +           [1],
112 +           [Define to warn for use of native system header directories])
113 +fi
114 +
115  # Substitute configuration variables
116  AC_SUBST(subdirs)
117  AC_SUBST(srcdir)
118 Index: b/gcc/doc/invoke.texi
119 ===================================================================
120 --- a/gcc/doc/invoke.texi
121 +++ b/gcc/doc/invoke.texi
122 @@ -260,6 +260,7 @@
123  -Woverlength-strings  -Wpacked  -Wpacked-bitfield-compat  -Wpadded @gol
124  -Wparentheses  -Wpedantic-ms-format -Wno-pedantic-ms-format @gol
125  -Wpointer-arith  -Wno-pointer-to-int-cast @gol
126 +-Wno-poison-system-directories @gol
127  -Wredundant-decls  -Wno-return-local-addr @gol
128  -Wreturn-type  -Wsequence-point  -Wshadow @gol
129  -Wsign-compare  -Wsign-conversion -Wfloat-conversion @gol
130 @@ -4209,6 +4210,14 @@
131   for most targets, it is made up of code and thus requires the stack
132   to be made executable in order for the program to work properly.
133  
134 +@item -Wno-poison-system-directories
135 +@opindex Wno-poison-system-directories
136 +Do not warn for @option{-I} or @option{-L} options using system
137 +directories such as @file{/usr/include} when cross compiling.  This
138 +option is intended for use in chroot environments when such
139 +directories contain the correct headers and libraries for the target
140 +system rather than the host.
141 +
142  @item -Wfloat-equal
143  @opindex Wfloat-equal
144  @opindex Wno-float-equal
145 Index: b/gcc/gcc.c
146 ===================================================================
147 --- a/gcc/gcc.c
148 +++ b/gcc/gcc.c
149 @@ -770,6 +770,8 @@
150     "%{fuse-ld=*:-fuse-ld=%*}\
151      %X %{o*} %{e*} %{N} %{n} %{r}\
152      %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} " VTABLE_VERIFICATION_SPEC " \
153 +    %{Wno-poison-system-directories:--no-poison-system-directories}\
154 +    %{Werror=poison-system-directories:--error-poison-system-directories}\
155      %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\
156      %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\
157      %{fcilkplus:%:include(libcilkrts.spec)%(link_cilkrts)}\
158 @@ -4034,6 +4036,12 @@
159        gcc_assert (!compare_debug_opt);
160      }
161  
162 +  temp = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH");
163 +  if (temp && strlen(temp) > 0)
164 +    {
165 +      save_switch("-Werror=poison-system-directories", 0, NULL, false, true);
166 +    }
167 +
168    /* Set up the search paths.  We add directories that we expect to
169       contain GNU Toolchain components before directories specified by
170       the machine description so that we will find GNU components (like
171 Index: b/gcc/incpath.c
172 ===================================================================
173 --- a/gcc/incpath.c
174 +++ b/gcc/incpath.c
175 @@ -28,6 +28,7 @@
176  #include "intl.h"
177  #include "incpath.h"
178  #include "cppdefault.h"
179 +#include "diagnostic-core.h"
180  
181  /* Microsoft Windows does not natively support inodes.
182     VMS has non-numeric inodes.  */
183 @@ -382,6 +383,24 @@
184         }
185        fprintf (stderr, _("End of search list.\n"));
186      }
187 +
188 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
189 +  if (flag_poison_system_directories)
190 +    {
191 +       struct cpp_dir *p;
192 +
193 +       for (p = heads[QUOTE]; p; p = p->next)
194 +         {
195 +          if ((!strncmp (p->name, "/usr/include", 12))
196 +              || (!strncmp (p->name, "/usr/local/include", 18))
197 +              || (!strncmp (p->name, "/usr/X11R6/include", 18)))
198 +            warning (OPT_Wpoison_system_directories,
199 +                     "include location \"%s\" is unsafe for "
200 +                     "cross-compilation",
201 +                     p->name);
202 +         }
203 +    }
204 +#endif
205  }
206  
207  /* Use given -I paths for #include "..." but not #include <...>, and