1
AC_ARG_ENABLE([gcc-vcheck],
2
[ --disable-gcc-vcheck do not check for buggy gcc version ],
3
gcc_check=$enableval, gcc_check="yes")
5
msg_gcc_check="use --disable-gcc-vcheck to disable this check. Before reporting any bugs check with a supported version of gcc"
7
dnl Check for gcc-4.1.0
8
if test "$gcc_check" = "yes"; then
9
if test "x$ac_compiler_gnu" = "xyes"; then
10
AC_MSG_CHECKING([for a supported version of gcc])
11
gcc_version=`${CC} -dumpversion`
12
case "${gcc_version}" in
14
AC_MSG_RESULT([no (${gcc_version})])
15
AC_MSG_ERROR([gcc 4.1.0 is known to incorrectly compile upx.c. Upgrade your compiler to at least 4.1.1/4.1.2)])
18
AC_MSG_RESULT([ok (${gcc_version})])
21
case "${gcc_version}" in
22
[[56789]].* | 4.[[3456789]].*)
23
# bb #1581 - temporarely add -fno-strict-aliasing so gcc 4.4.0
25
CFLAGS="$CFLAGS -fno-strict-aliasing"
33
VERSION_SUFFIX="$VERSION_SUFFIX-broken-compiler"
36
# add distcheck warning flags
37
distcheck_enable_flags=0
38
if test "x$ac_compiler_gnu" = "xyes"; then
39
gcc_version=`${CC} -dumpversion`
40
case "${gcc_version}" in
42
distcheck_enable_flags=1
45
distcheck_enable_flags=1
50
dnl Checks if compiler produces valid code, regardless of compiler
51
dnl we do these checks here to avoid receiving endless bugreports about
52
dnl breakages due to compiler bugs.
54
dnl Check if compiler produces invalid code on gcc PR27603 (affects upx.c)
55
dnl testcase from gcc testsuite
56
AC_MSG_CHECKING([for gcc bug PR27603])
59
/* (C) Richard Guenther */
66
for (j = 0; j < 6; j++)
68
if ((unsigned)j - 3 <= 1)
74
], [AC_MSG_RESULT([ok, bug not present])],
75
[AC_MSG_ERROR([your compiler has gcc PR27603 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27603])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
77
dnl Check if compiler produces invalid code on gcc PR26763-2 (affects upx.c)
78
dnl testcase from gcc testsuite
79
AC_MSG_CHECKING([for gcc bug PR26763-2])
82
/* (C) Richard Guenther */
83
extern void abort(void);
85
static int try (char *a, int d)
94
if (try (bla + 50, -1))
99
], [AC_MSG_RESULT([ok, bug not present])],
100
[AC_MSG_ERROR([your compiler has gcc PR26763-2 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26763])],[AC_MSG_RESULT([cross-compiling, assumed ok])])
102
dnl Check if compiler produces invalid code on own testcase based on upx.c
103
AC_MSG_CHECKING([for valid code generation of CLI_ISCONTAINED])
111
unsigned int backsize;
112
signed int unp_offset;
114
{(char*)0xf78ab008, 0x2e000, 1, 4, -1594},
115
{(char*)0xb7af1008, 0x2e000, 1, 4, -1594}
118
extern void abort(void);
120
#define CLI_ISCONTAINED(bb, bb_size, sb, sb_size) \
121
((bb_size) > 0 && (sb_size) > 0 && (size_t)(sb_size) <= (size_t)(bb_size) \
122
&& (sb) >= (bb) && ((sb) + (sb_size)) <= ((bb) + (bb_size)) && ((sb) + (sb_size)) > (bb) && (sb) < ((bb) + (bb_size)))
126
unsigned int backsize, dcur;
127
int dval=0x12000, unp_offset;
129
char* dst = (char*)0x12000;
133
unp_offset=0x800002c7;
135
if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0)
145
for(i=0;i<sizeof(values)/sizeof(values[0]);i++) {
146
struct v* v= &values[i];
148
unsigned int* dsize = &v->dsize;
149
unsigned int dcur = v->dcur;
150
unsigned int backsize = v->backsize-1;
151
signed int unp_offset = v->unp_offset;
153
if(!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) ||
154
!CLI_ISCONTAINED(dst, *dsize,dst+dcur,backsize) || unp_offset >= 0) {
162
], [AC_MSG_RESULT([ok, bug not present])],
163
[AC_MSG_ERROR([your compiler has a bug that causes clamav bug no. 670, use a different compiler, see http://bugs.clamav.net/bugzilla/show_bug.cgi?id=670])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
165
dnl Check if compiler produces invalid code on gcc PR28045 (affects upx.c)
166
dnl testcase from gcc testsuite
167
AC_MSG_CHECKING([for gcc bug PR28045])
170
/* (C) Andrew Pinski */
171
extern void abort(void);
174
unsigned int bits : 1;
175
signed long val : ((sizeof(long) * 8) - 1);
177
static int Fnegate (struct a b)
179
if ((-((long)b.val)) <= ((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))
180
&& (-((long)b.val)) >= (-(((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))) - 1))
190
], [AC_MSG_RESULT([ok, bug not present])],
191
[AC_MSG_ERROR([your compiler has gcc PR28045 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28045])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
193
dnl Check if compiler produces invalid code on gcc PR37573 (affects autoit.c)
194
dnl this is a bug in gcc 4.4.0, but for some reason it affects gcc 4.1.2 too
195
dnl gcc 4.1.3 is OK. This bug occurs only at -O3.
196
AC_MSG_CHECKING([for gcc bug PR37573])
213
unsigned int *c = s->c;
216
for (i = 0; i < 227; i++)
218
((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
219
((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i + 397];
222
((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
223
((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i - 227];
225
((((c[623] ^ c[0]) & 0x7ffffffe) ^ c[623]) >> 1) ^ ((0 - (c[0] & 1)) &
232
r ^= ((r & 0xff3a58ad) << 7);
233
r ^= ((r & 0xffffdf8c) << 15);
235
return (unsigned char) (r >> 1);
239
bar (unsigned char *p, unsigned int q, unsigned int r)
243
unsigned int *c = s.c;
245
for (i = 1; i < 624; i++)
246
c[i] = i + 0x6c078965 * ((c[i - 1] >> 30) ^ c[i - 1]);
252
static unsigned char p[23] = {
253
0xc0, 0x49, 0x17, 0x32, 0x62, 0x1e, 0x2e, 0xd5, 0x4c, 0x19, 0x28, 0x49,
254
0x91, 0xe4, 0x72, 0x83, 0x91, 0x3d, 0x93, 0x83, 0xb3, 0x61, 0x38
257
static unsigned char q[23] = {
258
0x3e, 0x41, 0x55, 0x54, 0x4f, 0x49, 0x54, 0x20, 0x55, 0x4e, 0x49, 0x43,
259
0x4f, 0x44, 0x45, 0x20, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x3c
267
bar (p, s, s + 0xa25e);
268
if (memcmp (p, q, s) != 0)
273
], [AC_MSG_RESULT([ok, bug not present])],
274
[AC_MSG_ERROR([your compiler has gcc PR37573 bug, use a lower optimization level (-O1 or -O2), see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37573])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
276
# It's not fatal if gperf is missing
277
AM_MISSING_PROG(GPERF, gperf)
281
AC_COMPILE_CHECK_SIZEOF([short])
282
AC_COMPILE_CHECK_SIZEOF([int])
283
AC_COMPILE_CHECK_SIZEOF([long])
284
AC_COMPILE_CHECK_SIZEOF([long long])
285
AC_COMPILE_CHECK_SIZEOF([void *])