summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch')
-rw-r--r--meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch140
1 files changed, 83 insertions, 57 deletions
diff --git a/meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch b/meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch
index 30a8486016..492300047d 100644
--- a/meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch
+++ b/meta/recipes-devtools/gcc/gcc/0002-gcc-poison-system-directories.patch
@@ -1,6 +1,6 @@
1From 74cc21f474402cf3578e37e1d7a1a22bbd070f6a Mon Sep 17 00:00:00 2001 1From 52676b5934ba127c3af39fc484c8236c8fa60b96 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com> 2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 29 Mar 2013 08:59:00 +0400 3Date: Mon, 8 Mar 2021 16:04:20 -0800
4Subject: [PATCH] gcc: poison-system-directories 4Subject: [PATCH] gcc: poison-system-directories
5 5
6Add /sw/include and /opt/include based on the original 6Add /sw/include and /opt/include based on the original
@@ -11,25 +11,24 @@ aborted.
11Instead, we add the two missing items to the current scan. If the user 11Instead, we add the two missing items to the current scan. If the user
12wants this to be a failure, they can add "-Werror=poison-system-directories". 12wants this to be a failure, they can add "-Werror=poison-system-directories".
13 13
14Upstream-Status: Inappropriate [OE configuration]
14Signed-off-by: Mark Hatle <mark.hatle@windriver.com> 15Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
15Signed-off-by: Khem Raj <raj.khem@gmail.com> 16Signed-off-by: Khem Raj <raj.khem@gmail.com>
16
17Upstream-Status: Pending
18--- 17---
19 gcc/common.opt | 4 ++++ 18 gcc/common.opt | 4 ++++
20 gcc/config.in | 6 ++++++ 19 gcc/config.in | 10 ++++++++++
21 gcc/configure | 16 ++++++++++++++++ 20 gcc/configure | 19 +++++++++++++++++++
22 gcc/configure.ac | 10 ++++++++++ 21 gcc/configure.ac | 16 ++++++++++++++++
23 gcc/doc/invoke.texi | 9 +++++++++ 22 gcc/doc/invoke.texi | 9 +++++++++
24 gcc/gcc.c | 2 ++ 23 gcc/gcc.cc | 9 +++++++--
25 gcc/incpath.c | 21 +++++++++++++++++++++ 24 gcc/incpath.cc | 21 +++++++++++++++++++++
26 7 files changed, 68 insertions(+) 25 7 files changed, 86 insertions(+), 2 deletions(-)
27 26
28diff --git a/gcc/common.opt b/gcc/common.opt 27diff --git a/gcc/common.opt b/gcc/common.opt
29index 65a82410abc..415f38fa1f4 100644 28index 862c474d3c8..64c4277c991 100644
30--- a/gcc/common.opt 29--- a/gcc/common.opt
31+++ b/gcc/common.opt 30+++ b/gcc/common.opt
32@@ -682,6 +682,10 @@ Wreturn-local-addr 31@@ -711,6 +711,10 @@ Wreturn-local-addr
33 Common Var(warn_return_local_addr) Init(1) Warning 32 Common Var(warn_return_local_addr) Init(1) Warning
34 Warn about returning a pointer/reference to a local or temporary variable. 33 Warn about returning a pointer/reference to a local or temporary variable.
35 34
@@ -41,10 +40,10 @@ index 65a82410abc..415f38fa1f4 100644
41 Common Var(warn_shadow) Warning 40 Common Var(warn_shadow) Warning
42 Warn when one variable shadows another. Same as -Wshadow=global. 41 Warn when one variable shadows another. Same as -Wshadow=global.
43diff --git a/gcc/config.in b/gcc/config.in 42diff --git a/gcc/config.in b/gcc/config.in
44index 809e7b26823..5adeaeed36b 100644 43index 4cad077bfbe..80e832fdb84 100644
45--- a/gcc/config.in 44--- a/gcc/config.in
46+++ b/gcc/config.in 45+++ b/gcc/config.in
47@@ -224,6 +224,12 @@ 46@@ -236,6 +236,16 @@
48 #endif 47 #endif
49 48
50 49
@@ -52,24 +51,28 @@ index 809e7b26823..5adeaeed36b 100644
52+#ifndef USED_FOR_TARGET 51+#ifndef USED_FOR_TARGET
53+#undef ENABLE_POISON_SYSTEM_DIRECTORIES 52+#undef ENABLE_POISON_SYSTEM_DIRECTORIES
54+#endif 53+#endif
54+/* Define to warn for use of native system header directories */
55+#ifndef USED_FOR_TARGET
56+#undef POISON_BY_DEFAULT
57+#endif
55+ 58+
56+ 59+
57 /* Define if you want all operations on RTL (the basic data structure of the 60 /* 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. 61 optimizer and back end) to be checked for dynamic type safety at runtime.
59 This is quite expensive. */ 62 This is quite expensive. */
60diff --git a/gcc/configure b/gcc/configure 63diff --git a/gcc/configure b/gcc/configure
61index cd3d9516fce..8de766a942c 100755 64index c7b26d1927d..3508be7b439 100755
62--- a/gcc/configure 65--- a/gcc/configure
63+++ b/gcc/configure 66+++ b/gcc/configure
64@@ -1010,6 +1010,7 @@ with_system_zlib 67@@ -1026,6 +1026,7 @@ enable_maintainer_mode
65 enable_maintainer_mode
66 enable_link_mutex 68 enable_link_mutex
69 enable_link_serialization
67 enable_version_specific_runtime_libs 70 enable_version_specific_runtime_libs
68+enable_poison_system_directories 71+enable_poison_system_directories
69 enable_plugin 72 enable_plugin
70 enable_host_shared 73 enable_host_shared
71 enable_libquadmath_support 74 enable_libquadmath_support
72@@ -1766,6 +1767,8 @@ Optional Features: 75@@ -1788,6 +1789,8 @@ Optional Features:
73 --enable-version-specific-runtime-libs 76 --enable-version-specific-runtime-libs
74 specify that runtime libraries should be installed 77 specify that runtime libraries should be installed
75 in a compiler-specific directory 78 in a compiler-specific directory
@@ -78,7 +81,7 @@ index cd3d9516fce..8de766a942c 100755
78 --enable-plugin enable plugin support 81 --enable-plugin enable plugin support
79 --enable-host-shared build host code as shared libraries 82 --enable-host-shared build host code as shared libraries
80 --disable-libquadmath-support 83 --disable-libquadmath-support
81@@ -30235,6 +30238,19 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then : 84@@ -31753,6 +31756,22 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then :
82 fi 85 fi
83 86
84 87
@@ -89,9 +92,12 @@ index cd3d9516fce..8de766a942c 100755
89+ enable_poison_system_directories=no 92+ enable_poison_system_directories=no
90+fi 93+fi
91+ 94+
92+if test "x${enable_poison_system_directories}" = "xyes"; then 95+if test "x${enable_poison_system_directories}" != "xno"; then
93+ 96+
94+$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h 97+$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h
98+if test "$enable_poison_system_directories" = "error"; then
99+$as_echo "#define POISON_BY_DEFAULT 1" >>confdefs.h
100+fi
95+ 101+
96+fi 102+fi
97+ 103+
@@ -99,58 +105,64 @@ index cd3d9516fce..8de766a942c 100755
99 105
100 106
101diff --git a/gcc/configure.ac b/gcc/configure.ac 107diff --git a/gcc/configure.ac b/gcc/configure.ac
102index 0de3b4bf97b..8bfd6feb780 100644 108index 09082e8ccae..6cd01a8966b 100644
103--- a/gcc/configure.ac 109--- a/gcc/configure.ac
104+++ b/gcc/configure.ac 110+++ b/gcc/configure.ac
105@@ -6595,6 +6595,16 @@ AC_ARG_ENABLE(version-specific-runtime-libs, 111@@ -7292,6 +7292,22 @@ AC_ARG_ENABLE(version-specific-runtime-libs,
106 [specify that runtime libraries should be 112 [specify that runtime libraries should be
107 installed in a compiler-specific directory])]) 113 installed in a compiler-specific directory])])
108 114
109+AC_ARG_ENABLE([poison-system-directories], 115+AC_ARG_ENABLE([poison-system-directories],
110+ AS_HELP_STRING([--enable-poison-system-directories], 116+ AS_HELP_STRING([--enable-poison-system-directories],
111+ [warn for use of native system header directories]),, 117+ [warn for use of native system header directories (no/yes/error)]),,
112+ [enable_poison_system_directories=no]) 118+ [enable_poison_system_directories=no])
113+if test "x${enable_poison_system_directories}" = "xyes"; then 119+AC_MSG_NOTICE([poisoned directories $enable_poison_system_directories])
120+if test "x${enable_poison_system_directories}" != "xno"; then
121+ AC_MSG_NOTICE([poisoned directories enabled])
114+ AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES], 122+ AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES],
115+ [1], 123+ [1],
116+ [Define to warn for use of native system header directories]) 124+ [Define to warn for use of native system header directories])
125+ if test $enable_poison_system_directories = "error"; then
126+ AC_MSG_NOTICE([poisoned directories are fatal])
127+ AC_DEFINE([POISON_BY_DEFAULT], [1], [Define to make poison warnings errors])
128+ fi
117+fi 129+fi
118+ 130+
119 # Substitute configuration variables 131 # Substitute configuration variables
120 AC_SUBST(subdirs) 132 AC_SUBST(subdirs)
121 AC_SUBST(srcdir) 133 AC_SUBST(srcdir)
122diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi 134diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
123index f98161391a0..f12d8d12150 100644 135index de40f62e219..d6f203c8b71 100644
124--- a/gcc/doc/invoke.texi 136--- a/gcc/doc/invoke.texi
125+++ b/gcc/doc/invoke.texi 137+++ b/gcc/doc/invoke.texi
126@@ -348,6 +348,7 @@ Objective-C and Objective-C++ Dialects}. 138@@ -384,6 +384,7 @@ Objective-C and Objective-C++ Dialects}.
127 -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded @gol 139 -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded
128 -Wparentheses -Wno-pedantic-ms-format @gol 140 -Wparentheses -Wno-pedantic-ms-format
129 -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast @gol 141 -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast
130+-Wno-poison-system-directories @gol 142+-Wno-poison-system-directories
131 -Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls @gol 143 -Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls
132 -Wrestrict -Wno-return-local-addr -Wreturn-type @gol 144 -Wrestrict -Wno-return-local-addr -Wreturn-type
133 -Wno-scalar-storage-order -Wsequence-point @gol 145 -Wno-scalar-storage-order -Wsequence-point
134@@ -6924,6 +6925,14 @@ made up of data only and thus requires no special treatment. But, for 146@@ -8426,6 +8427,14 @@ made up of data only and thus requires no special treatment. But, for
135 most targets, it is made up of code and thus requires the stack to be 147 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. 148 made executable in order for the program to work properly.
137 149
138+@item -Wno-poison-system-directories
139+@opindex Wno-poison-system-directories 150+@opindex Wno-poison-system-directories
151+@item -Wno-poison-system-directories
140+Do not warn for @option{-I} or @option{-L} options using system 152+Do not warn for @option{-I} or @option{-L} options using system
141+directories such as @file{/usr/include} when cross compiling. This 153+directories such as @file{/usr/include} when cross compiling. This
142+option is intended for use in chroot environments when such 154+option is intended for use in chroot environments when such
143+directories contain the correct headers and libraries for the target 155+directories contain the correct headers and libraries for the target
144+system rather than the host. 156+system rather than the host.
145+ 157+
146 @item -Wfloat-equal
147 @opindex Wfloat-equal 158 @opindex Wfloat-equal
148 @opindex Wno-float-equal 159 @opindex Wno-float-equal
149diff --git a/gcc/gcc.c b/gcc/gcc.c 160 @item -Wfloat-equal
150index 9f790db0daf..b2200c5185a 100644 161diff --git a/gcc/gcc.cc b/gcc/gcc.cc
151--- a/gcc/gcc.c 162index 16bb07f2cdc..5feae021545 100644
152+++ b/gcc/gcc.c 163--- a/gcc/gcc.cc
153@@ -1041,6 +1041,8 @@ proper position among the other output files. */ 164+++ b/gcc/gcc.cc
165@@ -1146,6 +1146,8 @@ proper position among the other output files. */
154 "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ 166 "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \
155 "%X %{o*} %{e*} %{N} %{n} %{r}\ 167 "%X %{o*} %{e*} %{N} %{n} %{r}\
156 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ 168 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \
@@ -159,10 +171,24 @@ index 9f790db0daf..b2200c5185a 100644
159 %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ 171 %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \
160 VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ 172 VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \
161 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ 173 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\
162diff --git a/gcc/incpath.c b/gcc/incpath.c 174@@ -1241,8 +1243,11 @@ static const char *cpp_unique_options =
163index 8a2bda00f80..9098ab044ab 100644 175 static const char *cpp_options =
164--- a/gcc/incpath.c 176 "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\
165+++ b/gcc/incpath.c 177 %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\
178- %{!fno-working-directory:-fworking-directory}}} %{O*}\
179- %{undef} %{save-temps*:-fpch-preprocess}";
180+ %{!fno-working-directory:-fworking-directory}}} %{O*}"
181+#ifdef POISON_BY_DEFAULT
182+ " -Werror=poison-system-directories"
183+#endif
184+ " %{undef} %{save-temps*:-fpch-preprocess}";
185
186 /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al.
187
188diff --git a/gcc/incpath.cc b/gcc/incpath.cc
189index 4d44321183f..46c0d543205 100644
190--- a/gcc/incpath.cc
191+++ b/gcc/incpath.cc
166@@ -26,6 +26,7 @@ 192@@ -26,6 +26,7 @@
167 #include "intl.h" 193 #include "intl.h"
168 #include "incpath.h" 194 #include "incpath.h"
@@ -171,7 +197,7 @@ index 8a2bda00f80..9098ab044ab 100644
171 197
172 /* Microsoft Windows does not natively support inodes. 198 /* Microsoft Windows does not natively support inodes.
173 VMS has non-numeric inodes. */ 199 VMS has non-numeric inodes. */
174@@ -393,6 +394,26 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose) 200@@ -399,6 +400,26 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose)
175 } 201 }
176 fprintf (stderr, _("End of search list.\n")); 202 fprintf (stderr, _("End of search list.\n"));
177 } 203 }
@@ -182,17 +208,17 @@ index 8a2bda00f80..9098ab044ab 100644
182+ struct cpp_dir *p; 208+ struct cpp_dir *p;
183+ 209+
184+ for (p = heads[INC_QUOTE]; p; p = p->next) 210+ for (p = heads[INC_QUOTE]; p; p = p->next)
185+ { 211+ {
186+ if ((!strncmp (p->name, "/usr/include", 12)) 212+ if ((!strncmp (p->name, "/usr/include", 12))
187+ || (!strncmp (p->name, "/usr/local/include", 18)) 213+ || (!strncmp (p->name, "/usr/local/include", 18))
188+ || (!strncmp (p->name, "/usr/X11R6/include", 18)) 214+ || (!strncmp (p->name, "/usr/X11R6/include", 18))
189+ || (!strncmp (p->name, "/sw/include", 11)) 215+ || (!strncmp (p->name, "/sw/include", 11))
190+ || (!strncmp (p->name, "/opt/include", 12))) 216+ || (!strncmp (p->name, "/opt/include", 12)))
191+ warning (OPT_Wpoison_system_directories, 217+ warning (OPT_Wpoison_system_directories,
192+ "include location \"%s\" is unsafe for " 218+ "include location \"%s\" is unsafe for "
193+ "cross-compilation", 219+ "cross-compilation",
194+ p->name); 220+ p->name);
195+ } 221+ }
196+ } 222+ }
197+#endif 223+#endif
198 } 224 }