Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore asan warnings (clang) #3844

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,25 @@ else()
endif()

if(${USING_ASAN} OR ${USING_ASAN_INT})

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-fsanitize-blacklist and -fsanitize=integer only seem to be available with Clang so I added some checks

configure_file(asan_blacklist.in asan_blacklist)
add_compile_options(
"-fsanitize-blacklist=${CMAKE_BINARY_DIR}/asan_blacklist")
endif()

if(${USING_ASAN_INT})
add_compile_options(-fsanitize=address,undefined,integer)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fsanitize=address,undefined,integer)
else()
message(
WARNING "ASAN_INT is only supported with clang, defaulting to ASAN")
add_compile_options(-fsanitize=address,undefined)
endif()
else()
add_compile_options(-fsanitize=address,undefined)
endif()

add_definitions(-DED25519_NO_INLINE_ASM)
add_definitions(-DROCKSDB_UBSAN_RUN)
elseif(${USING_TSAN})
Expand Down Expand Up @@ -325,8 +339,13 @@ else()
endif()

if(${USING_ASAN_INT})
set(PLATFORM_LINK_FLAGS
"${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined,integer")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(PLATFORM_LINK_FLAGS
"${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined,integer")
else()
set(PLATFORM_LINK_FLAGS
"${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined")
endif()
elseif(${USING_ASAN})
set(PLATFORM_LINK_FLAGS
"${PLATFORM_LINK_FLAGS} -fsanitize=address,undefined")
Expand Down
1 change: 0 additions & 1 deletion asan_blacklist

This file was deleted.

5 changes: 5 additions & 0 deletions asan_blacklist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src:${BOOST_ROOT}/*
src:${PROJECT_SOURCE_DIR}/crypto/*
src:${PROJECT_SOURCE_DIR}/diskhash/*
src:${PROJECT_SOURCE_DIR}/lmdb/*
src:${PROJECT_SOURCE_DIR}/rocksdb/*
1 change: 1 addition & 0 deletions nano/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ endif()
add_library(
nano_lib
${platform_sources}
asan_warnings.hpp
asio.hpp
asio.cpp
blockbuilders.hpp
Expand Down
13 changes: 13 additions & 0 deletions nano/lib/asan_warnings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if defined(__clang__)
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW __attribute__ ((no_sanitize ("unsigned-integer-overflow")))
#else
#define ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW
#endif
#else
#define ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW
#endif
#else
#define ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW
#endif
3 changes: 3 additions & 0 deletions nano/lib/numbers.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <nano/lib/asan_warnings.hpp>

#include <boost/multiprecision/cpp_int.hpp>

namespace nano
Expand Down Expand Up @@ -274,6 +276,7 @@ namespace std
template <>
struct hash<::nano::uint256_union>
{
ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW
size_t operator() (::nano::uint256_union const & data_a) const
{
return data_a.qwords[0] + data_a.qwords[1] + data_a.qwords[2] + data_a.qwords[3];
Expand Down
5 changes: 5 additions & 0 deletions nano/node/xorshift.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#pragma once

#include <nano/lib/asan_warnings.hpp>

#include <array>

namespace nano
Expand All @@ -8,6 +11,8 @@ class xorshift1024star final
public:
std::array<uint64_t, 16> s;
unsigned p{ 0 };

ATTRIBUTE_NO_SANITIZE_UINT_OVERFLOW
uint64_t next ()
{
auto p_l (p);
Expand Down