Skip to content

Commit

Permalink
Autoconf: Globally add -std=gnu99 to compiler, if supported.
Browse files Browse the repository at this point in the history
Using -std=c99 breaks anonymous structs/unions with gcc-4 (only).

Closes #5595
  • Loading branch information
magnumripper authored and solardiz committed Dec 4, 2024
1 parent 6433323 commit b1d063a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ zip2john.o: zip2john.c arch.h common.h memory.h jumbo.h formats.h params.h misc.
######## End auto-generated

princeprocessor:
$(CC) @CFLAGS@ @JOHN_NO_SIMD@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ @OPENMP_CFLAGS@ @HAVE_MPI@ @PTHREAD_CFLAGS@ $(CPPFLAGS) $(OPT_NORMAL) -std=c99 -DLINUX pp.c $(LDFLAGS) -o ../run/pp
$(CC) @CFLAGS@ @JOHN_NO_SIMD@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ @OPENMP_CFLAGS@ @HAVE_MPI@ @PTHREAD_CFLAGS@ $(CPPFLAGS) $(OPT_NORMAL) -DLINUX pp.c $(LDFLAGS) -o ../run/pp

pp.o: pp.c autoconfig.h arch.h mem_map.h os.h os-autoconf.h jumbo.h mmap-windows.c memory.h mpz_int128.h int128.h misc.h config.h params.h common.h path.h signals.h loader.h list.h formats.h logger.h status.h recovery.h options.h getopt.h external.h compiler.h cracker.h john.h unicode.h prince.h rpp.h rules.h mask.h
$(CC) $(CFLAGS) $(OPT_NORMAL) -DJTR_MODE -std=c99 -c pp.c
$(CC) $(CFLAGS) $(OPT_NORMAL) -DJTR_MODE -c pp.c

version.h: find_version

Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -1916,7 +1916,7 @@ config_g.o: config.c
$(CC) $(CFLAGS) -DBENCH_BUILD config.c -o config_g.o

pp.o: pp.c
$(CC) $(CFLAGS) $(OPT_NORMAL) -DJTR_MODE -Wno-declaration-after-statement -std=c99 pp.c -o pp.o
$(CC) $(CFLAGS) $(OPT_NORMAL) -DJTR_MODE -Wno-declaration-after-statement -std=gnu99 pp.c -o pp.o

# This is for the BENCH build (to not depend upon options.o)
common_g.o: common.o
Expand Down
50 changes: 50 additions & 0 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -6075,6 +6075,56 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu



if test 1 -gt 0; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC supports -std=gnu99" >&5
$as_echo_n "checking if $CC supports -std=gnu99... " >&6; }
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu

ac_saved_cflags="$CFLAGS"
CFLAGS="-Werror -std=gnu99"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main ()
{

;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if test "1" -gt 0; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
fi
CFLAGS_EX="$CFLAGS_EX -std=gnu99"

else
if test 1 -gt 0; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
if test "1" = 2; then :
as_fn_error $? "Not supported by compiler" "$LINENO" 5
fi

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$ac_saved_cflags"
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu



if (test "x$asan" != xyes); then
warn="-Wstringop-truncation"
nowarn="-Wno-stringop-truncation"
Expand Down
3 changes: 3 additions & 0 deletions src/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ fi
CFLAGS_EX=""
JTR_FLAG_CHECK([-Wall], 1)
dnl Add -std=gnu99 if supported
JTR_FLAG_CHECK([-std=gnu99], 1)
dnl False positives from gcc 8
if (test "x$asan" != xyes); then
JTR_NOWARN_CHECK([stringop-truncation], 1)
Expand Down
2 changes: 1 addition & 1 deletion src/johnswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#elif (_MSC_VER > 1300) && (_M_IX86 >= 400 || defined(CPU_IA32) || defined(CPU_X64)) /* MS VC */
#define JOHNSWAP(x) _byteswap_ulong((x))
#define JOHNSWAP64(x) _byteswap_uint64 (((unsigned __int64)x))
#elif !defined(__STRICT_ANSI__)
#else /* was elif !defined(__STRICT_ANSI__) - no idea why - and a catch-all #else were missing*/
#define JOHNSWAP(x) john_bswap_32((x))
#define JOHNSWAP64(x) john_bswap_64((x))
#define ROTATE_LEFT(x, n) (x) = (((x)<<(n))|((uint32_t)(x)>>(32-(n))))
Expand Down
2 changes: 1 addition & 1 deletion src/mbedtls/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CC = @CC@
AS = @CC@
LD = @CC@
CPP = @CC@
CFLAGS = -c -DAC_BUILT @CC_CPU@ @CC_MAIN_CPU@ @CFLAGS@ @JOHN_NO_SIMD@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ @OPENMP_CFLAGS@ @HAVE_MPI@ @PTHREAD_CFLAGS@ @CPPFLAGS@ -std=c99
CFLAGS = -c -DAC_BUILT @CC_CPU@ @CC_MAIN_CPU@ @CFLAGS@ @JOHN_NO_SIMD@ @CFLAGS_EXTRA@ @OPENSSL_CFLAGS@ @OPENMP_CFLAGS@ @HAVE_MPI@ @PTHREAD_CFLAGS@ @CPPFLAGS@
ASFLAGS = @ASFLAGS@ -c @EXTRA_AS_FLAGS@
LDFLAGS = @LDFLAGS@
AR = @AR@
Expand Down
6 changes: 3 additions & 3 deletions src/mbedtls/Makefile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ default: aes.a
all: aes.a

aes.o: aes.c common.h build_info.h mbedtls_config.h alignment.h aes.h private_access.h platform_util.h platform.h error.h aesni.h aesce.h ctr.h
$(CC) $(CFLAGS) -std=c99 -c aes.c -o aes.o
$(CC) $(CFLAGS) -std=gnu99 -c aes.c -o aes.o

aesce.o: aesce.c common.h build_info.h mbedtls_config.h alignment.h aesce.h aes.h private_access.h platform_util.h
$(CC) $(CFLAGS) -std=c99 -c aesce.c -o aesce.o
$(CC) $(CFLAGS) -std=gnu99 -c aesce.c -o aesce.o

aesni.o: aesni.c common.h build_info.h mbedtls_config.h alignment.h aesni.h aes.h private_access.h platform_util.h
$(CC) $(CFLAGS) -std=c99 -c aesni.c -o aesni.o
$(CC) $(CFLAGS) -std=gnu99 -c aesni.c -o aesni.o

aes.a: $(AESIN)
$(AR) -rs aes.a $(AESIN)
Expand Down

0 comments on commit b1d063a

Please sign in to comment.