This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to "poison" bcmp/bzero/rindex
- To: gcc-patches at gcc dot gnu dot org
- Subject: Patch to "poison" bcmp/bzero/rindex
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Sun, 12 Nov 2000 17:37:52 -0500 (EST)
- Cc: jsm28 at cam dot ac dot uk, rth at redhat dot com
> From: Richard Henderson <rth@redhat.com>
>
> I wouldn't mind trying the poison and seeing how much trouble we get in.
> If there are problems on weird outlyers, we might be able to get away
> with limiting the poisoning to those hosts defining TARGET_MEM_FUNCTIONS.
> r~
Okay, voila. The following patch "poisons" the bcmp, bzero and rindex
identifiers in {t}system.h. I also included stubs for bcopy and index
if/when these can be poisoned too.
Right now, we still have a few bcopy uses laying around awaiting an
eyeball to see whether it needs memcpy or memmove. For index, this
token appears many times in contexts besides a function call.
E.g. `index' appears in the form of variable names and structure
members, etc. So I couldn't poison either at the moment.
The patch bootstraps on solaris2.7, but then dies after the 3-stage
compiling libio on the unrelated wchar_t issue many people have
reported.
Okay to install?
--Kaveh
2000-11-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* system.h (bzero, bcmp, rindex): Poison these identifiers.
* tsystem.h (bzero, bcmp, rindex): Likewise.
diff -rup ../egcs-CVS20001111/gcc/system.h egcs-CVS20001111/gcc/system.h
--- ../egcs-CVS20001111/gcc/system.h Thu Nov 9 10:17:55 2000
+++ egcs-CVS20001111/gcc/system.h Sat Nov 11 23:11:34 2000
@@ -597,4 +597,29 @@ extern void *alloca (__SIZE_TYPE__);
#endif /* ! __FUNCTION__ */
#endif
+/* Ensure we don't use the BSD style functions in our source code by
+ poisoning those tokens. Only do it if we don't see macros which
+ might possibly contain the forbidden functions. */
+#if GCC_VERSION >= 2097
+#ifndef memcpy
+/*#pragma GCC poison bcopy*/
+#endif
+
+#ifndef memset
+ #pragma GCC poison bzero
+#endif
+
+#ifndef memcmp
+ #pragma GCC poison bcmp
+#endif
+
+#ifndef strrchr
+ #pragma GCC poison rindex
+#endif
+
+#ifndef strchr
+/*#pragma GCC poison index*/
+#endif
+#endif /* GCC >= 2.97 */
+
#endif /* __GCC_SYSTEM_H__ */
diff -rup ../egcs-CVS20001111/gcc/tsystem.h egcs-CVS20001111/gcc/tsystem.h
--- ../egcs-CVS20001111/gcc/tsystem.h Tue Feb 1 16:24:43 2000
+++ egcs-CVS20001111/gcc/tsystem.h Sun Nov 12 13:07:33 2000
@@ -83,4 +83,27 @@ extern int errno;
#define NULL 0
#endif
+/* Ensure we don't use the BSD style functions in our source code by
+ poisoning those tokens. Only do it if we don't see macros which
+ might possibly contain the forbidden functions. */
+#ifndef memcpy
+/*#pragma GCC poison bcopy*/
+#endif
+
+#ifndef memset
+ #pragma GCC poison bzero
+#endif
+
+#ifndef memcmp
+ #pragma GCC poison bcmp
+#endif
+
+#ifndef strrchr
+ #pragma GCC poison rindex
+#endif
+
+#ifndef strchr
+/*#pragma GCC poison index*/
+#endif
+
#endif /* __GCC_TSYSTEM_H__ */