This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Linker error regarding optimizations levels

Tags: None
(comma "," separated)
noether
Registered Member
Posts
10
Karma
0
OS
I'm trying to figure out a strange compilation/linking problem that involves Eigen.

This is my code:

Code: Select all
#include "ch.h"
#include "hal.h"

#include "Eigen/Dense"

using namespace Eigen;

static WORKING_AREA(waThread1, 128);
static msg_t Thread1(void *arg) {

   (void)arg;
   chRegSetThreadName("blinker");

   int i = 1;
   Matrix<float, 13, 13> A, L;
   A = Matrix<float, 13, 13>::Identity(13, 13) +
   Matrix<float, 13, 13>::Constant(1);

   while (TRUE)
   {
      i++;
      A(0, 0) += i;
      L = A.llt().matrixL();  <---------

      palSetPad(GPIOD, GPIOD_LED3);       /* Orange.  */
      chThdSleepMilliseconds(500);
      palClearPad(GPIOD, GPIOD_LED3);     /* Orange.  */
      chThdSleepMilliseconds(500);
   }

}

int main(void) {

   halInit();
   chSysInit();

   chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);

   while (TRUE) {
      chThdSleepMilliseconds(500);
   }
}


for now, you can ignore the specifics as this code is targeting a particular embedded RTOS. The general idea is that I'm just doing some computations with a matrix.

When I compile this file with -O1 (Os O2 and O3 give the same result for that matter), the code compiles and links fine. However, when I use -O0 the file compiles correctly, but then fails to link with:

Code: Select all
/home/noether/workspace/tool-chains/arm-none-eabi-4.6.2/lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/libg.a(lib_a-abort.o): In function `abort':
/home/noether/workspace/tool-chains/summon-arm-toolchain/build/arm-none-eabi/newlib/libc/stdlib/../../../../../gcc-4.6.2/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
/home/noether/workspace/tool-chains/arm-none-eabi-4.6.2/lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/libg.a(lib_a-signalr.o): In function `_kill_r':
/home/noether/workspace/tool-chains/summon-arm-toolchain/build/arm-none-eabi/newlib/libc/reent/../../../../../gcc-4.6.2/newlib/libc/reent/signalr.c:61: undefined reference to `_kill'
/home/noether/workspace/tool-chains/arm-none-eabi-4.6.2/lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/libg.a(lib_a-signalr.o): In function `_getpid_r':
/home/noether/workspace/tool-chains/summon-arm-toolchain/build/arm-none-eabi/newlib/libc/reent/../../../../../gcc-4.6.2/newlib/libc/reent/signalr.c:96: undefined reference to `_getpid'
collect2: ld returned 1 exit status
make: *** [build/ch.elf] Error 1



I'm using the following CXXFLAGS:

Code: Select all
-mcpu=cortex-m4 -ggdb -fomit-frame-pointer -falign-functions=16 -mhard-float -mfpu=fpv4-sp-d16 -fsingle-precision-constant -DNDEBUG -ffunction-sections -fdata-sections -fno-common -fno-rtti -fno-exceptions -O0 -Wall -Wextra -Wa,-alms=build/lst/main.lst   -DTHUMB_PRESENT -mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/main.o.d -mthumb -DTHUMB


If I remove Eigen from main.cpp the code compiles and links fine regardless of the optimization level I use. This makes me suspect that Eigen has something to do with it. Moreover, if I comment the line marked with an arrow, the code compiles and links fine as well.

Does anybody have any idea? Does Eigen generate a call to abort even when compiled with NDEBUG? Anything I can try?

Thanks in advance.

Cheers,
Andre
Registered Member
Posts
90
Karma
1
That is a pretty interesting error. :)

First, doesn't your RTOS provide you a minimal stdlib implementation for system calls? That would be the obvious solution.

The not so obvious seems to be why there are assertions in your DNDEBUG build. I assume that assertions are the problem, because there seems to be an abort() which triggers the signal and kill(getpid()).
As it doesn't happen with the optimized build, perhaps its compile time assertions? Could for example be for your constant size matrices. Perhaps EIGEN_NO_STATIC_ASSERT could help you there?


'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett

'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger
noether
Registered Member
Posts
10
Karma
0
OS
Hello Andre, thanks for your response.

Unfortunately -DEIGEN_NO_STATIC_ASSERT flag didn't work. Actually looking into the asm code there is any reference to assert/abort.

I can implement a simple abort(), but it should not be required. I actually suspect of a bug in Eigen.

More ideas?

Cheers.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
that's strange. what if you only compile a matrix-vector product?
noether
Registered Member
Posts
10
Karma
0
OS
Hello ggael,

thanks for the response. This is the code

Code: Select all
int i = 1;
   Matrix<float, 13, 13> A;
   A = Matrix<float, 13, 13>::Identity(13, 13) +
      Matrix<float, 13, 13>::Constant(1);
   Matrix<float, 13, 1> V, VV;
   V.setZero();
   VV.setZero();

   volatile float aa;

   while (TRUE)
   {
      i++;

      VV = A * V;
      aa = VV(0, 0);
      V(0, 0) += aa;
      A(0, 0) += aa;

      palSetPad(GPIOD, GPIOD_LED3);       /* Orange.  */
      chThdSleepMilliseconds(500);
      palClearPad(GPIOD, GPIOD_LED3);     /* Orange.  */
      chThdSleepMilliseconds(500);
   }


But I get the same linker error output.

Any idea or suggestion of what is happening?
Andre
Registered Member
Posts
90
Karma
1
noether wrote:Unfortunately -DEIGEN_NO_STATIC_ASSERT flag didn't work. Actually looking into the asm code there is any reference to assert/abort.


Well, the linker specifically says: "In function `abort':", so there sure is a reference to it in the code. :)
Is still think it could be an assertion.

ggael: Is there any other way to completely disable compile-time assertions?


'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett

'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger
Andre
Registered Member
Posts
90
Karma
1
What version of Eigen do you use btw?


'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett

'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I'm still clueless, so 2 more things to try:

1) try to compile with -DEIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD=64

2) try with VV = A.lazyProduct(V);

thanks.
noether
Registered Member
Posts
10
Karma
0
OS
Sorry for the late response,

I tried with lazyProduct and -DEIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD=64 -DEIGEN_NO_STATIC_ASSERT, and I have the same linker error mmm

It is strange, because checking out the asm, there is any call to abort ?¿?

If you are interested in try it out, I can attach the project and the compiler cab be downloaded from https://launchpad.net/gcc-arm-embedded


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]