[clang] 11b7ce2 - [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is enabled

2023-08-02 Thread Blue Gaston via cfe-commits

Author: Blue Gaston
Date: 2023-08-02T11:30:29-07:00
New Revision: 11b7ce26f2a22ca147feaaf1cfd2d21b85fc3d83

URL: 
https://github.com/llvm/llvm-project/commit/11b7ce26f2a22ca147feaaf1cfd2d21b85fc3d83
DIFF: 
https://github.com/llvm/llvm-project/commit/11b7ce26f2a22ca147feaaf1cfd2d21b85fc3d83.diff

LOG: [ASanStableABI][Driver] Stop linking to asan dylib when stable abi is 
enabled

This patch enables linking of the static archive when fsanitize-stable-abi is 
set and stops linking to the asan dylib.

To link to the Address Sanitizer stable abi static library use 
"-fsanitize=address -fsanitize-stable-abi"

Updates a test with these flags.

rdar://112480890

Differential Revision: https://reviews.llvm.org/D156718

Added: 


Modified: 
clang/include/clang/Driver/SanitizerArgs.h
clang/lib/Driver/ToolChains/Darwin.cpp
compiler-rt/test/asan_abi/CMakeLists.txt
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
compiler-rt/test/asan_abi/lit.site.cfg.py.in

Removed: 




diff  --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 047b50626c44c5..07070ec4fc0653 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -76,6 +76,7 @@ class SanitizerArgs {
 bool DiagnoseErrors = true);
 
   bool needsSharedRt() const { return SharedRuntime; }
+  bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 65bd6c6a7eb35a..239fbf21d77f5a 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1484,9 +1484,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 
   if (Sanitize.linkRuntimes()) {
 if (Sanitize.needsAsanRt()) {
-  assert(Sanitize.needsSharedRt() &&
- "Static sanitizer runtimes not supported");
-  AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+  if (Sanitize.needsStableAbi()) {
+AddLinkSanitizerLibArgs(Args, CmdArgs, "asan_abi", /*shared=*/false);
+  } else {
+assert(Sanitize.needsSharedRt() &&
+   "Static sanitizer runtimes not supported");
+AddLinkSanitizerLibArgs(Args, CmdArgs, "asan");
+  }
 }
 if (Sanitize.needsLsanRt())
   AddLinkSanitizerLibArgs(Args, CmdArgs, "lsan");

diff  --git a/compiler-rt/test/asan_abi/CMakeLists.txt 
b/compiler-rt/test/asan_abi/CMakeLists.txt
index a1f42ca076edf7..f28cf6cd1da6ea 100644
--- a/compiler-rt/test/asan_abi/CMakeLists.txt
+++ b/compiler-rt/test/asan_abi/CMakeLists.txt
@@ -13,7 +13,6 @@ set(ASAN_ABI_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 if(NOT COMPILER_RT_STANDALONE_BUILD)
   list(APPEND ASAN_ABI_TEST_DEPS asan_abi)
 endif()
-set(ASAN_ABI_DYNAMIC_TEST_DEPS ${ASAN_ABI_TEST_DEPS})
 
 set(ASAN_ABI_TEST_ARCH ${ASAN_ABI_SUPPORTED_ARCH})
 if(APPLE)
@@ -27,7 +26,6 @@ foreach(arch ${ASAN_ABI_TEST_ARCH})
   string(TOLOWER "-${arch}-${OS_NAME}" ASAN_ABI_TEST_CONFIG_SUFFIX)
   get_bits_for_arch(${arch} ASAN_ABI_TEST_BITS)
   get_test_cc_for_arch(${arch} ASAN_ABI_TEST_TARGET_CC 
ASAN_ABI_TEST_TARGET_CFLAGS)
-  set(ASAN_ABI_TEST_DYNAMIC True)
 
   string(TOUPPER ${arch} ARCH_UPPER_CASE)
   set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)

diff  --git 
a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp 
b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
index 96f59191b8d46a..c651c32b489e4e 100644
--- a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
+++ b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_asan_abi -O0 -c -fsanitize-stable-abi -fsanitize=address %s -o 
%t.o
 // RUN: %clangxx -c %p/../../../../lib/asan_abi/asan_abi.cpp -o asan_abi.o
-// RUN: %clangxx -dead_strip -o %t %t.o %libasan_abi asan_abi.o && %run %t 2>&1
+// RUN: %clangxx -dead_strip -o %t %t.o -fsanitize-stable-abi 
-fsanitize=address asan_abi.o && %run %t 2>&1
 // RUN: %clangxx -x c++-header -o - -E 
%p/../../../../lib/asan/asan_interface.inc \
 // RUN: | sed "s/INTERFACE_FUNCTION/\nINTERFACE_FUNCTION/g" > 
%t.asan_interface.inc
 // RUN: llvm-nm -g %libasan_abi   \
@@ -22,6 +22,9 @@
 // RUN: sort %t.exports | uniq > %t.exports-sorted
 // RUN: 
diff  %t.imports-sorted %t.exports-sorted
 
+// Ensure that there is no dynamic dylib linked.
+// RUN: otool -L %t | (! grep -q "dynamic.dylib")
+
 // UNSUPPORTED: ios
 
 int main() { return 0; }

diff  --git a/compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp 
b/compiler-rt/test/asan_abi/TestCases/linkstaticlibrary.cpp
index 0bb14d322c67c2

[clang] 7cabb54 - [Darwin][StableABI][ASan] Remove version mismatch check from stable abi shim

2023-08-24 Thread Blue Gaston via cfe-commits

Author: Blue Gaston
Date: 2023-08-24T13:11:54-07:00
New Revision: 7cabb54f3867867451368ce72928f76cf38831cb

URL: 
https://github.com/llvm/llvm-project/commit/7cabb54f3867867451368ce72928f76cf38831cb
DIFF: 
https://github.com/llvm/llvm-project/commit/7cabb54f3867867451368ce72928f76cf38831cb.diff

LOG: [Darwin][StableABI][ASan] Remove version mismatch check from stable abi 
shim

By its nature the stable abi does not require a version check symbol.
This patch sets -asan-guard-against-version-mismatch=0 for stable abi.
And updates tests to reflect this

rdar://114208627

Differential Revision: https://reviews.llvm.org/D158570

Added: 


Modified: 
clang/lib/Driver/SanitizerArgs.cpp
compiler-rt/lib/asan_abi/asan_abi_shim.cpp
compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp

Removed: 




diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index c3ce13f93464d7..12f7e9fb9d2966 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -1287,6 +1287,8 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const 
llvm::opt::ArgList &Args,
 CmdArgs.push_back("-asan-instrumentation-with-call-threshold=0");
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-asan-max-inline-poisoning-size=0");
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-asan-guard-against-version-mismatch=0");
   }
 
   // Only pass the option to the frontend if the user requested,

diff  --git a/compiler-rt/lib/asan_abi/asan_abi_shim.cpp 
b/compiler-rt/lib/asan_abi/asan_abi_shim.cpp
index 61c45db4bb9d6f..02cd778ba48d25 100644
--- a/compiler-rt/lib/asan_abi/asan_abi_shim.cpp
+++ b/compiler-rt/lib/asan_abi/asan_abi_shim.cpp
@@ -49,7 +49,7 @@ void __asan_init(void) {
 
   __asan_abi_init();
 }
-void __asan_version_mismatch_check_v8(void) {}
+
 void __asan_handle_no_return(void) { __asan_abi_handle_no_return(); }
 
 // Variables concerning RTL state. These provisionally exist for completeness

diff  --git 
a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp 
b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
index c651c32b489e4e..5da18aa971d43a 100644
--- a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
+++ b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
@@ -7,7 +7,6 @@
 // RUN: | grep " [TU] "   \
 // RUN: | grep -o "\(__asan\)[^ ]*"   \
 // RUN: | grep -v "\(__asan_abi\)[^ ]*"   \
-// RUN: | sed -e 
"s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
 // RUN: > %t.exports
 // RUN: sed -e ':a' -e 'N' -e '$!ba'  \
 // RUN: -e 's/ //g'   \
@@ -17,7 +16,9 @@
 // RUN: | grep -v -f %p/../../../../lib/asan_abi/asan_abi_tbd.txt \
 // RUN: | grep -e "INTERFACE_\(WEAK_\)\?FUNCTION" \
 // RUN: | grep -v "__sanitizer[^ ]*"  \
-// RUN: | sed -e "s/.*(//" -e "s/).*//" > %t.imports
+// RUN: | sed -e "s/.*(//" -e "s/).*//"   \
+// RUN: | sed -e "/^__asan_version_mismatch_check/d"  \
+// RUN: > %t.imports
 // RUN: sort %t.imports | uniq > %t.imports-sorted
 // RUN: sort %t.exports | uniq > %t.exports-sorted
 // RUN: 
diff  %t.imports-sorted %t.exports-sorted



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits