Introduce three new toolchains in edk2. The first two ones support Link Time
Optimization (LTO) for aggressive code size improvement and the third one is
for static analysis.
CLANG38 : Enable LLVM Link Time Optimization (LTO) and code size
optimization flag (-Os) by default for aggressive code size improvement. X64
code is small code model + position independent code (PIE).
GCC53 : Enabled GCC Link Time Optimization (LTO) and code size
optimization (–Os) for more aggressive code size improvement. X64 code is small
+ PIE (why not GCCLTO49? Because GCC 4.9 LTO cannot work with latest GNU ld
linker)
CLANGSCAN38: Base on CLANG38 to seamlessly integrate Clang scan-build analyzer
infrastructure into edk2 build infrastructure. X64 code is small code model +
PIE.
Test pass platforms: OVMF (OvmfPkgIa32.dsc, OvmfPkgX64.dsc) and Quark
(Quark.dsc).
Test compiler and linker version: LLVM 3.8, GCC 5.3, GCC 5.4, GNU ld 2.26.
Code size data comparison:
FV (Byte) VS2015x86 | GCC49 | CLANG38 | GCC53
-----------------------------------------------------------------------------------
Quark (IA32) FVMAIN_COMPACT DEBUG 0xb7730 | 0xe4e68 | 0xbf618 |
0xd1ad8
Quark (IA32) FVRECOVERY DEBUG 0x5b3c8 | 0x84198 | 0x59240 |
0x5f6f8
Quark (IA32) FVMAIN_COMPACT RELEASE 0x73e58 | 0xcec48 | 0x85870 |
0x80370
Quark (IA32) FVRECOVERY RELEASE 0x25f08 | 0x5b190 | 0x28468 |
0x2a330
OvmfX64 FVMAIN_COMPACT DEBUG 0xfc3c0 | 0x121090| 0x100168|
0x10ea20
OvmfX64 PEIFV(X64) DEBUG 0x244b0 | 0x4efb0 | 0x219f0 |
0x21670
OvmfX64 FVMAIN_COMPACT RELEASE 0xc6688 | 0xd4cd8 | 0xce7a8 |
0xc7588
OvmfX64 PEIFV(X64) RELEASE 0xf170 | 0x264f0 | 0xf870 | 0xf5f0
Module (KB) VS2015x86 | GCC49 | CLANG38 | GCC53
-----------------------------------------------------------------------------------
RELEASE IA32 PeiCore.efi 20KB | 26.6KB | 22.1KB |
22.4KB
DEBUG IA32 PeiCore.efi 39.8KB | 56.4KB | 41.2KB |
44.1KB
RELEASE X64 DxeCore.efi 95.3KB | 183KB | 101KB | 91.2KB
RELEASE X64 DxeCore.efi lzma compress 43.5KB | 51.2KB | 45.2KB | 44.5KB
DEBUG X64 DxeCore.efi 138KB | 273KB | 138KB | 137KB
DEBUG X64 DxeCore.efi lzma compress 57.2KB | 68.9KB | 58.4KB | 61.7KB
RELEASE X64 Timer.efi 1.84KB | 3KB | 1.62KB | 1.56KB
RELEASE X64 Timer.efi lzma compress 764 Byte | 1.11KB | 737 Byte| 735
Byte
DEBUG X64 Timer.efi 9.68KB | 20KB | 8.37KB | 7.62KB
DEBUG X64 Timer.efi lzma compress 4.63KB | 6.0KB | 4.20KB | 3.95KB
Example steps to use the CLANG38 tool chain to build OVMF platform:
Download and extract the llvm 3.8.0 Pre-Built Binaries from
http://www.llvm.org/releases/ (e.g.
http://www.llvm.org/releases/3.8.0/clang+llvm-3.8.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
and extract it as ~/clang38).
Copy LLVMgold.so from
https://github.com/shijunjing/edk2/blob/llvm/BaseTools/Bin/LLVMgold.so to above
clang lib folder (e.g. ~/clang38/lib/LLVMgold.so, this step is needed only for
CLANG38)
Install new version linker with plugin support (e.g. ld 2.26 in GNU
Binutils 2.26 or Ubuntu16.04, this step is needed only for CLANG38)
$ cd edk2
$ git checkout llvm
$ export CLANG38_BIN=path/to/your/clang38/ (e.g. export
CLANG38_BIN=~/clang38/bin/)
$ source edksetup.sh
$ make -C BaseTools/Source/C
$ build -t CLANG38 -a X64 -p OvmfPkg/OvmfPkgX64.dsc -n 5 -b DEBUG
-DDEBUG_ON_SERIAL_PORT
$ cd edk2/Build/OvmfX64/DEBUG_CLANG38/FV
$ qemu-system-x86_64.exe -bios OVMF.fd -serial file:serial.log -m 4096 -hda
fat:.
If you want, you can build and install GNU Binutils 2.26 as below steps in
Ubuntu
Download binutils-2.26 source code from http://ftp.gnu.org/gnu/binutils/
and extract it to ~/binutils-2.26
$sudo apt-get install bison
$sudo apt-get install flex
Install other necessary binutils build tools if missing
$ mkdir build
$ cd build
$ ../binutils-2.26/configure --enable-gold --enable-plugins
--disable-werror --prefix=/usr
$ make -j 5
$ sudo make install
If you want, you can build LLVMgold.so as below steps
Download llvm-3.8.0 source code from
http://www.llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz and extract it to
~/llvm-3.8.0.src
Download clang3.8.0 source code from
http://www.llvm.org/releases/3.8.0/cfe-3.8.0.src.tar.xz and extract it to
~/llvm-3.8.0.src/tools/clang
Refer http://clang.llvm.org/get_started.html to Install other necessary
clang build tools if missing
$ mkdir llvm38build
$ cd llvm38build
If your GNU Binutils 2.26 is in /home/jshi19/binutils-2.26, $ cmake
../llvm-3.8.0.src -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release"
-DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_VERBOSE_MAKEFILE=ON
-DCMAKE_CXX_COMPILER="/usr/bin/g++" -DCMAKE_C_COMPILER="/usr/bin/gcc"
-DLLVM_BINUTILS_INCDIR=/home/jshi19/binutils-2.26/include
$ make -j 5 LLVMgold The LLVMgold.so is in ~/llvm38build/lib/LLVMgold.so
Shi, Steven (7):
BaseTools: Enable three new toolchains
BaseTools: Add missing Elf relocation type for LTO build
MdePkg: Enable new MS VA intrinsics for GNUC 64bits build
QuarkPlatformPkg-AcpiPlatform: Downgrade the optimization to O1
QuarkSocPkg-MemoryInitPei: Enable compiler builtin and disable CLANG
LTO
QuarkSocPkg-OhicPei: Fix wrong operator
ShellPkg-UefiShellTftpCommandLib: Replace compiler builtin
BaseTools/Conf/build_rule.template | 17 +-
BaseTools/Conf/tools_def.template | 267 +++++++++++++++++++++
BaseTools/Source/C/GenFw/Elf64Convert.c | 98 +++++++-
BaseTools/Source/C/GenFw/elf_common.h | 2 +-
MdePkg/Include/Base.h | 27 ++-
.../Acpi/Dxe/AcpiPlatform/AcpiPlatform.inf | 4 +
.../MemoryInit/Pei/MemoryInitPei.inf | 3 +
.../QuarkSouthCluster/Usb/Ohci/Pei/OhciReg.c | 2 +-
ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c | 2 +-
9 files changed, 403 insertions(+), 19 deletions(-)
mode change 100644 => 100755 BaseTools/Conf/build_rule.template
mode change 100644 => 100755 BaseTools/Conf/tools_def.template
mode change 100644 => 100755 BaseTools/Source/C/GenFw/Elf64Convert.c
mode change 100644 => 100755 BaseTools/Source/C/GenFw/elf_common.h
mode change 100644 => 100755 MdePkg/Include/Base.h
mode change 100644 => 100755
QuarkPlatformPkg/Acpi/Dxe/AcpiPlatform/AcpiPlatform.inf
mode change 100644 => 100755
QuarkSocPkg/QuarkNorthCluster/MemoryInit/Pei/MemoryInitPei.inf
mode change 100644 => 100755
QuarkSocPkg/QuarkSouthCluster/Usb/Ohci/Pei/OhciReg.c
mode change 100644 => 100755 ShellPkg/Library/UefiShellTftpCommandLib/Tftp.c
--
2.7.4
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel