Skip to content

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
CREDITSCOM:masterfrom
CreditsCommunity:official/log-class-names
Open

EnzinoBB wants to merge 1 commit into
CREDITSCOM:masterfrom
CreditsCommunity:official/log-class-names

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Nov 4, 2026

Copy link
Copy Markdown

Why this PR

lib/include/lib/system/reflection.hpp defines className() as NAMEOF_TYPE_EXPR(*this), and csexpression/cstype also come from nameof. The log helpers csmeta, csname, csexpression and cstype all go through it.

The pinned nameof submodule (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 for Node, 0 for cs::ConveyerBase. As a size_t, -12 is a huge width, so a logged csmeta(...) 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: new cs::reflection::typeName<T>() reads the name from the compiler's own signature of that function by its T = marker (GCC and clang); other compilers (MSVC) keep nameof. className(), csexpression and cstype use it. Only the text of log lines changes.
  • tests/lib_system/lib_system_tests.cpp: Reflection.TypeNamesAreExact checks className() in a polymorphic and a plain class, cstype(int) and csexpression(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:

A standalone check with the pinned nameof and GCC 13.3 prints the sizes -12 (Node) and 0 (cs::ConveyerBase); typeName<T>() returns Node and cs::ConveyerBase.

Same change in the community fork: CreditsCommunity#24, running on mainnet community nodes.

🤖 Generated with Claude Code

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant