<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=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:宋体;
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:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"\@宋体";
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;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 129.75pt 1.0in 129.7pt;}
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="MsoPlainText">Hi Mehdi,<o:p></o:p></p>
<p class="MsoPlainText">After deeper debug, I found my firmware LTO wrong code issue is related to X64 code model (-mcmodel=large) is always overridden as small (-mcmodel=small) if LTO build. And I don't know how to correctly specific the large code model for
my X64 firmware LTO build. Appreciate if you could let me know it. <o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">You know, parts of my Uefi firmware (BIOS) have to been loaded to run in high address (larger than 2 GB) at the very beginning, and I need the code makes absolutely no assumptions about the addresses and data sections. But current LLVM
LTO seems stick to use the small code model and generate many code with 32-bit RIP-relative addressing, which cause CPU exceptions when run in address larger than 2GB.<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Below, I just simply reuse the Eli's codemodel1.c example (link:
<a href="http://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models">
http://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models</a>) to show the LLVM LTO code model issue.<o:p></o:p></p>
<p class="MsoPlainText">$ clang -g -O0 codemodel1.c -mcmodel=large -o codemodel1_large.bin<o:p></o:p></p>
<p class="MsoPlainText">$ clang -g -O0 codemodel1.c -mcmodel=small -o codemodel1_small.bin<o:p></o:p></p>
<p class="MsoPlainText">$ clang -g -O0 -flto codemodel1.c -mcmodel=large -o codemodel1_large_lto.bin<o:p></o:p></p>
<p class="MsoPlainText">$ clang -g -O0 -flto codemodel1.c -mcmodel=small -o codemodel1_small_lto.bin<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">You will see the codemodel1_large_lto.bin and codemodel1_small_lto.bin are exactly the same!<o:p></o:p></p>
<p class="MsoPlainText">And if you disassemble the codemodel1_large_lto.bin, you will see it uses the small code model (32-bit RIP-relative), not large, to do addressing as below.
<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">$ objdump -dS codemodel1_large_lto.bin<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">int main(int argc, const char* argv[])<o:p></o:p></p>
<p class="MsoPlainText">{<o:p></o:p></p>
<p class="MsoPlainText"> 4004f0: 55 push %rbp<o:p></o:p></p>
<p class="MsoPlainText"> 4004f1: 48 89 e5 mov %rsp,%rbp<o:p></o:p></p>
<p class="MsoPlainText"> 4004f4: 48 83 ec 20 sub $0x20,%rsp<o:p></o:p></p>
<p class="MsoPlainText"> 4004f8: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> 4004ff: 89 7d f8 mov %edi,-0x8(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> 400502: 48 89 75 f0 mov %rsi,-0x10(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> int t = global_func(argc);<o:p></o:p></p>
<p class="MsoPlainText"> 400506: 8b 7d f8 mov -0x8(%rbp),%edi<o:p></o:p></p>
<p class="MsoPlainText"><span style="color:red"> 400509: e8 d2 ff ff ff callq 4004e0 <global_func></span><o:p></o:p></p>
<p class="MsoPlainText"> 40050e: 89 45 ec mov %eax,-0x14(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> t += global_arr[7];<o:p></o:p></p>
<p class="MsoPlainText"><span style="color:red"> 400511: 8b 04 25 4c 10 60 00 mov 0x60104c,%eax<o:p></o:p></span></p>
<p class="MsoPlainText"> 400518: 03 45 ec add -0x14(%rbp),%eax<o:p></o:p></p>
<p class="MsoPlainText"> 40051b: 89 45 ec mov %eax,-0x14(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> t += static_arr[7];<o:p></o:p></p>
<p class="MsoPlainText"><span style="color:red"> 40051e: 8b 04 25 dc 11 60 00 mov 0x6011dc,%eax</span><o:p></o:p></p>
<p class="MsoPlainText"> 400525: 03 45 ec add -0x14(%rbp),%eax<o:p></o:p></p>
<p class="MsoPlainText"> 400528: 89 45 ec mov %eax,-0x14(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> t += global_arr_big[7];<o:p></o:p></p>
<p class="MsoPlainText"><span style="color:red"> 40052b: 8b 04 25 6c 13 60 00 mov 0x60136c,%eax</span><o:p></o:p></p>
<p class="MsoPlainText"> 400532: 03 45 ec add -0x14(%rbp),%eax<o:p></o:p></p>
<p class="MsoPlainText"> 400535: 89 45 ec mov %eax,-0x14(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> t += static_arr_big[7];<o:p></o:p></p>
<p class="MsoPlainText"><span style="color:red"> 400538: 8b 04 25 ac 20 63 00 mov 0x6320ac,%eax</span><o:p></o:p></p>
<p class="MsoPlainText"> 40053f: 03 45 ec add -0x14(%rbp),%eax<o:p></o:p></p>
<p class="MsoPlainText"> 400542: 89 45 ec mov %eax,-0x14(%rbp)<o:p></o:p></p>
<p class="MsoPlainText"> return t;<o:p></o:p></p>
<p class="MsoPlainText"> 400545: 8b 45 ec mov -0x14(%rbp),%eax<o:p></o:p></p>
<p class="MsoPlainText"> 400548: 48 83 c4 20 add $0x20,%rsp<o:p></o:p></p>
<p class="MsoPlainText"> 40054c: 5d pop %rbp<o:p></o:p></p>
<p class="MsoPlainText"> 40054d: c3 retq<o:p></o:p></p>
<p class="MsoPlainText"> 40054e: 66 90 xchg %ax,%ax<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">So, does LTO support large code model? How to correctly specify the LTO code model option?<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Steven Shi<o:p></o:p></p>
<p class="MsoPlainText">Intel\SSG\STO\UEFI Firmware<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText">Tel: +86 021-61166522<o:p></o:p></p>
<p class="MsoPlainText">iNet: 821-6522<o:p></o:p></p>
<p class="MsoPlainText"><o:p> </o:p></p>
<p class="MsoPlainText"><a name="_____replyseparator"></a>> -----Original Message-----</p>
<p class="MsoPlainText">> From: mehdi.amini@apple.com [mailto:mehdi.amini@apple.com]</p>
<p class="MsoPlainText">> Sent: Wednesday, May 18, 2016 4:02 AM</p>
<p class="MsoPlainText">> To: Umesh Kalappa <umesh.kalappa0@gmail.com></p>
<p class="MsoPlainText">> Cc: Shi, Steven <steven.shi@intel.com>; llvm-dev <llvm-dev@lists.llvm.org>;</p>
<p class="MsoPlainText">> cfe-dev@lists.llvm.org</p>
<p class="MsoPlainText">> Subject: Re: [cfe-dev] [llvm-dev] How to debug if LTO generate wrong code?</p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> > On May 17, 2016, at 11:21 AM, Umesh Kalappa</p>
<p class="MsoPlainText">> <<a href="mailto:umesh.kalappa0@gmail.com"><span style="color:windowtext;text-decoration:none">umesh.kalappa0@gmail.com</span></a>> wrote:</p>
<p class="MsoPlainText">> ></p>
<p class="MsoPlainText">> > Steven,</p>
<p class="MsoPlainText">> ></p>
<p class="MsoPlainText">> > As mehdi stated , the optimisation level is specific to linker and it</p>
<p class="MsoPlainText">> > enables Inter-Pro opts passes ,please refer function</p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> To be very clear: the -O option may trigger *linker* optimizations as well,</p>
<p class="MsoPlainText">> independently of LTO.</p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> --</p>
<p class="MsoPlainText">> Mehdi</p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText">> </p>
<p class="MsoPlainText"><o:p> </o:p></p>
</div>
</body>
</html>