Statically linking it with libstdc ++ and folly broken because of experimental/exception_tracer
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
In commit: https://github.com/facebook/folly/commit/8140959ee90ac4fd41955f10664a1c4b6ca8dc46#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a
> Permits including `folly/experimental/exception_tracer/` in the cmake build.
>
> Closes: #1524.
>
`experimental/exception_tracer` library became a part of main `CMakeList.txt` file and now a part of main `folly.a` library. But...
This make broken logic described in library annotation:
> Exception tracer library
>
> This library allows you to inspect the exception stack at runtime. The library can be used in three ways:
>
> Link in the exception_tracer_base library. You get access to the functions in ExceptionTracer.h, but no stack traces. This has no runtime overhead, and is compliant with the C++ ABI.
>
> Link in the (full) exception_tracer library. You get access to the functions in ExceptionTracer.h, the std::terminate and std::unexpected handlers are installed by default, and you get full stack traces with all exceptions. This has some runtime overhead (the stack trace must be captured and stored whenever an exception is thrown) added to throw and catch, but no runtime overhead otherwise. This is less portable (depends on internal details of GNU's libstdc++).
>
> LD_PRELOAD libexceptiontracer.so. This is equivalent to #2 above, but requires no link-time changes. On the other hand, you need to ensure that libexceptiontracer.so is compiled with the same compiler and flags as your binary, and the usual caveats about LD_PRELOAD apply (it propagates to child processes, etc)
In principle, it is incorrect because the file `ExceptionTracerLib.cpp` ignores `FOLLY_HAVE_ELF` & `FOLLY_HAVE_DWARF` definitions, although relevant libraries may not be available on the build platform.
**And most dramatically, it made it impossible to build an application by statically linking it with libstdc ++ and folly.**
```
[100%] Linking CXX executable
/usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a(eh_catch.o): In function `__cxa_begin_catch':
(.text.__cxa_begin_catch+0x0): multiple definition of `__cxa_begin_catch'
/usr/local/lib/libfolly.a(ExceptionTracerLib.cpp.o):/tmp/build/folly/folly/experimental/exception_tracer/ExceptionTracerLib.cpp:123: first defined here
```
It would be nice to rollback these changes or still make it cleaner by providing the necessary compilation options.
Contributor guide
Research direction
Start with the main CMakeLists.txt and folly/experimental/exception_tracer/ExceptionTracerLib.cpp, then review how FOLLY_HAVE_ELF and FOLLY_HAVE_DWARF are handled. Reproduce the reported static libstdc++ and folly link failure, and compare the exception tracer annotation with the current build integration. Done means supported builds no longer produce the duplicate-symbol failure while the exception tracer options remain explicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100