toolchain's output depends on toolchain used to build the compiler?

toolchain's output depends on toolchain used to build the compiler?

Shachar Shemesh shachar at shemesh.biz
Tue Feb 9 08:36:35 IST 2010


Hi all,

I'm having a weird problem at a client's. They need a toolchain for both 
Windows (cygwin) and Linux. What's more, then need the two toolchains to 
match exactly - given identical source code, the toolchains must produce 
the exact same machine code (tested by doing objdump -d and diffing the 
outputs). The toolchains are for bare metal power-pc (powerpc-eabi target).

At first I just compiled gcc and newlib on both systems, but the results 
from compilation varied greatly. I traced it down to cygwin and Debian 
Lenny providing different versions of the supporting libraries (mpfr 
etc), which caused to optimizer to perform different different 
optimizations, producing correct, but different, results when compiling 
the same code on Windows or on Linux.

For my second run, I compiled all supporting libraries as well. I made 
sure to run "make check" on every step. I got two toolchains, and 
compiled newlib and the actual project with both. This time, the results 
were noticeably better. The newlib libraries, as well as some of the 
libraries for the project, did compile the same with the Linux and the 
Cygwin toolchains. Some libraries, however, did not. Again, this does 
not appear to be a case of the compiler producing wrong code, just 
different.

In case you are wondering, I made sure that the code the compiler sees 
is identical between the build environments, by stopping after the 
pre-processor stage and comparing the files. Except for the source file 
paths, the files post-pre-processing and pre-compilation are identical.

One thing that was different between the setups was the native compiler 
version used to compile the cross compiler itself. With Cygwin, I used 
gcc 4.3.4 to compile the libraries and gcc, on Linux I used gcc 4.4.3. 
In both cases, the cross compiler itself is gcc 4.4.3 with fairly latest 
versions of everything. While I am definitely going to next try 
compiling on Linux with 4.3.4, I fail to see how the version of the 
compiler has such an effect on the output of the program.

Since this question is some what recursive, I'll try to recap in the 
form of a table:
Cygwin 1.7
	Linux Debian Lenny/Sid
Use native gcc-4.3.4 to build toolchain
	Use native gcc-4.4.3 (from Sid) to build toolchain
Build native mpc-0.8.1, mpfr-2.4.2, gmp-4.3.2, cloog-ppl-0.15.7, 
ppl-0.10.2 using gcc-4.3.4 as static objects
	Build the same libraries as on the left using gcc-4.4.3, with same 
configure options, except as shared objects
Build cross binutils-2.20.51 and gcc-4.4.3 using gcc-4.3.4
	Build the same versions of binutils and gcc using gcc-4.4.3. Same 
command line options
Build newlib-1.18.0 using the cross-gcc 4.4.3 compiled in the previous step
	Build the same version using the gcc compiled in the previous step. 
Same configure options
Build the client's project using the above toolchain
	Build the client's project using the above toolchain


The newlib libraries built are compared, and are identical down to the 
last assembly instruction. The client libraries are compared. Some are 
identical, some are not.

Any thoughts and/or suggestions are welcome.

Shachar

-- 
Shachar Shemesh
Lingnu Open Source Consulting Ltd.
http://www.lingnu.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20100209/c0484d5e/attachment-0001.html>


More information about the Linux-il mailing list