Skip to content

Commit 0f12480

Browse files
author
Zola Bridges
committed
[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
1 parent 8541a3c commit 0f12480

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

clang/docs/DataFlowSanitizer.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ specific class of bugs on its own. Instead, it provides a generic
2020
dynamic data flow analysis framework to be used by clients to help
2121
detect application-specific issues within their own code.
2222

23+
How to build libc++ with DFSan
24+
==============================
25+
26+
DFSan requires either all of your code to be instrumented or for uninstrumented
27+
functions to be listed as``uninstrumented`` in the `ABI list`_.
28+
29+
If you'd like to have instrumented libc++ functions, then you need to build it
30+
with DFSan instrumentation from source. Here is an example of how to build
31+
libc++ and the libc++ ABI with data flow sanitizer instrumentation.
32+
33+
.. code-block:: console
34+
cd libcxx-build
35+
36+
# An example using ninja
37+
cmake -GNinja path/to/llvm-project/llvm \
38+
-DCMAKE_C_COMPILER=clang \
39+
-DCMAKE_CXX_COMPILER=clang++ \
40+
-DLLVM_USE_SANITIZER="DataFlow" \
41+
-DLLVM_ENABLE_LIBCXX=ON \
42+
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi"
43+
44+
ninja cxx cxxabi
45+
46+
Note: Ensure you are building with a sufficiently new version of Clang.
47+
2348
Usage
2449
=====
2550

@@ -33,6 +58,8 @@ The APIs are defined in the header file ``sanitizer/dfsan_interface.h``.
3358
For further information about each function, please refer to the header
3459
file.
3560

61+
.. _ABI list:
62+
3663
ABI List
3764
--------
3865

libcxx/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ function(get_sanitizer_flags OUT_VAR USE_SANITIZER)
682682
append_flags(SANITIZER_FLAGS "-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all")
683683
elseif (USE_SANITIZER STREQUAL "Thread")
684684
append_flags(SANITIZER_FLAGS -fsanitize=thread)
685+
elseif (USE_SANITIZER STREQUAL "DataFlow")
686+
append_flags(SANITIZER_FLAGS -fsanitize=dataflow)
685687
else()
686688
message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${USE_SANITIZER}")
687689
endif()

libcxx/utils/libcxx/test/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ def add_ubsan():
907907
self.cxx.flags += ['-fsanitize=thread']
908908
self.config.available_features.add('tsan')
909909
self.config.available_features.add('sanitizer-new-delete')
910+
elif san == 'DataFlow':
911+
self.cxx.flags += ['-fsanitize=dataflow']
910912
else:
911913
self.lit_config.fatal('unsupported value for '
912914
'use_sanitizer: {0}'.format(san))

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ if(LLVM_USE_SANITIZER)
728728
elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
729729
append_common_sanitizer_flags()
730730
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
731+
elseif (LLVM_USE_SANITIZER STREQUAL "DataFlow")
732+
append("-fsanitize=dataflow" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
731733
elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
732734
LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
733735
append_common_sanitizer_flags()

llvm/docs/CMake.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ LLVM-specific variables
422422
**LLVM_USE_SANITIZER**:STRING
423423
Define the sanitizer used to build LLVM binaries and tests. Possible values
424424
are ``Address``, ``Memory``, ``MemoryWithOrigins``, ``Undefined``, ``Thread``,
425-
and ``Address;Undefined``. Defaults to empty string.
425+
``DataFlow``, and ``Address;Undefined``. Defaults to empty string.
426426

427427
**LLVM_ENABLE_LTO**:STRING
428428
Add ``-flto`` or ``-flto=`` flags to the compile and link command

0 commit comments

Comments
 (0)