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
6 Adapted to Buildroot and gcc arc-4.8-R3 by Thomas Petazzoni,
7 especially the addition of the BR_COMPILER_PARANOID_UNSAFE_PATH
10 Signed-off-by: Khem Raj <raj.khem@gmail.com>
11 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
13 Upstream-Status: Inappropriate [distribution: codesourcery]
15 gcc/Makefile.in | 2 +-
16 gcc/common.opt | 4 ++++
17 gcc/config.in | 6 ++++++
18 gcc/configure | 20 ++++++++++++++++++--
19 gcc/configure.ac | 10 ++++++++++
20 gcc/doc/invoke.texi | 9 +++++++++
22 gcc/incpath.c | 19 +++++++++++++++++++
23 8 files changed, 69 insertions(+), 3 deletions(-)
25 Index: b/gcc/common.opt
26 ===================================================================
30 Common Var(pedantic) Warning
31 Issue warnings needed for strict compliance to the standard
33 +Wpoison-system-directories
34 +Common Var(flag_poison_system_directories) Init(1) Warning
35 +Warn for -I and -L options using system directories if cross compiling
38 Common Var(warn_shadow) Warning
39 Warn when one local variable shadows another
40 Index: b/gcc/config.in
41 ===================================================================
48 +/* Define to warn for use of native system header directories */
49 +#ifndef USED_FOR_TARGET
50 +#undef ENABLE_POISON_SYSTEM_DIRECTORIES
54 /* Define if you want all operations on RTL (the basic data structure of the
55 optimizer and back end) to be checked for dynamic type safety at runtime.
56 This is quite expensive. */
57 Index: b/gcc/configure
58 ===================================================================
63 enable_maintainer_mode
64 enable_version_specific_runtime_libs
65 +enable_poison_system_directories
67 enable_libquadmath_support
68 with_linker_hash_style
70 --enable-version-specific-runtime-libs
71 specify that runtime libraries should be installed
72 in a compiler-specific directory
73 + --enable-poison-system-directories
74 + warn for use of native system header directories
75 --enable-plugin enable plugin support
76 --disable-libquadmath-support
77 disable libquadmath support for Fortran
78 @@ -27103,6 +27106,19 @@
82 +# Check whether --enable-poison-system-directories was given.
83 +if test "${enable_poison_system_directories+set}" = set; then :
84 + enableval=$enable_poison_system_directories;
86 + enable_poison_system_directories=no
89 +if test "x${enable_poison_system_directories}" = "xyes"; then
91 +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
95 # Substitute configuration variables
98 Index: b/gcc/configure.ac
99 ===================================================================
100 --- a/gcc/configure.ac
101 +++ b/gcc/configure.ac
102 @@ -5063,6 +5063,16 @@
103 [specify that runtime libraries should be
104 installed in a compiler-specific directory])])
106 +AC_ARG_ENABLE([poison-system-directories],
107 + AS_HELP_STRING([--enable-poison-system-directories],
108 + [warn for use of native system header directories]),,
109 + [enable_poison_system_directories=no])
110 +if test "x${enable_poison_system_directories}" = "xyes"; then
111 + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
113 + [Define to warn for use of native system header directories])
116 # Substitute configuration variables
119 Index: b/gcc/doc/invoke.texi
120 ===================================================================
121 --- a/gcc/doc/invoke.texi
122 +++ b/gcc/doc/invoke.texi
124 -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded @gol
125 -Wparentheses -Wpedantic-ms-format -Wno-pedantic-ms-format @gol
126 -Wpointer-arith -Wno-pointer-to-int-cast @gol
127 +-Wno-poison-system-directories @gol
128 -Wredundant-decls -Wno-return-local-addr @gol
129 -Wreturn-type -Wsequence-point -Wshadow @gol
130 -Wsign-compare -Wsign-conversion -Wsizeof-pointer-memaccess @gol
131 @@ -4025,6 +4026,14 @@
132 for most targets, it is made up of code and thus requires the stack
133 to be made executable in order for the program to work properly.
135 +@item -Wno-poison-system-directories
136 +@opindex Wno-poison-system-directories
137 +Do not warn for @option{-I} or @option{-L} options using system
138 +directories such as @file{/usr/include} when cross compiling. This
139 +option is intended for use in chroot environments when such
140 +directories contain the correct headers and libraries for the target
141 +system rather than the host.
144 @opindex Wfloat-equal
145 @opindex Wno-float-equal
147 ===================================================================
151 "%{fuse-ld=*:-fuse-ld=%*}\
152 %X %{o*} %{e*} %{N} %{n} %{r}\
153 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}}\
154 + %{Wno-poison-system-directories:--no-poison-system-directories}\
155 + %{Werror=poison-system-directories:--error-poison-system-directories}\
156 %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\
157 %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\
158 %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
159 @@ -3990,6 +3992,12 @@
160 gcc_assert (!compare_debug_opt);
163 + temp = getenv("BR_COMPILER_PARANOID_UNSAFE_PATH");
164 + if (temp && strlen(temp) > 0)
166 + save_switch("-Werror=poison-system-directories", 0, NULL, false, true);
169 /* Set up the search paths. We add directories that we expect to
170 contain GNU Toolchain components before directories specified by
171 the machine description so that we will find GNU components (like
172 Index: b/gcc/incpath.c
173 ===================================================================
179 #include "cppdefault.h"
180 +#include "diagnostic-core.h"
182 /* Microsoft Windows does not natively support inodes.
183 VMS has non-numeric inodes. */
186 fprintf (stderr, _("End of search list.\n"));
189 +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES
190 + if (flag_poison_system_directories)
194 + for (p = heads[QUOTE]; p; p = p->next)
196 + if ((!strncmp (p->name, "/usr/include", 12))
197 + || (!strncmp (p->name, "/usr/local/include", 18))
198 + || (!strncmp (p->name, "/usr/X11R6/include", 18)))
199 + warning (OPT_Wpoison_system_directories,
200 + "include location \"%s\" is unsafe for "
201 + "cross-compilation",
208 /* Use given -I paths for #include "..." but not #include <...>, and
209 Index: b/gcc/config/arc/arc.h
210 ===================================================================
211 --- a/gcc/config/arc/arc.h
212 +++ b/gcc/config/arc/arc.h
214 %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
215 %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\
216 %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\
217 + %{Wno-poison-system-directories:--no-poison-system-directories}\
218 + %{Werror=poison-system-directories:--error-poison-system-directories}\
219 %{static:} %{L*} %(mfwrap) %(link_libgcc) %o\
220 %{fopenmp:%:include(libgomp.spec)%(link_gomp)} %(mflib)\
221 %{fprofile-arcs|fprofile-generate|coverage:-lgcov}\