From 54cf2b1a6c9ee35a460dca355f1ec9a4f14de6ce Mon Sep 17 00:00:00 2001 From: mengqinggang Date: Sun, 17 Jul 2022 16:46:55 +0800 Subject: [PATCH] Add new relocation type support --- docs/LoongArch-ELF-ABI-CN.adoc | 201 ++++++++++++++++++++++++++++++++- docs/LoongArch-ELF-ABI-EN.adoc | 201 ++++++++++++++++++++++++++++++++- 2 files changed, 400 insertions(+), 2 deletions(-) diff --git a/docs/LoongArch-ELF-ABI-CN.adoc b/docs/LoongArch-ELF-ABI-CN.adoc index d6148e2..da43fb8 100644 --- a/docs/LoongArch-ELF-ABI-CN.adoc +++ b/docs/LoongArch-ELF-ABI-CN.adoc @@ -1,6 +1,6 @@ = 龙芯架构 ELF psABI 规范 龙芯中科技术股份有限公司 -v1.00 +v2.00 :docinfodir: ../themes :docinfo: shared :doctype: book @@ -647,6 +647,205 @@ v1.00 |R_LARCH_GNU_VTENTRY |GNU C++ vtable 支持 | + +4+|... 保留项 + +|64 +|R_LARCH_B16 +|18 位相对 PC 跳转 +|`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +带 18 位有符号数溢出和4字节对齐检测功能 + +|65 +|R_LARCH_B21 +|23 位相对 PC 跳转 +|`+(*(uint32_t *) PC) [4 ... 0] = (S+A-PC) [22 ... 18],+` + +`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +带 23 位有符号数溢出和4字节对齐检测功能 + +|66 +|R_LARCH_B26 +|28 位相对 PC 跳转 +|`+(*(uint32_t *) PC) [9 ... 0] = (S+A-PC) [27 ... 18],+` + +`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +带 28 位有符号数溢出和4字节对齐检测功能 + +|67 +|R_LARCH_ABS_HI20 +|32/64 位绝对地址的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A) [31 ... 12]+` + +|68 +|R_LARCH_ABS_LO12 +|32/64 位绝对地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [11 ... 0]+` + +|69 +|R_LARCH_ABS64_LO20 +|64 位绝对地址 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A) [51 ... 32]+` + +|70 +|R_LARCH_ABS64_HI12 +|64 位绝对地址 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [63 ... 52]+` + +|71 +|R_LARCH_PCALA_HI20 +|相对 PC 偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (((S+A) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +`+注意:所有相对 PC 偏移计算都不包含低12位。+` + +|72 +|R_LARCH_PCALA_LO12 +|32/64 位地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [11 ... 0]+` + +|73 +|R_LARCH_PCALA64_LO20 +|相对 PC 偏移 64 位的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A - (PC & ~0xffffffff)) [51 ... 32]+` + +|74 +|R_LARCH_PCALA64_HI12 +|相对 PC 偏移 64 位的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A - (PC & ~0xffffffff)) [63 ... 52]+` + +|75 +|R_LARCH_GOT_PC_HI20 +|GOT 表项相对 PC 偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+G) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|76 +|R_LARCH_GOT_PC_LO12 +|GOT 表项 32/64 位地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [11 ... 0]+` + +|77 +|R_LARCH_GOT64_PC_LO20 +|GOT 表项相对 PC 偏移 64 位的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G - (PC & ~0xffffffff)) [51 ... 32]+` + +|78 +|R_LARCH_GOT64_PC_HI12 +|GOT 表项相对 PC 偏移 64 位的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G - (PC & ~0xffffffff)) [63 ... 52]+` + +|79 +|R_LARCH_GOT_HI20 +|GOT 表项 32/64 位绝对地址的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G) [31 ... 12]+` + +|80 +|R_LARCH_GOT_LO12 +|GOT 表项 32/64 位绝对地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [11 ... 0]+` + +|81 +|R_LARCH_GOT64_LO20 +|GOT 表项 64 位绝对地址的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G) [51 ... 32]+` + +|82 +|R_LARCH_GOT64_HI12 +|GOT 表项 64 位绝对地址的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [63 ... 52]+` + +|83 +|R_LARCH_TLS_LE_HI20 +|TLS LE 符号相对 TP 寄存器偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = T [31 ... 12]+` + +|84 +|R_LARCH_TLS_LE_LO12 +|TLS LE 符号相对 TP 寄存器偏移 32/64 位的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = T [11 ... 0]+` + +|85 +|R_LARCH_TLS_LE64_LO20 +|TLS LE 符号相对 TP 寄存器偏移 64 位的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = T [51 ... 32]+` + +|86 +|R_LARCH_TLS_LE64_HI12 +|TLS LE 符号相对 TP 寄存器偏移 64 位的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = T [63 ... 52]+` + +|87 +|R_LARCH_TLS_IE_PC_HI20 +|TLS IE 符号 GOT 表项相对 PC 偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+IE) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|88 +|R_LARCH_TLS_IE_PC_LO12 +|TLS IE 符号 GOT 表项 32/64 位地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [11 ... 0]+` + +|89 +|R_LARCH_TLS_IE64_PC_LO20 +|TLS IE 符号 GOT 表项相对 PC 偏移 64 位的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE - (PC & ~0xffffffff)) [51 ... 32]+` + +|90 +|R_LARCH_TLS_IE64_PC_HI12 +|TLS IE 符号 GOT 表项相对 PC 偏移 64 位的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE - (PC & ~0xffffffff)) [63 ... 52]+` + +|91 +|R_LARCH_TLS_IE_HI20 +|TLS IE 符号 GOT 表项 32/64 位绝对地址的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|92 +|R_LARCH_TLS_IE_LO12 +|TLS IE 符号 GOT 表项 32/64 位绝对地址的 [11 ... 0] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [11 ... 0]+` + +|93 +|R_LARCH_TLS_IE64_LO20 +|TLS IE 符号 GOT 表项 64 位绝对地址的 [51 ... 32] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [51 ... 32]+` + +|94 +|R_LARCH_TLS_IE64_HI12 +|TLS IE 符号 GOT 表项 64 位绝对地址的 [63 ... 52] 位 +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [63 ... 52]+` + +|95 +|R_LARCH_TLS_LD_PC_HI20 +|TLS LD 符号 GOT 表项相对 PC 偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+GD) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|96 +|R_LARCH_TLS_LD_HI20 +|TLS LD 符号 GOT 表项 32/64 位绝对地址的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|97 +|R_LARCH_TLS_GD_PC_HI20 +|TLS GD 符号 GOT 表项相对 PC 偏移 32/64 位的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+GD) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|98 +|R_LARCH_TLS_GD_HI20 +|TLS GD 符号 GOT 表项 32/64 位绝对地址的 [31 ... 12] 位 +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|99 +|R_LARCH_32_PCREL +|32 位相对 PC 偏移 +|`+(*(uint32_t *) PC) = (S+A-PC) [31 ... 0]+` + +|100 +|R_LARCH_RELAX +|在相同的地址和其它重定位成对使用,标识指令可能被修改或删除(relaxed)。 +| |=== diff --git a/docs/LoongArch-ELF-ABI-EN.adoc b/docs/LoongArch-ELF-ABI-EN.adoc index d006242..005f7a1 100644 --- a/docs/LoongArch-ELF-ABI-EN.adoc +++ b/docs/LoongArch-ELF-ABI-EN.adoc @@ -1,6 +1,6 @@ = LoongArch ELF ABI specification Loongson Technology Corporation Limited -v1.00 +v2.00 :docinfodir: ../themes :docinfo: shared :doctype: book @@ -645,6 +645,205 @@ with check 32-bit unsigned overflow |R_LARCH_GNU_VTENTRY |GNU C++ vtable member usage | + +4+|... Reserved + +|64 +|R_LARCH_B16 +|18-bit PC-relative jump +|`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +with check 18-bit signed overflow and 4-bit aligned + +|65 +|R_LARCH_B21 +|23-bit PC-relative jump +|`+(*(uint32_t *) PC) [4 ... 0] = (S+A-PC) [22 ... 18],+` + +`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +with check 23-bit signed overflow and 4-bit aligned + +|66 +|R_LARCH_B26 +|28-bit PC-relative jump +|`+(*(uint32_t *) PC) [9 ... 0] = (S+A-PC) [27 ... 18],+` + +`+(*(uint32_t *) PC) [25 ... 10] = (S+A-PC) [17 ... 2]+` + +with check 28-bit signed overflow and 4-bit aligned + +|67 +|R_LARCH_ABS_HI20 +| [31 ... 12] bits of 32/64-bit absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A) [31 ... 12]+` + +|68 +|R_LARCH_ABS_LO12 +|[11 ... 0] bits of 32/64-bit absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [11 ... 0]+` + +|69 +|R_LARCH_ABS64_LO20 +|[51 ... 32] bits of 64-bit absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A) [51 ... 32]+` + +|70 +|R_LARCH_ABS64_HI12 +|[63 ... 52] bits of 64-bit absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [63 ... 52]+` + +|71 +|R_LARCH_PCALA_HI20 +|[31 ... 12] bits of 32/64-bit PC-relative offset +|`+(*(uint32_t *) PC) [24 ... 5] = (((S+A) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +`+Note: The lower 12 bits are not included when calculating the PC-relative offset.+` + +|72 +|R_LARCH_PCALA_LO12 +|[11 ... 0] bits of 32/64-bit address +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A) [11 ... 0]+` + +|73 +|R_LARCH_PCALA64_LO20 +|[51 ... 32] bits of 64-bit PC-relative offset +|`+(*(uint32_t *) PC) [24 ... 5] = (S+A - (PC & ~0xffffffff)) [51 ... 32]+` + +|74 +|R_LARCH_PCALA64_HI12 +|[63 ... 52] bits of 64-bit PC-relative offset +|`+(*(uint32_t *) PC) [21 ... 10] = (S+A - (PC & ~0xffffffff)) [63 ... 52]+` + +|75 +|R_LARCH_GOT_PC_HI20 +|[31 ... 12] bits of 32/64-bit PC-relative offset to GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+G) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|76 +|R_LARCH_GOT_PC_LO12 +|[11 ... 0] bits of 32/64-bit GOT entry address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [11 ... 0]+` + +|77 +|R_LARCH_GOT64_PC_LO20 +|[51 ... 32] bits of 64-bit PC-relative offset to GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G - (PC & ~0xffffffff)) [51 ... 32]+` + +|78 +|R_LARCH_GOT64_PC_HI12 +|[63 ... 52] bits of 64-bit PC-relative offset to GOT entry +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G - (PC & ~0xffffffff)) [63 ... 52]+` + +|79 +|R_LARCH_GOT_HI20 +|[31 ... 12] bits of 32/64-bit GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G) [31 ... 12]+` + +|80 +|R_LARCH_GOT_LO12 +|[11 ... 0] bits of 32/64-bit GOT entry absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [11 ... 0]+` + +|81 +|R_LARCH_GOT64_LO20 +|[51 ... 32] bits of 64-bit GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+G) [51 ... 32]+` + +|82 +|R_LARCH_GOT64_HI12 +|[63 ... 52] bits of 64-bit GOT entry absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+G) [63 ... 52]+` + +|83 +|R_LARCH_TLS_LE_HI20 +|[31 ... 12] bits of TLS LE 32/64-bit offset from TP register +|`+(*(uint32_t *) PC) [24 ... 5] = T [31 ... 12]+` + +|84 +|R_LARCH_TLS_LE_LO12 +|[11 ... 0] bits of TLS LE 32/64-bit offset from TP register +|`+(*(uint32_t *) PC) [21 ... 10] = T [11 ... 0]+` + +|85 +|R_LARCH_TLS_LE64_LO20 +|[51 ... 32] bits of TLS LE 64-bit offset from TP register +|`+(*(uint32_t *) PC) [24 ... 5] = T [51 ... 32]+` + +|86 +|R_LARCH_TLS_LE64_HI12 +|[63 ... 52] bits of TLS LE 64-bit offset from TP register +|`+(*(uint32_t *) PC) [21 ... 10] = T [63 ... 52]+` + +|87 +|R_LARCH_TLS_IE_PC_HI20 +|[31 ... 12] bits of 32/64-bit PC-relative offset to TLS IE GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+IE) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|88 +|R_LARCH_TLS_IE_PC_LO12 +|[11 ... 0] bits of 32/64-bit TLS IE GOT entry address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [11 ... 0]+` + +|89 +|R_LARCH_TLS_IE64_PC_LO20 +|[51 ... 32] bits of 64-bit PC-relative offset to TLS IE GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE - (PC & ~0xffffffff)) [51 ... 32]+` + +|90 +|R_LARCH_TLS_IE64_PC_HI12 +|[63 ... 52] bits of 64-bit PC-relative offset to TLS IE GOT entry +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE - (PC & ~0xffffffff)) [63 ... 52]+` + +|91 +|R_LARCH_TLS_IE_HI20 +|[31 ... 12] bits of 32/64-bit TLS IE GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|92 +|R_LARCH_TLS_IE_LO12 +|[11 ... 0] bits of 32/64-bit TLS IE GOT entry absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [11 ... 0]+` + +|93 +|R_LARCH_TLS_IE64_LO20 +|[51 ... 32] bits of 64-bit TLS IE GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [51 ... 32]+` + +|94 +|R_LARCH_TLS_IE64_HI12 +|[63 ... 52] bits of 64-bit TLS IE GOT entry absolute address +|`+(*(uint32_t *) PC) [21 ... 10] = (GP+IE) [63 ... 52]+` + +|95 +|R_LARCH_TLS_LD_PC_HI20 +|[31 ... 12] bits of 32/64-bit PC-relative offset to TLS LD GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+GD) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|96 +|R_LARCH_TLS_LD_HI20 +|[31 ... 12] bits of 32/64-bit TLS LD GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|97 +|R_LARCH_TLS_GD_PC_HI20 +|[31 ... 12] bits of 32/64-bit PC-relative offset to TLS GD GOT entry +|`+(*(uint32_t *) PC) [24 ... 5] = (((GP+GD) & ~0xfff) - (PC & ~0xfff)) [31 ... 12]+` + +|98 +|R_LARCH_TLS_GD_HI20 +|[31 ... 12] bits of 32/64-bit TLS GD GOT entry absolute address +|`+(*(uint32_t *) PC) [24 ... 5] = (GP+IE) [31 ... 12]+` + +|99 +|R_LARCH_32_PCREL +|32-bit PC relative +|`+(*(uint32_t *) PC) = (S+A-PC) [31 ... 0]+` + +|100 +|R_LARCH_RELAX +|Instruction can be relaxed, paired with a normal relocation at the same address +| |===