[PATCH] D25766: [ELF] - Implemented --section-ordering-file option.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 09:12:28 PDT 2016

grimar added a comment.

Short update: I was able to use gcc to extract section ordering files. For start I generated order list for clang launch without any arguments.
I used gcc from svn://gcc.gnu.org/svn/gcc/branches/google/gcc-4_9.
For doing these next steps were performed:

1. Build llvm with:

-DCMAKE_BUILD_TYPE=Release -DLLVM_PARALLEL_COMPILE_JOBS=8 -DLLVM_ENABLE_THREADS=true -DCMAKE_CXX_FLAGS="-fPIC -std=c++11 -ffunction-sections -fdata-sections -fprofile-generate=/home/umb/LLVM/gcda" -DCMAKE_C_FLAGS="-fPIC -ffunction-sections -fdata-sections -fprofile-generate=/home/umb/LLVM/gcda" -DCMAKE_C_COMPILER=/home/umb/gcc49google/bin/gcc -DCMAKE_CXX_COMPILER=/home/umb/gcc49google/bin/g++

2. Run binary in the way we are interested in. It was ./clang w/o arguments in my case (.gcda files should be produced after that).

3. Now rebuild llvm with -fprofile-use and use of .gcda files we obtained earlier. Use gold linker.

-DCMAKE_BUILD_TYPE=Release -DLLVM_PARALLEL_COMPILE_JOBS=8 -DLLVM_ENABLE_THREADS=true -DCMAKE_CXX_FLAGS="-B/usr/local/bin -fPIC -std=c++11 -ffunction-sections -fdata-sections -fprofile-dir=/home/umb/LLVM/gcda -fprofile-use -freorder-functions=callgraph -Wl,--plugin-opt,file=/home/umb/LLVM/order.txt" -DCMAKE_C_FLAGS="-B/usr/local/bin -fPIC -ffunction-sections -fdata-sections -fprofile-dir=/home/umb/LLVM/gcda -fprofile-use -freorder-functions=callgraph -Wl,--plugin-opt,file=/home/umb/LLVM/order.txt" -DCMAKE_C_COMPILER=/home/umb/gcc49google/bin/gcc -DCMAKE_CXX_COMPILER=/home/umb/gcc49google/bin/g++

4. Remove order.txt and relink clang, that will create order.txt containing sections order for its executable.

I shared it here: https://drive.google.com/file/d/0B_OWr6ld9gUmd1hnV1k4Z25NQVk/view?usp=sharing
It is 18 megabytes in size.

Order list file contains next sections:

BTW, both gold and ld recognize suzh sections by name and use names as hint for sorting (no matter was order file used or not). 
I did not check how it works, but that is what I saw in bfd/gold source code.
Do we want to implement the same for compatibility ?

Finally, now when I have such file I am going to write a tool or script to prepare it to be used as linker input ordering file (looks it contains excessive data, I'll check) and run some tests.
First one will be estimate clang launch time with sections ordered and without. I am thinking about other possible ones, may be compile simple helloworld ?


More information about the llvm-commits mailing list