PPC64: Add special instructions for PIC code setup

In order to support to the following instruction described by ABI,
dynasm needed to be updated:

"""
The following code might appear in a PIC code setup sequence to compute
the distance from a function entry point to the TOC base:
addis 2,12,.TOC.-func@ha
addi 2,2,.TOC.-func@l
"""

Power Architecture 64-Bit ELF V2 ABI Specification, version 1.0, page 99
Source: http://openpowerfoundation.org/technical/technical-resources/technical-specifications/
This commit is contained in:
Gustavo Serra Scalet 2015-06-02 14:35:00 -03:00 committed by Gustavo Serra Scalet
parent 821f0b7535
commit 04c444e533
2 changed files with 12 additions and 0 deletions

View File

@ -257,9 +257,11 @@ map_op = {
addic_3 = "30000000RRI", addic_3 = "30000000RRI",
["addic._3"] = "34000000RRI", ["addic._3"] = "34000000RRI",
addi_3 = "38000000RR0I", addi_3 = "38000000RR0I",
addil_3 = "38000000RR0J",
li_2 = "38000000RI", li_2 = "38000000RI",
la_2 = "38000000RD", la_2 = "38000000RD",
addis_3 = "3c000000RR0I", addis_3 = "3c000000RR0I",
addisl_3 = "3c000000RR0J",
lis_2 = "3c000000RI", lis_2 = "3c000000RI",
lus_2 = "3c000000RU", lus_2 = "3c000000RU",
bc_3 = "40000000AAK", bc_3 = "40000000AAK",

View File

@ -139,6 +139,16 @@ static void emit_asm_wordreloc(BuildCtx *ctx, uint8_t *p, int n,
if ((ins >> 26) == 16) { if ((ins >> 26) == 16) {
fprintf(ctx->fp, "\t%s %d, %d, " TOCPREFIX "%s\n", fprintf(ctx->fp, "\t%s %d, %d, " TOCPREFIX "%s\n",
(ins & 1) ? "bcl" : "bc", (ins >> 21) & 31, (ins >> 16) & 31, sym); (ins & 1) ? "bcl" : "bc", (ins >> 21) & 31, (ins >> 16) & 31, sym);
#if LJ_ARCH_PPC64
} else if ((ins >> 26) == 14) {
if (strcmp(sym, "TOC") < 0) {
fprintf(ctx->fp, "\taddi 2,2,%s\n", sym);
}
} else if ((ins >> 26) == 15) {
if (strcmp(sym, "TOC") < 0) {
fprintf(ctx->fp, "\taddis 2,12,%s\n", sym);
}
#endif
} else if ((ins >> 26) == 18) { } else if ((ins >> 26) == 18) {
#if LJ_ARCH_PPC64 #if LJ_ARCH_PPC64
char *suffix = strchr(sym, '@'); char *suffix = strchr(sym, '@');