<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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-IN" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am facing issue (llvm assertion) in evaluating expressions for MIPS on Linux.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">(lldb) p fooptr(a,b)<o:p></o:p></p>
<p class="MsoNormal">lldb: /home/battarde/git/llvm/lib/MC/ELFObjectWriter.cpp:791: void {anonymous}::ELFObjectWriter::computeSymbolTable(llvm::MCAssembler&, const llvm::MCAsmLayout&, const SectionIndexMapTy&, const RevGroupMapTy&, {anonymous}::ELFObjectWriter::SectionOffsetsTy&):
Assertion `Local || !Symbol.isTemporary()' failed.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I debugged it and found that, LLDB inserts calls to dynamic checker function for pointer validation at appropriate locations in expression’s IR.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The issue is that this checker function’s name (hard-coded in LLDB in lldb\source\Expression\IRDynamicChecks.cpp) starts with “$” i.e “$__lldb_valid_pointer_check”.
<o:p></o:p></p>
<p class="MsoNormal">While creating a MCSymbol (MCContext::createSymbol() in llvm/lib/MC/MCContext.cpp) for this function llvm detects the name starts with “$” and marks that symbol as ‘temporary’ symbol (PrivateGlobalPrefix is '$' for MIPS)<o:p></o:p></p>
<p class="MsoNormal">Further while computing a symbol table in ELFObjectWriter::computeSymbolTable() the assertion triggers because this symbol is 'temporary'.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I tried couple of things that solves this issue for MIPS.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1. Remove '$' from the function name.<o:p></o:p></p>
<p class="MsoNormal">2. Remove "C Language linkage" from the dynamic pointer validation function i.e the below piece of code in lldb\source\Expression\IRDynamicChecks.cpp<o:p></o:p></p>
<p class="MsoNormal">---------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">static const char g_valid_pointer_check_text[] =<o:p></o:p></p>
<p class="MsoNormal">"extern \"C\" void\n"<o:p></o:p></p>
<p class="MsoNormal">"$__lldb_valid_pointer_check (unsigned char *$__lldb_arg_ptr)\n"<o:p></o:p></p>
<p class="MsoNormal">"{\n"<o:p></o:p></p>
<p class="MsoNormal">" unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n"<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">becomes <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">--------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">static const char g_valid_pointer_check_text[] =<o:p></o:p></p>
<p class="MsoNormal">"void\n"<o:p></o:p></p>
<p class="MsoNormal">"$__lldb_valid_pointer_check (unsigned char *$__lldb_arg_ptr)\n"<o:p></o:p></p>
<p class="MsoNormal">"{\n"<o:p></o:p></p>
<p class="MsoNormal">" unsigned char $__lldb_local_val = *$__lldb_arg_ptr;\n"<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">Removing C Language linkage will enable mangling and will mangle "$__lldb_valid_pointer_check" to something like "_Z27$__lldb_valid_pointer_checkPh".<o:p></o:p></p>
<p class="MsoNormal">So the mangled name won't start with '$' and the symbol will not be marked as Temporary and hence assertion won't be triggered.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Please let me know if there is any better solution to this issue.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Bhushan<o:p></o:p></p>
</div>
</body>
</html>