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

Build issues on QNX 7.0 #8593

Closed
dschopf opened this issue May 10, 2021 · 3 comments
Closed

Build issues on QNX 7.0 #8593

dschopf opened this issue May 10, 2021 · 3 comments
Labels
c++ platform related Any issue releated to specific platform or OS

Comments

@dschopf
Copy link
Contributor

dschopf commented May 10, 2021

What version of protobuf and what language are you using?
Version: v3.16.0
Language: C++

What operating system (Linux, Windows, ...) and version?
QNX 7.0 build on Ubuntu 20.04

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

What did you do?
Steps to reproduce the behavior:
Check out v3.16.0
Run CC=qcc CXX=q++ ./configure --host aarch64-qnx-gnu && make

What did you expect to see
Build succeeds

What did you see instead?
Build fails

First, there are many errors about #include <endian.h>, which is not available on QNX.
This can be fixed with the following patch which also adds support for 64 bit builds:

diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index b6c11d27a..1cf006832 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -136,8 +136,10 @@
 #elif defined(__FreeBSD__)
 #include <sys/endian.h>  // __BYTE_ORDER
 #else
+#if !defined(__QNX__)
 #include <endian.h>  // __BYTE_ORDER
 #endif
+#endif
 #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) ||    \
      (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \
     !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
diff --git a/src/google/protobuf/stubs/platform_macros.h b/src/google/protobuf/stubs/platform_macros.h
index ce1b1e365..6d8135755 100644
--- a/src/google/protobuf/stubs/platform_macros.h
+++ b/src/google/protobuf/stubs/platform_macros.h
@@ -46,7 +46,11 @@
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
 #elif defined(__QNX__)
 #define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1
+#if defined(aarch64)
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
+#else
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
+#endif
 #elif defined(_M_ARM) || defined(__ARMEL__)
 #define GOOGLE_PROTOBUF_ARCH_ARM 1
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h
index 0f3b5aa62..a64101862 100644
--- a/src/google/protobuf/stubs/port.h
+++ b/src/google/protobuf/stubs/port.h
@@ -62,8 +62,10 @@
 #elif defined(__FreeBSD__)
 #include <sys/endian.h>  // __BYTE_ORDER
 #else
+#if !defined(__QNX__)
 #include <endian.h>  // __BYTE_ORDER
 #endif
+#endif
 #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) ||   \
      (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
      (defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN)) &&      \

Once this is fixed, there are additional errors due to -std=c++11being used instead of -std=gnu++11, which I could fix like this

diff --git a/configure.ac b/configure.ac
index 6251e37f3..7627152d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,7 +93,7 @@ AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
   # Protocol Buffers contains several checks that are intended to be used only
   # for debugging and which might hurt performance.  Most users are probably
   # end users who don't want these checks, so add -DNDEBUG by default.
-  CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG"
+  CXXFLAGS="$CXXFLAGS -std=gnu++11 -DNDEBUG"

   AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS])
 ],[

But for the final error, I am not sure, since this also happens in the generated code:

google/protobuf/descriptor.pb.cc: In constructor 'constexpr google::protobuf::SourceCodeInfo_Location::SourceCodeInfo_Location(google::protobuf::internal::ConstantInitialized)':
google/protobuf/descriptor.pb.cc:401:88: error: call to non-constexpr function 'std::__1::atomic<_Tp>::atomic() [with _Tp = int]'
   , trailing_comments_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
                                                                                        ^
In file included from ./google/protobuf/io/coded_stream.h:115:0,
                 from ./google/protobuf/descriptor.pb.h:23,
                 from google/protobuf/descriptor.pb.cc:4:
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:1008:5: note: 'std::__1::atomic<_Tp>::atomic() [with _Tp = int]' is not usable as a constexpr function because:
     atomic() _NOEXCEPT _LIBCPP_DEFAULT
     ^
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:927:5: note: defaulted constructor calls non-constexpr 'std::__1::__atomic_base<_Tp, true>::__atomic_base() [with _Tp = int]'
     __atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
     ^
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:927:5: note: 'std::__1::__atomic_base<_Tp, true>::__atomic_base() [with _Tp = int]' is not usable as a constexpr function because:
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:900:5: note: defaulted constructor calls non-constexpr 'std::__1::__atomic_base<_Tp, <anonymous> >::__atomic_base() [with _Tp = int; bool <anonymous> = false]'
     __atomic_base() _NOEXCEPT = default;
     ^
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:900:5: note: 'std::__1::__atomic_base<_Tp, <anonymous> >::__atomic_base() [with _Tp = int; bool <anonymous> = false]' is not usable as a constexpr function because:
/opt/toolchains/qnx700/target/qnx7/usr/include/c++/v1/atomic:562:3: note: defaulted constructor calls non-constexpr 'std::__1::__gcc_atomic::__gcc_atomic_t<_Tp>::__gcc_atomic_t() [with _Tp = int]'
   __gcc_atomic_t() _NOEXCEPT {}
   ^
google/protobuf/descriptor.pb.cc: In constructor 'constexpr google::protobuf::GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(google::protobuf::internal::ConstantInitialized)':
google/protobuf/descriptor.pb.cc:429:13: error: call to non-constexpr function 'std::__1::atomic<_Tp>::atomic() [with _Tp = int]'
   , end_(0){}
             ^
cc: /opt/toolchains/qnx700/host/linux/x86_64/usr/lib/gcc/i586-pc-nto-qnx7.0.0/5.4.0/cc1plus error 1

The following patch fixes this as well:

diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc
index c22ae431c..4df886ab6 100644
--- a/src/google/protobuf/descriptor.pb.cc
+++ b/src/google/protobuf/descriptor.pb.cc
@@ -393,9 +393,9 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT UninterpretedOptionDefaultTypeI
 constexpr SourceCodeInfo_Location::SourceCodeInfo_Location(
   ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
   : path_()
-  , _path_cached_byte_size_()
+  , _path_cached_byte_size_(0)
   , span_()
-  , _span_cached_byte_size_()
+  , _span_cached_byte_size_(0)
   , leading_detached_comments_()
   , leading_comments_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
   , trailing_comments_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string){}
@@ -423,7 +423,7 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT SourceCodeInfoDefaultTypeIntern
 constexpr GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(
   ::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized)
   : path_()
-  , _path_cached_byte_size_()
+  , _path_cached_byte_size_(0)
   , source_file_(&::PROTOBUF_NAMESPACE_ID::internal::fixed_address_empty_string)
   , begin_(0)
   , end_(0){}

Am I supposed to fix this manually for all .pb.cc files or could this be fixed more generally?

And finally there is a linker error, which I don't care about because I can run protoc on my host system:

/opt/toolchains/qnx700/host/linux/x86_64/usr/bin/i586-pc-nto-qnx7.0.0-ld: .libs/protoc: hidden symbol `__moddi3' in /opt/toolchains/qnx700/host/linux/x86_64/usr/lib/gcc/i586-pc-nto-qnx7.0.0/5.4.0/pic/libgcc.a(_moddi3.o) is referenced by DSO
/opt/toolchains/qnx700/host/linux/x86_64/usr/bin/i586-pc-nto-qnx7.0.0-ld: final link failed: Bad value
cc: /opt/cinemo/toolchains/qnx700/host/linux/x86_64/usr/bin/i586-pc-nto-qnx7.0.0-ld error 1
@haberman
Copy link
Member

Feel free to send a PR for these fixes.

The codegen fixes can be made in the code generator, for example:

format("\n, _$name$_cached_byte_size_()");

format("\n, _$name$_cached_byte_size_()");

Which errors did you get that require -std=gnu++11?

@dschopf
Copy link
Contributor Author

dschopf commented May 21, 2021

The errors which require -std=gnu++11 are these:

google/protobuf/io/zero_copy_stream_impl.cc: In function 'int google::protobuf::io::{anonymous}::close_no_eintr(int)':
google/protobuf/io/zero_copy_stream_impl.cc:76:22: error: 'close' was not declared in this scope
     result = close(fd);
                      ^
google/protobuf/io/zero_copy_stream_impl.cc: In member function 'virtual int google::protobuf::io::FileInputStream::CopyingFileInputStream::Read(void*, int)':
google/protobuf/io/zero_copy_stream_impl.cc:136:38: error: 'read' was not declared in this scope
     result = read(file_, buffer, size);
                                      ^
google/protobuf/io/zero_copy_stream_impl.cc: In member function 'virtual int google::protobuf::io::FileInputStream::CopyingFileInputStream::Skip(int)':
google/protobuf/io/zero_copy_stream_impl.cc:150:61: error: 'lseek' was not declared in this scope
   if (!previous_seek_failed_ && lseek(file_, count, SEEK_CUR) != (off_t)-1) {
                                                             ^
google/protobuf/io/zero_copy_stream_impl.cc: In member function 'virtual bool google::protobuf::io::FileOutputStream::CopyingFileOutputStream::Write(const void*, int)':
google/protobuf/io/zero_copy_stream_impl.cc:218:77: error: 'write' was not declared in this scope
       bytes = write(file_, buffer_base + total_written, size - total_written);
                                                                             ^
google/protobuf/io/zero_copy_stream_impl.cc: In member function 'virtual int google::protobuf::io::FileInputStream::CopyingFileInputStream::Skip(int)':
google/protobuf/io/zero_copy_stream_impl.cc:163:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

It looks like there are some defines which accomplish the same while still using -std=c++11, I will have to check.

Yes, defining _XOPEN_SOURCE fixes these issues for me with -std=c++11.

fowles added a commit that referenced this issue Jun 4, 2021
@elharo elharo added c++ platform related Any issue releated to specific platform or OS labels Aug 25, 2021
@deannagarcia
Copy link
Member

Closing since the PR to fix has already been merged.

bithium pushed a commit to bithium/protobuf that referenced this issue Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ platform related Any issue releated to specific platform or OS
Projects
None yet
Development

No branches or pull requests

4 participants