This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH-PING] libssp and FORTIFY_SOURCE


Hello all,

if the target libc does not provide __stack_chk_fail then libssp is
build and the library libssp or libssp_nonshared is added automatically
if stack smashing protector is used. libssp also provides FORTIFY_SOURCE
capabilities. But the include path is _not_ added automatically.

For example an application which uses a fixed buffer and strcpy:

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

does not fortify source because the string.h file of libssp isn't
included. To solve the problem the include path of libssp needs to be
added 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? At least it is not the same behavior
as with glibc where no extra include path has to be specified manually.

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
2008-11-10  Stefan Schulze Frielinghaus  <stefan@seekline.net>

	* configure.ac (LIBSSP_INCLUDE_DIR): Define LIBSSP_INCLUDE_DIR to
	represent the include path of libssp if libc does not provide
	__stack_chk_fail.
	* configure: Re-generated.
	* cppdefault.h (cpp_LIBSSP_INCLUDE_DIR, cpp_LIBSSP_INCLUDE_DIR_len):
	Declare and externalize new variables.
	* cppdefault.c (cpp_LIBSSP_INCLUDE_DIR, cpp_LIBSSP_INCLUDE_DIR_len):
	Initialize both variables.
	* Makefile.in (@LIBSSP_INCLUDE_DIR@): Add result of configure script
	to PREPROCESSOR_DEFINES.

Index: configure
===================================================================
--- configure	(revision 141731)
+++ configure	(working copy)
@@ -458,7 +458,7 @@
 # include <unistd.h>
 #endif"
 
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os target_noncanonical build_libsubdir build_subdir host_subdir target_subdir GENINSRC CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT GNATBIND ac_ct_GNATBIND GNATMAKE ac_ct_GNATMAKE NO_MINUS_C_MINUS_O OUTPUT_OPTION CPP EGREP loose_warn strict_warn warn_cflags nocommon_flag TREEBROWSER valgrind_path valgrind_path_defines valgrind_command coverage_flags enable_multilib enable_decimal_float enable_fixed_point enable_shared TARGET_SYSTEM_ROOT TARGET_SYSTEM_ROOT_DEFINE CROSS_SYSTEM_HEADER_DIR onestep PKGVERSION REPORT_BUGS_TO REPORT_BUGS_TEXI datarootdir docdir htmldir SET_MAKE AWK LN_S LN RANLIB ac_ct_RANLIB ranlib_flags INSTALL INSTALL_PROGRAM INSTALL_DATA make_compare_target have_mktemp_command MAKEINFO BUILD_INFO GENERATED_MANPAGES FLEX BISON NM AR COLLECT2_LIBS GNAT_LIBEXC LDEXP_LIB TARGET_GETGROUPS_T LIBICONV LTLIBICONV LIBICONV_DEP manext objext gthread_flags extra_modes_file extra_opt_files USE_NLS LIBINTL LIBINTL_DEP INCINTL XGETTEXT GMSGFMT POSUB CATALOGS DATADIRNAME INSTOBJEXT GENCAT CATOBJEXT CROSS ALL SYSTEM_HEADER_DIR inhibit_libc CC_FOR_BUILD BUILD_CFLAGS BUILD_LDFLAGS STMP_FIXINC STMP_FIXPROTO collect2 LIBTOOL SED FGREP GREP LD DUMPBIN ac_ct_DUMPBIN OBJDUMP ac_ct_OBJDUMP ac_ct_AR STRIP ac_ct_STRIP lt_ECHO DSYMUTIL ac_ct_DSYMUTIL NMEDIT ac_ct_NMEDIT LIPO ac_ct_LIPO OTOOL ac_ct_OTOOL OTOOL64 ac_ct_OTOOL64 objdir enable_fast_install gcc_cv_as ORIGINAL_AS_FOR_TARGET gcc_cv_ld ORIGINAL_LD_FOR_TARGET gcc_cv_nm ORIGINAL_NM_FOR_TARGET gcc_cv_objdump libgcc_visibility GGC zlibdir zlibinc MAINT gcc_tooldir dollar slibdir subdirs srcdir all_compilers all_gtfiles all_lang_makefrags all_lang_makefiles all_languages all_selected_languages build_exeext build_install_headers_dir build_xm_file_list build_xm_include_list build_xm_defines build_file_translate check_languages cpp_install_dir xmake_file tmake_file extra_gcc_objs extra_headers_list extra_objs extra_parts extra_passes extra_programs float_h_file gcc_config_arguments gcc_gxx_include_dir host_exeext host_xm_file_list host_xm_include_list host_xm_defines out_host_hook_obj install lang_opt_files lang_specs_files lang_tree_files local_prefix md_file objc_boehm_gc out_file out_object_file thread_file tm_file_list tm_include_list tm_defines tm_p_file_list tm_p_include_list xm_file_list xm_include_list xm_defines c_target_objs cxx_target_objs fortran_target_objs target_cpu_default GMPLIBS GMPINC PPLLIBS PPLINC CLOOGLIBS CLOOGINC LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os target_noncanonical build_libsubdir build_subdir host_subdir target_subdir GENINSRC CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT GNATBIND ac_ct_GNATBIND GNATMAKE ac_ct_GNATMAKE NO_MINUS_C_MINUS_O OUTPUT_OPTION CPP EGREP loose_warn strict_warn warn_cflags nocommon_flag TREEBROWSER valgrind_path valgrind_path_defines valgrind_command coverage_flags enable_multilib enable_decimal_float enable_fixed_point enable_shared TARGET_SYSTEM_ROOT TARGET_SYSTEM_ROOT_DEFINE CROSS_SYSTEM_HEADER_DIR onestep PKGVERSION REPORT_BUGS_TO REPORT_BUGS_TEXI datarootdir docdir htmldir SET_MAKE AWK LN_S LN RANLIB ac_ct_RANLIB ranlib_flags INSTALL INSTALL_PROGRAM INSTALL_DATA make_compare_target have_mktemp_command MAKEINFO BUILD_INFO GENERATED_MANPAGES FLEX BISON NM AR COLLECT2_LIBS GNAT_LIBEXC LDEXP_LIB TARGET_GETGROUPS_T LIBICONV LTLIBICONV LIBICONV_DEP manext objext gthread_flags extra_modes_file extra_opt_files USE_NLS LIBINTL LIBINTL_DEP INCINTL XGETTEXT GMSGFMT POSUB CATALOGS DATADIRNAME INSTOBJEXT GENCAT CATOBJEXT CROSS ALL SYSTEM_HEADER_DIR inhibit_libc CC_FOR_BUILD BUILD_CFLAGS BUILD_LDFLAGS STMP_FIXINC STMP_FIXPROTO collect2 LIBTOOL SED FGREP GREP LD DUMPBIN ac_ct_DUMPBIN OBJDUMP ac_ct_OBJDUMP ac_ct_AR STRIP ac_ct_STRIP lt_ECHO DSYMUTIL ac_ct_DSYMUTIL NMEDIT ac_ct_NMEDIT LIPO ac_ct_LIPO OTOOL ac_ct_OTOOL OTOOL64 ac_ct_OTOOL64 objdir enable_fast_install gcc_cv_as ORIGINAL_AS_FOR_TARGET gcc_cv_ld ORIGINAL_LD_FOR_TARGET gcc_cv_nm ORIGINAL_NM_FOR_TARGET gcc_cv_objdump libgcc_visibility LIBSSP_INCLUDE_DIR GGC zlibdir zlibinc MAINT gcc_tooldir dollar slibdir subdirs srcdir all_compilers all_gtfiles all_lang_makefrags all_lang_makefiles all_languages all_selected_languages build_exeext build_install_headers_dir build_xm_file_list build_xm_include_list build_xm_defines build_file_translate check_languages cpp_install_dir xmake_file tmake_file extra_gcc_objs extra_headers_list extra_objs extra_parts extra_passes extra_programs float_h_file gcc_config_arguments gcc_gxx_include_dir host_exeext host_xm_file_list host_xm_include_list host_xm_defines out_host_hook_obj install lang_opt_files lang_specs_files lang_tree_files local_prefix md_file objc_boehm_gc out_file out_object_file thread_file tm_file_list tm_include_list tm_defines tm_p_file_list tm_p_include_list xm_file_list xm_include_list xm_defines c_target_objs cxx_target_objs fortran_target_objs target_cpu_default GMPLIBS GMPINC PPLLIBS PPLINC CLOOGLIBS CLOOGINC LIBOBJS LTLIBOBJS'
 ac_subst_files='language_hooks'
 ac_pwd=`pwd`
 
@@ -24346,8 +24346,12 @@
 #define TARGET_LIBC_PROVIDES_SSP 1
 _ACEOF
 
+  LIBSSP_INCLUDE_DIR=""
+else
+  LIBSSP_INCLUDE_DIR="-DLIBSSP_INCLUDE_DIR=\\\"\$(libsubdir)/include/ssp\\\""
 fi
 
+
 # Check if TFmode long double should be used by default or not.
 # Some glibc targets used DFmode long double, but with glibc 2.4
 # and later they can use TFmode.
@@ -25553,6 +25557,7 @@
 s,@ORIGINAL_NM_FOR_TARGET@,$ORIGINAL_NM_FOR_TARGET,;t t
 s,@gcc_cv_objdump@,$gcc_cv_objdump,;t t
 s,@libgcc_visibility@,$libgcc_visibility,;t t
+s,@LIBSSP_INCLUDE_DIR@,$LIBSSP_INCLUDE_DIR,;t t
 s,@GGC@,$GGC,;t t
 s,@zlibdir@,$zlibdir,;t t
 s,@zlibinc@,$zlibinc,;t t
Index: configure.ac
===================================================================
--- configure.ac	(revision 141731)
+++ configure.ac	(working copy)
@@ -3540,7 +3540,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: cppdefault.c
===================================================================
--- cppdefault.c	(revision 141731)
+++ 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: cppdefault.h
===================================================================
--- cppdefault.h	(revision 141731)
+++ 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: Makefile.in
===================================================================
--- Makefile.in	(revision 141731)
+++ Makefile.in	(working copy)
@@ -3500,7 +3500,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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]