server
server copied to clipboard
MDEV-25454 - UBSAN fixes and use clang when building with UBSAN in GitLab CI
- [x] The Jira issue number for this PR is: MDEV-25454
Description
This PR addresses two common UBSAN violations found when running the MTR main suite with -DWITH_UBSAN=YES
on clang-16. Currently running the MTR with UBSAN using gcc will not output any errors. The aim is to bring us closer to the eventual goal of this same result on both compilers.
Attempting to offset a null pointer by zero
- Adding zero as an offset to a null pointer is considered undefined behaviour and will be reported by UBSAN as such with error: "runtime error: applying zero offset to null pointer". Simply refactor the offending cases to ignore the offset when it's value is zero.
Unrepresentable NaN values
- UBSAN will report cases where NaN is casted to a type as undefined behaviour (example: "runtime error: -nan is outside the range of representable values of type 'unsigned long long'"). Check for NaN values for the offending cases and handle them accordingly.
Furthermore, edits were made to the .gitlab-ci.yml
file to further support sanitizer testing.
- As stated above, many sanitizer violations that are outputted are compiler specific. Running the MTR with sanitizers enabled when compiling with clang:latest will still output violations that are not experienced when building with gcc. This causes an ever-failing job which makes it harder to detect new genuine sanitizer related regressions. Refactor GitLab sanitizer jobs to use gcc instead.
- Additionally, allow for the override of default MTR parameters. Useful for jobs like TSAN where the MTR does not complete without violations and the default
max-test-fails
is 10. This prevents the test running from exitting early so it can still provide us with info of the failures for all tests in the suite.
Release Notes
N/A
How can this PR be tested?
./mtr --suite=main
successfully passing and the targeted UBSAN violations are no longer occurring when building/running with -DWITH_UBSAN=YES
on clang.
PR quality check
- [x] I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
- [x] For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.
All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.