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 is an older version of ax_cflags_no_writable_strings.m4
21 dnl which is nowadays to be found in the Autoconf Archive. Nowadays,
22 dnl this file has this permission notice there::
24 dnl Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
26 dnl This program is free software; you can redistribute it and/or modify it
27 dnl under the terms of the GNU General Public License as published by the
28 dnl Free Software Foundation; either version 3 of the License, or (at your
29 dnl option) any later version.
31 dnl This program is distributed in the hope that it will be useful, but
32 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
33 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
34 dnl Public License for more details.
36 dnl You should have received a copy of the GNU General Public License along
37 dnl with this program. If not, see <https://www.gnu.org/licenses/>.
39 dnl As a special exception, the respective Autoconf Macro's copyright owner
40 dnl gives unlimited permission to copy, distribute and modify the configure
41 dnl scripts that are the output of Autoconf when processing the Macro. You
42 dnl need not follow the terms of the GNU General Public License when using
43 dnl or distributing such scripts, even though portions of the text of the
44 dnl Macro appear in them. The GNU General Public License (GPL) does govern
45 dnl all other use of the material that constitutes the Autoconf Macro.
47 dnl This special exception to the GPL applies to versions of the Autoconf
48 dnl Macro released by the Autoconf Archive. When you make and distribute a
49 dnl modified version of the Autoconf Macro, you may extend this special
50 dnl exception to the GPL to apply to your modified version as well.
53 AC_DEFUN([AC_PROG_CC_NO_WRITEABLE_STRINGS], [
54 pushdef([CV],ac_cv_prog_cc_no_writeable_strings)dnl
56 if test -z "$hard"; then
57 msg="C to warn about writing to stringliterals"
59 msg="C to prohibit any write to stringliterals"
61 AC_CACHE_CHECK($msg, CV, [
62 cat > conftest.c <<EOF
67 if (strcpy (test, "test")) return 0;
72 if test "$GCC" = "yes";
74 if test -z "$hard"; then
77 CV="-fno-writable-strings -Wwrite-strings"
80 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
81 CV="suppressed: string.h"
84 dnl Solaris C compiler
85 elif $CC -flags 2>&1 | grep "Xc.*strict ANSI C" > /dev/null 2>&1 &&
86 $CC -c -xstrconst conftest.c > /dev/null 2>&1 &&
89 # strings go into readonly segment
93 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
94 CV="suppressed: string.h"
98 elif $CC > /dev/null 2>&1 &&
99 $CC -c +ESlit conftest.c > /dev/null 2>&1 &&
102 # strings go into readonly segment
106 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
107 CV="suppressed: string.h"
110 dnl Digital Unix C compiler
111 elif ! $CC > /dev/null 2>&1 &&
112 $CC -c -readonly_strings conftest.c > /dev/null 2>&1 &&
115 # strings go into readonly segment
116 CV="-readonly_strings"
119 if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then
120 CV="suppressed: string.h"
123 dnl C for AIX Compiler
126 # -use_readonly_const is the default for IRIX C,
127 # puts them into .rodata, but they are copied later.
128 # need to be "-G0 -rdatashared" for strictmode but
129 # I am not sure what effect that has really.
134 if test -z "[$]$1" ; then
135 if test -n "$CV" ; then
137 suppressed*) $1="" ;; # known but suppressed