This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: gcc(2.95 for ARM) optimize error
- From: Andrew Lunn <andrew dot lunn at ascom dot ch>
- To: james chen <james_ch1 at sina dot com>
- Cc: ecos-discuss at sources dot redhat dot com
- Date: Tue, 27 Nov 2001 13:10:14 +0100
- Subject: Re: [ECOS] gcc(2.95 for ARM) optimize error
- References: <000601c17732$ebdd3ee0$c408aa0a@inc.inventec>
On Tue, Nov 27, 2001 at 07:01:52PM +0800, james chen wrote:
> Hi,
> I am using eCos, when I use -O0 or -O1 to compile eCos and my test
> application, it runs OK, but If I GCC optimize to -O2, it will failed. After
> check it's assembler, I find that GCC(2.95 for ARM) has changed
> application's code order and also miss some code. have anyone found this?
I've not had problems.
What sort of code is it? IO for a device driver? do you have all the
required volatiles? The compile is allowed to change the order and
remove redundant code that does nothing...
eg
a = *(unsigned int *)0x41000000;
b = *(unsigned int *)0x41000008;
a = *(unsigned int *)0x41000004;
The compile is allowed to remove the first assignment since the result
is never used. Also it can do the b assignment first or last since the
result is not needed for the other two assignments.
If you want to force it to keep the redundant loads and keep the order
you need to add volatile
a = *(volatile unsigned int *)0x41000000;
b = *(volatile unsigned int *)0x41000008;
a = *(volatile unsigned int *)0x41000004;
There was a discussion about all this a month or two ago on the
list. Read back in the archives.
Andrew