Build failing (undefined symbols) with --enable-asan

I'm currently debugging some strange memory issues and wanted to build the compiler with ASan enabled. I ran the build script as:

utils/build-script --enable-asan --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping

which eventually crashed at the step:

[9/1164][  0%][0.213s] Linking Swift shared library lib/libTestPureSwiftSharedLib.dylib

with the following linker errors:

Undefined symbols for architecture x86_64:
  "___asan_init", referenced from:
      _asan.module_ctor in libTestCPPLib.a(CPPLib.cpp.o)
  "___asan_register_globals", referenced from:
      _asan.module_ctor in libTestCPPLib.a(CPPLib.cpp.o)
  "___asan_unregister_globals", referenced from:
      _asan.module_dtor in libTestCPPLib.a(CPPLib.cpp.o)
  "___asan_version_mismatch_check_apple_clang_1205", referenced from:
      _asan.module_ctor in libTestCPPLib.a(CPPLib.cpp.o)
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Is there anything additional I should do to build with ASan enabled other than pass the --enable-asan option? Has anyone else seen issues with ASan builds recently?

Try using this patch: Pass sanitizer flags to swift driver by etcwilde · Pull Request #37958 · apple/swift · GitHub

2 Likes

Thanks @Varun_Gandhi, that seems to have done the trick!

1 Like
Terms of Service

Privacy Policy

Cookie Policy