In embedded software design it is common to want to have the code footprint as small as possible.  Therefore, it is fairly common when using the GNU C++ compiler to use the -O2 option which includes the -O optimization flags plus a whole slew of others.  You would think that the best optimization is always what you want when compiling embedded systems code.  Not so, my young apprentice, at least that’s what I found out the hard way.

I was building some code using a compiler created for MIPS and I began getting a long list of messages from standard input that looked like this:

Warning: AT used after ".set noat" or macro used after ".set nomacro"

These were followed by a long list errors that looked like this:

Error: Branch out of range

Needless to say, I wasn’t sure what was going on.  Well after a little bit of research a senior developer pointed out that the code had been assembled in such a way that a jump was being attempted that was more than 32K instructions away, thus causing the error.  And how did we fix this problem?  By removing the -O2 option from the compilation command.

You wouldn’t normally run into these kinds of issues with modern compilers but it turns out we were forced to use an older compiler (3.3.1) with an older version of the standard C++ library (2.2.5).  So there you have it.  A small tip when using older compilers.

Post to Twitter Tweet This Post