Skip to content

Commit c0ccad9

Browse files
gnoliyilcharles-lunarg
authored andcommitted
gn: Disable function UBsan check
KhronosGroup/Vulkan-Hpp#2020 added `vk::PFN_...` function pointer types as the preferred function pointers used in vulkan.hpp structs and functions. These function pointer types use C++-styled types for the function arguments and return values, so the compiler treats them as types different from the C-styled "PFN_...` function pointers types. Vulkan-Hpp guarantees that they are binary identical during compile time, but UBsan's function sanitizer trigger a "function pointer type different" runtime error when these function pointers are invoked in the Vulkan-Loader (for example, debug_utils.c and allocation.c). Thus, we need to disable the function sanitizer from the Vulkan-Loader so that Vulkan applications created using Vulkan-Hpp can run correctly when UBsan is enabled. Test: Vulkan examples (https://fuchsia.googlesource.com/fuchsia/+/ main/src/graphics/tests/common/test_vkcontext.cc) didn't crash on Fuchsia core.x64-asan build. Bug: https://fxbug.dev/378964821 Change-Id: I8406daa884e741dbc8ade8c0e402550c450858e0
1 parent b4b6b14 commit c0ccad9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

BUILD.gn

+14-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ config("vulkan_loader_config") {
7777
"LOADER_USE_UNSAFE_FILE_SEARCH=1",
7878
]
7979

80+
cflags = []
8081
if (is_win) {
81-
cflags = [ "/wd4201" ]
82+
cflags += [ "/wd4201" ]
8283
}
8384
if (is_linux || is_chromeos) {
8485
defines += [
@@ -90,6 +91,18 @@ config("vulkan_loader_config") {
9091
"LOADER_ENABLE_LINUX_SORT",
9192
]
9293
}
94+
if (is_clang) {
95+
# Vulkan-Hpp uses `vk::PFN_...` function pointer types, which are different
96+
# from the C-styled `PFN_...` function pointers.
97+
#
98+
# These types are guaranteed to be identical during Vulkan-Hpp compile time.
99+
# However, UBsan's function sanitizer treats them as different types and
100+
# triggers a runtime error when these functions are called.
101+
#
102+
# Thus, we need to disable the function sanitizer so that Vulkan
103+
# applications created using Vulkan-Hpp can run correctly.
104+
cflags += [ "-fno-sanitize=function" ]
105+
}
93106
}
94107

95108
if (!is_android) {

0 commit comments

Comments
 (0)