Hi.

Apologies for taking so long to look at this again; I've been busy.

I just looked into it, and my conclusion is that there's no way to
ensure that Eigen won't crash without us patching our package. So we
should patch our package.

I'm attaching a tiny demo program. Extract it and

  make && ./main

You'll see that it crashes. We have lib.cc:

  #include <Eigen/Core>

  __attribute__((visibility("default")))
  Eigen::MatrixXd* make_array()
  {
      return new Eigen::MatrixXd(10,20);
  }

This is an analogue of some library we would be packaging for Debian.
This would be built with no cpu-specific options, which is what the
Makefile in this demo does.

We also have a main.cc:

  #include <Eigen/Core>

  Eigen::MatrixXd* make_array();
  int main(void)
  {
      Eigen::MatrixXd* matrix = make_array();
      delete matrix;
      return 0;
  }

This is an analogue of some user program that uses this library. This
isn't going into Debian, and the user wants to use their CPU fully, so
they build with -mavx. This causes Eigen to crash. Because the
allocation and deallocation paths don't work the same.

In this demo no Eigen symbols are exported from lib.so, so it's not a
case of the linker picking the wrong weak symbol, and this cannot be
fixed by symbol versioning or visibility settings or anything.

This isn't a contrived example. I hit this in the real-world with a
package I'm going to upload soon (g2o).

Can anybody see ways to make Eigen work reliably here without patching
away the different paths in aligned_malloc() and aligned_free() ?

  
https://sources.debian.org/src/eigen3/3.4.0-4/Eigen/src/Core/util/Memory.h/#L179
  
https://sources.debian.org/src/eigen3/3.4.0-4/Eigen/src/Core/util/Memory.h/#L200

I don't see any way to do it currently, and probably we should patch
these out.

There was also a second similar problem I saw earlier, that resulted in
crashes due to inconsistent alignment. I'm going to revisit that
shortly.

Thanks.

Attachment: eigen-weak-linking-bug.tar.gz
Description: application/gzip

Reply via email to