Skip to content

Commit 87d31ba

Browse files
committed
Add support for enabling UBSAN
1 parent 89452fd commit 87d31ba

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ option(ASTCENC_DECOMPRESSOR "Enable astcenc builds for decompression only")
4444
option(ASTCENC_SHAREDLIB "Enable astcenc builds with core library shared objects")
4545
option(ASTCENC_DIAGNOSTICS "Enable astcenc builds with diagnostic trace")
4646
option(ASTCENC_ASAN "Enable astcenc builds with address sanitizer")
47+
option(ASTCENC_UBSAN "Enable astcenc builds with undefined behavior sanitizer")
4748
option(ASTCENC_UNITTEST "Enable astcenc builds with unit tests")
4849
option(ASTCENC_INVARIANCE "Enable astcenc floating point invariance" ON)
4950
option(ASTCENC_CLI "Enable build of astcenc command line tools" ON)
@@ -129,6 +130,7 @@ printopt("Shared libs " ${ASTCENC_SHAREDLIB})
129130
printopt("Decompressor " ${ASTCENC_DECOMPRESSOR})
130131
printopt("Diagnostics " ${ASTCENC_DIAGNOSTICS})
131132
printopt("ASAN " ${ASTCENC_ASAN})
133+
printopt("UBSAN " ${ASTCENC_UBSAN})
132134
printopt("Unit tests " ${ASTCENC_UNITTEST})
133135

134136
# Subcomponents

Docs/Building.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,15 @@ cd build
225225
ctest --verbose
226226
```
227227

228-
### Address sanitizer builds
228+
### Sanitizer builds
229229

230-
We support building with ASAN on Linux and macOS when using a compiler that
231-
supports it. To build binaries with ASAN checking enabled add `-DASTCENC_ASAN=ON`
232-
to the CMake command line when configuring.
230+
We support building with sanitizers on Linux and macOS when using Clang.
231+
232+
To build binaries with ASAN checking enabled add `-DASTCENC_ASAN=ON` to the
233+
CMake command line when configuring.
234+
235+
To build binaries with UBSAN checking enabled add `-DASTCENC_UBSAN=ON` to the
236+
CMake command line when configuring.
233237

234238
### Android builds
235239

@@ -297,4 +301,4 @@ details.
297301

298302
- - -
299303

300-
_Copyright © 2019-2023, Arm Limited and contributors. All rights reserved._
304+
_Copyright © 2019-2024, Arm Limited and contributors. All rights reserved._

Docs/ChangeLog-4x.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ The 4.8.0 release is a minor maintenance release.
1616
* **General:**
1717
* **Bug fix:** Native builds on macOS will now correctly build for arm64 when
1818
run outside of Rosetta on an Apple silicon device.
19+
* **Feature:** Builds using Clang can now build with undefined behavior
20+
sanitizer by setting `-DASTCENC_UBSAN=ON` on the CMake configure line.
1921

2022
<!-- ---------------------------------------------------------------------- -->
2123
## 4.7.0

Source/cmake_core.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
207207
$<${is_clang}:-fsanitize=address>)
208208
endif()
209209

210+
if(${ASTCENC_UBSAN})
211+
target_compile_options(${ASTCENC_TARGET_NAME}
212+
PRIVATE
213+
$<${is_clang}:-fsanitize=undefined>)
214+
215+
target_link_options(${ASTCENC_TARGET_NAME}
216+
PRIVATE
217+
$<${is_clang}:-fsanitize=undefined>)
218+
endif()
219+
210220
if(NOT ${ASTCENC_INVARIANCE})
211221
target_compile_definitions(${ASTCENC_TARGET_NAME}
212222
PRIVATE

0 commit comments

Comments
 (0)