-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[Arch] | ||
PointerSize = 8 | ||
SymbolReloc = R_PPC64_ADDR64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
* Copyright 2024 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
.machine power9 | ||
.abiversion 2 | ||
|
||
.section .note.GNU-stack,"",@progbits | ||
|
||
.data | ||
|
||
.globl _${lib_suffix}_tramp_table | ||
.hidden _${lib_suffix}_tramp_table | ||
.align 8 | ||
_${lib_suffix}_tramp_table: | ||
.zero $table_size | ||
|
||
.section ".toc","aw" | ||
.align 3 | ||
.LC0: | ||
.quad _${lib_suffix}_tramp_table | ||
|
||
.section ".text" | ||
|
||
.globl _${lib_suffix}_tramp_resolve | ||
.hidden _${lib_suffix}_tramp_resolve | ||
|
||
.globl _${lib_suffix}_save_regs_and_resolve | ||
.hidden _${lib_suffix}_save_regs_and_resolve | ||
.type _${lib_suffix}_save_regs_and_resolve, %function | ||
|
||
_${lib_suffix}_save_regs_and_resolve: | ||
.cfi_startproc | ||
.LCF0: | ||
addis 2, 12, .TOC. - .LCF0@ha | ||
addi 2, 2, .TOC. - .LCF0@l | ||
.localentry _${lib_suffix}_save_regs_and_resolve, . - _${lib_suffix}_save_regs_and_resolve | ||
|
||
// Slow path which calls dlsym, taken only on first call. | ||
// Registers are saved acc. to PPC64 ELF ABI | ||
// For DWARF directives, read https://www.imperialviolet.org/2017/01/18/cfi.html. | ||
|
||
mflr 0 | ||
std 0, 16(1) | ||
|
||
ld 0, 48-8(1) | ||
|
||
std 3, -8(1) | ||
std 4, -16(1) | ||
std 5, -24(1) | ||
std 6, -32(1) | ||
std 7, -40(1) | ||
std 8, -48(1) | ||
std 9, -56(1) | ||
std 10, -64(1) | ||
|
||
stfd 1, -72(1) | ||
stfd 2, -80(1) | ||
stfd 3, -88(1) | ||
stfd 4, -96(1) | ||
stfd 5, -104(1) | ||
stfd 6, -112(1) | ||
stfd 7, -120(1) | ||
stfd 8, -128(1) | ||
stfd 9, -136(1) | ||
stfd 10, -144(1) | ||
stfd 11, -152(1) | ||
stfd 12, -160(1) | ||
stfd 13, -168(1) | ||
|
||
// TODO: also save Altivec registers | ||
|
||
stdu 1, -256(1) | ||
|
||
.cfi_def_cfa_offset 256 | ||
.cfi_offset r3, -8 | ||
.cfi_offset r4, -16 | ||
.cfi_offset r5, -24 | ||
.cfi_offset r6, -32 | ||
.cfi_offset r7, -40 | ||
.cfi_offset r8, -48 | ||
.cfi_offset r9, -56 | ||
.cfi_offset r10, -64 | ||
.cfi_offset f1, -72 | ||
.cfi_offset f2, -80 | ||
.cfi_offset f3, -88 | ||
.cfi_offset f4, -96 | ||
.cfi_offset f5, -104 | ||
.cfi_offset f6, -112 | ||
.cfi_offset f7, -120 | ||
.cfi_offset f8, -128 | ||
.cfi_offset f9, -136 | ||
.cfi_offset f10, -144 | ||
.cfi_offset f11, -152 | ||
.cfi_offset f12, -160 | ||
.cfi_offset f13, -168 | ||
|
||
mr 3, 0 | ||
|
||
bl _${lib_suffix}_tramp_resolve | ||
nop | ||
|
||
addi 1, 1, 256 | ||
.cfi_def_cfa_offset 0 | ||
|
||
ld 3, -8(1) | ||
ld 4, -16(1) | ||
ld 5, -24(1) | ||
ld 6, -32(1) | ||
ld 7, -40(1) | ||
ld 8, -48(1) | ||
ld 9, -56(1) | ||
ld 10, -64(1) | ||
|
||
lfd 1, -72(1) | ||
lfd 2, -80(1) | ||
lfd 3, -88(1) | ||
lfd 4, -96(1) | ||
lfd 5, -104(1) | ||
lfd 6, -112(1) | ||
lfd 7, -120(1) | ||
lfd 8, -128(1) | ||
lfd 9, -136(1) | ||
lfd 10, -144(1) | ||
lfd 11, -152(1) | ||
lfd 12, -160(1) | ||
lfd 13, -168(1) | ||
|
||
ld 0, 16(1) | ||
mtlr 0 | ||
|
||
.cfi_restore r3 | ||
.cfi_restore r4 | ||
.cfi_restore r5 | ||
.cfi_restore r6 | ||
.cfi_restore r7 | ||
.cfi_restore r8 | ||
.cfi_restore r9 | ||
.cfi_restore r10 | ||
.cfi_restore f1 | ||
.cfi_restore f2 | ||
.cfi_restore f3 | ||
.cfi_restore f4 | ||
.cfi_restore f5 | ||
.cfi_restore f6 | ||
.cfi_restore f7 | ||
.cfi_restore f8 | ||
.cfi_restore f9 | ||
.cfi_restore f10 | ||
.cfi_restore f11 | ||
.cfi_restore f12 | ||
.cfi_restore f13 | ||
|
||
blr | ||
|
||
.cfi_endproc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 Yury Gribov | ||
* | ||
* The MIT License (MIT) | ||
* | ||
* Use of this source code is governed by MIT license that can be | ||
* found in the LICENSE.txt file. | ||
*/ | ||
|
||
.globl $sym | ||
.p2align 4 | ||
.type $sym, %function | ||
#ifndef IMPLIB_EXPORT_SHIMS | ||
.hidden $sym | ||
#endif | ||
|
||
$sym: | ||
.cfi_startproc | ||
.$sym.LCF0: | ||
addis 2, 12, .TOC. - .$sym.LCF0@ha | ||
addi 2, 2, .TOC. - .$sym.LCF0@l | ||
.localentry $sym, . - $sym | ||
|
||
1: | ||
// Load address | ||
addis 12, 2, .LC0@toc@ha | ||
ld 12, .LC0@toc@l(12) | ||
ld 12, $offset(12) | ||
|
||
cmpdi 12, 0 | ||
beq 3f | ||
|
||
2: // "Fast" path | ||
// TODO: can we get rid of prologue/epilogue here? | ||
|
||
mflr 0 | ||
std 0, 16(1) | ||
stdu 1, -112(1) | ||
.cfi_def_cfa_offset 112 | ||
.cfi_offset lr, 16 | ||
|
||
std 2, 24(1) | ||
|
||
mtctr 12 | ||
bctrl | ||
|
||
ld 2, 24(1) | ||
addi 1, 1, 112 | ||
.cfi_def_cfa_offset 0 | ||
ld 0, 16(1) | ||
mtlr 0 | ||
.cfi_restore lr | ||
blr | ||
|
||
3: // Slow path | ||
|
||
mflr 0 | ||
std 0, 16(1) | ||
|
||
li 0, $number | ||
std 0, -8(1) | ||
|
||
stdu 1, -48(1) | ||
.cfi_def_cfa_offset 48 | ||
.cfi_offset lr, 16 | ||
|
||
bl _${lib_suffix}_save_regs_and_resolve | ||
nop | ||
|
||
addi 1, 1, 48 | ||
.cfi_def_cfa_offset 0 | ||
|
||
ld 0, 16(1) | ||
mtlr 0 | ||
.cfi_restore lr | ||
|
||
b 1b | ||
|
||
.cfi_endproc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters