Skip to content
/ server Public

MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization#4816

Merged
dr-m merged 1 commit intoMariaDB:10.6from
grooverdan:MDEV-39086
Mar 17, 2026
Merged

MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization#4816
dr-m merged 1 commit intoMariaDB:10.6from
grooverdan:MDEV-39086

Conversation

@grooverdan
Copy link
Member

MSAN/UBSAN/ASAN/TSAN builds are preforming addition runtime checks requiring additional CPU to do so. To help the test systems of these run with a bit faster, but still be debuggable, we should add -Og where another C/CXX optimization flag isn't specified.

Gcc/Clang environment that support these range of sanitizers use -O followed by 0-3, g, s, z, and apparently "fast". These are the flags matched by the regex.

MSAN/UBSAN/ASAN/TSAN builds are preforming addition runtime
checks requiring additional CPU to do so. To help the test
systems of these run with a bit faster, but still be debuggable,
we should add -Og where another C/CXX optimization flag isn't
specified.

Gcc/Clang environment that support these range of sanitizers
use -O followed by 0-3, g, s, z, and apparently "fast". These
are the flags matched by the regex.
@grooverdan grooverdan requested a review from dr-m March 17, 2026 06:04
@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label Mar 17, 2026
Copy link
Contributor

@dr-m dr-m left a comment

Choose a reason for hiding this comment

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

I see that there should be a way to generate an unoptimized build by setting -O0 in CMAKE_C_FLAGS or CMAKE_CXX_FLAGS. Therefore, this should be a safe change to apply.

@dr-m dr-m merged commit af0057a into MariaDB:10.6 Mar 17, 2026
12 of 13 checks passed
@grooverdan grooverdan deleted the MDEV-39086 branch March 17, 2026 06:42
AND NOT CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE} MATCHES "-O[0-9sgzf]")
MY_CHECK_AND_SET_COMPILER_FLAG("-Og")
ENDIF()

Copy link
Member

Choose a reason for hiding this comment

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

CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE} does not work unless you uppercase the build type.
You do not want that to run for MSVC, because options check is brittle, assume GCCisms

Copy link
Member Author

Choose a reason for hiding this comment

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

Given they where under the sanitizers I assumed MSVC wasn't an option.

Ack on upper case build type. I'll work out a fix.

Copy link
Member

Choose a reason for hiding this comment

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

MSVC is an option, for ASAN, not anything else yet.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, it is also an option because of both cl and clang-cl (which accepts MSVC command line). Thus please add AND NOT MSVC to the check

Copy link
Contributor

Choose a reason for hiding this comment

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

@vaintroub Can you suggest a follow-up patch?

Copy link
Member

Choose a reason for hiding this comment

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

I think @grooverdan is already on it, and it is totally doable by the original committer :) 2 points -

  • AND NOT MSVC
  • uppercase CMAKE_BUILD_TYPE when looking for flags.

Copy link
Member

Choose a reason for hiding this comment

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

Overall though, I think -Og should be something set in the CI, rather than in CMakeLists.txt, my opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

#4818.

Having seen a few years of developers asking for X flag and and Y flag out into the CI environment, I'm pretty firmly of the opinion that the build configuration should be standard, available to everyone external, usable by users in a default configuration, and go through a review process of developer peers rather than back channel.

Copy link
Member

@vaintroub vaintroub Mar 17, 2026

Choose a reason for hiding this comment

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

Having seen a bunch of CMake in a few years, I developed a certain dislike when people sneak other options that what was asked for. I have not seen it anywhere else, and I have seen a bunch of CMake code.

If I want ASAN it is just ASAN, and not "ASAN and lets make your debugging a little bit more complicated". If I want optimized ASAN, it will be -DCMAKE_BUILD_TYPE=RelWithDebInfo. If I want something special , CFLAGS and CXXFLAGS environment variables. Rather than forced -Og

There are times when something makes sense, such as disabling SAFEMALLOC with sanitizer, because it is layer upon another layer, and sanitizer is doing better job.

But here I do not remember anyone complained about slow ASAN. It is absolutely solely for speeding up CI, and this is how it was in the MDEV, "to help the CI systems .. run with a bit faster"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

3 participants