1 dnl @synopsis AC_PROG_CC_NO_WRITEABLE_STRINGS(substvar [,hard])
3 dnl Try to find a compiler option that warns when a stringliteral is
4 dnl used in a place that could potentially modify the address. This
5 dnl should warn on giving an stringliteral to a function that asks of
6 dnl a non-const-modified char-pointer.
8 dnl The sanity check is done by looking at string.h which has a set
9 dnl of strcpy definitions that should be defined with const-modifiers
10 dnl to not emit a warning in all so many places.
12 dnl Currently this macro knows about GCC.
13 dnl hopefully will evolve to use: Solaris C compiler,
14 dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler,
15 dnl and IRIX C compiler.
17 dnl @version $Id: ac_prog_cc_no_writeable_strings.m4,v 1.1 2002/02/20 16:18:18 steve Exp $
18 dnl @author Guido Draheim <guidod@gmx.de>
20 AC_DEFUN([AC_PROG_CC_NO_WRITEABLE_STRINGS], [
21 pushdef([CV],ac_cv_prog_cc_no_writeable_strings)dnl
23 if test -z "$hard"; then
24 msg="C to warn about writing to stringliterals"
26 msg="C to prohibit any write to stringliterals"
28 AC_CACHE_CHECK($msg, CV, [
29 cat > conftest.c <<EOF
34 if (strcpy (test, "test")) return 0;
39 if test "$GCC" = "yes";
41 if test -z "$hard"; then
44 CV="-fno-writable-strings -Wwrite-strings"
47 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
48 CV="suppressed: string.h"
51 dnl Solaris C compiler
52 elif $CC -flags 2>&1 | grep "Xc.*strict ANSI C" > /dev/null 2>&1 &&
53 $CC -c -xstrconst conftest.c > /dev/null 2>&1 &&
56 # strings go into readonly segment
60 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
61 CV="suppressed: string.h"
65 elif $CC > /dev/null 2>&1 &&
66 $CC -c +ESlit conftest.c > /dev/null 2>&1 &&
69 # strings go into readonly segment
73 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
74 CV="suppressed: string.h"
77 dnl Digital Unix C compiler
78 elif ! $CC > /dev/null 2>&1 &&
79 $CC -c -readonly_strings conftest.c > /dev/null 2>&1 &&
82 # strings go into readonly segment
83 CV="-readonly_strings"
86 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
87 CV="suppressed: string.h"
90 dnl C for AIX Compiler
93 # -use_readonly_const is the default for IRIX C,
94 # puts them into .rodata, but they are copied later.
95 # need to be "-G0 -rdatashared" for strictmode but
96 # I am not sure what effect that has really.
101 if test -z "[$]$1" ; then
102 if test -n "$CV" ; then
104 suppressed*) $1="" ;; # known but suppressed