changelog: mention hippotat
[secnet] / ac_prog_cc_no_writeable_strings.m4
CommitLineData
3b83c932
SE
1dnl @synopsis AC_PROG_CC_NO_WRITEABLE_STRINGS(substvar [,hard])
2dnl
3dnl Try to find a compiler option that warns when a stringliteral is
4dnl used in a place that could potentially modify the address. This
5dnl should warn on giving an stringliteral to a function that asks of
6dnl a non-const-modified char-pointer.
7dnl
8dnl The sanity check is done by looking at string.h which has a set
9dnl of strcpy definitions that should be defined with const-modifiers
10dnl to not emit a warning in all so many places.
11dnl
12dnl Currently this macro knows about GCC.
13dnl hopefully will evolve to use: Solaris C compiler,
14dnl Digital Unix C compiler, C for AIX Compiler, HP-UX C compiler,
15dnl and IRIX C compiler.
16dnl
17dnl @version $Id: ac_prog_cc_no_writeable_strings.m4,v 1.1 2002/02/20 16:18:18 steve Exp $
18dnl @author Guido Draheim <guidod@gmx.de>
c215a4bc
IJ
19
20dnl [This appears to be a previous version of
21dnl ax_cflags_no_writable_strings.m4 which is nowadays to be found in
22dnl the Autoconf Archive. It was imported there on 2007-02-14
23dnl in commit 16aee45643e593e2833e4dff19df7b5f14267a79 where the file
24dnl has a GPLv2 permission notice. Therefore I feel justified in
25dnl adding the copyright permission notice below: -iwj]
3b83c932 26dnl
c215a4bc
IJ
27dnl This file is Free Software. It has been copied into secnet.
28dnl
29dnl Copyright 2002 Guido Draheim
30dnl
31dnl You may redistribute secnet as a whole and/or modify it under the
32dnl terms of the GNU General Public License as published by the Free
33dnl Software Foundation; either version 3, or (at your option) any
34dnl later version.
35dnl
36dnl You may redistribute this file and/or modify it under the terms of
37dnl the GNU General Public License as published by the Free Software
38dnl Foundation; either version 2, or (at your option) any later
39dnl version.
40dnl
41dnl This software is distributed in the hope that it will be useful,
42dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
43dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44dnl GNU General Public License for more details.
45dnl
46dnl You should have received a copy of the GNU General Public License
47dnl along with this software; if not, see
48dnl https://www.gnu.org/licenses/gpl.html.
49
3b83c932
SE
50AC_DEFUN([AC_PROG_CC_NO_WRITEABLE_STRINGS], [
51 pushdef([CV],ac_cv_prog_cc_no_writeable_strings)dnl
52 hard=$2
53 if test -z "$hard"; then
54 msg="C to warn about writing to stringliterals"
55 else
56 msg="C to prohibit any write to stringliterals"
57 fi
58 AC_CACHE_CHECK($msg, CV, [
59 cat > conftest.c <<EOF
60#include <string.h>
61int main (void)
62{
63 char test[[16]];
64 if (strcpy (test, "test")) return 0;
65 return 1;
66}
67EOF
68 dnl GCC
69 if test "$GCC" = "yes";
70 then
71 if test -z "$hard"; then
72 CV="-Wwrite-strings"
73 else
74 CV="-fno-writable-strings -Wwrite-strings"
75 fi
76
77 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
78 CV="suppressed: string.h"
79 fi
80
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 &&
84 test -f conftest.o
85 then
86 # strings go into readonly segment
87 CV="-xstrconst"
88
89 rm conftest.o
90 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
91 CV="suppressed: string.h"
92 fi
93
94 dnl HP-UX C compiler
95 elif $CC > /dev/null 2>&1 &&
96 $CC -c +ESlit conftest.c > /dev/null 2>&1 &&
97 test -f conftest.o
98 then
99 # strings go into readonly segment
100 CV="+ESlit"
101
102 rm conftest.o
103 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
104 CV="suppressed: string.h"
105 fi
106
107 dnl Digital Unix C compiler
108 elif ! $CC > /dev/null 2>&1 &&
109 $CC -c -readonly_strings conftest.c > /dev/null 2>&1 &&
110 test -f conftest.o
111 then
112 # strings go into readonly segment
113 CV="-readonly_strings"
114
115 rm conftest.o
116 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
117 CV="suppressed: string.h"
118 fi
119
120 dnl C for AIX Compiler
121
122 dnl IRIX C 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.
127
128 fi
129 rm -f conftest.*
130 ])
131 if test -z "[$]$1" ; then
132 if test -n "$CV" ; then
133 case "$CV" in
134 suppressed*) $1="" ;; # known but suppressed
135 *) $1="$CV" ;;
136 esac
137 fi
138 fi
139 AC_SUBST($1)
140 popdef([CV])dnl
141])
142
143