cartographer icon indicating copy to clipboard operation
cartographer copied to clipboard

Workaround for misalignment of `SubmapSlice` and Eigen data structures in heterogeneous builds

Open twdragon opened this issue 2 years ago • 2 comments

Due to different structure alignment rules in different compilers (or even the same compiler in different compiling contexts), the SubmapSlice structure defined in ./cartographer/io/submap_painter.h comes into cartographer_ros or another external project misaligned by 48 bytes because of different sizeof() return values (224 vs 256 bytes). This behaviour is proven when testing Cartographer compiled using Clang 15 and GCC 11.3 on Mint Linux 22 with a customized build of ROS. The reason is deeply sitting problem with implementation-defined STL shipped with different kernels and build pipelines. This pull request adds a semi-portable workaround for this issue forcing alignment of SubmapSlice structure to 32 bytes as is required by GCC.

  • Added a workaround for misaligned SubmapSlice structure between cartographer and cartographer_ros built using different compilers or compilation contexts
  • Rearranged SubmapSlice field order after static analysis performed with clangd
  • Added commented non-portable workaround with #pragma pack
  • Closes #1909

twdragon avatar Nov 11 '22 15:11 twdragon

This issue persists also in other parts of the project, so I will continue the investigation

twdragon avatar Nov 11 '22 19:11 twdragon

Updated involving the DISABLE_AVX_ALIGNMENT CMake option to disable Eigen-side AVX alignment issues on recent CPUs

twdragon avatar Nov 14 '22 16:11 twdragon