From 61653dfb81b776bb72ce4304175b861d77c357a8 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Mon, 14 May 2012 15:42:52 -0700 Subject: [PATCH] BZ#10375: Configure magic to use -U_FORTIFY_SOURCE if needed. --- ChangeLog | 11 +++++++++++ Makeconfig | 3 ++- Makerules | 2 +- config.make.in | 1 + configure | 35 +++++++++++++++++++++++++++++++++++ configure.in | 16 ++++++++++++++++ time/ctime.c | 6 +----- 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 95a4055..cde0173 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-05-16 Roland McGrath + + [BZ #10375] + * configure.in: Check for _FORTIFY_SOURCE being predefined. + (CPPUNDEFS): New substituted variable; add -U_FORTIFY_SOURCE if needed. + * configure: Regenerated. + * config.make.in (CPPUNDEFS): New substituted variable. + * Makeconfig (CPPFLAGS): Put $(CPPUNDEFS) at the beginning. + * Makerules ($(stdio_lim:h=st)): Use $(CPPUNDEFS). + * time/ctime.c: Don't #undef __OPTIMIZE__ and ctime. + 2012-05-16 H.J. Lu * sysdeps/unix/sysv/linux/bits/mqueue.h: Include . diff --git a/Makeconfig b/Makeconfig index f68a752..b81594f 100644 --- a/Makeconfig +++ b/Makeconfig @@ -661,7 +661,8 @@ libio-include = -I$(..)libio # Note that we can't use -std=* in CPPFLAGS, because it overrides # the implicit -lang-asm and breaks cpp behavior for .S files--notably # it causes cpp to stop predefining __ASSEMBLER__. -CPPFLAGS = $(CPPFLAGS-config) $($(subdir)-CPPFLAGS) $(+includes) $(defines) \ +CPPFLAGS = $(CPPUNDEFS) $(CPPFLAGS-config) $($(subdir)-CPPFLAGS) \ + $(+includes) $(defines) \ -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \ $(CPPFLAGS-$(suffix $@)) \ $(foreach lib,$(libof-$(basename $(@F))) \ diff --git a/Makerules b/Makerules index f374700..528077a 100644 --- a/Makerules +++ b/Makerules @@ -1233,7 +1233,7 @@ $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \ echo '#define _LIBC 1'; \ echo '#include "$(..)misc/sys/uio.h"'; } | \ $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \ - $(+includes) -xc - -o $(@:st=hT) + $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT) sed $(sed-remove-objpfx) $(sed-remove-dotdot) \ $(@:st=dT) > $(@:st=dt) mv -f $(@:st=dt) $(@:st=d) diff --git a/config.make.in b/config.make.in index 6c4d04e..4fa2608 100644 --- a/config.make.in +++ b/config.make.in @@ -104,6 +104,7 @@ CXX = @CXX@ BUILD_CC = @BUILD_CC@ CFLAGS = @CFLAGS@ CPPFLAGS-config = @CPPFLAGS@ +CPPUNDEFS = @CPPUNDEFS@ ASFLAGS-config = @ASFLAGS_config@ AR = @AR@ MAKEINFO = @MAKEINFO@ diff --git a/configure b/configure index e664260..c295277 100755 --- a/configure +++ b/configure @@ -632,6 +632,7 @@ libc_cv_localedir libc_cv_slibdir old_glibc_headers libc_cv_gcc_unwind_find_fde +CPPUNDEFS sizeof_long_double EGREP GREP @@ -7542,6 +7543,40 @@ _ACEOF sizeof_long_double=$ac_cv_sizeof_long_double +CPPUNDEFS= +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _FORTIFY_SOURCE predefine" >&5 +$as_echo_n "checking for _FORTIFY_SOURCE predefine... " >&6; } +if ${libc_cv_predef_fortify_source+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifdef _FORTIFY_SOURCE +# error bogon +#endif + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + libc_cv_predef_fortify_source=no +else + libc_cv_predef_fortify_source=yes +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_predef_fortify_source" >&5 +$as_echo "$libc_cv_predef_fortify_source" >&6; } +if test $libc_cv_predef_fortify_source = yes; then + CPPUNDEFS="${CPPUNDEFS:+$CPPUNDEFS }-U_FORTIFY_SOURCE" +fi + + ### End of automated tests. ### Now run sysdeps configure fragments. diff --git a/configure.in b/configure.in index ce4b7ad..0916e9e 100644 --- a/configure.in +++ b/configure.in @@ -2036,6 +2036,22 @@ AC_CHECK_SIZEOF(long double, 0) sizeof_long_double=$ac_cv_sizeof_long_double AC_SUBST(sizeof_long_double) +CPPUNDEFS= +dnl Check for silly hacked compilers predefining _FORTIFY_SOURCE. +dnl Since we are building the implementations of the fortified functions here, +dnl having the macro defined interacts very badly. +AC_CACHE_CHECK([for _FORTIFY_SOURCE predefine], libc_cv_predef_fortify_source, +[AC_TRY_COMPILE([], [ +#ifdef _FORTIFY_SOURCE +# error bogon +#endif], + [libc_cv_predef_fortify_source=no], + [libc_cv_predef_fortify_source=yes])]) +if test $libc_cv_predef_fortify_source = yes; then + CPPUNDEFS="${CPPUNDEFS:+$CPPUNDEFS }-U_FORTIFY_SOURCE" +fi +AC_SUBST(CPPUNDEFS) + ### End of automated tests. ### Now run sysdeps configure fragments. diff --git a/time/ctime.c b/time/ctime.c index 28321af..ca2d3ea 100644 --- a/time/ctime.c +++ b/time/ctime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1996 Free Software Foundation, Inc. +/* Copyright (C) 1991-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -15,12 +15,8 @@ License along with the GNU C Library; if not, see . */ -#undef __OPTIMIZE__ /* Avoid inline `ctime' function. */ #include -#undef ctime - - /* Return a string as returned by asctime which is the representation of *T in that form. */ char * -- 2.7.4