Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 7 | |
| 8 | Upstream-Status: Inappropriate [distribution: codesourcery] |
| 9 | --- |
| 10 | gcc/Makefile.in | 2 +- |
| 11 | gcc/common.opt | 4 ++++ |
| 12 | gcc/config.in | 6 ++++++ |
| 13 | gcc/configure | 20 ++++++++++++++++++-- |
| 14 | gcc/configure.ac | 10 ++++++++++ |
| 15 | gcc/doc/invoke.texi | 9 +++++++++ |
| 16 | gcc/gcc.c | 2 ++ |
| 17 | gcc/incpath.c | 19 +++++++++++++++++++ |
| 18 | 8 files changed, 69 insertions(+), 3 deletions(-) |
| 19 | |
| 20 | Index: gcc-4.8.4/gcc/Makefile.in |
| 21 | =================================================================== |
| 22 | --- gcc-4.8.4.orig/gcc/Makefile.in |
| 23 | +++ gcc-4.8.4/gcc/Makefile.in |
| 24 | @@ -2019,7 +2019,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYST |
| 25 | |
| 26 | incpath.o: incpath.c incpath.h $(CONFIG_H) $(SYSTEM_H) $(CPPLIB_H) \ |
| 27 | intl.h prefix.h coretypes.h $(TM_H) cppdefault.h $(TARGET_H) \ |
| 28 | - $(MACHMODE_H) |
| 29 | + $(MACHMODE_H) $(FLAGS_H) toplev.h |
| 30 | |
| 31 | CFLAGS-prefix.o += -DPREFIX=\"$(prefix)\" -DBASEVER=$(BASEVER_s) |
| 32 | prefix.o: prefix.c $(CONFIG_H) $(SYSTEM_H) coretypes.h prefix.h \ |
| 33 | Index: gcc-4.8.4/gcc/common.opt |
| 34 | =================================================================== |
| 35 | --- gcc-4.8.4.orig/gcc/common.opt |
| 36 | +++ gcc-4.8.4/gcc/common.opt |
| 37 | @@ -595,6 +595,10 @@ Wpedantic |
| 38 | Common Var(pedantic) Warning |
| 39 | Issue warnings needed for strict compliance to the standard |
| 40 | |
| 41 | +Wpoison-system-directories |
| 42 | +Common Var(flag_poison_system_directories) Init(1) Warning |
| 43 | +Warn for -I and -L options using system directories if cross compiling |
| 44 | + |
| 45 | Wshadow |
| 46 | Common Var(warn_shadow) Warning |
| 47 | Warn when one local variable shadows another |
| 48 | Index: gcc-4.8.4/gcc/config.in |
| 49 | =================================================================== |
| 50 | --- gcc-4.8.4.orig/gcc/config.in |
| 51 | +++ gcc-4.8.4/gcc/config.in |
| 52 | @@ -138,6 +138,12 @@ |
| 53 | #endif |
| 54 | |
| 55 | |
| 56 | +/* Define to warn for use of native system header directories */ |
| 57 | +#ifndef USED_FOR_TARGET |
| 58 | +#undef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 59 | +#endif |
| 60 | + |
| 61 | + |
| 62 | /* Define if you want all operations on RTL (the basic data structure of the |
| 63 | optimizer and back end) to be checked for dynamic type safety at runtime. |
| 64 | This is quite expensive. */ |
| 65 | Index: gcc-4.8.4/gcc/configure |
| 66 | =================================================================== |
| 67 | --- gcc-4.8.4.orig/gcc/configure |
| 68 | +++ gcc-4.8.4/gcc/configure |
| 69 | @@ -918,6 +918,7 @@ with_gc |
| 70 | with_system_zlib |
| 71 | enable_maintainer_mode |
| 72 | enable_version_specific_runtime_libs |
| 73 | +enable_poison_system_directories |
| 74 | enable_plugin |
| 75 | enable_libquadmath_support |
| 76 | with_linker_hash_style |
| 77 | @@ -1639,6 +1640,8 @@ Optional Features: |
| 78 | --enable-version-specific-runtime-libs |
| 79 | specify that runtime libraries should be installed |
| 80 | in a compiler-specific directory |
| 81 | + --enable-poison-system-directories |
| 82 | + warn for use of native system header directories |
| 83 | --enable-plugin enable plugin support |
| 84 | --disable-libquadmath-support |
| 85 | disable libquadmath support for Fortran |
| 86 | @@ -17847,7 +17850,7 @@ else |
| 87 | lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 |
| 88 | lt_status=$lt_dlunknown |
| 89 | cat > conftest.$ac_ext <<_LT_EOF |
| 90 | -#line 17850 "configure" |
| 91 | +#line 17853 "configure" |
| 92 | #include "confdefs.h" |
| 93 | |
| 94 | #if HAVE_DLFCN_H |
| 95 | @@ -17953,7 +17956,7 @@ else |
| 96 | lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 |
| 97 | lt_status=$lt_dlunknown |
| 98 | cat > conftest.$ac_ext <<_LT_EOF |
| 99 | -#line 17956 "configure" |
| 100 | +#line 17959 "configure" |
| 101 | #include "confdefs.h" |
| 102 | |
| 103 | #if HAVE_DLFCN_H |
| 104 | @@ -27219,6 +27222,19 @@ if test "${enable_version_specific_runti |
| 105 | fi |
| 106 | |
| 107 | |
| 108 | +# Check whether --enable-poison-system-directories was given. |
| 109 | +if test "${enable_poison_system_directories+set}" = set; then : |
| 110 | + enableval=$enable_poison_system_directories; |
| 111 | +else |
| 112 | + enable_poison_system_directories=no |
| 113 | +fi |
| 114 | + |
| 115 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 116 | + |
| 117 | +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h |
| 118 | + |
| 119 | +fi |
| 120 | + |
| 121 | # Substitute configuration variables |
| 122 | |
| 123 | |
| 124 | Index: gcc-4.8.4/gcc/configure.ac |
| 125 | =================================================================== |
| 126 | --- gcc-4.8.4.orig/gcc/configure.ac |
| 127 | +++ gcc-4.8.4/gcc/configure.ac |
| 128 | @@ -5120,6 +5120,16 @@ AC_ARG_ENABLE(version-specific-runtime-l |
| 129 | [specify that runtime libraries should be |
| 130 | installed in a compiler-specific directory])]) |
| 131 | |
| 132 | +AC_ARG_ENABLE([poison-system-directories], |
| 133 | + AS_HELP_STRING([--enable-poison-system-directories], |
| 134 | + [warn for use of native system header directories]),, |
| 135 | + [enable_poison_system_directories=no]) |
| 136 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 137 | + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES], |
| 138 | + [1], |
| 139 | + [Define to warn for use of native system header directories]) |
| 140 | +fi |
| 141 | + |
| 142 | # Substitute configuration variables |
| 143 | AC_SUBST(subdirs) |
| 144 | AC_SUBST(srcdir) |
| 145 | Index: gcc-4.8.4/gcc/doc/invoke.texi |
| 146 | =================================================================== |
| 147 | --- gcc-4.8.4.orig/gcc/doc/invoke.texi |
| 148 | +++ gcc-4.8.4/gcc/doc/invoke.texi |
| 149 | @@ -258,6 +258,7 @@ Objective-C and Objective-C++ Dialects}. |
| 150 | -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded @gol |
| 151 | -Wparentheses -Wpedantic-ms-format -Wno-pedantic-ms-format @gol |
| 152 | -Wpointer-arith -Wno-pointer-to-int-cast @gol |
| 153 | +-Wno-poison-system-directories @gol |
| 154 | -Wredundant-decls -Wno-return-local-addr @gol |
| 155 | -Wreturn-type -Wsequence-point -Wshadow @gol |
| 156 | -Wsign-compare -Wsign-conversion -Wsizeof-pointer-memaccess @gol |
| 157 | @@ -4022,6 +4023,14 @@ headers---for that, @option{-Wunknown-pr |
| 158 | for most targets, it is made up of code and thus requires the stack |
| 159 | to be made executable in order for the program to work properly. |
| 160 | |
| 161 | +@item -Wno-poison-system-directories |
| 162 | +@opindex Wno-poison-system-directories |
| 163 | +Do not warn for @option{-I} or @option{-L} options using system |
| 164 | +directories such as @file{/usr/include} when cross compiling. This |
| 165 | +option is intended for use in chroot environments when such |
| 166 | +directories contain the correct headers and libraries for the target |
| 167 | +system rather than the host. |
| 168 | + |
| 169 | @item -Wfloat-equal |
| 170 | @opindex Wfloat-equal |
| 171 | @opindex Wno-float-equal |
| 172 | Index: gcc-4.8.4/gcc/gcc.c |
| 173 | =================================================================== |
| 174 | --- gcc-4.8.4.orig/gcc/gcc.c |
| 175 | +++ gcc-4.8.4/gcc/gcc.c |
| 176 | @@ -741,6 +741,8 @@ proper position among the other output f |
| 177 | "%{fuse-ld=*:-fuse-ld=%*}\ |
| 178 | %X %{o*} %{e*} %{N} %{n} %{r}\ |
| 179 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}}\ |
| 180 | + %{Wno-poison-system-directories:--no-poison-system-directories}\ |
| 181 | + %{Werror=poison-system-directories:--error-poison-system-directories}\ |
| 182 | %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\ |
| 183 | %{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\ |
| 184 | %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ |
| 185 | Index: gcc-4.8.4/gcc/incpath.c |
| 186 | =================================================================== |
| 187 | --- gcc-4.8.4.orig/gcc/incpath.c |
| 188 | +++ gcc-4.8.4/gcc/incpath.c |
| 189 | @@ -28,6 +28,7 @@ |
| 190 | #include "intl.h" |
| 191 | #include "incpath.h" |
| 192 | #include "cppdefault.h" |
| 193 | +#include "diagnostic-core.h" |
| 194 | |
| 195 | /* Microsoft Windows does not natively support inodes. |
| 196 | VMS has non-numeric inodes. */ |
| 197 | @@ -382,6 +383,24 @@ merge_include_chains (const char *sysroo |
| 198 | } |
| 199 | fprintf (stderr, _("End of search list.\n")); |
| 200 | } |
| 201 | + |
| 202 | +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 203 | + if (flag_poison_system_directories) |
| 204 | + { |
| 205 | + struct cpp_dir *p; |
| 206 | + |
| 207 | + for (p = heads[QUOTE]; p; p = p->next) |
| 208 | + { |
| 209 | + if ((!strncmp (p->name, "/usr/include", 12)) |
| 210 | + || (!strncmp (p->name, "/usr/local/include", 18)) |
| 211 | + || (!strncmp (p->name, "/usr/X11R6/include", 18))) |
| 212 | + warning (OPT_Wpoison_system_directories, |
| 213 | + "include location \"%s\" is unsafe for " |
| 214 | + "cross-compilation", |
| 215 | + p->name); |
| 216 | + } |
| 217 | + } |
| 218 | +#endif |
| 219 | } |
| 220 | |
| 221 | /* Use given -I paths for #include "..." but not #include <...>, and |