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

Compiling tests fails on s390x (big-endian) with -Werror=stringop-overflow #7366

Closed
musicinmybrain opened this issue Jun 23, 2022 · 2 comments · Fixed by #7422
Closed

Compiling tests fails on s390x (big-endian) with -Werror=stringop-overflow #7366

musicinmybrain opened this issue Jun 23, 2022 · 2 comments · Fixed by #7422

Comments

@musicinmybrain
Copy link
Contributor

Compiling the C++ tests with:

  • Fedora Linux (35, 36, or 37/Rawhide)
  • flatbuffers 2.0.6
  • gcc 11.3.1 or 12.1.1

using the distribution’s default flags for RPM builds, I see the following error on s390x, which is the only big-endian primary architecture in Fedora Linux.

/usr/bin/g++ -DFLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1 -DFLATBUFFERS_LOCALE_INDEPENDENT=1 -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE -I/builddir/build/BUILD/flatbuffers-2.0.6/include -I/builddir/build/BUILD/flatbuffers-2.0.6/grpc -I/builddir/build/BUILD/flatbuffers-2.0.6/redhat-linux-build/tests -I/builddir/build/BUILD/flatbuffers-2.0.6/redhat-linux-build/samples -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=zEC12 -mtune=z13 -fasynchronous-unwind-tables -fstack-clash-protection -std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow -faligned-new -Werror=implicit-fallthrough=2 -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter -fsigned-char -DNDEBUG -MD -MT CMakeFiles/flattests.dir/tests/test.cpp.o -MF CMakeFiles/flattests.dir/tests/test.cpp.o.d -o CMakeFiles/flattests.dir/tests/test.cpp.o -c /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/array.h:20,
                 from /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/flatbuffers.h:22,
                 from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:19:
In function 'flatbuffers::WriteScalar<unsigned char>(void*, unsigned char)void',
    inlined from 'flatbuffers::Vector<unsigned char>::Mutate(unsigned int, unsigned char const&)' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/vector.h:226:16,
    inlined from 'MutateFlatBuffersTest(unsigned char*, unsigned long)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:473:20:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  420 |   *reinterpret_cast<T *>(p) = EndianScalar(t);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:24:
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h: In function 'MutateFlatBuffersTest(unsigned char*, unsigned long)':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h:1244:8: note: at offset 14 into destination object '<anonymous>' of size 1
 1244 | struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
      |        ^~~~~~~
In function 'flatbuffers::WriteScalar<unsigned char>(void*, unsigned char)void',
    inlined from 'flatbuffers::Vector<unsigned char>::Mutate(unsigned int, unsigned char const&)' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/vector.h:226:16,
    inlined from 'MutateFlatBuffersTest(unsigned char*, unsigned long)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:475:20:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  420 |   *reinterpret_cast<T *>(p) = EndianScalar(t);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h: In function 'MutateFlatBuffersTest(unsigned char*, unsigned long)':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/monster_test_generated.h:1244:8: note: at offset 14 into destination object '<anonymous>' of size 1
 1244 | struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
      |        ^~~~~~~
In function 'flatbuffers::WriteScalar<signed char>(void*, signed char)void',
    inlined from 'flatbuffers::Table::SetField<signed char>(unsigned short, signed char)bool' at /builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/table.h:83:16,
    inlined from 'optional_scalars::ScalarStuff::mutate_maybe_i8(signed char)' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h:147:28,
    inlined from 'OptionalScalarsTest()' at /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:3986:3:
/builddir/build/BUILD/flatbuffers-2.0.6/include/flatbuffers/base.h:420:29: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  420 |   *reinterpret_cast<T *>(p) = EndianScalar(t);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /builddir/build/BUILD/flatbuffers-2.0.6/tests/test.cpp:27:
/builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h: In function 'OptionalScalarsTest()':
/builddir/build/BUILD/flatbuffers-2.0.6/tests/optional_scalars_generated.h:93:8: note: at offset 1 into destination object '<anonymous>' of size 1
   93 | struct ScalarStuff FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
      |        ^~~~~~~~~~~
cc1plus: all warnings being treated as errors

If I add -Wno-error=stringop-overflow, the build succeeds and the tests pass. I have not attempted to determine whether the warning reflects a real problem.

@aardappel
Copy link
Collaborator

aardappel commented Aug 8, 2022

The class Vector it writes to has statically indeed 0 bytes at the pointer returned from data() that Mutate is writing to. This is intentional since it is a handle into serialized memory. As such, there is no way for us to silence this warning with code, it simply must be turned off for anything in the FlatBuffers headers.

It should not represent a real problem by itself.

It is curious we have not seen this warning ever before on any other systems, and does not appear related to big-endian-ness. Great to hear things are working on big-endian, since unfortunately we do not have a big-endian CI machine.

@dbaileychess
Copy link
Collaborator

Thanks for the report!

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 a pull request may close this issue.

3 participants