| To: | <linux-mips@linux-mips.org> |
|---|---|
| Subject: | Differing results from cross and native compilers |
| From: | "Eric DeVolder" <edevolder@razamicroelectronics.com> |
| Date: | Tue, 19 Sep 2006 08:39:25 -0700 |
| Original-recipient: | rfc822;linux-mips@linux-mips.org |
| Sender: | linux-mips-bounce@linux-mips.org |
| Thread-index: | AcbcAclb8MTuu14LT86YiDumaL+whA== |
| Thread-topic: | Differing results from cross and native compilers |
|
Hi, I have a MIPS native and cross
compiler (gcc 3.4.4 and binutils 2.15)
both built using crosstool-0.42. I have an Alchemy system (MIPS32) for which I am building code. When I compile a simple example, I get different instructions from the cross and native compilers. Specifically, the source file
is:
#include
<stdio.h>
int main (int argc, char **argv) { return -printf("Hello, world!\n"); } To compile natively, I
use:
% gcc -c hello.c -o
obj1.o
To cross compile, I use:
%
mipsel-unknown-linux-gnu-gcc -c hello.c -o obj2.o
If I use the -O0 or -O1 flags with
each, I get identical output
(for the .text), but when I compile in both environments with -O2; the compilers produce different results. The native compiler on the Alchemy
board results in the following:
obj1.o: file format
elf32-tradlittlemips
Disassembly of section
.text:
00000000
<main>:
0: 3c1c0000 lui gp,0x0 4: 279c0000 addiu gp,gp,0 8: 0399e021 addu gp,gp,t9 c: 27bdffe0 addiu sp,sp,-32 10: afbf0018 sw ra,24(sp) 14: afbc0010 sw gp,16(sp) 18: 8f840000 lw a0,0(gp) 1c: 00000000 nop 20: 24840000 addiu a0,a0,0 24: 8f990000 lw t9,0(gp) 28: 00000000 nop 2c: 0320f809 jalr t9 30: 00000000 nop 34: 8fbc0010 lw gp,16(sp) 38: 8fbf0018 lw ra,24(sp) 3c: 00021023 negu v0,v0 40: 03e00008 jr ra 44: 27bd0020 addiu sp,sp,32 The cross compiler results
in:
obj2.o: file format
elf32-tradlittlemips
Disassembly of section
.text:
00000000
<main>:
0: 3c1c0000 lui gp,0x0 4: 279c0000 addiu gp,gp,0 8: 0399e021 addu gp,gp,t9 c: 27bdffe0 addiu sp,sp,-32 10: afbf0018 sw ra,24(sp) 14: afbc0010 sw gp,16(sp) 18: 8f840000 lw a0,0(gp) 1c: 8f990000 lw t9,0(gp) 20: 00000000 nop 24: 0320f809 jalr t9 28: 24840000 addiu a0,a0,0 2c: 8fbc0010 lw gp,16(sp) 30: 8fbf0018 lw ra,24(sp) 34: 00021023 negu v0,v0 38: 03e00008 jr ra 3c: 27bd0020 addiu sp,sp,32 I would have thought that for this simple example
I'd get identical
results. For reasons I have yet to figure out, the cross compiler is finding better optimizations than the native, though both are the same gcc version. I checked the specs files, and the two are identical other than the "cross_compile" setting. I'd like to solve this little mystery to get to the
bigger prize, and
that is the ability to actually compile code (e.g. the entire system) for MIPS32. As is demonstrated above, the compilers are generating MIPS1 code (based on the NOPs between the load-to-use), but if I could get the compiler to honor -mips32 (this discovery I originally made while trying to get native -mips32 to work), I
can get even
tighter code...
I've done quite a bit of googling to no avail. I've
also done some
digging into gcc/binutils sources, and it appears that binutils has a "from-abi" option for choosing its architecture, which is o32 which probably means just MIPS1. I thought about trying to rebuild all the tools for mipsisa32-unknown-linux-gnu, but am concerned I'd still have the same problem of a particular compiler optimziation option not being honored by the compiler. Any tips/advice much appreciated,
thanks!
Eric |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: [PATCH] au1x00 serial real interrupt, Sergei Shtylyov |
|---|---|
| Next by Date: | Re: Differing results from cross and native compilers, Thiemo Seufer |
| Previous by Thread: | Re: Performance counters and profiling on MIPS, Philip Mucci |
| Next by Thread: | Re: Differing results from cross and native compilers, Thiemo Seufer |
| Indexes: | [Date] [Thread] [Top] [All Lists] |