Skip to content

Commit ce92c3f

Browse files
authored
[GSan] Robustly detect the right C++ stdlib for clang++ (#9791)
Without this, getting an error like ``` fatal error: 'climits' file not found 41 | #include <climits> | ^~~~~~~~~ 1 error generated when compiling for sm_80. ``` Apparently, the GCC version auto-detected by clang++ did not match the `libstdc++` version installed on my system.
1 parent a45fe34 commit ce92c3f

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

third_party/nvidia/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ if(TRITON_BUILD_PYTHON_MODULE)
2424
list(APPEND GSAN_RUNTIME_PLATFORM_FLAGS -isysroot "${CMAKE_OSX_SYSROOT}")
2525
endif()
2626

27+
set(GSAN_RUNTIME_TOOLCHAIN_FLAGS)
28+
# Detect the right include directory for C++ stdlib.
29+
# The way this is currently done is GCC specific.
30+
# TODO: Support libc++-based systems.
31+
set(GSAN_HOST_GNU_CXX "${CMAKE_CXX_COMPILER}")
32+
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
33+
# Force g++ to be used for querying -print-file-name on libstdc++.so
34+
# clang++ does not print an absolute path in this case.
35+
find_program(GSAN_HOST_GNU_CXX NAMES g++ c++)
36+
endif()
37+
if(GSAN_HOST_GNU_CXX)
38+
execute_process(
39+
COMMAND "${GSAN_HOST_GNU_CXX}" -print-file-name=libstdc++.so
40+
OUTPUT_VARIABLE LIBSTDCXX_PATH
41+
OUTPUT_STRIP_TRAILING_WHITESPACE
42+
)
43+
if(IS_ABSOLUTE "${LIBSTDCXX_PATH}")
44+
get_filename_component(GCC_INSTALL_DIR "${LIBSTDCXX_PATH}" DIRECTORY)
45+
list(APPEND GSAN_RUNTIME_TOOLCHAIN_FLAGS "--gcc-install-dir=${GCC_INSTALL_DIR}")
46+
endif()
47+
endif()
48+
2749
add_custom_command(
2850
OUTPUT "${GSAN_RUNTIME_IR}"
2951
COMMAND "${CMAKE_COMMAND}" -E make_directory
@@ -38,6 +60,7 @@ if(TRITON_BUILD_PYTHON_MODULE)
3860
-fcuda-flush-denormals-to-zero
3961
--cuda-gpu-arch=sm_80
4062
-Wno-unknown-cuda-version
63+
${GSAN_RUNTIME_TOOLCHAIN_FLAGS}
4164
${GSAN_RUNTIME_PLATFORM_FLAGS}
4265
-isystem "${CMAKE_CURRENT_SOURCE_DIR}/clang_cuda_shims"
4366
-isystem "${CMAKE_CURRENT_SOURCE_DIR}/backend/include"

0 commit comments

Comments
 (0)