[Build] OpenBLAS getarch fails on aarch64 with LSAN/ASAN/ASAN_UT/UBSAN/TSAN sanitizer modes
- Dominant language
- Java
- Stars
- 15.9k
- Forks
- 3.9k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 520
Description
### Version
trunk
### What's Wrong?
On aarch64, building Doris BE with LSAN, ASAN, ASAN_UT, or UBSAN sanitizer modes fails.
**1. LSAN/ASAN/ASAN_UT - CMake configuration failure**
The OpenBLAS getarch build-time tool inherits sanitizer flags from the parent CMake context, which causes LeakSanitizer to detect memory leaks in OpenBLAS's `detect()` function (strdup without free on aarch64). This causes getarch to exit with non-zero code, and CMake configuration fails.
Error example (LSAN):
```
==641==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 480 byte(s) in 96 object(s) allocated from:
#0 malloc
#1 strdup
#2 detect (getarch)
#3 get_corename (getarch)
#4 main (getarch)
SUMMARY: LeakSanitizer: 972 byte(s) leaked in 194 allocation(s).
```
Additionally, `__lsan_ignore_object` is only enabled under `ADDRESS_SANITIZER` but `LEAK_SANITIZER` also provides this symbol. Under LSAN mode, an empty stub is used instead, causing link errors:
```
undefined reference to '__lsan_ignore_object'
```
**2. UBSAN - Compilation failure**
`-mcmodel=medium` is x86_64-specific and unsupported on aarch64. It is hardcoded in `CXX_FLAGS_UBSAN` and causes compilation failure:
```
clang: error: unsupported argument 'medium' to option '-mcmodel=' for target 'aarch64-unknown-linux-gnu'
```
After fixing `-mcmodel=medium`, UBSAN build on aarch64 also fails due to `-Wunused-macros` errors (promoted to errors by `-Werror`):
2a. `-Wno-unused-macros` suppression not working for flex/bison generated files — the flag was incorrectly gated behind the `-Wno-unused-but-set-variable` check in `be/src/exprs/CMakeLists.txt`, so the suppression never took effect:
```
be/ut_build_UBSAN/__/gensrc/build/geo/wkt_lex.l.cpp:7:9: error: macro is not used [-Werror,-Wunused-macros]
7 | #define FLEX_SCANNER
| ^~~~~~~~~~~~~
be/ut_build_UBSAN/__/gensrc/build/geo/wkt_yacc.y.cpp:80:9: error: macro is not used [-Werror,-Wunused-macros]
80 | #define YYCOPY(Dst, Src, Count) \
| ^
```
2b. Unused `#define PMR` macro in `function_string_misc.cpp`:
```
be/src/exprs/function/function_string_misc.cpp:82:9: error: macro is not used [-Werror,-Wunused-macros]
82 | #define PMR std::pmr
| ^~~
```
2c. Unused `ALIGN_CACHE_LINE` and `PURE` macros in `compiler_util.h`:
```
be/src/common/compiler_util.h:51:9: error: macro is not used [-Werror,-Wunused-macros]
51 | #define ALIGN_CACHE_LINE __attribute__((aligned(CACHE_LINE_SIZE)))
| ^~~~~~~~~~~~~~~~
be/src/common/compiler_util.h:53:9: error: macro is not used [-Werror,-Wunused-macros]
53 | #define PURE __attribute__((pure))
| ^~~~
```
**3. TSAN - CMake configuration failure**
The OpenBLAS getarch build-time tool inherits `-fsanitize=thread` flag, causing getarch to produce incorrect output. This leads to `SGEMM_DEFAULT_UNROLL_M` and other macros being undefined when compiling getarch_2nd, resulting in CMake configuration failure.
Error example:
```
error: use of undeclared identifier 'SGEMM_DEFAULT_UNROLL_M'
22 | printf("SGEMM_UNROLL_M=%d\n", SGEMM_DEFAULT_UNROLL_M);
```
Note: TSAN was verified to work on aarch64 without additional changes after the sanitizer flag stripping fix.
### What You Expected?
BE should build successfully with LSAN/ASAN/ASAN_UT/UBSAN/TSAN sanitizer modes on aarch64, and BE UT should run normally.
### How to Reproduce?
On an aarch64 machine:
1. Build Doris BE with LSAN mode: `BUILD_TYPE=LSAN bash build.sh --be`
2. Or with ASAN_UT mode: `BUILD_TYPE=ASAN_UT bash build.sh --be`
3. Or with ASAN mode: `BUILD_TYPE=ASAN bash build.sh --be`
4. Or with UBSAN mode: `BUILD_TYPE=UBSAN bash build.sh --be`
5. Or with TSAN mode: `BUILD_TYPE=TSAN bash build.sh --be`
6. CMake configuration or compilation fails
### Are you willing to submit PR?
Yes
Contributor guide
Assessment
This issue has not been assessed yet.