Index: lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- lib/Driver/ToolChains/CommonArgs.cpp +++ lib/Driver/ToolChains/CommonArgs.cpp @@ -598,6 +598,7 @@ ArgStringList &CmdArgs) { // Force linking against the system libraries sanitizers depends on // (see PR15823 why this is necessary). + CmdArgs.push_back("--push-state"); CmdArgs.push_back("--no-as-needed"); // There's no libpthread or librt on RTEMS & Android. if (TC.getTriple().getOS() != llvm::Triple::RTEMS && @@ -617,6 +618,7 @@ if (TC.getTriple().getOS() == llvm::Triple::NetBSD || TC.getTriple().getOS() == llvm::Triple::FreeBSD) CmdArgs.push_back("-lexecinfo"); + CmdArgs.push_back("--pop-state"); } static void Index: test/Driver/sanitizer-ld.c =================================================================== --- test/Driver/sanitizer-ld.c +++ test/Driver/sanitizer-ld.c @@ -220,6 +220,20 @@ // CHECK-ASAN-MYRIAD-NOT: "-lc" // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a" +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -static \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-ASAN-LINUX-STATIC %s +// +// CHECK-ASAN-LINUX-STATIC: "--push-state" +// CHECK-ASAN-LINUX-STATIC: "--no-as-needed" +// CHECK-ASAN-LINUX-STATIC: "-lpthread" +// CHECK-ASAN-LINUX-STATIC: "-lrt" +// CHECK-ASAN-LINUX-STATIC: "-lm" +// CHECK-ASAN-LINUX-STATIC: "-ldl" +// CHECK-ASAN-LINUX-STATIC: "--pop-state" + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -target x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \ // RUN: -fsanitize=thread \