<div dir="ltr">Ah, you're right. This accomplishes what I need. Thanks!</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 6, 2020 at 5:43 PM Eli Friedman <<a href="mailto:efriedma@quicinc.com">efriedma@quicinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="gmail-m_1216773541556289595WordSection1">
<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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">-Eli<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal" style="margin-left:0.5in"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>>
<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 <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> [EXT] [llvm-dev] Emitting a local alias<u></u><u></u></p>
</div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-left:0.5in">Hi,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">I wanted to see if there was a way in IR to emit a local alias such that I would get:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"> .type _ZTVSt13bad_exception,@object # @_ZTVSt13bad_exception<br>
.globl _ZTVSt13bad_exception<br>
_ZTVSt13bad_exception:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.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" target="_blank">_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
.long (<a href="mailto:_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8" target="_blank">_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
.long (<a href="mailto:_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8" target="_blank">_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">rather than:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.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" target="_blank">_ZNSt13bad_exceptionD2Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
.long (<a href="mailto:_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8" target="_blank">_ZNSt13bad_exceptionD0Ev.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
.long (<a href="mailto:_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8" target="_blank">_ZNKSt13bad_exception4whatEv.stub@PLT-.L_ZTVSt13bad_exception)-8</a><br>
<br>
<b>.set .L_ZTVSt13bad_exception, _ZTVSt13bad_exception</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">```<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.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" target="_blank">data.rel.ro</a>
which requires that the object does not need a relocation.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.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".<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.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"?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:0.5in">- Leonard<u></u><u></u></p>
</div>
</div>
</div>
</div>
</blockquote></div>