Hi,
I wanted to see if there was a way in IR to emit a local alias such that I
would get:
```
.type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception
.globl _ZTVSt13bad_exception
_ZTVSt13bad_exception:
*.L_ZTVSt13bad_exception:*
.long 0 # 0x0
.long (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD2Ev.stub at PLT-
.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD0Ev.stub at PLT-
.L_ZTVSt13bad_exception)-8
.long (_ZNKSt13bad_exception4whatEv.stub at PLT-
.L_ZTVSt13bad_exception)-8
```
rather than:
```
.type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception
.globl _ZTVSt13bad_exception
_ZTVSt13bad_exception:
.long 0 # 0x0
.long (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD2Ev.stub at PLT-
.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD0Ev.stub at PLT-
.L_ZTVSt13bad_exception)-8
.long (_ZNKSt13bad_exception4whatEv.stub at PLT-
.L_ZTVSt13bad_exception)-8
*.set .L_ZTVSt13bad_exception, _ZTVSt13bad_exception*
```
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 .data.rel.ro which requires
that the object does not need a relocation.
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".
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"?
- Leonard
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20200506/e113ab4a/attachment.html>
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.
-Eli
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Leonard
Chan via llvm-dev
Sent: Wednesday, May 6, 2020 5:22 PM
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [EXT] [llvm-dev] Emitting a local alias
Hi,
I wanted to see if there was a way in IR to emit a local alias such that I would
get:
```
.type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception
.globl _ZTVSt13bad_exception
_ZTVSt13bad_exception:
.L_ZTVSt13bad_exception:
.long 0 # 0x0
.long (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD2Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNSt13bad_exceptionD2Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8>
.long (_ZNSt13bad_exceptionD0Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNSt13bad_exceptionD0Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8>
.long (_ZNKSt13bad_exception4whatEv.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNKSt13bad_exception4whatEv.stub at
PLT-.L_ZTVSt13bad_exception)-8>
```
rather than:
```
.type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception
.globl _ZTVSt13bad_exception
_ZTVSt13bad_exception:
.long 0 # 0x0
.long (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8
.long (_ZNSt13bad_exceptionD2Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNSt13bad_exceptionD2Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8>
.long (_ZNSt13bad_exceptionD0Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNSt13bad_exceptionD0Ev.stub at
PLT-.L_ZTVSt13bad_exception)-8>
.long (_ZNKSt13bad_exception4whatEv.stub at
PLT-.L_ZTVSt13bad_exception)-8<mailto:_ZNKSt13bad_exception4whatEv.stub at
PLT-.L_ZTVSt13bad_exception)-8>
.set .L_ZTVSt13bad_exception, _ZTVSt13bad_exception
```
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
.data.rel.ro<http://data.rel.ro> which requires that the object does not
need a relocation.
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".
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"?
- Leonard
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20200507/8661c1c5/attachment.html>
Ah, you're right. This accomplishes what I need. Thanks! On Wed, May 6, 2020 at 5:43 PM Eli Friedman <efriedma at quicinc.com> wrote:> 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. > > > > -Eli > > > > *From:* llvm-dev <llvm-dev-bounces at lists.llvm.org> *On Behalf Of *Leonard > Chan via llvm-dev > *Sent:* Wednesday, May 6, 2020 5:22 PM > *To:* llvm-dev <llvm-dev at lists.llvm.org> > *Subject:* [EXT] [llvm-dev] Emitting a local alias > > > > Hi, > > > > I wanted to see if there was a way in IR to emit a local alias such that I > would get: > > > > ``` > > .type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception > .globl _ZTVSt13bad_exception > _ZTVSt13bad_exception: > > *.L_ZTVSt13bad_exception:* > .long 0 # 0x0 > .long > (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNSt13bad_exceptionD2Ev.stub at PLT-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNSt13bad_exceptionD0Ev.stub at PLT-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNKSt13bad_exception4whatEv.stub at PLT-.L_ZTVSt13bad_exception)-8 > ``` > > > > rather than: > > > > ``` > > .type _ZTVSt13bad_exception, at object # @_ZTVSt13bad_exception > .globl _ZTVSt13bad_exception > _ZTVSt13bad_exception: > .long 0 # 0x0 > .long > (_ZTISt13bad_exception.rtti_proxy-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNSt13bad_exceptionD2Ev.stub at PLT-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNSt13bad_exceptionD0Ev.stub at PLT-.L_ZTVSt13bad_exception)-8 > .long ( > _ZNKSt13bad_exception4whatEv.stub at PLT-.L_ZTVSt13bad_exception)-8 > > *.set .L_ZTVSt13bad_exception, _ZTVSt13bad_exception* > > ``` > > > > 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 .data.rel.ro which requires > that the object does not need a relocation. > > > > 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". > > > > 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"? > > > > - Leonard >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200507/859a7d64/attachment-0001.html>