SH-2 also -> Re: Disabling local optimizations with GCC

John Mills
Thu Jun 29 06:50:00 GMT 2000

Cross-gcc'ers -

On Wed, 28 Jun 2000, Christopher Bahns wrote:

> Here's my problem:
> ... It is important for all assignments to occur because each one
> causes the hardware to perform a particular action, and all actions need
> to occur in the order I've placed them in the C-language functions. The
> problem is that with any GCC optimization level  (-O, -O1, -O2, or -O3),
> it "optimizes" out all but the last assignment to a given location. This
> causes my program not to work.

I have been banging against this problem with sh-hms (COFF) versions of
gcc and have not gotten it under control. At present, my
sh-hms-gcc(2.95.2)/newlib(1.8.[1|2]) tools will _not_ initialize on-chip
serial I/O properly, but 'gcc' and 'g++' built from the ecosSWtools-990319
(egcs-1.?) sources _do_ set them up: same SH-2 sources, same makefile.
Since the 'egcs' version is in WinNT/Cygwin and the 2.95.2 version is in
Linux, I can't yet work through selectively, module by module.

'sh-hms-gcc'-2.95.2 patched for RTEMS is successful or not, based on
optimization setting, but contrarily to what I would have expected: '-O4'
works; '-O0', '-O1', or no selection fails. (Not sure about other

That last (RTEMS) compiler also emits code at some optimization levels
which cannot be assembled, apparently because it puts locals or pointers
out of range of the processor's allowable offset. That problem has the
[expected?] inverse relation to optimization: '-O0' causes emission of
assemblable code; other levels crash the assembler. Naturally this is down
in the middle of a complicated source tree, and I definitely need
optimization overall in order that some apps fit into on-chip FLASH in my

I could adjust optimization level for individual branches (except with the
compiler from which I've not been able to get good code) but I haven't
gotten that to work properly with 'automake' and friends. I also worry
whether I'm getting reliable code at all, based on these observed
problems: what's there that I _haven't_ seen??

I am trying to dig out concise examples for knowledgable folks to look at,
but I haven't gotten there, yet.

Suggestions are naturally welcome.

   John Mills
   Sr. Software Engineer
   TGA Technologies, Inc.
   100 Pinnacle Way, Suite 140
   Norcross, GA 30071-3633
   Phone: 770-441-2100 ext.124 (voice)
          770-449-7740 (FAX)

Want more information?  See the CrossGCC FAQ,
Want to unsubscribe? Send a note to

More information about the crossgcc mailing list