Skip to content

Commit

Permalink
Fix -DBUILD_CONFIG=mysql_release to keep standard cmake flags
Browse files Browse the repository at this point in the history
-DCMAKE_BUILD_TYPE=xxx sets some C compiler flags according to the build type.
-DBUILD_CONFIG was completely overwriting them in some compiler / arch
combinations and not in others. Make it consistently "append-only", not
overwrite.

Also, enforce the same set of flags for Release and RelWithDebInfo.

This reverts ff1f611 as it is no longer
necessary.

    Avoid assert()

    By default, CMAKE_BUILD_TYPE RelWithDebInfo or Release implies
    -DNDEBUG, which disables the assert() macro. MariaDB is deviating
    from that. Let us be explicit to use assert() only in debug builds.
  • Loading branch information
cvicentiu committed Jan 10, 2025
1 parent ff1f611 commit 43233fe
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 39 deletions.
104 changes: 69 additions & 35 deletions cmake/build_configurations/mysql_release.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,40 @@ IF(UNIX)
# Default GCC flags
IF(CMAKE_COMPILER_IS_GNUCC)
SET(COMMON_C_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing -Wno-uninitialized")
SET(CMAKE_C_FLAGS_DEBUG "-O ${COMMON_C_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_DEBUG " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${COMMON_C_FLAGS}")
# MariaDB uses -O3 for release builds
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(COMMON_CXX_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing -Wno-uninitialized")
SET(CMAKE_CXX_FLAGS_DEBUG "-O ${COMMON_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " ${COMMON_CXX_FLAGS}")
# MariaDB uses -O3 for release builds
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
ENDIF()

# IBM Z flags
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
IF(RPM MATCHES "(rhel|centos)6" OR RPM MATCHES "(suse|sles)11")
SET(z_flags "-funroll-loops -march=z9-109 -mtune=z10 ")
SET(z_flags "-funroll-loops -march=z9-109 -mtune=z10")
ELSEIF(RPM MATCHES "(rhel|centos)7" OR RPM MATCHES "(suse|sles)12")
SET(z_flags "-funroll-loops -march=z196 -mtune=zEC12 ")
SET(z_flags "-funroll-loops -march=z196 -mtune=zEC12")
ELSE()
SET(z_flags "")
ENDIF()

IF(CMAKE_COMPILER_IS_GNUCC)
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${z_flags}${CMAKE_C_FLAGS_RELWITHDEBINFO}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " ${z_flags}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${z_flags}")
ENDIF()
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${z_flags}${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " ${z_flags}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " ${z_flags}")
ENDIF()
UNSET(z_flags)
ENDIF()
Expand All @@ -221,11 +231,13 @@ IF(UNIX)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ia64")
SET(COMMON_C_FLAGS "+DSitanium2 -mt -AC99")
SET(COMMON_CXX_FLAGS "+DSitanium2 -mt -Aa")
SET(CMAKE_C_FLAGS_DEBUG "+O0 -g ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "+O0 -g ${COMMON_CXX_FLAGS}")
# We have seen compiler bugs with optimisation and -g, so disabled for now
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "+O2 ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "+O2 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_DEBUG " +O0 -g ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " +O0 -g ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " +O0 -g ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " +O0 -g ${COMMON_CXX_FLAGS}")
# We have seen compiler bugs with optimisation and -g, so disabled for now
STRING(APPEND CMAKE_C_FLAGS_RELEASE " +O2 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " +O2 ${COMMON_CXX_FLAGS}")
ENDIF()
ENDIF()
SET(WITH_SSL no)
Expand All @@ -240,24 +252,40 @@ IF(UNIX)
SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -no-ftz -no-prefetch")
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -no-ftz -no-prefetch")
ENDIF()
SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -unroll2 -ip ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_DEBUG " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " -unroll2 -ip ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " -unroll2 -ip ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -unroll2 -ip ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -unroll2 -ip ${COMMON_CXX_FLAGS}")

# MariaDB uses -O3 for release builds.
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
SET(WITH_SSL no)
ENDIF()
ENDIF()

# Default Clang flags
IF(CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(COMMON_C_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing -Wno-parentheses-equality -Wno-string-plus-int")
SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_DEBUG " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " ${COMMON_C_FLAGS}")
# MariaDB uses -O3 for release builds.
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
ENDIF()
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(COMMON_CXX_FLAGS "-g -fno-omit-frame-pointer -fno-strict-aliasing -Wno-parentheses-equality -Wno-string-plus-int")
SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " ${COMMON_CXX_FLAGS}")
# MariaDB uses -O3 for release builds.
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
STRING(REGEX REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
ENDIF()

# Solaris flags
Expand All @@ -270,27 +298,33 @@ IF(UNIX)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "i386")
SET(COMMON_C_FLAGS "-g -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -xlibmil -xlibmopt -xtarget=generic")
SET(COMMON_CXX_FLAGS "-g0 -mt -fsimple=1 -ftrap=%none -nofstore -xbuiltin=%all -features=no%except -xlibmil -xlibmopt -xtarget=generic")
SET(CMAKE_C_FLAGS_DEBUG "-xO1 ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-xO1 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_DEBUG " -xO1 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " -xO1 ${COMMON_CXX_FLAGS}")
IF(32BIT)
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-xO2 ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-xO2 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " -xO2 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " -xO2 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -xO2 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -xO2 ${COMMON_CXX_FLAGS}")
ELSEIF(64BIT)
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-xO3 ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-xO3 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " -xO3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " -xO3 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -xO3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -xO3 ${COMMON_CXX_FLAGS}")
ENDIF()
ELSE()
ELSE()
# Assume !x86 is SPARC
SET(COMMON_C_FLAGS "-g -Xa -xstrconst -mt")
SET(COMMON_CXX_FLAGS "-g0 -noex -mt")
IF(32BIT)
SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -xarch=sparc")
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -xarch=sparc")
ENDIF()
SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-xO3 ${COMMON_C_FLAGS}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-xO3 ${COMMON_CXX_FLAGS}")
STRING(APPEND COMMON_C_FLAGS " -xarch=sparc")
STRING(APPEND COMMON_CXX_FLAGS " -xarch=sparc")
ENDIF()
STRING(APPEND CMAKE_C_FLAGS_DEBUG " ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_DEBUG " ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELEASE " -xO3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELEASE " -xO3 ${COMMON_CXX_FLAGS}")
STRING(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO " -xO3 ${COMMON_C_FLAGS}")
STRING(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO " -xO3 ${COMMON_CXX_FLAGS}")
ENDIF()
ENDIF()
ENDIF()
Expand Down
8 changes: 4 additions & 4 deletions storage/innobase/include/trx0trx.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,14 @@ struct trx_t : ilist_node<>
{
ut_ad(!mutex_is_owner());
mutex.wr_lock();
ut_d(assert(!mutex_owner.exchange(pthread_self(),
std::memory_order_relaxed)));
assert(!mutex_owner.exchange(pthread_self(),
std::memory_order_relaxed));
}
/** Release the mutex */
void mutex_unlock()
{
ut_d(assert(mutex_owner.exchange(0, std::memory_order_relaxed) ==
pthread_self()));
assert(mutex_owner.exchange(0, std::memory_order_relaxed) ==
pthread_self());
mutex.wr_unlock();
}
#ifndef SUX_LOCK_GENERIC
Expand Down

0 comments on commit 43233fe

Please sign in to comment.