<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hello,<o:p></o:p></p>
<p class="MsoNormal">I'm enabling clang LTO to improve code size of Uefi standard (<a href="http://www.uefi.org/">http://www.uefi.org/</a>) firmware (<a href="https://github.com/tianocore/edk2">https://github.com/tianocore/edk2</a>), which is mostly C code.
 My project is in https://github.com/shijunjing/edk2 branch llvm : <a href="https://github.com/shijunjing/edk2/tree/llvm">
https://github.com/shijunjing/edk2/tree/llvm</a>. I find my most firmware modules work well after enable LTO, but some X64 modules will not run (e.g. hang with CPU exception) , and these X64 modules work well if build with the LTO disabled (-fno-lto).
<o:p></o:p></p>
<p class="MsoNormal">I don’t know how to efficiently debug these LTO wrong code and investigate if there is compiler’s bug. I appreciate if anyone can  give me some suggestions about the clang LTO issue debug method, commands, or BKMs.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Below are  my clang LTO build tools and options, I use clang 3.8 release with
<span style="color:black">binutils 2.26</span> ld (I’ve pushed ld support LLVM gold plugin
<a href="https://sourceware.org/bugzilla/show_bug.cgi?id=20070">https://sourceware.org/bugzilla/show_bug.cgi?id=20070</a>). Any suggestion is welcome!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">##################<o:p></o:p></p>
<p class="MsoNormal"># CLANGLTO38 X64 definitions<o:p></o:p></p>
<p class="MsoNormal">##################<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_OBJCOPY_PATH         = DEF(GCC53_X64_PREFIX)objcopy<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_CC_PATH              = DEF(CLANG38_X64_PREFIX)clang<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_SLINK_PATH           = DEF(CLANG38_X64_PREFIX)llvm-ar
<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_DLINK_PATH           = DEF(CLANG38_X64_PREFIX)clang<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_ASM_PATH             = DEF(CLANG38_X64_PREFIX)clang<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_PP_PATH              = DEF(CLANG38_X64_PREFIX)clang<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_RC_PATH              = DEF(GCC53_X64_PREFIX)objcopy<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_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 -m64 -Wno-enum-conversion
 "-DEFIAPI=__attribute__((ms_abi))" -mno-red-zone -mcmodel=large -g <span style="color:red">
-Os -flto  </span><o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_DLINK_FLAGS  = <span style="color:red">-flto
</span>-nostdlib -Wl,-n -Wl,-q -Wl,--gc-sections -Wl,-z,common-page-size=0x40 -Wl,--entry,$(IMAGE_ENTRY_POINT) -Wl,-u,$(IMAGE_ENTRY_POINT) -Wl,-Map,$(DEST_DIR_DEBUG)/$(BASE_NAME).map -Wl,-melf_x86_64 -Wl,--oformat=elf64-x86-64<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_ASM_FLAGS            = -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h -m64 -target x86_64-pc-linux-gnu
<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_RC_FLAGS             = -I binary -O elf64-x86-64        -B i386    --rename-section .data=.hii<o:p></o:p></p>
<p class="MsoNormal">*_CLANGLTO38_X64_NASM_FLAGS           = -f elf64<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Steven Shi</span></b><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial",sans-serif">Intel\SSG\STO\UEFI Firmware</span></b><b><span style="font-size:12.0pt;font-family:"Arial",sans-serif"><o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></b></p>
<p class="MsoNormal" style="text-align:justify;text-justify:inter-ideograph"><span style="font-size:9.0pt;font-family:"Arial",sans-serif">Tel: +86 021-61166522<o:p></o:p></span></p>
<p class="MsoNormal" style="text-align:justify;text-justify:inter-ideograph"><span style="font-size:9.0pt;font-family:"Arial",sans-serif">iNet: 821-6522<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>