Skip to content

Commit c9efa69

Browse files
committed
[Linux] Make the backtracing symbol reference conditional.
On the LSan builds, we disable the backtracer, which results in a link error because we completely remove the code from libswiftCore. rdar://116105222
1 parent 580e618 commit c9efa69

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

stdlib/public/runtime/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ set(LLVM_OPTIONAL_SOURCES
100100
${swift_runtime_leaks_sources}
101101
${swift_runtime_backtracing_sources})
102102

103+
set(swift_enable_backtracing)
103104
if(SWIFT_ENABLE_BACKTRACING)
104105
list(APPEND swift_runtime_sources ${swift_runtime_backtracing_sources})
106+
set(swift_enable_backtracing -DSWIFT_ENABLE_BACKTRACING)
105107
endif()
106108

107109
set(swift_runtime_library_compile_flags ${swift_runtime_compile_flags})
@@ -172,7 +174,9 @@ endforeach()
172174
add_swift_target_library(swiftImageRegistrationObjectELF
173175
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
174176
SwiftRT-ELF-WASM.cpp
175-
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
177+
C_COMPILE_FLAGS
178+
${SWIFT_RUNTIME_CORE_CXX_FLAGS}
179+
${swift_enable_backtracing}
176180
C_COMPILE_FLAGS_LINUX -fno-lto
177181
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
178182
TARGET_SDKS ${ELFISH_SDKS}
@@ -183,7 +187,9 @@ add_swift_target_library(swiftImageRegistrationObjectELF
183187
add_swift_target_library(swiftImageRegistrationObjectCOFF
184188
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
185189
SwiftRT-COFF.cpp
186-
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
190+
C_COMPILE_FLAGS
191+
${SWIFT_RUNTIME_CORE_CXX_FLAGS}
192+
${swift_enable_backtracing}
187193
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
188194
TARGET_SDKS ${COFF_SDKS}
189195
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
@@ -192,7 +198,9 @@ add_swift_target_library(swiftImageRegistrationObjectCOFF
192198
add_swift_target_library(swiftImageRegistrationObjectWASM
193199
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
194200
SwiftRT-ELF-WASM.cpp
195-
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
201+
C_COMPILE_FLAGS
202+
${SWIFT_RUNTIME_CORE_CXX_FLAGS}
203+
${swift_enable_backtracing}
196204
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
197205
TARGET_SDKS ${WASM_SDKS}
198206
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}

stdlib/public/runtime/SwiftRT-ELF-WASM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ extern "C" const char __dso_handle[];
2525
static constexpr const void *__dso_handle = nullptr;
2626
#endif
2727

28+
#if SWIFT_ENABLE_BACKTRACING
2829
// Drag in a symbol from the backtracer, to force the static linker to include
2930
// the code.
3031
static const void *__backtraceRef __attribute__((used))
3132
= (const void *)swift::runtime::backtrace::_swift_backtrace_isThunkFunction;
33+
#endif
3234

3335
// Create empty sections to ensure that the start/stop symbols are synthesized
3436
// by the linker. Otherwise, we may end up with undefined symbol references as

0 commit comments

Comments
 (0)