Author: Zola Bridges Date: 2020-04-20T10:30:52-07:00 New Revision: 0f12480bd13ad2d08b6ef3d64388dd8a12e1a503
URL: https://github.com/llvm/llvm-project/commit/0f12480bd13ad2d08b6ef3d64388dd8a12e1a503 DIFF: https://github.com/llvm/llvm-project/commit/0f12480bd13ad2d08b6ef3d64388dd8a12e1a503.diff LOG: [dfsan] Add "DataFlow" option to LLVM_USE_SANITIZER Summary: This patch add the dataflow option to LLVM_USE_SANITIZER and documents it. Tested via check-cxx (wip to fix the errors). Reviewers: morehouse, #libc! Subscribers: mgorny, cfe-commits, libcxx-commits Tags: #clang, #libc Differential Revision: https://reviews.llvm.org/D78390 Added: Modified: clang/docs/DataFlowSanitizer.rst libcxx/CMakeLists.txt libcxx/utils/libcxx/test/config.py llvm/cmake/modules/HandleLLVMOptions.cmake llvm/docs/CMake.rst Removed: ################################################################################ diff --git a/clang/docs/DataFlowSanitizer.rst b/clang/docs/DataFlowSanitizer.rst index e0e9d74efde9..cc9b8e6e1699 100644 --- a/clang/docs/DataFlowSanitizer.rst +++ b/clang/docs/DataFlowSanitizer.rst @@ -20,6 +20,31 @@ specific class of bugs on its own. Instead, it provides a generic dynamic data flow analysis framework to be used by clients to help detect application-specific issues within their own code. +How to build libc++ with DFSan +============================== + +DFSan requires either all of your code to be instrumented or for uninstrumented +functions to be listed as``uninstrumented`` in the `ABI list`_. + +If you'd like to have instrumented libc++ functions, then you need to build it +with DFSan instrumentation from source. Here is an example of how to build +libc++ and the libc++ ABI with data flow sanitizer instrumentation. + +.. code-block:: console + cd libcxx-build + + # An example using ninja + cmake -GNinja path/to/llvm-project/llvm \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DLLVM_USE_SANITIZER="DataFlow" \ + -DLLVM_ENABLE_LIBCXX=ON \ + -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" + + ninja cxx cxxabi + +Note: Ensure you are building with a sufficiently new version of Clang. + Usage ===== @@ -33,6 +58,8 @@ The APIs are defined in the header file ``sanitizer/dfsan_interface.h``. For further information about each function, please refer to the header file. +.. _ABI list: + ABI List -------- diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index cab3f7b14036..b05cad79d76a 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -682,6 +682,8 @@ function(get_sanitizer_flags OUT_VAR USE_SANITIZER) append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") elseif (USE_SANITIZER STREQUAL "Thread") append_flags(SANITIZER_FLAGS -fsanitize=thread) + elseif (USE_SANITIZER STREQUAL "DataFlow") + append_flags(SANITIZER_FLAGS -fsanitize=dataflow) else() message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}") endif() diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py index c31a47fb4f5d..ce77ec8c71c9 100644 --- a/libcxx/utils/libcxx/test/config.py +++ b/libcxx/utils/libcxx/test/config.py @@ -907,6 +907,8 @@ def add_ubsan(): self.cxx.flags += ['-fsanitize=thread'] self.config.available_features.add('tsan') self.config.available_features.add('sanitizer-new-delete') + elif san == 'DataFlow': + self.cxx.flags += ['-fsanitize=dataflow'] else: self.lit_config.fatal('unsupported value for ' 'use_sanitizer: {0}'.format(san)) diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake index 0c5f4e08aaba..91133d00782d 100644 --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -728,6 +728,8 @@ if(LLVM_USE_SANITIZER) elseif (LLVM_USE_SANITIZER STREQUAL "Thread") append_common_sanitizer_flags() append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) + elseif (LLVM_USE_SANITIZER STREQUAL "DataFlow") + append("-fsanitize=dataflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR LLVM_USE_SANITIZER STREQUAL "Undefined;Address") append_common_sanitizer_flags() diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst index 32d2ebdfc2c2..b8686b6d786e 100644 --- a/llvm/docs/CMake.rst +++ b/llvm/docs/CMake.rst @@ -422,7 +422,7 @@ LLVM-specific variables **LLVM_USE_SANITIZER**:STRING Define the sanitizer used to build LLVM binaries and tests. Possible values are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``, - and ``Address;Undefined``. Defaults to empty string. + ``DataFlow``, and ``Address;Undefined``. Defaults to empty string. **LLVM_ENABLE_LTO**:STRING Add ``-flto`` or ``-flto=`` flags to the compile and link command _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits