facebook / folly

An open-source C++ library developed and used at Facebook.
https://groups.google.com/forum/?fromgroups#!forum/facebook-folly
Apache License 2.0
27.53k stars 5.47k forks source link

MSVC, fail building folly with `/fsanitize=address` CXX flag #2021

Open SolomidHero opened 1 year ago

SolomidHero commented 1 year ago

Hi! I found that using following flag leads to errors

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /fsanitize=address")

Installation via vcpkg:

.\vcpkg\vcpkg.exe install folly:x64-windows

my cmake file:

cmake_minimum_required(VERSION 3.24)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /fsanitize=address") # using this line lead to fail
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} /fsanitize=address") # this line is ok in any case

project(AudioStreaming VERSION 0.0.1 LANGUAGES C CXX)
set_property(GLOBAL PROPERTY CXX_STANDARD 17)
set_property(GLOBAL PROPERTY USE_FOLDERS YES)

find_package(folly CONFIG REQUIRED)
set(folly_targets Folly::folly Folly::folly_deps Folly::follybenchmark Folly::folly_test_util)
add_executable(HelloWorld main.cpp)
target_link_libraries(HelloWorld ${folly_targets})

main.cpp:

#include <folly/logging/xlog.h>
#include <folly/logging/LogLevel.h>

int main() {
  XLOG(INFO, "Hello World!");
  return 0;
}

Errors when building in Debug:

cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=C:\Users\Administrator\vcpkg\scripts\buildsystems\vcpkg.cmake ..
cmake --build . --config=Debug

Outputs

Configure and build ```cmake (base) PS C:\Users\Administrator\folly_helloworld\build> cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=C:\Users\Administrator\vcpkg\scripts\buildsystems\vcpkg.cmake .. -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.20348. -- Found libevent include directory: C:/Users/Administrator/vcpkg/installed/x64-windows/include -- Found libevent component: C:/Users/Administrator/vcpkg/installed/x64-windows/debug/bin/event_cored.dll -- Found libevent component: C:/Users/Administrator/vcpkg/installed/x64-windows/bin/event_core.dll -- Found libevent component: C:/Users/Administrator/vcpkg/installed/x64-windows/debug/bin/event_extrad.dll -- Found libevent component: C:/Users/Administrator/vcpkg/installed/x64-windows/bin/event_extra.dll -- Found libevent 2.2.0 in C:/Users/Administrator/vcpkg/installed/x64-windows CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) CMake Warning at C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1384 (message): New Boost version may have incorrect or missing dependencies and imported targets Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:1508 (_Boost_COMPONENT_DEPENDENCIES) C:/Program Files/CMake/share/cmake-3.26/Modules/FindBoost.cmake:2119 (_Boost_MISSING_DEPENDENCIES) C:/Users/Administrator/vcpkg/installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:11 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/folly-config.cmake:84 (find_dependency) C:/Users/Administrator/vcpkg/installed/x64-windows/share/folly/vcpkg-cmake-wrapper.cmake:4 (_find_package) C:/Users/Administrator/vcpkg/scripts/buildsystems/vcpkg.cmake:807 (include) CMakeLists.txt:53 (find_package) -- Found folly: C:/Users/Administrator/vcpkg/installed/x64-windows -- Configuring done (0.2s) -- Generating done (0.1s) -- Build files have been written to: C:/Users/Administrator/folly_helloworld/build (base) PS C:\Users\Administrator\folly_helloworld\build> cmake --build . --config=Debug MSBuild version 17.6.3+07e294721 for .NET Framework main.cpp C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(74,1): error C3861: 'n o_sanitize': identifier not found [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj ] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(75,1): error C2062: ty pe 'unsigned __int64' unexpected [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(76,58): error C2143: s yntax error: missing ';' before '{' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxpr oj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(76,58): error C2447: ' {': missing function header (old-style formal list?) [C:\Users\Administrator\folly_helloworld\build \HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(93,1): error C2374: 'f olly::hash::__attribute__': redefinition; multiple initialization [C:\Users\Administrator\folly_hel loworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(74,1): message : see d eclaration of 'folly::hash::__attribute__' [C:\Users\Administrator\folly_helloworld\build\HelloWorl d.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(93,1): error C3861: 'n o_sanitize': identifier not found [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj ] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(94,1): error C2062: ty pe 'unsigned __int64' unexpected [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(95,58): error C2143: s yntax error: missing ';' before '{' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxpr oj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(95,58): error C2447: ' {': missing function header (old-style formal list?) [C:\Users\Administrator\folly_helloworld\build \HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(104,1): error C2374: ' folly::hash::__attribute__': redefinition; multiple initialization [C:\Users\Administrator\folly_he lloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(74,1): message : see d eclaration of 'folly::hash::__attribute__' [C:\Users\Administrator\folly_helloworld\build\HelloWorl d.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(104,1): error C3861: ' no_sanitize': identifier not found [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxpro j] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(105,1): error C2062: t ype 'unsigned __int64' unexpected [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj ] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(105,55): error C2143: syntax error: missing ';' before '{' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxp roj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(105,55): error C2447: '{': missing function header (old-style formal list?) [C:\Users\Administrator\folly_helloworld\buil d\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(526,40): error C2039: 'twang_mix64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\Hell oWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(49,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(534,2): message : see reference to class template instantiation 'folly::detail::integral_hasher' being compiled [C:\ Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(531,20): error C2039: 'hash_128_to_64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\H elloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(49,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(549,38): error C2039: 'twang_mix64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\Hell oWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(49,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(551,2): message : see reference to class template instantiation 'folly::detail::float_hasher' being compiled [C:\Users \Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(567,18): error C2039: 'hash_128_to_64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\H elloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(49,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(566,20): message : Thi s diagnostic occurred in the compiler generated function 'size_t folly::Hash::operator ()(const T & ,const Ts &...) const' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(904,32): error C3861: 'hash_128_to_64': identifier not found [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vc xproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(904,46): message : 'ha sh_128_to_64': function declaration must be available as none of the arguments depend on a template parameter [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/synchronization/ParkingLot.h(260,2 0): error C2039: 'twang_mix64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_hell oworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(782,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/synchronization/ParkingLot.h(203,1 4): message : This diagnostic occurred in the compiler generated function 'folly::ParkResult folly: :ParkingLot::park_until(const Key,D &&,ToPark &&,PreWait &&,std::chrono::time_point)' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/synchronization/ParkingLot.h(298,2 0): error C2039: 'twang_mix64': is not a member of 'folly::hash' [C:\Users\Administrator\folly_hell oworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/hash/Hash.h(782,11): message : see declaration of 'folly::hash' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxproj] C:\Users\Administrator\vcpkg\installed\x64-windows\include\folly/synchronization/ParkingLot.h(243,8 ): message : This diagnostic occurred in the compiler generated function 'void folly::ParkingLot::unpark(const Key,Unparker &&)' [C:\Users\Administrator\folly_helloworld\build\HelloWorld.vcxpr oj] ```

Seems like uses not needed qualifiers from macros

Is there a way to enable sanitizers in program that uses folly? I also don't care if folly itself package uses or not address sanitizer, but other part of my program.

SolomidHero commented 1 year ago

Hi! Any help?

Orvid commented 1 year ago

If I'm understanding this issue correctly, https://github.com/facebook/folly/pull/1992 should fix this.

Also https://github.com/facebook/folly/pull/2036 should, in theory, make the existing ASAN suppressions work under MSVC as well.