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

eigen: add a patch for a segfault with c++23 and libc++ #26435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jimbopython
Copy link
Contributor

Summary

Changes to recipe: eigen/3.4.0

Motivation

When running code compiled with c++23 and libc++ depending on the eigen config, a segfault may occur, when eigen allocator is used. This is the case for the pcl library, which segfaults on a Pointcloud with that allocator is used in a 32 bit binary.

Details

Eigen Issue: https://gitlab.com/libeigen/eigen/-/issues/2895

This PR adds a patch, which is already on eigen master, that removes the inheritence from std::allocator. The error occurs because c++23 introduced std::allocate_at_least, libc++ is calling it and eigen does not provide an implementation for it. When the destructor is called, eigen calls its own deallocate function, which results in a mismatch.

One can observe it with valgrind:

==14616== Invalid read of size 1
==14616==    at 0x10A637: Eigen::internal::handmade_aligned_free(void*) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A614: Eigen::internal::aligned_free(void*) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A5EC: Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::deallocate(Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A4B4: std::__1::allocator_traits<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::deallocate[abi:ne190101](Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10AAFD: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::__destroy_vector::operator()[abi:ne190101]() (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x1093A7: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::~vector[abi:ne190101]() (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109268: main (in /home/markus/Eigen_allocate_at_least)
==14616==  Address 0x4d1203f is 1 bytes before a block of size 160 alloc'd
==14616==    at 0x4848FD3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==14616==    by 0x10A304: void* std::__1::__libcpp_operator_new[abi:ne190101]<unsigned long>(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A282: std::__1::__libcpp_allocate[abi:ne190101](unsigned long, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A1D3: std::__1::allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::allocate[abi:ne190101](unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A16C: std::__1::allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::allocate_at_least[abi:ne190101](unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A12C: std::__1::allocation_result<Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long> std::__1::allocator_traits<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::allocate_at_least[abi:ne190101]<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >(Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A08C: auto std::__1::__allocate_at_least[abi:ne190101]<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >(Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x1097E1: std::__1::__split_buffer<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&>::__split_buffer(unsigned long, unsigned long, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109554: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::__append(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10930B: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::resize(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109232: main (in /home/markus/Eigen_allocate_at_least)
==14616== 
==14616== Mismatched free() / delete / delete []
==14616==    at 0x484B8BF: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==14616==    by 0x10A661: Eigen::internal::handmade_aligned_free(void*) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A614: Eigen::internal::aligned_free(void*) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A5EC: Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::deallocate(Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A4B4: std::__1::allocator_traits<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::deallocate[abi:ne190101](Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10AAFD: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::__destroy_vector::operator()[abi:ne190101]() (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x1093A7: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::~vector[abi:ne190101]() (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109268: main (in /home/markus/Eigen_allocate_at_least)
==14616==  Address 0x4d12040 is 0 bytes inside a block of size 160 alloc'd
==14616==    at 0x4848FD3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==14616==    by 0x10A304: void* std::__1::__libcpp_operator_new[abi:ne190101]<unsigned long>(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A282: std::__1::__libcpp_allocate[abi:ne190101](unsigned long, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A1D3: std::__1::allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::allocate[abi:ne190101](unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A16C: std::__1::allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >::allocate_at_least[abi:ne190101](unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A12C: std::__1::allocation_result<Eigen::Matrix<float, 4, 1, 0, 4, 1>*, unsigned long> std::__1::allocator_traits<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::allocate_at_least[abi:ne190101]<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >(Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10A08C: auto std::__1::__allocate_at_least[abi:ne190101]<Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >(Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&, unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x1097E1: std::__1::__split_buffer<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&>::__split_buffer(unsigned long, unsigned long, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> >&) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109554: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::__append(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x10930B: std::__1::vector<Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::aligned_allocator<Eigen::Matrix<float, 4, 1, 0, 4, 1> > >::resize(unsigned long) (in /home/markus/Eigen_allocate_at_least)
==14616==    by 0x109232: main (in /home/markus/Eigen_allocate_at_least)

The patch is cherry-picked and conflicts have been resolved.


@Jimbopython Jimbopython force-pushed the fix/eigen-cpp23-segfault branch from 65f031e to 3ee4f8f Compare January 21, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant