google / s2geometry

Computational geometry and spatial indexing on the sphere
http://s2geometry.io/
Apache License 2.0
2.32k stars 308 forks source link

BN_ext_get_uint64 fails to compile on ARM 32 with OpenSSL1.1 #157

Closed rinigus closed 3 years ago

rinigus commented 3 years ago

As expected earlier by others, current s2geometry fails to compile on ARM 32-bit platform:

/usr/bin/c++  -DABSL_MIN_LOG_LEVEL=1 -Ds2_EXPORTS -Isrc -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fPIC   -Wno-attributes -Wno-deprecated-declarations -std=c++11 -MD -MT CMakeFiles/s2.dir/src/s2/util/math/exactfloat/exactfloat.cc.o -MF CMakeFiles/s2.dir/src/s2/util/math/exactfloat/exactfloat.cc.o.d -o CMakeFiles/s2.dir/src/s2/util/math/exactfloat/exactfloat.cc.o -c src/s2/util/math/exactfloat/exactfloat.cc
src/s2/util/math/exactfloat/exactfloat.cc: In function ‘uint64 BN_ext_get_uint64(const BIGNUM*)’:
src/s2/util/math/exactfloat/exactfloat.cc:104:9: error: invalid use of incomplete type ‘const BIGNUM’ {aka ‘const struct bignum_st’}
  104 |   if (bn->top == 0) return 0;
      |         ^~
In file included from /usr/include/openssl/bn.h:19,
                 from src/s2/util/math/exactfloat/exactfloat.h:119,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM’ {aka ‘struct bignum_st’}
   80 | typedef struct bignum_st BIGNUM;
      |                ^~~~~~~~~
src/s2/util/math/exactfloat/exactfloat.cc:105:9: error: invalid use of incomplete type ‘const BIGNUM’ {aka ‘const struct bignum_st’}
  105 |   if (bn->top == 1) return BN_get_word(bn);
      |         ^~
In file included from /usr/include/openssl/bn.h:19,
                 from src/s2/util/math/exactfloat/exactfloat.h:119,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM’ {aka ‘struct bignum_st’}
   80 | typedef struct bignum_st BIGNUM;
      |                ^~~~~~~~~
In file included from src/s2/util/math/exactfloat/exactfloat.h:122,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
src/s2/util/math/exactfloat/exactfloat.cc:106:18: error: invalid use of incomplete type ‘const BIGNUM’ {aka ‘const struct bignum_st’}
  106 |   S2_DCHECK_EQ(bn->top, 2);
      |                  ^~
src/s2/base/logging.h:131:7: note: in definition of macro ‘S2_LOG_IF’
  131 |     !(condition) ? (void)0 : S2LogMessageVoidify() & S2_LOG(severity)
      |       ^~~~~~~~~
src/s2/base/logging.h:134:22: note: in expansion of macro ‘ABSL_PREDICT_FALSE’
  134 |     S2_LOG_IF(FATAL, ABSL_PREDICT_FALSE(!(condition))) \
      |                      ^~~~~~~~~~~~~~~~~~
src/s2/base/logging.h:140:19: note: in expansion of macro ‘S2_CHECK’
  140 | #define S2_DCHECK S2_CHECK
      |                   ^~~~~~~~
src/s2/base/logging.h:160:34: note: in expansion of macro ‘S2_DCHECK_OP’
  160 | #define S2_DCHECK_EQ(val1, val2) S2_DCHECK_OP(==, val1, val2)
      |                                  ^~~~~~~~~~~~
src/s2/util/math/exactfloat/exactfloat.cc:106:3: note: in expansion of macro ‘S2_DCHECK_EQ’
  106 |   S2_DCHECK_EQ(bn->top, 2);
      |   ^~~~~~~~~~~~
In file included from /usr/include/openssl/bn.h:19,
                 from src/s2/util/math/exactfloat/exactfloat.h:119,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM’ {aka ‘struct bignum_st’}
   80 | typedef struct bignum_st BIGNUM;
      |                ^~~~~~~~~
src/s2/util/math/exactfloat/exactfloat.cc:107:33: error: invalid use of incomplete type ‘const BIGNUM’ {aka ‘const struct bignum_st’}
  107 |   return (static_cast<uint64>(bn->d[1]) << 32) + bn->d[0];
      |                                 ^~
In file included from /usr/include/openssl/bn.h:19,
                 from src/s2/util/math/exactfloat/exactfloat.h:119,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM’ {aka ‘struct bignum_st’}
   80 | typedef struct bignum_st BIGNUM;
      |                ^~~~~~~~~
src/s2/util/math/exactfloat/exactfloat.cc:107:52: error: invalid use of incomplete type ‘const BIGNUM’ {aka ‘const struct bignum_st’}
  107 |   return (static_cast<uint64>(bn->d[1]) << 32) + bn->d[0];
      |                                                    ^~
In file included from /usr/include/openssl/bn.h:19,
                 from src/s2/util/math/exactfloat/exactfloat.h:119,
                 from src/s2/util/math/exactfloat/exactfloat.cc:18:
/usr/include/openssl/ossl_typ.h:80:16: note: forward declaration of ‘BIGNUM’ {aka ‘struct bignum_st’}
   80 | typedef struct bignum_st BIGNUM;
      |                ^~~~~~~~~

Any updates regarding BN_ext_get_uint64 for such platform? As I am not really familiar with bignum at OpenSSL, any suggestions on fixing it?

Usecase: Linux flatpak for ARM32; Linux mobile OSes (Sailfish, Ubuntu Touch) that have either 32-bit userspace or support 32-bit HW.

rinigus commented 3 years ago

This seems to fix it: https://github.com/rethinkdb/rethinkdb/pull/6407

AlbertWigmore commented 3 years ago

Also experiencing an ARM 32 bit related issue on the following hardware/software. It would be useful to be able to compile and run S2Geometry on ARM 32 bit platforms.

Hardware

Raspberry Pi 2 Model B Rev 1.1 ARMV7l, Cortex-A7

Software

Error whilst running make

[  4%] Built target s2testing
[  5%] Building CXX object CMakeFiles/s2.dir/src/s2/encoded_s2cell_id_vector.cc.o
In file included from /home/pi/s2geometry/src/s2/encoded_uint_vector.h:23,
                 from /home/pi/s2geometry/src/s2/encoded_s2cell_id_vector.h:22,
                 from /home/pi/s2geometry/src/s2/encoded_s2cell_id_vector.cc:18:
/home/pi/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h:289:8: error: ‘uint64’ does not name a type; did you mean ‘uint64_t’?
 inline uint64 UnalignedLoad64(const void *p) {
        ^~~~~~
        uint64_t
/home/pi/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h:299:39: error: ‘uint64’ has not been declared
 inline void UnalignedStore64(void *p, uint64 v) { memcpy(p, &v, sizeof v); }
                                       ^~~~~~
/home/pi/s2geometry/src/s2/encoded_uint_vector.h: In function ‘T s2coding::GetUintWithLength(const char*, int)’:
/home/pi/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h:309:25: error: ‘UnalignedLoad64’ is not a member of ‘absl::base_internal’
   (absl::base_internal::UnalignedLoad64(_p))
                         ^~~~~~~~~~~~~~~
/home/pi/s2geometry/src/s2/encoded_uint_vector.h:166:32: note: in expansion of macro ‘ABSL_INTERNAL_UNALIGNED_LOAD64’
     if (sizeof(T) == 8) return ABSL_INTERNAL_UNALIGNED_LOAD64(ptr);
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/s2geometry/src/s2/third_party/absl/base/internal/unaligned_access.h:309:25: note: suggested alternative: ‘UnalignedLoad32’
   (absl::base_internal::UnalignedLoad64(_p))
                         ^~~~~~~~~~~~~~~
/home/pi/s2geometry/src/s2/encoded_uint_vector.h:166:32: note: in expansion of macro ‘ABSL_INTERNAL_UNALIGNED_LOAD64’
     if (sizeof(T) == 8) return ABSL_INTERNAL_UNALIGNED_LOAD64(ptr);
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/s2.dir/build.make:89: CMakeFiles/s2.dir/src/s2/encoded_s2cell_id_vector.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:110: CMakeFiles/s2.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
jmr commented 3 years ago

Should be fixed by #183