This is v3 of the series to enable compiler optimization under GCC for builds targetting X64. It includes a patch from Steven Shi, taken from his series to introduce support for GCC 5.x and Clang 3.8/X64 to EDK2.
The first patch fixes the issue that __builtin_unreachable() is not implemented by GCC 4.4 or earlier. Patch #2 sets a new define for OpensslLib that we will test in patches #3 and #4 to inhibit the use of the MS varargs ABI when building OpenSSL, which lacks the ms_abi attributes on its variadic functions. Patch #3 is Steven's patch to switch to the flavor of VA_LIST that is explicitly modeled after the MS implementation. This by itself is an improvement, since the open coded implementation that performs arithmetic on the address of explicit arguments to obtain the variadic arguments is fragile and difficult to maintain, and should be best avoided. Patch #4 ports patch #3 to EdkCompatibilityPkg Patch #5 enables -Os optimization for X64/RELEASE and X86/DEBUG all the way back to GCC44. This aligns X64 with IA32, which is already built using -Os for both DEBUG and RELEASE. Note that the reported breakage regarding the use of -Os [0] is likely caused by the poor man's __builtin_ms_va_list (NO_BUILTIN_VA_FUNCS) that we used for GCC/X64 before Steven's patch above switches us to a properly defined builtin type. (The poor man's implementation uses pointer arithmetic involving the address of the last named argument to calculate pointers to the variadic arguments and dereferences them to obtain the argument values. I'm quite surprised it works as well as it does at -O0, to be honest) I tested this change with both Ovmf and EmulatorPkg built in various ways and with various versions, with the caveat that I did not always use a matching binutils (i.e., of the same era). Since the issues this series deal with are all code generation issues, I think this is reasonable, but more testing would be appreciated. (v2: this still applies, I have tested DEBUG and RELEASE builds using GCC44, GCC46, GCC47 and GCC48, but all on the same Ubuntu 14.04 system, which means they all use the same ld version 2.24.90) [0] http://thread.gmane.org/gmane.comp.bios.tianocore.devel/10963 Patch #6 explicitly forbids the poor man's MS ABI varargs implementation when using GCC with optimization enabled. Patch #7 drops checks for the NO_BUILTIN_VA_FUNCS macro, which is never defined anymore. Patch #8 applies the visibility 'protected' GCC pragma globally. Please refer to the commit log for the motivation. Patch #9 switches GCC/X64 to the PIE small code model, which results in smaller code. Changes in v3: - Ensure OpensslLib does not switch to the MS varargs ABI inadvertently - Switch to -fpie code generation rather than -fpic, which is more suitable for executables. Note that this is *not* the -pie linker switch which generates a RELA section and a _DYNAMIC entrypoint. - Use 'protected' rather than 'hidden' visibility, which is equally suitable for our purposes (inhibiting generation of GOT entries) but interoperates better with LTO, which we intend to enable for GCC 5 and up - dropped Laszlo's 'tested-by' from all patches, which was given based on v1 Branch can be found here https://git.linaro.org/people/ard.biesheuvel/uefi-next.git/shortlog/refs/heads/gcc-x64-opt-v3 Changes in v2: - Switch to -Os optimization, both for DEBUG and RELEASE builds. This turns out to work fine (as far as I could establish) and gives the best results in terms of code size. Ard Biesheuvel (8): MdePkg: avoid __builtin_unreachable() on GCC v4.4 CryptoPkg: set new define to avoid MS ABI VA_LIST on GCC/X64 EdkCompatibilityPkg: Enable new MS VA intrinsics for GNUC x86 64bits build BaseTools/tools_def: enable Os optimization for GCC X64 builds MdePkg: disallow open coded varargs implementation on optimizing GCC MdePkg CryptoPkg EdkCompatibilityPkg: retire NO_BUILTIN_VA_FUNCS define MdePkg X64: force 'protected' visibility when building with -fpic BaseTools/tools_def: switch GCC/X64 to the PIE small model Shi, Steven (1): MdePkg: Enable new MS VA intrinsics for GNUC x86 64bits build BaseTools/Conf/tools_def.template | 2 +- CryptoPkg/Library/OpensslLib/OpensslLib.inf | 2 +- EdkCompatibilityPkg/Foundation/Include/EfiStdArg.h | 28 ++++++++++++++- MdePkg/Include/Base.h | 36 ++++++++++++++++++-- MdePkg/Include/X64/ProcessorBind.h | 9 +++++ 5 files changed, 72 insertions(+), 5 deletions(-) -- 1.9.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

