Link error in FiberManager with mixed ASAN config
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
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
#include
#include
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](https://github.com/facebook/folly/blob/af0a489dbc1cac6868651da55ca30d723fe28c4e/folly/fibers/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
Contributor guide
Research direction
Start with folly/fibers/FiberManager.cpp and the FOLLY_SANITIZE_ADDRESS definition in folly/CPortability.h. Reproduce the reported case by building folly without ASAN and the downstream example with -fsanitize=address, then inspect which FiberManager symbols are emitted and referenced. Done means the mixed configuration links and the Futures or Fibers example runs successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100