This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
-fno-stack-protector (was: Building glibc from CVS on x86 UbuntuHardy)
Reuben Thomas <rrt@sc3d.org> wrote:
> On Fri, 2 May 2008, Ryan S. Arnold wrote:
> > Try it without the -fno-stack-protector too to see if that works.
>
> That doesn't work. Why not? I see it says "Checking for -fstack-protector"
> while configuring. Is it because the Ubuntu compiler switches this on by
> default and the libc configure doesn't know to turn it off?
That's exactly it. Ubuntu has some notes about this on
<https://wiki.ubuntu.com/GccSsp>.
By the way, I have some notes on issues like this on
<http://plash.beasts.org/wiki/GlibcBuildIssues> which may be useful to
people on this mailing list.
It would be useful if glibc knew how to turn gcc's stack-protector
option off. This patch should do the trick. If -fno-stack-protector
is available it adds it to CFLAGS:
--- configure.in 11 Apr 2008 17:52:55 -0000 1.475
+++ configure.in 5 May 2008 15:01:17 -0000
@@ -1633,6 +1633,24 @@
fi
AC_SUBST(fno_unit_at_a_time)
+AC_CACHE_CHECK(for -fno-stack-protector, libc_cv_fno_stack_protector, [dnl
+cat > conftest.c <<EOF
+int foo;
+main () { return 0;}
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fno-stack-protector
+ -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
+then
+ libc_cv_fno_stack_protector=yes
+else
+ libc_cv_fno_stack_protector=no
+fi
+rm -f conftest*])
+if test $libc_cv_fno_stack_protector = yes; then
+ CFLAGS="$CFLAGS -fno-stack-protector"
+fi
+AC_SUBST(libc_cv_fno_stack_protector)
+
AC_CACHE_CHECK(for -fstack-protector, libc_cv_ssp, [dnl
cat > conftest.c <<EOF
int foo;
A slightly cleverer approach might be to test whether gcc introduces
references to stack check functions when -fno-stack-protector is not
passed:
--- configure.in 11 Apr 2008 17:52:55 -0000 1.475
+++ configure.in 5 May 2008 15:25:04 -0000
@@ -1633,6 +1633,25 @@
fi
AC_SUBST(fno_unit_at_a_time)
+AC_CACHE_CHECK(whether -fno-stack-protector is needed, libc_cv_fno_stack_protector, [dnl
+cat > conftest.c <<EOF
+#include <string.h>
+void foo(char *str) { char buf@<:@100@:>@; strcpy(buf, str); }
+EOF
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS
+ -o conftest.o -c conftest.c 1>&AS_MESSAGE_LOG_FD]) &&
+ nm conftest.o | grep -q __stack_chk_fail
+then
+ libc_cv_fno_stack_protector=yes
+else
+ libc_cv_fno_stack_protector=no
+fi
+rm -f conftest*])
+if test $libc_cv_fno_stack_protector = yes; then
+ CFLAGS="$CFLAGS -fno-stack-protector"
+fi
+AC_SUBST(libc_cv_fno_stack_protector)
+
AC_CACHE_CHECK(for -fstack-protector, libc_cv_ssp, [dnl
cat > conftest.c <<EOF
int foo;
Regards,
Mark