Illegal instruction caused by optimization

Discussion created by kuzmenkor on Oct 26, 2011
Latest reply on Oct 31, 2011 by carlos_odonell



I have a problem to build net-SNMP for ucLinux (-mcpu=53015: mcf53015) using Sourcery toolchains.


The exact toolchains versions are:

1) Sourcery G++ Lite 4.4-53 (gcc version 4.4.1)

2) Sourcery CodeBench Lite 2011.03-97 (gcc version 4.5.2)


I have a set of tests that passes successfully with no optimization (-O0).

The same tests fail if the flags -O1 or -O2 are used (even if the stack size is increased few times, just in case).

Instrumenting the source code makes the test cases to fail in other places.

The way the crash look like is always different.

Sometimes the code behaves unexpectedly: some functions return values that are not supposed to be returned.

But most of the times just an illegal instruction exception is thrown out.


Breaking down -O1 and -O2 in individual flags gives the following results.

If any of the following flags is specifiied, then the tests crash (the behavior does not vary a lot, it looks like the same problem is hit every time).

-fomit-frame-pointer (included in -O1)

-fauto-inc-dec (included in -O1)

-ftree-forw-prop (included in -O1, 4.5.2 only)

-fcrossjumping  (included in -O2)

-fcse-follow-jumps (included in -O2)

There are more -O2 flags involved, I just gave up to find them all.


What can be wrong with -fauto-inc-dec???

I double checked few places of the binary where this flag makes changes.

The changes look just fine.


Could you, please, help me to identify the cause of this problem?

Are there any updates available for the toolchain, that can solve it?

What would you recommed to do to continue the investigation process?


Thank you

Roman Kuzmenko