Edited by: Whitehound on 10/04/2011 06:08:38Hello,
for those who already know what Link Time Optimization means just know that gcc-4.6.0 has been released recently and one can now compile WINE with gcc-4.6.0 and with link time optimization enabled. It works!
For those who do not know what this is will I give a brief explanation, and I have to start with the beginning of the language C itself.
In the beginning of C did people have to pass their source code to the compiler to turn it into assembly language (human readable machine code), then pass it to the assembler to turn it into real machine code. In a final step, the link editor (aka linker), was the machine code patched together with other machine code (i.e. libraries) into an executable file. This looked like this:
> cc program1.c -o program1.s
> as program1.s -o program1.o
> cc program2.c -o program2.s
> as program2.s -o program2.o
> ld program1.o program2.o -lc -o program.exe
Because programmers often do not have the time to think about every detail of the assembly language and the hardware, but have to focus on writing their programs (a game, a spreadsheet, a text editor, etc.) did the compiler start to optimize the code to make it run as efficiently as possible. The compilers also took over the task of calling the assembler and linker, and one only needed to enter:
> cc program1.c -o program1.o
> cc program2.c -o program2.o
> cc program1.o program2.o -o program.exe
This all happened in the late 1980's and it is how it is still done today, almost 25 years after C was born. Computer programs got bigger and what started with a single source code file became many files, thousands and sometimes millions of files.
While the compilers optimized the code better each year did they still only optimize a program in parts. Until now. Link time optimization optimizes programs as a whole and not only each file individually. As simple as it may seem is this a rather big step in the history of the C.
To use this new feature does one need gcc-4.6.0. The latest GNU C Compiler supports the new optimization method along with the old and makes a transition very easy. In example:
> gcc -flto program1.c -o program1.o
> gcc -flto program2.c -o program2.o
> gcc -flto program1.o program2.o -o program.exe
The compiler still optimizes each file individually, but appends a compressed copy of the source code to the output file. During the final step does it read the code again (from the object file) and optimizes it as one, to produce the best possible optimization.
To compile WINE with the new method does one need to use the following CFLAGS:
> export CC="gcc -m32"
> export PATH="$HOME/gcc/bin:$PATH"
> export LD_LIBRARY_PATH="$HOME/gcc/lib:$LD_LIBRARY_PATH"
> export LD_RUN_PATH="/home/$HOME/gcc/lib:$LD_RUN_PATH"
> export CFLAGS="-pipe -O2 -march=native \
-flto=1 -flto-partition=none -fuse-linker-plugin \
-fipa-pta"
You need to have the latest
gcc and
binutils installed under
$HOME/gcc or change the variables to point to it. Avoid using
-O3 and
-Ofast as it breaks the WINE build currently. The option
-fuse-linker-plugin enables gcc to look through the libraries to see if they contain object files compiled with LTO, allowing for very deep optimizations. Needless to say that the new method achieves some pretty amazing results.
After you have set up these variables can you call the configure script to WINE and start building it from its source code. See the WINE Wiki on how to build WINE from its source code if you have not done this before.