facebook / fbthrift

Facebook's branch of Apache Thrift, including a new C++ server.
Apache License 2.0
2.55k stars 609 forks source link

clang18 + libc++abi unittest failure #607

Open sternezsl opened 3 weeks ago

sternezsl commented 3 weeks ago

When running unittest thrift/lib/cpp2/test/FutureTest.cpp

# ./bin/cpp2_test_FutureTest
[==========] Running 8 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 8 tests from ThriftServer
[ RUN      ] ThriftServer.FutureExceptions
*** Aborted at 1717719275 (Unix time, try 'date -d @1717719275') ***
*** Signal 11 (SIGSEGV) (0x399f5aa1403e8) received by PID 2529977 (pthread TID 0xffff257aa180) (linux TID 2529977) (c
ode: address not mapped to object), stack trace: ***
/usr/lib64/libfolly.so.1(_ZN5folly10symbolizer21SafeStackTracePrinter15printStackTraceEb+0x3b) [0xffff2236fa07]
/usr/lib64/libfolly.so.1(_ZN5folly10symbolizer21SafeStackTracePrinter15printStackTraceEb+0x3b) [0xffff2236fa07]
/usr/lib64/libfolly.so.1(+0x3ed8cb) [0xffff2236d8cb]
linux-vdso.so.1(__kernel_rt_sigreturn+0) [0xffff257f8820]
/opt/llvm/18.1.6/lib/aarch64-unknown-linux-gnu/libc++abi.so.1(__dynamic_cast+0x1f) [0xffff2172075b]
/usr/lib64/libthriftcpp2.so.1.0.0(_ZN6apache6thrift12Thr
iftServer19setProcessorFactoryENSt3__110shared_ptrINS0_21AsyncProcessorFactoryEEE+0xf7) [0xffff236dcd1b]
./bin/cpp2_test_FutureTest(_ZN6apache6thrift23TestThriftServerFactoryI13TestInterfaceE6createEv+0x293) [0xaaab7c00a8d
b]
./bin/cpp2_test_FutureTest(_ZN34ThriftServer_FutureExceptions_Test8TestBodyEv+0x43) [0xaaab7c00453b]
/usr/lib64/libgtest.so(_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc+0x6f\
) [0xffff21915f1f]
/usr/lib64/libgtest.so(_ZN7testing4Test3RunEv+0xe3) [0xffff218f8047]
/usr/lib64/libgtest.so(_ZN7testing8TestInfo3RunEv+0x103) [0xffff218f94eb]
/usr/lib64/libgtest.so(_ZN7testing9TestSuite3RunEv+0x13b) [0xffff218f9daf]
/usr/lib64/libgtest.so(_ZN7testing8internal12UnitTestImpl11RunAllTestsEv+0x413) [0xffff2190772f]
/usr/lib64/libgtest.so(_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_\
vEPKc+0x6f) [0xffff21916d97]
/usr/lib64/libgtest.so(_ZN7testing8UnitTest3RunEv+0x7f) [0xffff219072e3]
/usr/lib64/libfolly_test_support.so(main+0x3b) [0xffff23a957cf]
/lib64/libc.so.6(+0x30a1b) [0xffff21a10a1b]
/lib64/libc.so.6(+0x30a1b) [0xffff21a10a1b]
(safe mode, symbolizer not available)

It crashed on https://github.com/facebook/fbthrift/blob/7db5a066e9d011c19e1df8b3e07aa37e3b7e9c99/thrift/lib/cpp2/server/ThriftServer.cpp#L393 Simple demo built with c++20 works well. The platform is linux aarch64(same segmentfault on macOS m1), LLVM version is 18.1.6

sternezsl commented 3 weeks ago

The reason is that there is a change related dynamic_cast in LLVM 17.0.1 https://releases.llvm.org/17.0.1/tools/clang/docs/ReleaseNotes.html

Improved code generation for dynamic_cast to a final type. Instead of dispatching to the runtime library to compare the RTTI data, Clang now generates a direct comparison of the vtable pointer in cases where the ABI requires the vtable for a class to be unique. This optimization can be disabled with -fno-assume-unique-vtables. This optimization is not yet implemented for the MS C++ ABI.

After add the compile option -fno-assume-unique-vtables, everything works now.