zhoukangsheng commented on PR #2256: URL: https://github.com/apache/brpc/pull/2256#issuecomment-1850074548
> ### What problem does this PR solve? > 高版本编译器编译的brpc,用户异常抛到brpc框架内部导致core栈不完整 > > Issue Number: [程序内部core但是core栈不完整 #1997](https://github.com/apache/brpc/issues/1997) [运行一段时间,就会core在brpc内部 #1437](https://github.com/apache/brpc/issues/1437) [crash #985](https://github.com/apache/brpc/issues/985) > > Problem Summary: 高版本GCC编译器(如GCC12)对于析构函数默认是noexcept的(也有人说是因为C++标准的问题 比如C++11之后才默认noexcept,但是GCC12下我使用C++11和C++17都是默认noexcept的), 低版本的GCC82默认就是noexcept(false)的。 > > 所以当你使用了高版本GCC编译程序的时候,业务代码抛出异常,在进行栈回溯之前会先沿着调用栈寻找处理异常的代码块(专业名词是Landing pad),如果找到Landing pad,那么就会进行栈回溯到Landing pad进行异常处理。找不到Landing pad就会原地调用std::terminate终止程序,这个时候你的core栈就是完整的,不会回溯陷入brpc框架。 > > 从我的测试看,Landing pad 一种是真正的 try catch 块,另一种就是整个调用链上有noexcept属性的函数结束的代码段地址(汇编代码就是一块Unwind_Resume代码块),brpc整个调用链上没有try catch 非 bthread::ExitException 异常的Landing pad。 所以我hook了__gxx_personality_v0函数,找出了具有noexcept属性的函数  > > 修改这个析构函数为noexcept(false)之后,__gxx_personality_v0就在brpc框架内找不到Landing pad代码块了,于是就会在抛异常的地方终止,堆栈也就完整了 > > ### What is changed and the side effects? > Changed: > > Side effects: > > * Performance effects(性能影响): > * Breaking backward compatibility(向后兼容性): > > ### Check List: > * Please make sure your changes are compilable(请确保你的更改可以通过编译). > * When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试). > * Please follow [Contributor Covenant Code of Conduct](../../master/CODE_OF_CONDUCT.md).(请遵循贡献者准则). 给后来者提供一个参考信息,我们在使用c++11,gcc5.2的情况下,析构函数默认也是noexcept(true)的,也会导致core栈不完整,所以brpc一些关键路径上的仿函数,析构函数也需要显示加上noexcept(false) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
