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 dnl [This appears to be a previous version of
21 dnl ax_cflags_no_writable_strings.m4 which is nowadays to be found in
22 dnl the Autoconf Archive. It was imported there on 2007-02-14
23 dnl in commit 16aee45643e593e2833e4dff19df7b5f14267a79 where the file
24 dnl has a GPLv2 permission notice. Therefore I feel justified in
25 dnl adding the copyright permission notice below: -iwj]
27 dnl This file is Free Software. It has been copied into secnet.
29 dnl Copyright 2002 Guido Draheim
31 dnl You may redistribute secnet as a whole and/or modify it under the
32 dnl terms of the GNU General Public License as published by the Free
33 dnl Software Foundation; either version 3, or (at your option) any
36 dnl You may redistribute this file and/or modify it under the terms of
37 dnl the GNU General Public License as published by the Free Software
38 dnl Foundation; either version 2, or (at your option) any later
41 dnl This software is distributed in the hope that it will be useful,
42 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
43 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 dnl GNU General Public License for more details.
46 dnl You should have received a copy of the GNU General Public License
47 dnl along with this software; if not, see
48 dnl https://www.gnu.org/licenses/gpl.html.
50 AC_DEFUN([AC_PROG_CC_NO_WRITEABLE_STRINGS], [
51 pushdef([CV],ac_cv_prog_cc_no_writeable_strings)dnl
53 if test -z "$hard"; then
54 msg="C to warn about writing to stringliterals"
56 msg="C to prohibit any write to stringliterals"
58 AC_CACHE_CHECK($msg, CV, [
59 cat > conftest.c <<EOF
64 if (strcpy (test, "test")) return 0;
69 if test "$GCC" = "yes";
71 if test -z "$hard"; then
74 CV="-fno-writable-strings -Wwrite-strings"
77 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
78 CV="suppressed: string.h"
81 dnl Solaris C compiler
82 elif $CC -flags 2>&1 | grep "Xc.*strict ANSI C" > /dev/null 2>&1 &&
83 $CC -c -xstrconst conftest.c > /dev/null 2>&1 &&
86 # strings go into readonly segment
90 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
91 CV="suppressed: string.h"
95 elif $CC > /dev/null 2>&1 &&
96 $CC -c +ESlit conftest.c > /dev/null 2>&1 &&
99 # strings go into readonly segment
103 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
104 CV="suppressed: string.h"
107 dnl Digital Unix C compiler
108 elif ! $CC > /dev/null 2>&1 &&
109 $CC -c -readonly_strings conftest.c > /dev/null 2>&1 &&
112 # strings go into readonly segment
113 CV="-readonly_strings"
116 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
117 CV="suppressed: string.h"
120 dnl C for AIX Compiler
123 # -use_readonly_const is the default for IRIX C,
124 # puts them into .rodata, but they are copied later.
125 # need to be "-G0 -rdatashared" for strictmode but
126 # I am not sure what effect that has really.
131 if test -z "[$]$1" ; then
132 if test -n "$CV" ; then
134 suppressed*) $1="" ;; # known but suppressed