From a361408217c0fae02ead1a993c34f4173c49f362 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Mon, 29 Aug 2016 23:42:34 +0000 Subject: [PATCH] [cfi] Export __cfi_check when linking with -fsanitize-cfi-cross-dso. Multi-DSO CFI model requires every DSO to export a __cfi_check function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280031 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/SanitizerArgs.h | 1 + lib/Driver/Tools.cpp | 5 +++++ test/Driver/sanitizer-ld.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/clang/Driver/SanitizerArgs.h b/include/clang/Driver/SanitizerArgs.h index 7b293e03d3..59dd191311 100644 --- a/include/clang/Driver/SanitizerArgs.h +++ b/include/clang/Driver/SanitizerArgs.h @@ -66,6 +66,7 @@ class SanitizerArgs { bool requiresPIE() const; bool needsUnwindTables() const; bool linkCXXRuntimes() const { return LinkCXXRuntimes; } + bool hasCrossDsoCfi() const { return CfiCrossDso; } void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const; }; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 5852ac1b2e..464c4242ac 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -3194,6 +3194,11 @@ static bool addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, // to be dynamic to be sure we export sanitizer interface functions. if (AddExportDynamic) CmdArgs.push_back("-export-dynamic"); + + const SanitizerArgs &SanArgs = TC.getSanitizerArgs(); + if (SanArgs.hasCrossDsoCfi() && !AddExportDynamic) + CmdArgs.push_back("-export-dynamic-symbol=__cfi_check"); + return !StaticRuntimes.empty(); } diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index 49561f4838..d22815e7de 100644 --- a/test/Driver/sanitizer-ld.c +++ b/test/Driver/sanitizer-ld.c @@ -365,6 +365,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s // CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-LINUX: "-whole-archive" "{{[^"]*}}libclang_rt.cfi-x86_64.a" "-no-whole-archive" +// CHECK-CFI-CROSS-DSO-LINUX: -export-dynamic // Cross-DSO CFI with diagnostics links just the CFI runtime. // RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \ @@ -374,6 +375,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "-whole-archive" "{{[^"]*}}libclang_rt.cfi_diag-x86_64.a" "-no-whole-archive" +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: -export-dynamic // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \ // RUN: -mmacosx-version-min=10.6 \ @@ -452,6 +454,26 @@ // CHECK-SAFESTACK-ANDROID-AARCH64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-SAFESTACK-ANDROID-AARCH64-NOT: libclang_rt.safestack +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target arm-linux-androideabi -fsanitize=cfi \ +// RUN: --sysroot=%S/Inputs/basic_android_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CFI-ANDROID %s +// +// CHECK-CFI-ANDROID: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" +// CHECK-CFI-ANDROID-NOT: libclang_rt.cfi +// CHECK-CFI-ANDROID-NOT: __cfi_check + +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +// RUN: -target arm-linux-androideabi -fsanitize=cfi \ +// RUN: -fsanitize-cfi-cross-dso \ +// RUN: --sysroot=%S/Inputs/basic_android_tree \ +// RUN: | FileCheck --check-prefix=CHECK-CROSSDSO-CFI-ANDROID %s +// +// CHECK-CROSSDSO-CFI-ANDROID: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" +// CHECK-CROSSDSO-CFI-ANDROID-NOT: libclang_rt.cfi +// CHECK-CROSSDSO-CFI-ANDROID: -export-dynamic-symbol=__cfi_check +// CHECK-CROSSDSO-CFI-ANDROID-NOT: libclang_rt.cfi + // RUN: %clang -fsanitize=undefined %s -### -o %t.o 2>&1 \ // RUN: -target x86_64-scei-ps4 \ // RUN: -shared \ -- 2.40.0