Skip to content

Commit

Permalink
Fix build errors by testing for compiler flags #31
Browse files Browse the repository at this point in the history
  • Loading branch information
dharple committed Feb 13, 2021
1 parent 9d030b8 commit 07df16c
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 7 deletions.
116 changes: 116 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3789,6 +3789,122 @@ fi
done


#
# References and reasons for compiler flags:
#
# https://github.com/klange/prboom/blob/master/autotools/ac_c_compile_flags.m4
# https://github.com/dharple/detox/issues/31
# https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cjh1548250046139.htm
# https://developers.redhat.com/blog/2020/05/22/stack-clash-mitigation-in-gcc-part-3/
# https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html
#




HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler supports -flto=auto" >&5
$as_echo_n "checking whether compiler supports -flto=auto... " >&6; }
CFLAGS="$HOLD -flto=auto"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }


fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$HOLD"


HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler supports -fstack-clash-protection" >&5
$as_echo_n "checking whether compiler supports -fstack-clash-protection... " >&6; }
CFLAGS="$HOLD -fstack-clash-protection"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }


fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$HOLD"


HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler supports -fstack-protector-strong" >&5
$as_echo_n "checking whether compiler supports -fstack-protector-strong... " >&6; }
CFLAGS="$HOLD -fstack-protector-strong"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

HOLD="$CFLAGS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }


fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS="$HOLD"


#
#
#

ac_config_headers="$ac_config_headers src/config.h"

ac_config_files="$ac_config_files Makefile src/Makefile"
Expand Down
38 changes: 38 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,44 @@ AC_PROG_YACC

AC_CHECK_FUNCS([getopt_long])

#
# References and reasons for compiler flags:
#
# https://github.com/klange/prboom/blob/master/autotools/ac_c_compile_flags.m4
# https://github.com/dharple/detox/issues/31
# https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cjh1548250046139.htm
# https://developers.redhat.com/blog/2020/05/22/stack-clash-mitigation-in-gcc-part-3/
# https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html
#

AC_DEFUN([AC_CHECK_CFLAG], [
HOLD="$CFLAGS"
AC_MSG_CHECKING(whether compiler supports $1)
CFLAGS="$HOLD $1"
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[]],
[[]]
)],
[
HOLD="$CFLAGS"
AC_MSG_RESULT(yes)
],
[
AC_MSG_RESULT(no)
]
)
CFLAGS="$HOLD"
])

AC_CHECK_CFLAG([[-flto=auto]])
AC_CHECK_CFLAG([[-fstack-clash-protection]])
AC_CHECK_CFLAG([[-fstack-protector-strong]])

#
#
#

AC_CONFIG_HEADER([src/config.h])
AC_CONFIG_FILES([
Makefile
Expand Down
14 changes: 7 additions & 7 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#
# References and reasons for compiler flags:
#
# https://github.com/dharple/detox/issues/31
# https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
# https://www.keil.com/support/man/docs/armclang_ref/armclang_ref_cjh1548250046139.htm
# https://developers.redhat.com/blog/2020/05/22/stack-clash-mitigation-in-gcc-part-3/
# https://gcc.gnu.org/onlinedocs/gccint/LTO-Overview.html
# https://access.redhat.com/blogs/766093/posts/1976213
#

AM_CFLAGS = \
Expand All @@ -14,10 +13,11 @@ AM_CFLAGS = \
-DYY_NO_UNPUT \
-D_FORTIFY_SOURCE=2 \
-Wall \
-Werror=return-type \
-flto=auto \
-fstack-clash-protection \
-fstack-protector-strong
-Werror

#
#
#

AM_YFLAGS = -d

Expand Down

0 comments on commit 07df16c

Please sign in to comment.