Skip to content

Commit 03d23bc

Browse files
committed
Link sanitizers with libgcc on Linux, allow undefined symbols
1 parent 738384d commit 03d23bc

File tree

1 file changed

+19
-3
lines changed
  • utils/swift_build_support/swift_build_support/products

1 file changed

+19
-3
lines changed

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,22 @@ def should_build(self, host_target):
217217
# LLVM will always be built in part
218218
return True
219219

220+
@classmethod
221+
def compute_cmake_args_for_runtimes(cls, host_target):
222+
# Swift expects the old layout for the runtime directory
223+
args_for_runtime = '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR:BOOL=OFF'
224+
225+
if host_target.startswith('linux'):
226+
# This preserves the behaviour we had when using
227+
# LLVM_BUILD_EXTERNAL COMPILER_RT --
228+
# that is, having the linker not complaing if symbols used
229+
# by TSan are undefined (namely the ones for Blocks Runtime)
230+
# In the long term, we want to remove this and
231+
# build Blocks Runtime before LLVM
232+
args_for_runtime += ';-DSANITIZER_COMMON_LINK_FLAGS:STRING=-Wl,-z,undefs'
233+
234+
return args_for_runtime
235+
220236
def build(self, host_target):
221237
"""build() -> void
222238
@@ -291,7 +307,9 @@ def build(self, host_target):
291307
llvm_cmake_options.define('LLVM_INCLUDE_DOCS:BOOL', 'TRUE')
292308
llvm_cmake_options.define('LLVM_ENABLE_LTO:STRING', self.args.lto_type)
293309
llvm_cmake_options.define('COMPILER_RT_INTERCEPT_LIBDISPATCH', 'ON')
294-
llvm_cmake_options.define('RUNTIMES_CMAKE_ARGS', '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR:BOOL=OFF')
310+
llvm_cmake_options.define(
311+
'RUNTIMES_CMAKE_ARGS',
312+
LLVM.compute_cmake_args_for_runtimes(host_target))
295313

296314
if self.args.build_embedded_stdlib and system() == "Darwin":
297315
# Ask for Mach-O cross-compilation builtins (for Embedded Swift)
@@ -306,8 +324,6 @@ def build(self, host_target):
306324
not self.is_cross_compile_target(host_target):
307325
llvm_enable_runtimes.append('compiler-rt')
308326
build_targets.append("runtimes")
309-
# This is needed to build correctly TSan under Linux
310-
llvm_cmake_options.define('COMPILER_RT_USE_BUILTINS_LIBRARY', 'ON')
311327

312328
if self.args.build_clang_tools_extra:
313329
llvm_enable_projects.append('clang-tools-extra')

0 commit comments

Comments
 (0)