Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-35462

Remove redundant checks for obsolete compiler features

    XMLWordPrintable

Details

    Description

      In CMake, we have many costly checks "do we have this or that GCC or clang option" which should be redundant by now. These checks are expensive, because the CMake configuration step runs in a single thread, and each check needs to attempt to compile a test program.

      Currently, the oldest GCC version that was shipped with a supported GNU/Linux distribution is GCC 7. For a long time (starting with MariaDB Server 10.4), the minimum supported GCC version was 4.8.5, which was included in Red Hat Enterprise Linux 7 and CentOS 7.

      This is not only about CMake but also about some source code, such as the following:

      #if !defined(__GNUC__) || (__GNUC__ < 4)
      

      or

      #  if GCC_VERSION < 2008
      /* code that must have become obsolete in MariaDB 5.5 already */
      #  elif defined(__cplusplus) && GCC_VERSION < 3004
      /* code that should have been obsolete in MariaDB 10.2 already */
      # if (GCC_VERSION >= 3001)
      /* code that is always used */
      

      We have at least the following redundant compiler version check in storage/rocksdb/CMakeLists.txt:

      IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
        EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
        IF (GCC_VERSION VERSION_LESS 4.8)
          SKIP_ROCKSDB_PLUGIN("${OLD_COMPILER_MSG}")
        ENDIF()
        SET(CXX11_FLAGS "-std=c++11")
        IF (GCC_VERSION VERSION_LESS 5.0)
          SET(CXX11_FLAGS "-std=c++11 -Wno-missing-field-initializers")
        ENDIF()
      ELSEIF (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
        IF ((CMAKE_CXX_COMPILER_VERSION AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS  3.3) OR
           (CLANG_VERSION_STRING AND CLANG_VERSION_STRING VERSION_LESS  3.3))
          SKIP_ROCKSDB_PLUGIN("${OLD_COMPILER_MSG}")
        ENDIF()
        SET(CXX11_FLAGS "-std=c++11 -stdlib=libstdc++")
      

      and (the minimum required CMake version ought to be later than 3.0 by now):

      IF(CMAKE_VERSION GREATER 3.0)
        SET(CMAKE_CXX_STANDARD  11)
      ELSEIF(CXX11_FLAGS)
        ADD_DEFINITIONS(${CXX11_FLAGS})
      ENDIF()
      

      There also are plenty of MY_CHECK_AND_SET_COMPILER_FLAG() invocations that invoke a compiler, taking a lot of time. These could be replaced by a much cheaper check of MSVC or CMAKE_CXX_COMPILER_ID. Many options are supported by all supported versions of GCC and clang. Some options are specific to GCC or clang, and some might have been introduced in a more recent compiler version. Even those options could be enabled based on a compiler version check, rather than trying to invoke the compiler with a particular option.

      With https://godbolt.org it should be convenient to check the oldest GCC or Clang version that introduced a particular flag.

      Note: I do not have a good rule to determine what should be the oldest supported version of a Clang-like compiler. I know that valerii is running a Clang 10 based Apple XCode 10 on x86-64 hardware, so maybe we should target that as the minimum, even though currently supported FreeBSD or macOS versions use something newer.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              marko Marko Mäkelä
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.