Commit | Line | Data |
---|---|---|
3b83c932 SE |
1 | dnl @synopsis AC_PROG_CC_NO_WRITEABLE_STRINGS(substvar [,hard]) |
2 | dnl | |
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. | |
7 | dnl | |
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. | |
11 | dnl | |
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. | |
16 | dnl | |
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> | |
19 | dnl | |
20 | AC_DEFUN([AC_PROG_CC_NO_WRITEABLE_STRINGS], [ | |
21 | pushdef([CV],ac_cv_prog_cc_no_writeable_strings)dnl | |
22 | hard=$2 | |
23 | if test -z "$hard"; then | |
24 | msg="C to warn about writing to stringliterals" | |
25 | else | |
26 | msg="C to prohibit any write to stringliterals" | |
27 | fi | |
28 | AC_CACHE_CHECK($msg, CV, [ | |
29 | cat > conftest.c <<EOF | |
30 | #include <string.h> | |
31 | int main (void) | |
32 | { | |
33 | char test[[16]]; | |
34 | if (strcpy (test, "test")) return 0; | |
35 | return 1; | |
36 | } | |
37 | EOF | |
38 | dnl GCC | |
39 | if test "$GCC" = "yes"; | |
40 | then | |
41 | if test -z "$hard"; then | |
42 | CV="-Wwrite-strings" | |
43 | else | |
44 | CV="-fno-writable-strings -Wwrite-strings" | |
45 | fi | |
46 | ||
47 | if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then | |
48 | CV="suppressed: string.h" | |
49 | fi | |
50 | ||
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 && | |
54 | test -f conftest.o | |
55 | then | |
56 | # strings go into readonly segment | |
57 | CV="-xstrconst" | |
58 | ||
59 | rm conftest.o | |
60 | if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then | |
61 | CV="suppressed: string.h" | |
62 | fi | |
63 | ||
64 | dnl HP-UX C compiler | |
65 | elif $CC > /dev/null 2>&1 && | |
66 | $CC -c +ESlit conftest.c > /dev/null 2>&1 && | |
67 | test -f conftest.o | |
68 | then | |
69 | # strings go into readonly segment | |
70 | CV="+ESlit" | |
71 | ||
72 | rm conftest.o | |
73 | if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then | |
74 | CV="suppressed: string.h" | |
75 | fi | |
76 | ||
77 | dnl Digital Unix C compiler | |
78 | elif ! $CC > /dev/null 2>&1 && | |
79 | $CC -c -readonly_strings conftest.c > /dev/null 2>&1 && | |
80 | test -f conftest.o | |
81 | then | |
82 | # strings go into readonly segment | |
83 | CV="-readonly_strings" | |
84 | ||
85 | rm conftest.o | |
86 | if test -n "`${CC-cc} -c $CV conftest.c 2>&1`" ; then | |
87 | CV="suppressed: string.h" | |
88 | fi | |
89 | ||
90 | dnl C for AIX Compiler | |
91 | ||
92 | dnl IRIX C 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. | |
97 | ||
98 | fi | |
99 | rm -f conftest.* | |
100 | ]) | |
101 | if test -z "[$]$1" ; then | |
102 | if test -n "$CV" ; then | |
103 | case "$CV" in | |
104 | suppressed*) $1="" ;; # known but suppressed | |
105 | *) $1="$CV" ;; | |
106 | esac | |
107 | fi | |
108 | fi | |
109 | AC_SUBST($1) | |
110 | popdef([CV])dnl | |
111 | ]) | |
112 | ||
113 |