Link error in FiberManager with mixed ASAN config
When folly is compiled without ASAN, but the project using folly is compiled with ASAN, the following linker error occurs:
/usr/bin/ld: CMakeFiles/hello.dir/main.cpp.o: in function `folly::fibers::FiberManager::activateFiber(folly::fibers::Fiber*)::{lambda()#1}::operator()() const':
/usr/local/include/folly/fibers/FiberManagerInternal-inl.h:76: undefined reference to `folly::fibers::FiberManager::registerFinishSwitchStackWithAsan(void*, void const**, unsigned long*)'
/usr/bin/ld: CMakeFiles/hello.dir/main.cpp.o: in function `folly::fibers::FiberManager::activateFiber(folly::fibers::Fiber*)':
/usr/local/include/folly/fibers/FiberManagerInternal-inl.h:74: undefined reference to `folly::fibers::FiberManager::registerStartSwitchStackWithAsan(void**, void const*, unsigned long)'
The issue occurs when the code uses Futures or Fibers.
#include <iostream>
#include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/futures/Future.h>
int main() {
folly::CPUThreadPoolExecutor exec(1);
folly::via(&exec).thenValue([](auto&&) {
std::cout << "hello" << std::endl;
}).wait();
}
The project was compiled with -fsanitize=address in Debug configuration, while the folly library was compiled without any special options in Debug configuration.
The issue seems to relate to the use of FOLLY_SANITIZE_ADDRESS in a .cpp file, FiberManager.cpp. If folly is compiled without ASAN, then the functions registerFinishSwitchStackWithAsan, etc. won't be compiled into folly, causing the undefined reference issue later on.
The issue does not occur if both folly and the downstream project are compiled with ASAN. But it seems that the mixed ASAN configuration is intended to be supported, as shown by this comment:
https://github.com/facebook/folly/blob/120926cdbf20496eba553cc6c62b7499cfdcdd96/folly/CPortability.h#L62-L73
Also encountered this problem, and deleting the relevant codes within macro (FOLLY_SANITIZE_ADDRESS) in the header file as a temporarily workaround.
+1 to this issue, facing exact same problem.