<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:"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:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">You’re creating the alias backwards: _ZTVSt13bad_exception needs to be an externally visible alias pointing to the internal linkage L_ZTVSt13bad_exception. Then you can refer to L_ZTVSt13bad_exception, which is always the local one.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-Eli<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org>
<b>On Behalf Of </b>Leonard Chan via llvm-dev<br>
<b>Sent:</b> Wednesday, May 6, 2020 5:22 PM<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [EXT] [llvm-dev] Emitting a local alias<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">Hi,<o:p></o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">I wanted to see if there was a way in IR to emit a local alias such that I would get:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">        .type   _ZTVSt13bad_exception,@object # @_ZTVSt13bad_exception<br>
        .globl  _ZTVSt13bad_exception<br>
_ZTVSt13bad_exception:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><b>.L_ZTVSt13bad_exception:</b><br>
        .long   0                       # 0x0<br>
        .long   (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8<br>
        .long   (<a href="mailto:_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
        .long   (<a href="mailto:_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
        .long   (<a href="mailto:_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">rather than:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">        .type   _ZTVSt13bad_exception,@object # @_ZTVSt13bad_exception<br>
        .globl  _ZTVSt13bad_exception<br>
_ZTVSt13bad_exception:<br>
        .long   0                       # 0x0<br>
        .long   (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8<br>
        .long   (<a href="mailto:_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
        .long   (<a href="mailto:_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
        .long   (<a href="mailto:_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8">_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
<br>
<b>.set .L_ZTVSt13bad_exception, _ZTVSt13bad_exception</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">The latter is what's generated when using a GlobalAlias with private linkage. I'm asking because in either case, I want to be able to place _ZTVSt13bad_exception in .rodata instead of .<a href="http://data.rel.ro">data.rel.ro</a>
 which requires that the object does not need a relocation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">According to `Constant::needsRelocation()`, a reloc isn't needed if the offset I'm taking (.long symbol_A - symbol_B) contains symbols that are both dso_local. I can guarantee that `symbol_A` will be, but `symbol_B`
 needs to be a global with default visibility. My solution around this is to emit a local alias, but the issue is that with optimizations (-O3), the latter snippet seems to "resolve" the aliases and instead replaces them with my aliasee (_ZTVSt13bad_exception)
 which is not dso_local. An alternative solution to my problem would also be finding a way to somehow prevent the aliases from being "optimized out".<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">Any ideas on either (1) IR that can codegen into my first snippet or (2) prevent my alias in the second snippet from being "optimized out"?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:.5in">- Leonard<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>