diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -845,16 +845,16 @@ if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes()) StaticRuntimes.push_back("stats_client"); + // Always link the static runtime regardless of DSO or executable. + if (SanArgs.needsAsanRt()) + HelperStaticRuntimes.push_back("asan_static"); + // Collect static runtimes. if (Args.hasArg(options::OPT_shared)) { // Don't link static runtimes into DSOs. return; } - // Always link the static runtime for executable. - if (SanArgs.needsAsanRt()) - HelperStaticRuntimes.push_back("asan_static"); - // Each static runtime that has a DSO counterpart above is excluded below, // but runtimes that exist only as static are not affected by needsSharedRt. diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -39,7 +39,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s // -// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan_static-x86_64 +// CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static-x86_64 // CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan-x86_64 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \