public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libssp, fortify and TARGET_LIBC_PROVIDES_SSP
@ 2008-10-20 17:16 Stefan Schulze Frielinghaus
  0 siblings, 0 replies; only message in thread
From: Stefan Schulze Frielinghaus @ 2008-10-20 17:16 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 684 bytes --]

Hello,

If e.g. newlib is used TARGET_LIBC_PROVIDES_SSP expands to false.
Therefore, libssp is used. But the include path of libssp isn't added
automatically:

gcc -fstack-protector -O2 -D_FORTIFY_SOURCE=2 -v test.c

does not fortify source code. Only if the include path is specified
manually:

gcc -fstack-protector -O2 -D_FORTIFY_SOURCE=2 -v
-I$PREFIX/lib/gcc/spu/4.4.0/include/ssp test.c

Is there any reason why we don't include libssp path by default if libc
does not provide SSP functionality?

If not the attached patch might solve the problem. Tested against i386
where no libssp is needed (GLIBC 2.5) and a system with newlib 1.15
where libssp is mandatory.

cheers,
Stefan

[-- Attachment #2: fortify.patch --]
[-- Type: text/x-patch, Size: 2547 bytes --]

Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 141105)
+++ gcc/configure.ac	(working copy)
@@ -3515,7 +3515,11 @@
 if test x$gcc_cv_libc_provides_ssp = xyes; then
   AC_DEFINE(TARGET_LIBC_PROVIDES_SSP, 1,
 	    [Define if your target C library provides stack protector support])
+  LIBSSP_INCLUDE_DIR=""
+else
+  LIBSSP_INCLUDE_DIR="-DLIBSSP_INCLUDE_DIR=\\\"\$(libsubdir)/include/ssp\\\""
 fi
+AC_SUBST(LIBSSP_INCLUDE_DIR)
 
 # Check if TFmode long double should be used by default or not.
 # Some glibc targets used DFmode long double, but with glibc 2.4
Index: gcc/cppdefault.c
===================================================================
--- gcc/cppdefault.c	(revision 141105)
+++ gcc/cppdefault.c	(working copy)
@@ -46,6 +46,9 @@
 = INCLUDE_DEFAULTS;
 #else
 = {
+#ifdef LIBSSP_INCLUDE_DIR 
+    { LIBSSP_INCLUDE_DIR, "GCC", 0, 0, 0, 0 },
+#endif
 #ifdef GPLUSPLUS_INCLUDE_DIR
     /* Pick up GNU C++ generic include files.  */
     { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, 0, 0 },
@@ -109,6 +112,14 @@
 const size_t cpp_GCC_INCLUDE_DIR_len = 0;
 #endif
 
+#ifdef LIBSSP_INCLUDE_DIR
+const char cpp_LIBSSP_INCLUDE_DIR[] = LIBSSP_INCLUDE_DIR;
+const size_t cpp_LIBSSP_INCLUDE_DIR_len = sizeof LIBSSP_INCLUDE_DIR - 1;
+#else
+const char cpp_LIBSSP_INCLUDE_DIR[] = "";
+const size_t cpp_LIBSSP_INCLUDE_DIR_len = 0;
+#endif
+
 /* The configured prefix.  */
 const char cpp_PREFIX[] = PREFIX;
 const size_t cpp_PREFIX_len = sizeof PREFIX - 1;
Index: gcc/cppdefault.h
===================================================================
--- gcc/cppdefault.h	(revision 141105)
+++ gcc/cppdefault.h	(working copy)
@@ -51,6 +51,8 @@
 extern const struct default_include cpp_include_defaults[];
 extern const char cpp_GCC_INCLUDE_DIR[];
 extern const size_t cpp_GCC_INCLUDE_DIR_len;
+extern const char cpp_LIBSSP_INCLUDE_DIR[];
+extern const size_t cpp_LIBSSP_INCLUDE_DIR_len;
 
 /* The configure-time prefix, i.e., the value supplied as the argument
    to --prefix=.  */
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 141105)
+++ gcc/Makefile.in	(working copy)
@@ -3483,7 +3483,8 @@
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
   -DPREFIX=\"$(prefix)/\" \
   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
-  @TARGET_SYSTEM_ROOT_DEFINE@
+  @TARGET_SYSTEM_ROOT_DEFINE@ \
+  @LIBSSP_INCLUDE_DIR@
 
 cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
 	cppdefault.h Makefile

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-10-20 14:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-20 17:16 [PATCH] libssp, fortify and TARGET_LIBC_PROVIDES_SSP Stefan Schulze Frielinghaus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).