You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CMake: Tests crashing on Linux with "stack smashing detected" #1741
When I'm testing @enetheru's PRs, I do frequently run the tests, and I even tried rolling back to older versions that I thought I had tested, but at the moment they all crash, unless I go all the way back to 7d3870b
I tried doing a git bisect to find if there was a particular commit that broke it, but it's super hard to do because godot-cpp and Godot compatibility are intertwined and I'd need to pair with a Godot build from the same time period to be sure that that wasn't the cause of the crashes.
(Git bisect did conclude that 5c9529f was the first bad one, but I tried modifying current master to roll back those changes and use classdb_register_extension_class3 - it still crashed with the "stack smashing" error. So, I think my bisect was tainted by not matching with older Godot builds?)
However, if I build the tests using scons, then they run fine :-/
It's super weird!
Steps to reproduce
I'm building the tests like this:
mkdir cmake-build
cd cmake-build
cmake .. -DGODOTCPP_ENABLE_TESTING=YES -G Ninja
cmake --build . -target godot-cpp.test.template_debug
cd ..
... and then running them like this:
cd test
GODOT=/path/to/godot ./run-tests.sh
I'd love if anyone else on Linux could test and see if this is just me, or if there's a real problem here :-)
Minimal reproduction project
This is with the tests that come with the godot-cpp repo in the test/ directory
I think there really is a problem for me to solve
I'm using godot-cpp master
using Godot 4.4-stable-official, and my own compile of 4.4.1 with I believe harmless extras.
Build configuration is template_debug, with build_profile set to speed things up. but no other changes.
My problem was from cmake adding /RTC1 in debug builds which is an msvc flag for runtime error checking for stack issues.
This used to be present i believe in older versions. I have a PR for it, but I dont know how much of a solution it is, feels like hiding the real problem.
Which is the conclusion you came to already, and by the looks of it it just implements the changes for the updates in godot.
So the next step is figuring out why godot is smashing the stack. which I honestly have no idea how to go about.
I also got a failure if i reverted 65046d0 , so i created a branch at 65046d0, reverted it, and then replayed all the commits after and it works. :|
If I then cherry pick the commit, no matter what I api file i dump I either cant get it to compile because of missing hash values when performing code generation, or it exhibits the same error.
OK but hows this.. in my branch without 65046d0, i can dump godot-4.5-dev1 api, and compile, and it still exhibits the same error. WTF, so its the changes introduced in the api.json, and not necessarily the virtual method compatibility system? I'm just not that familiar with how this all fits together, its hard to understand.
This stacktrace is from my custom godot-4.4.1 build using the api dumped from it. with the godot-cpp branch with all changes except the virtual method compatibility. this is the only debug build i have on hand, all the other tests were with godot-4.5-dev1 or godot-4.4.1-stable
OK so i dont get it. I changed back to the master branch, added my /RTC1 call, and removed the meta keyword from the get and set_unicode functions. I get a passing test. I thought i screwed up the /RTC1 thing and re-did it which is why there are probably emails for deleted messages.
The only difference is the removal of the meta value, whats with that. It changes the expression of the get/set unicode functions from generation to use uint64_t rather than char32_t ..
I can see in the godot source its intended to be char32_t, I don't understand.
As the function arguments worm their way through the gdextension indirection, this function has the job of writing the uint32_t value. Except it says that *(int64_t *)p_ptr = p_val; writes a 64 bit value which probably clobbers the stack protection.
So I'm just going to go ahead and try changing it and compiling and see.
Except it says that *(int64_t *)p_ptr = p_val; writes a 64 bit value which probably clobbers the stack protection.
I think this bit of code is actually correct, because EncodeT is int64_t, and so that's what the pointer should be pointing to. But I think you're right, that the pointer isn't actually pointing to an int64_t, but a 32-bit value, and that's the problem.
So, I think the real fix, is finding where the value backing that pointer is, and I think that leads us back to godot-cpp :-)
The problem might be in godot-cpp's _call_native_mb_ret() (and probably all the similar *_ret() functions). I'll poke around and see if I can make a fix..
Doesnt that mean that the code generator meta value is needed twice? one for the native c++ inside the godot engine, and one for the native one in godot-cpp?
This is too confusing, if the godot-cpp code generator gets all its values from the registrations in godot, then it would be assumed that the char32_t is the appropriate type for both reading and writing. but i know godot's internal ints are 64 bit, so it would only write half the value if it was done differently?
There's the types that the engine uses for the actual function call, and then there's the type used for encoding values in ptrcalls (which is a Godot specific convention). Based on the PtrToArg<char32_t>::EncodeT, we're encoding char32_t's as pointers to int64_t when making ptrcalls. It looks like godot-cpp isn't actually doing that, though, it's using a pointer to a char32_t.
Just to give potential future investigators some links, it looks like this issue was caused when Godot started adding "meta" for char16_t and char32_t in PR godotengine/godot#95840, and when we adjusted godot-cpp for that change in PR #1554, we didn't ensure that those new types would be encoded correctly
Activity
enetheru commentedon Mar 27, 2025
I have a hunch, can you test for me compiling in Release mode like so:
Using the -S <source_dir> and -B <build_dir> is just cosmetic.
enetheru commentedon Mar 27, 2025
I've had some time to compile godot and test.
I think there really is a problem for me to solve
I'm using godot-cpp master
using Godot 4.4-stable-official, and my own compile of 4.4.1 with I believe harmless extras.
Build configuration is
template_debug, withbuild_profileset to speed things up. but no other changes.Scons compiled dll:
scons build_profile=build_profile.jsongodot -e --path project- Loads editor fine, Play: Test Passedgodot --path project- Test Passedgodot-4.4.1-custom -e --path test\project\- Loads editor fine, Play: Test Passedgodot-4.4.1-custom --path test\project\- Test PassedCMake compiled dll:
cmake -S . -B cmake-build --fresh -DGODOTCPP_ENABLE_TESTING=YES -DGODOTCPP_BUILD_PROFILE=".\test\build_profile.json"cmake --build cmake-build -t godot-cpp-testgodot-4.4 -e --path test\project\- Loads editor fine, Play: No outputgodot-4.4 --path test\project\- No outputgodot-4.4.1-custom -e --path test\project\- Loads editor fine, Play: No editor output, console shows backtracegodot-4.4 --path test\project\- Crash with BacktraceLoaded with a godot with debug symbols, my stacktrace looks nothing like what you describe, so I'm going to go do more testing.
enetheru commentedon Mar 27, 2025
My problem was from cmake adding /RTC1 in debug builds which is an msvc flag for runtime error checking for stack issues.
This used to be present i believe in older versions. I have a PR for it, but I dont know how much of a solution it is, feels like hiding the real problem.
enetheru commentedon Mar 28, 2025
OK, so we discussed and discovered that adding /rtc1 to scons also causes the bug to appear.
added /RTC1 to godot-cpp
This is what I have so far
enetheru commentedon Mar 28, 2025
Which is the conclusion you came to already, and by the looks of it it just implements the changes for the updates in godot.
So the next step is figuring out why godot is smashing the stack. which I honestly have no idea how to go about.
enetheru commentedon Mar 28, 2025
I also got a failure if i reverted 65046d0 , so i created a branch at 65046d0, reverted it, and then replayed all the commits after and it works. :|
If I then cherry pick the commit, no matter what I api file i dump I either cant get it to compile because of missing hash values when performing code generation, or it exhibits the same error.
enetheru commentedon Mar 28, 2025
OK but hows this.. in my branch without 65046d0, i can dump godot-4.5-dev1 api, and compile, and it still exhibits the same error. WTF, so its the changes introduced in the api.json, and not necessarily the virtual method compatibility system? I'm just not that familiar with how this all fits together, its hard to understand.
This stacktrace is from my custom godot-4.4.1 build using the api dumped from it. with the godot-cpp branch with all changes except the virtual method compatibility. this is the only debug build i have on hand, all the other tests were with godot-4.5-dev1 or godot-4.4.1-stable
enetheru commentedon Mar 28, 2025
OK for a laugh, i searched the api.json for
get_unicodeand reverted the difference, and I it worked.same for godot-4.5-dev1
enetheru commentedon Mar 28, 2025
OK so i dont get it. I changed back to the master branch, added my /RTC1 call, and removed the meta keyword from the get and set_unicode functions. I get a passing test. I thought i screwed up the /RTC1 thing and re-did it which is why there are probably emails for deleted messages.
The only difference is the removal of the meta value, whats with that. It changes the expression of the get/set unicode functions from generation to use uint64_t rather than char32_t ..
I can see in the godot source its intended to be char32_t, I don't understand.
enetheru commentedon Mar 28, 2025
changing the meta value to uint32 to change the function signature doesn't trigger the stack error
enetheru commentedon Mar 28, 2025
How the functions calls work their way through the boundary is too complicated for me.
And whils't I gave it a good shot, I ended up asking grok to help trace the execution flow.
https://x.com/i/grok/share/VfJp1ANgpO1fxXwpAmHL72iPt
It determined that this is the problem here:
core/variant/binder_common.h:224
As the function arguments worm their way through the gdextension indirection, this function has the job of writing the uint32_t value. Except it says that
*(int64_t *)p_ptr = p_val;writes a 64 bit value which probably clobbers the stack protection.So I'm just going to go ahead and try changing it and compiling and see.
enetheru commentedon Mar 28, 2025
Compilation of godot with the change worked.
I loaded up other extensions too, and no errors, so far.
I think this was it. what do you think?
dsnopek commentedon Mar 28, 2025
@enetheru Great investigation work!
I think this bit of code is actually correct, because
EncodeTisint64_t, and so that's what the pointer should be pointing to. But I think you're right, that the pointer isn't actually pointing to anint64_t, but a 32-bit value, and that's the problem.So, I think the real fix, is finding where the value backing that pointer is, and I think that leads us back to godot-cpp :-)
The problem might be in godot-cpp's
_call_native_mb_ret()(and probably all the similar*_ret()functions). I'll poke around and see if I can make a fix..enetheru commentedon Mar 28, 2025
Doesnt that mean that the code generator meta value is needed twice? one for the native c++ inside the godot engine, and one for the native one in godot-cpp?
This is too confusing, if the godot-cpp code generator gets all its values from the registrations in godot, then it would be assumed that the char32_t is the appropriate type for both reading and writing. but i know godot's internal ints are 64 bit, so it would only write half the value if it was done differently?
dsnopek commentedon Mar 28, 2025
There's the types that the engine uses for the actual function call, and then there's the type used for encoding values in ptrcalls (which is a Godot specific convention). Based on the
PtrToArg<char32_t>::EncodeT, we're encodingchar32_t's as pointers toint64_twhen making ptrcalls. It looks like godot-cpp isn't actually doing that, though, it's using a pointer to achar32_t.I think this PR is the fix: #1753
enetheru commentedon Mar 28, 2025
Nice, I'm honestly surprised I could trace the origin, even with the help. :D
dsnopek commentedon Mar 28, 2025
Just to give potential future investigators some links, it looks like this issue was caused when Godot started adding "meta" for
char16_tandchar32_tin PR godotengine/godot#95840, and when we adjusted godot-cpp for that change in PR #1554, we didn't ensure that those new types would be encoded correctly