On Fri, Jul 8, 2016 at 9:42 AM, Shi, Steven <steven....@intel.com> wrote:
> LANG38 uses Clang3.8.0, enable LLVM Link Time Optimization (LTO)
> and code size optimization flag (-Oz) by default for aggressive code
> size improvement. CLANG38 X64 code is small code model + PIE.
>
> Test pass platforms: OVMF (OvmfPkgIa32.dsc, OvmfPkgX64.dsc).
> Test compiler and linker version: LLVM 3.8, GNU ld 2.26.
>
> Example steps to use the CLANG38 tool chain to build OVMF platform:
> 1. 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).
> 2. 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)
> 3. 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
>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Steven Shi <steven....@intel.com>
> ---
>  BaseTools/Conf/build_rule.template |  7 ++-
>  BaseTools/Conf/tools_def.template  | 87 
> ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 92 insertions(+), 2 deletions(-)
>
> diff --git a/BaseTools/Conf/build_rule.template 
> b/BaseTools/Conf/build_rule.template
> index 25cf380..4530d92 100755
> --- a/BaseTools/Conf/build_rule.template
> +++ b/BaseTools/Conf/build_rule.template
> @@ -267,7 +267,10 @@
>
>      <Command.GCC>
>          "$(SLINK)" -cr ${dst} $(SLINK_FLAGS) @$(OBJECT_FILES_LIST)
> -
> +
> +    <Command.CLANG38>
> +        "$(SLINK)" cr ${dst} $(SLINK_FLAGS) @$(OBJECT_FILES_LIST)
> +
>      <Command.RVCT>
>          "$(SLINK)" $(SLINK_FLAGS) ${dst} --via $(OBJECT_FILES_LIST)
>
> @@ -295,7 +298,7 @@
>          "$(DLINK)" -o ${dst} $(DLINK_FLAGS) --start-group $(DLINK_SPATH) 
> @$(STATIC_LIBRARY_FILES_LIST) --end-group $(DLINK2_FLAGS)
>          "$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}
>
> -    <Command.GCC5>
> +    <Command.GCC5, Command.CLANG38>
>          "$(DLINK)" -o ${dst} $(DLINK_FLAGS) 
> -Wl,--start-group,$(DLINK_SPATH),@$(STATIC_LIBRARY_FILES_LIST) 
> -Wl,--end-group $(DLINK2_FLAGS)
>          "$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}
>
> diff --git a/BaseTools/Conf/tools_def.template 
> b/BaseTools/Conf/tools_def.template
> index e41aad14..092a393 100755
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -378,6 +378,12 @@ DEFINE SOURCERY_CYGWIN_TOOLS = /cygdrive/c/Program 
> Files/CodeSourcery/Sourcery G
>  #                             Required to build platforms or ACPI tables:
>  #                               Intel(r) ACPI Compiler from
>  #                               https://acpica.org/downloads
> +#   CLANG38  -Linux-  Requires:
> +#                             Clang v3.8 or later, LLVMgold plugin and GNU 
> binutils 2.26 targeting x86_64-linux-gnu
> +#                        Optional:
> +#                             Required to build platforms or ACPI tables:
> +#                               Intel(r) ACPI Compiler from
> +#                               https://acpica.org/downloads
>  #   ELFGCC      -Linux-  Requires:
>  #                             GCC(this tool chain uses whatever version of 
> gcc and binutils that is installed in /usr/bin)
>  #                        Optional:
> @@ -7417,6 +7423,87 @@ RELEASE_RVCTCYGWIN_ARM_CC_FLAGS  = "$(CCPATH_FLAG)" 
> $(ARCHCC_FLAGS) $(PLATFORM_F
>  #################
>  *_*_*_*_BUILDRULEORDER = nasm asm Asm ASM S s
>
> +####################################################################################
> +#
> +# Clang 3.8 - This configuration is used to compile under Linux to produce
> +#  PE/COFF binaries using LLVM/Clang 3.8 with Link Time Optimization enabled
> +#
> +####################################################################################
> +
> +*_CLANG38_*_*_FAMILY                = GCC
> +*_CLANG38_*_*_BUILDRULEFAMILY       = CLANG38
> +*_CLANG38_*_MAKE_PATH               = DEF(GCC49_IA32_PREFIX)make
> +*_CLANG38_*_*_DLL                   = ENV(CLANG38_DLL)
> +*_CLANG38_*_ASL_PATH                = DEF(UNIX_IASL_BIN)
> +
> +*_CLANG38_*_PP_FLAGS                = DEF(GCC_PP_FLAGS) -target 
> x86_64-pc-linux-gnu
> +*_CLANG38_*_ASLPP_FLAGS             = DEF(GCC_ASLPP_FLAGS) -target 
> x86_64-pc-linux-gnu
> +*_CLANG38_*_VFRPP_FLAGS             = DEF(GCC_VFRPP_FLAGS) -target 
> x86_64-pc-linux-gnu
> +*_CLANG38_*_APP_FLAGS               =
> +*_CLANG38_*_ASL_FLAGS               = DEF(IASL_FLAGS)
> +*_CLANG38_*_ASL_OUTFLAGS            = DEF(IASL_OUTFLAGS)
> +
> +DEFINE CLANG38_IA32_PREFIX          = ENV(CLANG38_BIN)
> +DEFINE CLANG38_X64_PREFIX           = ENV(CLANG38_BIN)
> +
> +DEFINE CLANG38_ALL_CC_FLAGS     = -c -fshort-wchar -fno-strict-aliasing 
> -Wall -Werror -Wno-array-bounds -Wno-empty-body -ffunction-sections 
> -fdata-sections -include AutoGen.h -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings 
> -fno-stack-protector -fno-builtin -mms-bitfields -Wno-address 
> -Wno-shift-negative-value -Wno-parentheses-equality -Wno-unknown-pragmas 
> -Wno-tautological-constant-out-of-range-compare 
> -Wno-incompatible-library-redeclaration -target x86_64-pc-linux-gnu 
> -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -msoft-float 
> -mno-implicit-float  
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
> -funsigned-char -fno-ms-extensions -fno-common -Wno-null-dereference 
> -Wno-tautological-compare
> +

Same remark from my previous email: you should not use
x86_64-pc-linux-gnu as a default target. Look at how it is done for
CLANG35

> +DEFINE CLANG38_ALL_DLINK_FLAGS  = -flto -nostdlib -Wl,-n -Wl,-q 
> -Wl,--gc-sections -z common-page-size=0x40 -Wl,--entry,$(IMAGE_ENTRY_POINT) 
> -Wl,-u,$(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map
> +DEFINE CLANG38_IA32_DLINK2_FLAGS = -Wl,--defsym=PECOFF_HEADER_SIZE=0x220 
> -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
> +DEFINE CLANG38_X64_DLINK2_FLAGS  = -Wl,--defsym=PECOFF_HEADER_SIZE=0x228 
> -Wl,--script=$(EDK_TOOLS_PATH)/Scripts/GccBase.lds
> +
> +###########################
> +# CLANG38 IA32 definitions
> +###########################
> +*_CLANG38_IA32_OBJCOPY_PATH         = DEF(GCC49_IA32_PREFIX)objcopy
> +*_CLANG38_IA32_CC_PATH              = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_SLINK_PATH           = DEF(CLANG38_IA32_PREFIX)llvm-ar
> +*_CLANG38_IA32_DLINK_PATH           = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_ASLDLINK_PATH        = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_ASM_PATH             = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_PP_PATH              = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_VFRPP_PATH           = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_ASLCC_PATH           = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_ASLPP_PATH           = DEF(CLANG38_IA32_PREFIX)clang
> +*_CLANG38_IA32_RC_PATH              = DEF(GCC49_IA32_PREFIX)objcopy
> +
> +*_CLANG38_IA32_ASLCC_FLAGS          = -x c -Os -m32 -target 
> x86_64-pc-linux-gnu -flto

Again, the target is wrong

> +*_CLANG38_IA32_ASLDLINK_FLAGS       = DEF(CLANG38_ALL_DLINK_FLAGS) -Wl,-Oz 
> -Wl,-melf_i386 -Wl,--entry,ReferenceAcpiTable -Wl,-u,ReferenceAcpiTable
> +*_CLANG38_IA32_ASM_FLAGS            = DEF(GCC49_ASM_FLAGS) -m32 -march=i386
> +DEBUG_CLANG38_IA32_CC_FLAGS         = DEF(CLANG38_ALL_CC_FLAGS) -m32 -Oz 
> -flto -march=i586 -g
> +RELEASE_CLANG38_IA32_CC_FLAGS       = DEF(CLANG38_ALL_CC_FLAGS) -m32 -Oz 
> -flto -march=i586
> +*_CLANG38_IA32_DLINK_FLAGS          = DEF(CLANG38_ALL_DLINK_FLAGS) -Wl,-Oz 
> -Wl,-melf_i386 -Wl,--oformat=elf32-i386
> +*_CLANG38_IA32_DLINK2_FLAGS         = DEF(CLANG38_IA32_DLINK2_FLAGS)
> +*_CLANG38_IA32_RC_FLAGS             = DEF(GCC_IA32_RC_FLAGS)
> +*_CLANG38_IA32_OBJCOPY_FLAGS        =
> +*_CLANG38_IA32_NASM_FLAGS           = -f elf32
> +
> +##########################
> +# CLANG38 X64 definitions
> +##########################
> +*_CLANG38_X64_OBJCOPY_PATH         = DEF(GCC49_X64_PREFIX)objcopy
> +*_CLANG38_X64_CC_PATH              = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_SLINK_PATH           = DEF(CLANG38_X64_PREFIX)llvm-ar
> +*_CLANG38_X64_DLINK_PATH           = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_ASLDLINK_PATH        = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_ASM_PATH             = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_PP_PATH              = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_VFRPP_PATH           = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_ASLCC_PATH           = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_ASLPP_PATH           = DEF(CLANG38_X64_PREFIX)clang
> +*_CLANG38_X64_RC_PATH              = DEF(GCC49_X64_PREFIX)objcopy
> +
> +*_CLANG38_X64_ASLCC_FLAGS          = -x c -Os -m64 -target 
> x86_64-pc-linux-gnu -flto
> +*_CLANG38_X64_ASLDLINK_FLAGS       = DEF(CLANG38_ALL_DLINK_FLAGS) -Wl,-Oz 
> -Wl,-melf_x86_64 -Wl,--entry,ReferenceAcpiTable -Wl,-u,ReferenceAcpiTable 
> -Wl,-pie -mcmodel=small
> +*_CLANG38_X64_ASM_FLAGS            = DEF(GCC49_ASM_FLAGS) -m64 -target 
> x86_64-pc-linux-gnu
> +DEBUG_CLANG38_X64_CC_FLAGS         = DEF(CLANG38_ALL_CC_FLAGS) -m64 
> "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -g -Oz 
> -flto
> +RELEASE_CLANG38_X64_CC_FLAGS       = DEF(CLANG38_ALL_CC_FLAGS) -m64 
> "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=small -fpie -Oz 
> -flto
> +*_CLANG38_X64_DLINK_FLAGS          = DEF(CLANG38_ALL_DLINK_FLAGS) -Wl,-Oz 
> -Wl,-melf_x86_64 -Wl,--oformat=elf64-x86-64 -Wl,-pie -mcmodel=small
> +*_CLANG38_X64_DLINK2_FLAGS         = DEF(CLANG38_X64_DLINK2_FLAGS)
> +*_CLANG38_X64_RC_FLAGS             = DEF(GCC_X64_RC_FLAGS)
> +*_CLANG38_X64_OBJCOPY_FLAGS        =
> +*_CLANG38_X64_NASM_FLAGS           = -f elf64
> +
>  
> ##########################################################################################
>  #
>  # GCC 5.x - This configuration is used to compile under Linux to produce
> --
> 2.7.4
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to