Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 1 | From 74cc21f474402cf3578e37e1d7a1a22bbd070f6a Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 29 Mar 2013 08:59:00 +0400 |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 4 | Subject: [PATCH] gcc: poison-system-directories |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | Add /sw/include and /opt/include based on the original |
| 7 | zecke-no-host-includes.patch patch. The original patch checked for |
| 8 | /usr/include, /sw/include and /opt/include and then triggered a failure and |
| 9 | aborted. |
| 10 | |
| 11 | Instead, we add the two missing items to the current scan. If the user |
| 12 | wants this to be a failure, they can add "-Werror=poison-system-directories". |
| 13 | |
| 14 | Signed-off-by: Mark Hatle <mark.hatle@windriver.com> |
| 15 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 16 | |
| 17 | Upstream-Status: Pending |
| 18 | --- |
| 19 | gcc/common.opt | 4 ++++ |
| 20 | gcc/config.in | 6 ++++++ |
| 21 | gcc/configure | 16 ++++++++++++++++ |
| 22 | gcc/configure.ac | 10 ++++++++++ |
| 23 | gcc/doc/invoke.texi | 9 +++++++++ |
| 24 | gcc/gcc.c | 2 ++ |
| 25 | gcc/incpath.c | 21 +++++++++++++++++++++ |
| 26 | 7 files changed, 68 insertions(+) |
| 27 | |
| 28 | diff --git a/gcc/common.opt b/gcc/common.opt |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 29 | index 65a82410abc..415f38fa1f4 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 30 | --- a/gcc/common.opt |
| 31 | +++ b/gcc/common.opt |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 32 | @@ -682,6 +682,10 @@ Wreturn-local-addr |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 33 | Common Var(warn_return_local_addr) Init(1) Warning |
| 34 | Warn about returning a pointer/reference to a local or temporary variable. |
| 35 | |
| 36 | +Wpoison-system-directories |
| 37 | +Common Var(flag_poison_system_directories) Init(1) Warning |
| 38 | +Warn for -I and -L options using system directories if cross compiling |
| 39 | + |
| 40 | Wshadow |
| 41 | Common Var(warn_shadow) Warning |
| 42 | Warn when one variable shadows another. Same as -Wshadow=global. |
| 43 | diff --git a/gcc/config.in b/gcc/config.in |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 44 | index 809e7b26823..5adeaeed36b 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | --- a/gcc/config.in |
| 46 | +++ b/gcc/config.in |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 47 | @@ -224,6 +224,12 @@ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 48 | #endif |
| 49 | |
| 50 | |
| 51 | +/* Define to warn for use of native system header directories */ |
| 52 | +#ifndef USED_FOR_TARGET |
| 53 | +#undef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 54 | +#endif |
| 55 | + |
| 56 | + |
| 57 | /* Define if you want all operations on RTL (the basic data structure of the |
| 58 | optimizer and back end) to be checked for dynamic type safety at runtime. |
| 59 | This is quite expensive. */ |
| 60 | diff --git a/gcc/configure b/gcc/configure |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 61 | index cd3d9516fce..8de766a942c 100755 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 62 | --- a/gcc/configure |
| 63 | +++ b/gcc/configure |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 64 | @@ -1010,6 +1010,7 @@ with_system_zlib |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 65 | enable_maintainer_mode |
| 66 | enable_link_mutex |
| 67 | enable_version_specific_runtime_libs |
| 68 | +enable_poison_system_directories |
| 69 | enable_plugin |
| 70 | enable_host_shared |
| 71 | enable_libquadmath_support |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 72 | @@ -1766,6 +1767,8 @@ Optional Features: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 73 | --enable-version-specific-runtime-libs |
| 74 | specify that runtime libraries should be installed |
| 75 | in a compiler-specific directory |
| 76 | + --enable-poison-system-directories |
| 77 | + warn for use of native system header directories |
| 78 | --enable-plugin enable plugin support |
| 79 | --enable-host-shared build host code as shared libraries |
| 80 | --disable-libquadmath-support |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 81 | @@ -30235,6 +30238,19 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then : |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 82 | fi |
| 83 | |
| 84 | |
| 85 | +# Check whether --enable-poison-system-directories was given. |
| 86 | +if test "${enable_poison_system_directories+set}" = set; then : |
| 87 | + enableval=$enable_poison_system_directories; |
| 88 | +else |
| 89 | + enable_poison_system_directories=no |
| 90 | +fi |
| 91 | + |
| 92 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 93 | + |
| 94 | +$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h |
| 95 | + |
| 96 | +fi |
| 97 | + |
| 98 | # Substitute configuration variables |
| 99 | |
| 100 | |
| 101 | diff --git a/gcc/configure.ac b/gcc/configure.ac |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 102 | index 0de3b4bf97b..8bfd6feb780 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 103 | --- a/gcc/configure.ac |
| 104 | +++ b/gcc/configure.ac |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 105 | @@ -6595,6 +6595,16 @@ AC_ARG_ENABLE(version-specific-runtime-libs, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 106 | [specify that runtime libraries should be |
| 107 | installed in a compiler-specific directory])]) |
| 108 | |
| 109 | +AC_ARG_ENABLE([poison-system-directories], |
| 110 | + AS_HELP_STRING([--enable-poison-system-directories], |
| 111 | + [warn for use of native system header directories]),, |
| 112 | + [enable_poison_system_directories=no]) |
| 113 | +if test "x${enable_poison_system_directories}" = "xyes"; then |
| 114 | + AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES], |
| 115 | + [1], |
| 116 | + [Define to warn for use of native system header directories]) |
| 117 | +fi |
| 118 | + |
| 119 | # Substitute configuration variables |
| 120 | AC_SUBST(subdirs) |
| 121 | AC_SUBST(srcdir) |
| 122 | diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 123 | index f98161391a0..f12d8d12150 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 124 | --- a/gcc/doc/invoke.texi |
| 125 | +++ b/gcc/doc/invoke.texi |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 126 | @@ -348,6 +348,7 @@ Objective-C and Objective-C++ Dialects}. |
| 127 | -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded @gol |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 128 | -Wparentheses -Wno-pedantic-ms-format @gol |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 129 | -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast @gol |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 130 | +-Wno-poison-system-directories @gol |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 131 | -Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls @gol |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 132 | -Wrestrict -Wno-return-local-addr -Wreturn-type @gol |
| 133 | -Wno-scalar-storage-order -Wsequence-point @gol |
| 134 | @@ -6924,6 +6925,14 @@ made up of data only and thus requires no special treatment. But, for |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 135 | most targets, it is made up of code and thus requires the stack to be |
| 136 | made executable in order for the program to work properly. |
| 137 | |
| 138 | +@item -Wno-poison-system-directories |
| 139 | +@opindex Wno-poison-system-directories |
| 140 | +Do not warn for @option{-I} or @option{-L} options using system |
| 141 | +directories such as @file{/usr/include} when cross compiling. This |
| 142 | +option is intended for use in chroot environments when such |
| 143 | +directories contain the correct headers and libraries for the target |
| 144 | +system rather than the host. |
| 145 | + |
| 146 | @item -Wfloat-equal |
| 147 | @opindex Wfloat-equal |
| 148 | @opindex Wno-float-equal |
| 149 | diff --git a/gcc/gcc.c b/gcc/gcc.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 150 | index 9f790db0daf..b2200c5185a 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 151 | --- a/gcc/gcc.c |
| 152 | +++ b/gcc/gcc.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 153 | @@ -1041,6 +1041,8 @@ proper position among the other output files. */ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 154 | "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ |
| 155 | "%X %{o*} %{e*} %{N} %{n} %{r}\ |
| 156 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ |
| 157 | + %{Wno-poison-system-directories:--no-poison-system-directories} \ |
| 158 | + %{Werror=poison-system-directories:--error-poison-system-directories} \ |
| 159 | %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ |
| 160 | VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ |
| 161 | %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ |
| 162 | diff --git a/gcc/incpath.c b/gcc/incpath.c |
Andrew Geissler | c182c62 | 2020-05-15 14:13:32 -0500 | [diff] [blame] | 163 | index 8a2bda00f80..9098ab044ab 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 164 | --- a/gcc/incpath.c |
| 165 | +++ b/gcc/incpath.c |
| 166 | @@ -26,6 +26,7 @@ |
| 167 | #include "intl.h" |
| 168 | #include "incpath.h" |
| 169 | #include "cppdefault.h" |
| 170 | +#include "diagnostic-core.h" |
| 171 | |
| 172 | /* Microsoft Windows does not natively support inodes. |
| 173 | VMS has non-numeric inodes. */ |
| 174 | @@ -393,6 +394,26 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose) |
| 175 | } |
| 176 | fprintf (stderr, _("End of search list.\n")); |
| 177 | } |
| 178 | + |
| 179 | +#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES |
| 180 | + if (flag_poison_system_directories) |
| 181 | + { |
| 182 | + struct cpp_dir *p; |
| 183 | + |
| 184 | + for (p = heads[INC_QUOTE]; p; p = p->next) |
| 185 | + { |
| 186 | + if ((!strncmp (p->name, "/usr/include", 12)) |
| 187 | + || (!strncmp (p->name, "/usr/local/include", 18)) |
| 188 | + || (!strncmp (p->name, "/usr/X11R6/include", 18)) |
| 189 | + || (!strncmp (p->name, "/sw/include", 11)) |
| 190 | + || (!strncmp (p->name, "/opt/include", 12))) |
| 191 | + warning (OPT_Wpoison_system_directories, |
| 192 | + "include location \"%s\" is unsafe for " |
| 193 | + "cross-compilation", |
| 194 | + p->name); |
| 195 | + } |
| 196 | + } |
| 197 | +#endif |
| 198 | } |
| 199 | |
| 200 | /* Use given -I paths for #include "..." but not #include <...>, and |