s2geometry
s2geometry copied to clipboard
S2Builder segfaults on aarch64
When building and running on an arm64 (v8.2 snapdragon 845) with gcc 8.3.0, I have the following segfault. Here's the output from valgrind:
==14080== Invalid read of size 8
==14080== at 0x356350: double util::math::internal_vector::BasicVector<Vector3, double, 3ul>::Dot<0ul, 1ul, 2ul>(double, double const*,
double const*, absl::integer_sequence<unsigned long, 0ul, 1ul, 2ul>) (vector.h:273)
==14080== by 0x3561C3: util::math::internal_vector::BasicVector<Vector3, double, 3ul>::DotProd(Vector3<double> const&) const (vector.h:169)
==14080== by 0x55FFA3: s2pred::GetCosDistance(Vector3<double> const&, Vector3<double> const&, double*) (s2predicates.cc:315)
==14080== by 0x56033F: int s2pred::TriageCompareCosDistances<double>(Vector3<double> const&, Vector3<double> const&, Vector3<double> const&) (s2predicates.cc:372)
==14080== by 0x55CC2B: s2pred::CompareDistances(Vector3<double> const&, Vector3<double> const&, Vector3<double> const&) (s2predicates.cc:446)
==14080== by 0x4AE12B: S2Builder::SnapEdge(int, std::vector<int, std::allocator<int> >*) const (s2builder.cc:1036)
==14080== by 0x4ACFCB: S2Builder::AddExtraSites(MutableS2ShapeIndex const&) (s2builder.cc:783)
==14080== by 0x4ABE63: S2Builder::ChooseSites() (s2builder.cc:511)
==14080== by 0x4ABC67: S2Builder::Build(S2Error*) (s2builder.cc:473)
One of the Vector3 references is invalid. I don't have this issue with the same gcc on amd64.
Do you have a self-contained test case? I need to see how you set up your S2Builder.
I'm also not familiar with valgrind. What does "invalid read" mean? Is there a more specific error like use after free or unaligned access?
You could also try clang++ -fsanitize=undefined for better error messages.
Thanks for the fast response. I've lost access to the hardware for the time being, but I was able to build and run that test with Clang 7 with no difficulty. The address sanitizer build didn't work first time, but I'll return to it. I'm also going to check gcc7. This feels like a compiler bug.
Valgrind's "invalid read" means access to memory outside of the process address space (this one was at 0x40 -- clearly some trash). Typically this happens from bad pointer arithmetic, bad memory allocation followed by a read, or just plain old reading from an uninitialized pointer (though valgrind flags this last one specially).
I'll leave this open until I can investigate further.