Repository navigation
lib: log helpers read class and type names without nameof's fixed offsets (crash on GCC 13 builds) - #100
Open
EnzinoBB wants to merge 1 commit into
Open
lib: log helpers read class and type names without nameof's fixed offsets (crash on GCC 13 builds)#100EnzinoBB wants to merge 1 commit into
EnzinoBB wants to merge 1 commit into
Conversation
The csmeta/csname log helpers (className()) and csexpression/cstype take type names from nameof, which cuts them out of __PRETTY_FUNCTION__ at fixed offsets matching older GCC versions. With GCC 13 the computed length is wrong (negative for short names such as Node, that is huge as a size), so a log line printing such a class or type name reads far past the string and the node ends with a segmentation fault. cs::reflection::typeName<T>() reads the name from the compiler's signature by its "T = " marker instead, for GCC and clang; other compilers keep nameof. Only log text changes; nothing on the wire or in consensus. Test: lib_system Reflection.TypeNamesAreExact pins the names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR
lib/include/lib/system/reflection.hppdefinesclassName()asNAMEOF_TYPE_EXPR(*this), andcsexpression/cstypealso come fromnameof. The log helperscsmeta,csname,csexpressionandcstypeall go through it.The pinned
nameofsubmodule (7e974384) cuts the type name out of__PRETTY_FUNCTION__at fixed offsets that match older GCC versions. With GCC 13 the length it computes is wrong: -12 forNode, 0 forcs::ConveyerBase. As asize_t, -12 is a huge width, so a loggedcsmeta(...)line in such a class reads far past the string and the node ends with a segmentation fault (SIGSEGV through a stack probe in the log formatter). We saw this in CI: an official node built with GCC 13 crashed while writing an error log line, after it had correctly handled the condition that line reports.Builds with older compilers are not affected; any GCC 13 build is, on every warning or error line that prints a class or type name.
What changes
lib/include/lib/system/reflection.hpp: newcs::reflection::typeName<T>()reads the name from the compiler's own signature of that function by itsT =marker (GCC and clang); other compilers (MSVC) keepnameof.className(),csexpressionandcstypeuse it. Only the text of log lines changes.tests/lib_system/lib_system_tests.cpp:Reflection.TypeNamesAreExactchecksclassName()in a polymorphic and a plain class,cstype(int)andcsexpression(value).Effect on the network
None. Only log text is produced differently; nothing on the wire, in storage or in consensus changes.
Tests
Built with GCC 13 and Boost 1.83 on 4a95aaa plus the test fixes of #77 (needed for the test suite to build on GCC 13), results:
ctest3/3,Reflection.TypeNamesAreExactpasses)className()ofreflection_test::Polymorphiccomes out as:Polymorphic(cut at the wrong offset)A standalone check with the pinned
nameofand GCC 13.3 prints the sizes -12 (Node) and 0 (cs::ConveyerBase);typeName<T>()returnsNodeandcs::ConveyerBase.Same change in the community fork: CreditsCommunity#24, running on mainnet community nodes.
🤖 Generated with Claude Code