Whitehound
The Whitehound Corporation Frontline Assembly Point
|
Posted - 2011.04.07 14:54:00 -
[1]
Edited by: Whitehound on 07/04/2011 14:56:43 Hello,
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 the language 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 the C programming language 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 language 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 results in 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. --
|
Karak Terrel
As Far As The eYe can see Chained Reactions
|
Posted - 2011.04.10 01:05:00 -
[2]
Awesome stuff! Thx for the explanation. Have to look into this then. Will probably result in a 46day skill and "emerge -e world" :-) if it is save to use it on the whole system.
Originally by: Whitehound a game, a spreadsheet,
can.. not.. resist..
sometimes it's the same! -- please consider to visit our w-space system, cake will be served immediately. |
Whitehound
The Whitehound Corporation Frontline Assembly Point
|
Posted - 2011.04.10 16:03:00 -
[3]
One needs to keep in mind that the deeper it optimizes and the more files it looks at, the more memory it needs and the longer it will take. It knows no limits and I very much doubt that one can compile an entire Linux distribution with it yet. It allows to break the final step down into larger chunks, but it quickly defeats the purpose of course. Just pick a few libraries together with the application you want to optimize, compile them separately and leave it at that. --
|