[eigen] Problem with compiler flag -march=native and external libraries |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: "eigen@xxxxxxxxxxxxxxxxxxx" <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Problem with compiler flag -march=native and external libraries
- From: Schlögl, Tristan <tristan.schloegl@xxxxxx>
- Date: Thu, 4 May 2017 11:53:06 +0000
- Accept-language: de-DE, en-US
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fau.de; s=fau-2013; t=1493898789; bh=vaZfhO0cnJW9a5k0+gl0KAt0RImsx7dSexCJGyTZ3kI=; h=From:To:Subject:Date:From:To:CC:Subject; b=Y+FX4bNp/Ju6o6brurvFdRdB95IMk2E4PPm/5c5Shw8lJ8/xTAjH/qt9kHkTmhHWe MJ8aI1X1JlSE3LGkO8FECBOY+LUQqvcuKZ6NqCwZWTMaDoxEJjREtpwqh5VB+onuej +qciHTR5d5hd3xhoeSr7aERdY8CldR7XQH1AmsPTQCOO7+MYXldwVm6waeOGCYbeOx YDo0drC4XL1HAYHneWC9ioY5UOGl+jaJt5nTr/gIcgiJDuli5RCC3Gy99zOiO2G6Wo QHXPX3qxUvNdwkN840FEXg9QGaodwWlFpXwlnt4mNho4TQkITxSw4CYI8AvhXhc+BO lhX/HyTcqMWvQ==
- Thread-index: AQHSxMz+rNumhpj/eEG1Cc3R7fsWVg==
- Thread-topic: Problem with compiler flag -march=native and external libraries
Hi,
I’m working on a shared library that is based on Eigen. The library is compiled *without* the ‘-march=native’ compiler flag. An executable that uses this library, however, is compiled *with* the ‘-march=native’ compiler flag. This does not cause any compile time problems but leads to nondeterministic behaviour of the executable. Valgrind reveals an invalid read error that is caused by some Eigen subroutine. I’m working with OSX 10.11.6 and the native Apple Clang compiler.
Is it generally not allowed to mix these flags in builds, or is this some Eigen specific behaviour? The following minimal example demonstrates the problem.
Three files (libA.h, libA.cpp and main.cpp), all in the same folder, with the following content:
libA.h:
------------------------------------------------
#include <Eigen/Dense>
Eigen::VectorXd get_vector_A(int n);
------------------------------------------------
libA.cpp:
------------------------------------------------
#include "libA.h"
Eigen::VectorXd get_vector_A(int n) {
return Eigen::VectorXd::Zero(n);
}
------------------------------------------------
main.cpp:
------------------------------------------------
#include "libA.h"
#include <iostream>
int main() {
int n = 3;
Eigen::VectorXd vec = get_vector_A(n);
std::cout << "vec = \n" << vec << std::endl;
}
------------------------------------------------
The library is compiled with the following command
clang++ libA.cpp –I<EIGEN> -shared -o libA.dylib
where <EIGEN> is the path to the Eigen include directory.
The executable is compiled via
clang++ main.cpp -I<EIGEN> -L. -lA -march=native -o main
At first sight the executable looks okay and runs as expected producing the following output:
vec =
0
0
0
However, when inspected with Valgrind by running ‘valgrind ./main’, then the following output is generated:
[…]
==94875== Invalid read of size 8
==94875== at 0x10000147B: Eigen::internal::handmade_aligned_free(void*) (in ./main)
==94875== by 0x100001454: Eigen::internal::aligned_free(void*) (in ./main)
==94875== by 0x100001434: void Eigen::internal::conditional_aligned_free<true>(void*) (in ./main)
==94875== by 0x10000140B: void Eigen::internal::conditional_aligned_delete_auto<double, true>(double*, unsigned long) (in ./main)
==94875== by 0x1000013DA: Eigen::DenseStorage<double, -1, -1, 1, 0>::~DenseStorage() (in ./main)
==94875== by 0x1000013A4: Eigen::DenseStorage<double, -1, -1, 1, 0>::~DenseStorage() (in ./main)
==94875== by 0x100001384: Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::~PlainObjectBase() (in ./main)
==94875== by 0x100001364: Eigen::Matrix<double, -1, 1, 0, -1, 1>::~Matrix() (in ./main)
==94875== by 0x100001334: Eigen::Matrix<double, -1, 1, 0, -1, 1>::~Matrix() (in ./main)
==94875== by 0x100000B3E: main (in ./main)
==94875== Address 0x100a9ff78 is 8 bytes before a block of size 24 alloc'd
==94875== at 0x100012681: malloc (vg_replace_malloc.c:302)
==94875== by 0x10001FD79: Eigen::internal::aligned_malloc(unsigned long) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001FD54: void* Eigen::internal::conditional_aligned_malloc<true>(unsigned long) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001FCE4: double* Eigen::internal::conditional_aligned_new_auto<double, true>(unsigned long) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001FC2F: Eigen::DenseStorage<double, -1, -1, 1, 0>::resize(long, long, long) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001FB49: Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::resize(long, long) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001F91B: void Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::resizeLike<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::EigenBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001F746: Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::PlainObjectBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::DenseBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001F6CC: Eigen::Matrix<double, -1, 1, 0, -1, 1>::Matrix<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::EigenBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001F36C: Eigen::Matrix<double, -1, 1, 0, -1, 1>::Matrix<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > >(Eigen::EigenBase<Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<double>, Eigen::Matrix<double, -1, 1, 0, -1, 1> > > const&) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x10001F305: get_vector_A(int) (in /Users/StTrSchl/Desktop/eigen_ex/libA.dylib)
==94875== by 0x100000ADC: main (in ./main)
[…]
Cheers
Tristan
--
Dipl.-Ing. Tristan Schlögl
Chair of Applied Dynamics
University of Erlangen-Nuremberg
Immerwahrstrasse 1
D-91058 Erlangen, Germany
room 00.013
phone +49 (0)9131 85 61003
fax +49 (0)9131 85 61011
url www.ltd.tf.uni-erlangen.de