Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame^] | 1 | From 7a90e62d557c78ae52006dff30c99006e10d9357 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 10/46] 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/common.opt | 4 ++++ |
| 11 | gcc/config.in | 6 ++++++ |
| 12 | gcc/configure | 16 ++++++++++++++++ |
| 13 | gcc/configure.ac | 10 ++++++++++ |
| 14 | gcc/doc/invoke.texi | 9 +++++++++ |
| 15 | gcc/gcc.c | 2 ++ |
| 16 | gcc/incpath.c | 19 +++++++++++++++++++ |
| 17 | 7 files changed, 66 insertions(+) |
| 18 | |
| 19 | diff --git a/gcc/common.opt b/gcc/common.opt |
| 20 | index 1218a71..bfba114 100644 |
| 21 | --- a/gcc/common.opt |
| 22 | +++ b/gcc/common.opt |
| 23 | @@ -623,6 +623,10 @@ Wreturn-local-addr |
| 24 | Common Var(warn_return_local_addr) Init(1) Warning |
| 25 | Warn about returning a pointer/reference to a local or temporary variable. |
| 26 | |
| 27 | +Wpoison-system-directories |
| 28 | +Common Var(flag_poison_system_directories) Init(1) Warning |
| 29 | +Warn for -I and -L options using system directories if cross compiling |
| 30 | + |
| 31 | Wshadow |
| 32 | Common Var(warn_shadow) Warning |
| 33 | Warn when one local variable shadows another |
| 34 | diff --git a/gcc/config.in b/gcc/config.in |
| 35 | index 5335258..f079826 100644 |
| 36 | --- a/gcc/config.in |
| 37 | +++ b/gcc/config.in |
| 38 | @@ -168,6 +168,12 @@ |
| 39 | #endif |
| 40 | |
| 41 | |
| 42 | +/* Define to warn for use of native system header directories */ |
| 43 | +#ifndef USED_FOR_TARGET |
| 44 | +#undef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 45 | +#endif |
| 46 | + |
| 47 | + |
| 48 | /* Define if you want all operations on RTL (the basic data structure of the |
| 49 | optimizer and back end) to be checked for dynamic type safety at runtime. |
| 50 | This is quite expensive. */ |
| 51 | diff --git a/gcc/configure b/gcc/configure |
| 52 | index 3c92795..34371a3 100755 |
| 53 | --- a/gcc/configure |
| 54 | +++ b/gcc/configure |
| 55 | @@ -933,6 +933,7 @@ with_system_zlib |
| 56 | enable_maintainer_mode |
| 57 | enable_link_mutex |
| 58 | enable_version_specific_runtime_libs |
| 59 | +enable_poison_system_directories |
| 60 | enable_plugin |
| 61 | enable_host_shared |
| 62 | enable_libquadmath_support |
| 63 | @@ -1670,6 +1671,8 @@ Optional Features: |
| 64 | --enable-version-specific-runtime-libs |
| 65 | specify that runtime libraries should be installed |
| 66 | in a compiler-specific directory |
| 67 | + --enable-poison-system-directories |
| 68 | + warn for use of native system header directories |
| 69 | --enable-plugin enable plugin support |
| 70 | --enable-host-shared build host code as shared libraries |
| 71 | --disable-libquadmath-support |
| 72 | @@ -28211,6 +28214,19 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then : |
| 73 | fi |
| 74 | |
| 75 | |
| 76 | +# Check whether --enable-poison-system-directories was given. |
| 77 | +if test "${enable_poison_system_directories+set}" = set; then : |
| 78 | + enableval=$enable_poison_system_directories; |
| 79 | +else |
| 80 | + enable_poison_system_directories=no |
| 81 | +fi |
| 82 | + |
| 83 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 84 | + |
| 85 | +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h |
| 86 | + |
| 87 | +fi |
| 88 | + |
| 89 | # Substitute configuration variables |
| 90 | |
| 91 | |
| 92 | diff --git a/gcc/configure.ac b/gcc/configure.ac |
| 93 | index d414081..240d322 100644 |
| 94 | --- a/gcc/configure.ac |
| 95 | +++ b/gcc/configure.ac |
| 96 | @@ -5654,6 +5654,16 @@ AC_ARG_ENABLE(version-specific-runtime-libs, |
| 97 | [specify that runtime libraries should be |
| 98 | installed in a compiler-specific directory])]) |
| 99 | |
| 100 | +AC_ARG_ENABLE([poison-system-directories], |
| 101 | + AS_HELP_STRING([--enable-poison-system-directories], |
| 102 | + [warn for use of native system header directories]),, |
| 103 | + [enable_poison_system_directories=no]) |
| 104 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 105 | + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES], |
| 106 | + [1], |
| 107 | + [Define to warn for use of native system header directories]) |
| 108 | +fi |
| 109 | + |
| 110 | # Substitute configuration variables |
| 111 | AC_SUBST(subdirs) |
| 112 | AC_SUBST(srcdir) |
| 113 | diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi |
| 114 | index d3be589..c81b55b 100644 |
| 115 | --- a/gcc/doc/invoke.texi |
| 116 | +++ b/gcc/doc/invoke.texi |
| 117 | @@ -269,6 +269,7 @@ Objective-C and Objective-C++ Dialects}. |
| 118 | -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded @gol |
| 119 | -Wparentheses -Wpedantic-ms-format -Wno-pedantic-ms-format @gol |
| 120 | -Wpointer-arith -Wno-pointer-to-int-cast @gol |
| 121 | +-Wno-poison-system-directories @gol |
| 122 | -Wredundant-decls -Wno-return-local-addr @gol |
| 123 | -Wreturn-type -Wsequence-point -Wshadow -Wno-shadow-ivar @gol |
| 124 | -Wshift-count-negative -Wshift-count-overflow @gol |
| 125 | @@ -4433,6 +4434,14 @@ made up of data only and thus requires no special treatment. But, for |
| 126 | most targets, it is made up of code and thus requires the stack to be |
| 127 | made executable in order for the program to work properly. |
| 128 | |
| 129 | +@item -Wno-poison-system-directories |
| 130 | +@opindex Wno-poison-system-directories |
| 131 | +Do not warn for @option{-I} or @option{-L} options using system |
| 132 | +directories such as @file{/usr/include} when cross compiling. This |
| 133 | +option is intended for use in chroot environments when such |
| 134 | +directories contain the correct headers and libraries for the target |
| 135 | +system rather than the host. |
| 136 | + |
| 137 | @item -Wfloat-equal |
| 138 | @opindex Wfloat-equal |
| 139 | @opindex Wno-float-equal |
| 140 | diff --git a/gcc/gcc.c b/gcc/gcc.c |
| 141 | index d956c36..675bcc1 100644 |
| 142 | --- a/gcc/gcc.c |
| 143 | +++ b/gcc/gcc.c |
| 144 | @@ -835,6 +835,8 @@ proper position among the other output files. */ |
| 145 | "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ |
| 146 | "%X %{o*} %{e*} %{N} %{n} %{r}\ |
| 147 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} " VTABLE_VERIFICATION_SPEC " \ |
| 148 | + %{Wno-poison-system-directories:--no-poison-system-directories}\ |
| 149 | + %{Werror=poison-system-directories:--error-poison-system-directories}\ |
| 150 | %{static:} %{L*} %(mfwrap) %(link_libgcc) " SANITIZER_EARLY_SPEC " %o\ |
| 151 | " CHKP_SPEC " \ |
| 152 | %{fopenacc|fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%(link_gomp)}\ |
| 153 | diff --git a/gcc/incpath.c b/gcc/incpath.c |
| 154 | index 6c54ca6..cc0c921 100644 |
| 155 | --- a/gcc/incpath.c |
| 156 | +++ b/gcc/incpath.c |
| 157 | @@ -28,6 +28,7 @@ |
| 158 | #include "intl.h" |
| 159 | #include "incpath.h" |
| 160 | #include "cppdefault.h" |
| 161 | +#include "diagnostic-core.h" |
| 162 | |
| 163 | /* Microsoft Windows does not natively support inodes. |
| 164 | VMS has non-numeric inodes. */ |
| 165 | @@ -383,6 +384,24 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose) |
| 166 | } |
| 167 | fprintf (stderr, _("End of search list.\n")); |
| 168 | } |
| 169 | + |
| 170 | +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 171 | + if (flag_poison_system_directories) |
| 172 | + { |
| 173 | + struct cpp_dir *p; |
| 174 | + |
| 175 | + for (p = heads[QUOTE]; p; p = p->next) |
| 176 | + { |
| 177 | + if ((!strncmp (p->name, "/usr/include", 12)) |
| 178 | + || (!strncmp (p->name, "/usr/local/include", 18)) |
| 179 | + || (!strncmp (p->name, "/usr/X11R6/include", 18))) |
| 180 | + warning (OPT_Wpoison_system_directories, |
| 181 | + "include location \"%s\" is unsafe for " |
| 182 | + "cross-compilation", |
| 183 | + p->name); |
| 184 | + } |
| 185 | + } |
| 186 | +#endif |
| 187 | } |
| 188 | |
| 189 | /* Use given -I paths for #include "..." but not #include <...>, and |
| 190 | -- |
| 191 | 2.6.3 |
| 192 | |