protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.88k stars 15.52k forks source link

Bug: Big endian assumed on little endian QNX targets #9920

Open glenn-elliott opened 2 years ago

glenn-elliott commented 2 years ago

What version of protobuf and what language are you using?

Version: v3.15 and later Language: C++

What operating system (Linux, Windows, ...) and version?

QNX SDP 7.0 for aarch64 (little endian)

What runtime / compiler are you using (e.g., python version or gcc version)

gcc 5.4 (supplied with QNX SDP 7.0)

What did you do?

Compile protobuf for a little endian aarch64 QNX SDP 7.0 target.

What did you expect to see

PROTOBUF_LITTLE_ENDIAN should be defined.

What did you see instead?

PROTOBUF_LITTLE_ENDIAN is not defined. We have root-caused this to be why we have observed byte-swapped fixed64 fields (!!).

The method to determine the endianess of the target changed in v3.15. Prior to this, the header sys/param.h was used. It was replaced by a method that includes endian.h for several different platforms. A later change (bd9d47db41) skipped over the inclusion of endian.h for QNX targets, since the file does not exist on the QNX platform. However, this leaves neither sys/param.h nor endian.h included for QNX targets, resulting in PROTOBUF_LITTLE_ENDIAN not being defined on little endian QNX targets.

We suggest small change like this could be applied to src/google/protobuf/stubs/port.h and src/google/protobuf/io/coded_stream.h

 #include <sys/endian.h>  // __BYTE_ORDER
+#elif defined(__QNX__)
+#include <sys/param.h>  // __BYTE_ORDER
 #else
acozzette commented 2 years ago

@glenn-elliott If you want to send a pull request with that change then I would be happy to merge it.