Skip to content

Commit b8d955c

Browse files
authored
[SYCL] Enable stack printing on crashes in post commit (#7934)
The initial attempt to enable LLVM stack printing on crashes(SEGFAULT) when running SYCL tests. The motivation is to simplify analysis of sporadic fails in CI. The patch: 1. If `DSYCL_ENABLE_STACK_PRINTING` `cmake` var is defined: a. Links the `libsycl.so` with `LLVMSupport` which provides needed functionality b. Calls `llvm::sys::PrintStackTraceOnErrorSignal`, which registers signal handlers, in a couple of places in SYCL RT c. Adds `llvm-sybmolizer` to the dependencies of `sycl-toolchain` 2. Modifies post-commit workflow to: a. build linux job (`linux_default` only) in RelWithDebInfo mode b. pass the `cmake` var to the `configure.py` 3. Sets `LLVM_SYMBOLIZER_PATH` in the `lit.cfg.py` for SYCL to the `llvm-sybmolizer` binary from the build dir
1 parent 8213074 commit b8d955c

File tree

7 files changed

+58
-0
lines changed

7 files changed

+58
-0
lines changed

.github/workflows/sycl_post_commit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
lts_matrix: ${{ needs.test_matrix.outputs.lts_matrix }}
3737
cts_matrix: ${{ needs.test_matrix.outputs.cts_matrix }}
3838
lts_aws_matrix: ${{ needs.test_matrix.outputs.lts_aws_matrix }}
39+
build_configure_extra_args: --cmake-opt="-DSYCL_ENABLE_STACK_PRINTING=ON" --cmake-opt="-DSYCL_LIB_WITH_DEBUG_SYMBOL=ON"
3940
linux_no_assert:
4041
name: Linux (no assert)
4142
if: github.repository == 'intel/llvm'

sycl/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ option(SYCL_ENABLE_WERROR "Treat all warnings as errors in SYCL project" OFF)
99
option(SYCL_DISABLE_STL_ASSERTIONS "Disable assertions in STL containers" ON)
1010
option(SYCL_ADD_DEV_VERSION_POSTFIX "Adds -V postfix to version string" ON)
1111
option(SYCL_ENABLE_COVERAGE "Enables code coverage for runtime and unit tests" OFF)
12+
option(SYCL_ENABLE_STACK_PRINTING "Enables stack printing on crashes of SYCL applications" OFF)
13+
option(SYCL_LIB_WITH_DEBUG_SYMBOLS "Builds SYCL runtime libraries with debug symbols" OFF)
1214

1315
if (NOT SYCL_COVERAGE_PATH)
1416
set(SYCL_COVERAGE_PATH "${CMAKE_CURRENT_BINARY_DIR}/profiles")
@@ -327,6 +329,10 @@ if (SYCL_ENABLE_XPTI_TRACING)
327329
endif()
328330
endif()
329331

332+
if (SYCL_ENABLE_STACK_PRINTING)
333+
add_dependencies(sycl-toolchain llvm-symbolizer)
334+
endif()
335+
330336
option(SYCL_INCLUDE_TESTS
331337
"Generate build targets for the SYCL unit tests."
332338
${LLVM_INCLUDE_TESTS})

sycl/cmake/modules/AddSYCL.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function(add_sycl_library LIB_NAME TYPE)
2424
add_stripped_pdb(${LIB_NAME})
2525
endif()
2626

27+
# TODO: Enabled for MSVC
28+
if (NOT MSVC AND SYCL_LIB_WITH_DEBUG_SYMBOLS)
29+
separate_arguments(CMAKE_CXX_FLAGS_DEBUG_SEPARATED UNIX_COMMAND "${CMAKE_CXX_FLAGS_DEBUG}")
30+
target_compile_options(${LIB_NAME} PRIVATE ${CMAKE_CXX_FLAGS_DEBUG_SEPARATED})
31+
endif()
32+
2733
# TODO remove add_common_options
2834
add_common_options(${LIB_NAME})
2935
endfunction()

sycl/source/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME)
2626
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>
2727
${CMAKE_CURRENT_BINARY_DIR}/version.rc)
2828

29+
# Unlike for sycl library, for LLVMSupport we have only one version for a given build,
30+
# so, we link LLVMSupport lib to matching sycl version only.
31+
if (SYCL_ENABLE_STACK_PRINTING)
32+
if(NOT MSVC OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARG_COMPILE_OPTIONS MATCHES ".*MDd.*") OR
33+
(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT ARG_COMPILE_OPTIONS MATCHES ".*MDd.*"))
34+
add_dependencies(${LIB_NAME} LLVMSupport)
35+
target_compile_definitions(${LIB_OBJ_NAME} PUBLIC ENABLE_STACK_TRACE)
36+
target_link_libraries(${LIB_NAME} PRIVATE LLVMSupport)
37+
endif()
38+
endif()
39+
40+
# TODO: Enabled for MSVC
41+
if (NOT MSVC AND SYCL_LIB_WITH_DEBUG_SYMBOLS)
42+
separate_arguments(CMAKE_CXX_FLAGS_DEBUG_SEPARATED UNIX_COMMAND "${CMAKE_CXX_FLAGS_DEBUG}")
43+
target_compile_options(${LIB_NAME} PRIVATE ${CMAKE_CXX_FLAGS_DEBUG_SEPARATED})
44+
endif()
45+
2946
if (SYCL_ENABLE_COVERAGE)
3047
target_compile_options(${LIB_OBJ_NAME} PUBLIC
3148
-fprofile-instr-generate -fcoverage-mapping

sycl/source/detail/global_handler.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#ifdef ENABLE_STACK_TRACE
10+
#include "llvm/ADT/StringRef.h"
11+
#include "llvm/Support/Signals.h"
12+
#endif
13+
914
#include <detail/config.hpp>
1015
#include <detail/global_handler.hpp>
1116
#include <detail/platform_impl.hpp>
@@ -95,9 +100,25 @@ void GlobalHandler::attachScheduler(Scheduler *Scheduler) {
95100
MScheduler.Inst.reset(Scheduler);
96101
}
97102

103+
static void enableOnCrashStackPrinting() {
104+
#ifdef ENABLE_STACK_TRACE
105+
static std::once_flag PrintStackFlag;
106+
std::call_once(PrintStackFlag, []() {
107+
llvm::sys::PrintStackTraceOnErrorSignal(llvm::StringRef());
108+
});
109+
#endif
110+
}
111+
98112
Scheduler &GlobalHandler::getScheduler() {
99113
getOrCreate(MScheduler);
100114
registerSchedulerUsage();
115+
// On Windows the registration of the signal handler before main function
116+
// (e.g. from DLLMain or from constructors of program scope objects) doesn't
117+
// work. So, registering signal handler here because:
118+
// 1) getScheduler is likely to be called for any non-trivial application;
119+
// 2) first call to getScheduler is likely to be done after main starts.
120+
// The same is done in getPlugins.
121+
enableOnCrashStackPrinting();
101122
return *MScheduler.Inst;
102123
}
103124

@@ -132,6 +153,7 @@ std::mutex &GlobalHandler::getFilterMutex() {
132153
return getOrCreate(MFilterMutex);
133154
}
134155
std::vector<plugin> &GlobalHandler::getPlugins() {
156+
enableOnCrashStackPrinting();
135157
return getOrCreate(MPlugins);
136158
}
137159
device_filter_list &

sycl/test/Unit/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
if symbolizer in os.environ:
5151
config.environment[symbolizer] = os.environ[symbolizer]
5252

53+
llvm_symbolizer = os.path.join(config.llvm_tools_dir, 'llvm-symbolizer')
54+
config.environment['LLVM_SYMBOLIZER_PATH'] = llvm_symbolizer
55+
5356
def find_shlibpath_var():
5457
if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
5558
yield 'LD_LIBRARY_PATH'

sycl/test/lit.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
config.substitutions.append( ('%llvm_build_lib_dir', config.llvm_build_lib_dir ) )
9494
config.substitutions.append( ('%llvm_build_bin_dir', config.llvm_build_bin_dir ) )
9595

96+
llvm_symbolizer = os.path.join(config.llvm_build_bin_dir, 'llvm-symbolizer')
97+
llvm_config.with_environment('LLVM_SYMBOLIZER_PATH', llvm_symbolizer)
98+
9699
config.substitutions.append( ('%fsycl-host-only', '-std=c++17 -Xclang -fsycl-is-host -isystem %s -isystem %s -isystem %s -isystem %s' % (config.sycl_include, config.level_zero_include_dir, config.opencl_include_dir, config.sycl_include + '/sycl/') ) )
97100
config.substitutions.append( ('%sycl_lib', ' -lsycl6' if platform.system() == "Windows" else '-lsycl') )
98101

0 commit comments

Comments
 (0)