Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-112301: Enable compiler flags with low performance impact and no warnings #120975

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,18 @@ AS_VAR_IF([with_strict_overflow], [yes],
[BASECFLAGS="$BASECFLAGS $STRICT_OVERFLOW_CFLAGS"],
[BASECFLAGS="$BASECFLAGS $NO_STRICT_OVERFLOW_CFLAGS"])


# Enable flags that warn and protect for potential security vulnerabilities.
# These flags should be enabled by default for all builds.
AX_CHECK_COMPILE_FLAG([-Wimplicit-fallthrough], [BASECFLAGS="$BASECFLAGS -Wimplicit-fallthrough"], [AC_MSG_WARN([-Wimplicit-fallthrough not supported])])
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [BASECFLAGS="$BASECFLAGS -fstack-protector-strong"], [AC_MSG_WARN([-fstack-protector-strong not supported])])
AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [BASECFLAGS="$BASECFLAGS -fno-strict-overflow"], [AC_MSG_WARN([-fno-strict-overflow not supported])])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But -fno-strict-overflow is already handled right above, isn't it?

dnl Historically, some of our code assumed that signed integer overflow
dnl is defined behaviour via twos-complement.
dnl Set STRICT_OVERFLOW_CFLAGS and NO_STRICT_OVERFLOW_CFLAGS depending on compiler support.
dnl Pass the latter to modules that depend on such behaviour.
_SAVE_VAR([CFLAGS])
CFLAGS="-fstrict-overflow -fno-strict-overflow"
AC_CACHE_CHECK([if $CC supports -fstrict-overflow and -fno-strict-overflow],
               [ac_cv_cc_supports_fstrict_overflow],
  AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[]], [[]])],
    [ac_cv_cc_supports_fstrict_overflow=yes],
    [ac_cv_cc_supports_fstrict_overflow=no]
  )
)
_RESTORE_VAR([CFLAGS])

AS_VAR_IF([ac_cv_cc_supports_fstrict_overflow], [yes],
          [STRICT_OVERFLOW_CFLAGS="-fstrict-overflow"
           NO_STRICT_OVERFLOW_CFLAGS="-fno-strict-overflow"],
          [STRICT_OVERFLOW_CFLAGS=""
           NO_STRICT_OVERFLOW_CFLAGS=""])

AC_MSG_CHECKING([for --with-strict-overflow])
AC_ARG_WITH([strict-overflow],
  AS_HELP_STRING(
    [--with-strict-overflow],
    [if 'yes', add -fstrict-overflow to CFLAGS, else add -fno-strict-overflow (default is no)]
  ),
  [
    AS_VAR_IF(
      [ac_cv_cc_supports_fstrict_overflow], [no],
      [AC_MSG_WARN([--with-strict-overflow=yes requires a compiler that supports -fstrict-overflow])],
      []
    )
  ],
  [with_strict_overflow=no]
)
AC_MSG_RESULT([$with_strict_overflow])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is true. I only checked that it was enabled when compiling and it looks like it is redundant. I have removed my addition

case $CC in
*gcc*)
# Add GCC-specific compiler flags
AX_CHECK_COMPILE_FLAG([-Wtrampolines], [BASECFLAGS="$BASECFLAGS -Wtrampolines"], [AC_MSG_WARN([-Wtrampolines not supported])])
esac

case $GCC in
yes)
CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
Expand Down
Loading