folly icon indicating copy to clipboard operation
folly copied to clipboard

Link error in FiberManager with mixed ASAN config

Open 0xjc opened this issue 4 years ago • 2 comments

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

0xjc avatar Jun 30 '21 17:06 0xjc

Also encountered this problem, and deleting the relevant codes within macro (FOLLY_SANITIZE_ADDRESS) in the header file as a temporarily workaround.

ShigureSuki avatar Aug 26 '21 07:08 ShigureSuki

+1 to this issue, facing exact same problem.

hkadayam avatar Apr 25 '23 01:04 hkadayam