Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiling on arm64 Linux with GCC #103303

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

aaronfranke
Copy link
Member

I tried to test compiling something in my arm64 Linux VM, specifically Ubuntu 24.04.2 LTS with GCC 13.3.0 and kernel 6.8.0, and I ran into this error:

[ 16%] Compiling modules/gltf/gltf_document.cpp ...
[ 99%] In file included from ./core/templates/vector.h:44,
                 from ./core/templates/local_vector.h:37,
                 from ./core/object/message_queue.h:36,
                 from ./core/object/object.h:35,
                 from ./core/variant/binder_common.h:35,
                 from ./core/object/method_bind.h:34,
                 from ./core/object/class_db.h:34,
                 from ./core/object/ref_counted.h:34,
                 from ./core/io/resource_uid.h:34,
                 from ./core/io/resource.h:34,
                 from modules/gltf/extensions/../extensions/gltf_light.h:34,
                 from modules/gltf/extensions/../gltf_state.h:34,
                 from modules/gltf/extensions/gltf_document_extension.h:34,
                 from modules/gltf/gltf_document.h:34,
                 from modules/gltf/gltf_document.cpp:31:
In member function 'CowData<T>::Size CowData<T>::size() const [with T = signed char]',
    inlined from 'Vector<T>::Size Vector<T>::size() const [with T = signed char]' at ./core/templates/vector.h:99:57,
    inlined from 'Error GLTFDocument::_encode_buffer_view(Ref<GLTFState>, const double*, int, GLTFAccessor::GLTFAccessorType, GLTFAccessor::GLTFComponentType, bool, int, bool, GLTFBufferViewIndex&, bool)' at modules/gltf/gltf_document.cpp:1204:33:
./core/templates/cowdata.h:197:33: error: array subscript -1 is outside array bounds of 'signed char []' [-Werror=array-bounds=]
  197 |                         return *size;
      |                                 ^~~~
cc1plus: all warnings being treated as errors

It seems that the compiler is trying to inline this function, and giving a warning that it is out of bounds, even though it is not out of bounds. A simple fix is to store the buffer size in a variable. This also reduces code duplication. While I was at it, I also made old_size const.

This only occurs on arm64 Linux with GCC. It doesn't occur with scons use_llvm=yes on the same system, and it doesn't occur on any other platforms as far as I can see. This problem also only occurs with Vector<int8_t>, it works fine for all the other integer sizes, however I made the same change for all of them for consistency, plus just in case some other platform out there is incorrectly inlining and warning for a different integer size.

I'm very confident this doesn't change behavior, but I tested exporting and importing a .glb file and it still works correctly.

@aaronfranke aaronfranke added this to the 4.4 milestone Feb 25, 2025
@aaronfranke aaronfranke requested a review from a team as a code owner February 25, 2025 23:09
@akien-mga akien-mga added topic:buildsystem cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Feb 25, 2025
@akien-mga akien-mga merged commit a398f4f into godotengine:master Feb 25, 2025
20 checks passed
@akien-mga
Copy link
Member

Thanks!

@aaronfranke aaronfranke deleted the fix-compile-arm64-linux branch February 25, 2025 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release platform:linuxbsd topic:buildsystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants