Skip to content

[build-script] Add support for compiling swift with leaks sanitizer. #10504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,18 @@ build-subdir=buildbot_incremental_asan

enable-asan

[preset: buildbot_incremental_linux,lsan]
build-subdir=buildbot_incremental_lsan

release-debuginfo
assertions
enable-lsan

dash-dash

build-ninja
reconfigure

#===------------------------------------------------------------------------===#
# OS X Package Builders
#===------------------------------------------------------------------------===#
Expand Down
12 changes: 12 additions & 0 deletions utils/build-script
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,14 @@ class BuildScriptInvocation(object):
# NOT pass them to build-script-impl.
if args.enable_asan:
impl_args += ["--enable-asan"]
# If we have lsan, we need to export our suppression list. The actual
# passing in of the LSAN flag is done via the normal cmake method. We
# do not pass the flag to build-script-impl.
if args.enable_lsan:
supp_file = os.path.join(SWIFT_SOURCE_ROOT, SWIFT_REPO_NAME,
"utils",
"lsan_leaks_suppression_list.txt")
os.environ['LSAN_OPTIONS'] = 'suppressions={}'.format(supp_file)
if args.verbose_build:
impl_args += ["--verbose-build"]
if args.install_symroot:
Expand Down Expand Up @@ -2018,6 +2026,10 @@ iterations with -O",
parser.add_argument(
"--enable-tsan-runtime",
help="enable Thread Sanitizer on the swift runtime")
parser.add_argument(
"--enable-lsan",
help="enable Leak Sanitizer for swift tools",
action=arguments.action.optional_bool)

parser.add_argument(
"--compiler-vendor",
Expand Down
2 changes: 2 additions & 0 deletions utils/lsan_leaks_suppression_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
leak:*buildCompilation*
leak:*llvm::TableGenMain*
2 changes: 2 additions & 0 deletions utils/swift_build_support/swift_build_support/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def common_options(self):
sanitizers.append('Undefined')
if args.enable_tsan:
sanitizers.append('Thread')
if args.enable_lsan:
sanitizers.append('Leaks')
if sanitizers:
define("LLVM_USE_SANITIZER", ";".join(sanitizers))

Expand Down
13 changes: 13 additions & 0 deletions utils/swift_build_support/tests/test_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def default_args(self):
enable_asan=False,
enable_ubsan=False,
enable_tsan=False,
enable_lsan=False,
export_compile_commands=False,
distcc=False,
cmake_generator="Ninja",
Expand Down Expand Up @@ -148,6 +149,18 @@ def test_common_options_asan_ubsan_tsan(self):
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])

def test_common_options_lsan(self):
args = self.default_args()
args.enable_lsan = True
cmake = self.cmake(args)
self.assertEqual(
list(cmake.common_options()),
["-G", "Ninja",
"-DLLVM_USE_SANITIZER=Leaks",
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++",
"-DCMAKE_MAKE_PROGRAM=" + self.which_ninja(args)])

def test_common_options_export_compile_commands(self):
args = self.default_args()
args.export_compile_commands = True
Expand Down