[llvm] [BinaryFormat][LoongArch] Define psABI v2.30 relocs (PR #77039)

Lu Weining via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 19:46:59 PST 2024


https://github.com/SixWeining created https://github.com/llvm/llvm-project/pull/77039

None

>From ed56c60d2abcad2d4457199da72436f2f93259f3 Mon Sep 17 00:00:00 2001
From: Weining Lu <luweining at loongson.cn>
Date: Wed, 27 Dec 2023 15:12:03 +0800
Subject: [PATCH] [BinaryFormat][LoongArch] Define psABI v2.30 relocs

---
 .../llvm/BinaryFormat/ELFRelocs/LoongArch.def | 23 ++++++++++++
 .../ELF/reloc-types-loongarch64.test          | 36 ++++++++++++++++++
 llvm/unittests/Object/ELFTest.cpp             | 37 +++++++++++++++++++
 3 files changed, 96 insertions(+)

diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
index df3a342151fb36..4859057abcbb92 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
@@ -126,3 +126,26 @@ ELF_RELOC(R_LARCH_64_PCREL,    109)
 //
 // Spec addition: https://github.com/loongson/la-abi-specs/pull/4
 ELF_RELOC(R_LARCH_CALL36, 110)
+
+// Relocs added in ELF for the LoongArchâ„¢ Architecture v20231219, part of the
+// v2.30 LoongArch ABI specs.
+//
+// Spec addition: https://github.com/loongson/la-abi-specs/pull/5
+ELF_RELOC(R_LARCH_TLS_DESC32,           13)
+ELF_RELOC(R_LARCH_TLS_DESC64,           14)
+ELF_RELOC(R_LARCH_TLS_DESC_PC_HI20,    111)
+ELF_RELOC(R_LARCH_TLS_DESC_PC_LO12,    112)
+ELF_RELOC(R_LARCH_TLS_DESC64_PC_LO20,  113)
+ELF_RELOC(R_LARCH_TLS_DESC64_PC_HI12,  114)
+ELF_RELOC(R_LARCH_TLS_DESC_HI20,       115)
+ELF_RELOC(R_LARCH_TLS_DESC_LO12,       116)
+ELF_RELOC(R_LARCH_TLS_DESC64_LO20,     117)
+ELF_RELOC(R_LARCH_TLS_DESC64_HI12,     118)
+ELF_RELOC(R_LARCH_TLS_DESC_LD,         119)
+ELF_RELOC(R_LARCH_TLS_DESC_CALL,       120)
+ELF_RELOC(R_LARCH_TLS_LE_HI20_R,       121)
+ELF_RELOC(R_LARCH_TLS_LE_ADD_R,        122)
+ELF_RELOC(R_LARCH_TLS_LE_LO12_R,       123)
+ELF_RELOC(R_LARCH_TLS_LD_PCREL20_S2,   124)
+ELF_RELOC(R_LARCH_TLS_GD_PCREL20_S2,   125)
+ELF_RELOC(R_LARCH_TLS_DESC_PCREL20_S2, 126)
diff --git a/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test b/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test
index 55a3e645b883cb..26c4e8f5ca8463 100644
--- a/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test
+++ b/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test
@@ -17,6 +17,8 @@
 # CHECK: Type: R_LARCH_TLS_TPREL32 (10)
 # CHECK: Type: R_LARCH_TLS_TPREL64 (11)
 # CHECK: Type: R_LARCH_IRELATIVE (12)
+# CHECK: Type: R_LARCH_TLS_DESC32 (13)
+# CHECK: Type: R_LARCH_TLS_DESC64 (14)
 # CHECK: Type: R_LARCH_MARK_LA (20)
 # CHECK: Type: R_LARCH_MARK_PCREL (21)
 # CHECK: Type: R_LARCH_SOP_PUSH_PCREL (22)
@@ -101,6 +103,22 @@
 # CHECK: Type: R_LARCH_SUB_ULEB128 (108)
 # CHECK: Type: R_LARCH_64_PCREL (109)
 # CHECK: Type: R_LARCH_CALL36 (110)
+# CHECK: Type: R_LARCH_TLS_DESC_PC_HI20 (111)
+# CHECK: Type: R_LARCH_TLS_DESC_PC_LO12 (112)
+# CHECK: Type: R_LARCH_TLS_DESC64_PC_LO20 (113)
+# CHECK: Type: R_LARCH_TLS_DESC64_PC_HI12 (114)
+# CHECK: Type: R_LARCH_TLS_DESC_HI20 (115)
+# CHECK: Type: R_LARCH_TLS_DESC_LO12 (116)
+# CHECK: Type: R_LARCH_TLS_DESC64_LO20 (117)
+# CHECK: Type: R_LARCH_TLS_DESC64_HI12 (118)
+# CHECK: Type: R_LARCH_TLS_DESC_LD (119)
+# CHECK: Type: R_LARCH_TLS_DESC_CALL (120)
+# CHECK: Type: R_LARCH_TLS_LE_HI20_R (121)
+# CHECK: Type: R_LARCH_TLS_LE_ADD_R (122)
+# CHECK: Type: R_LARCH_TLS_LE_LO12_R (123)
+# CHECK: Type: R_LARCH_TLS_LD_PCREL20_S2 (124)
+# CHECK: Type: R_LARCH_TLS_GD_PCREL20_S2 (125)
+# CHECK: Type: R_LARCH_TLS_DESC_PCREL20_S2 (126)
 
 --- !ELF
 FileHeader:
@@ -125,6 +143,8 @@ Sections:
       - Type: R_LARCH_TLS_TPREL32
       - Type: R_LARCH_TLS_TPREL64
       - Type: R_LARCH_IRELATIVE
+      - Type: R_LARCH_TLS_DESC32
+      - Type: R_LARCH_TLS_DESC64
       - Type: R_LARCH_MARK_LA
       - Type: R_LARCH_MARK_PCREL
       - Type: R_LARCH_SOP_PUSH_PCREL
@@ -209,3 +229,19 @@ Sections:
       - Type: R_LARCH_SUB_ULEB128
       - Type: R_LARCH_64_PCREL
       - Type: R_LARCH_CALL36
+      - Type: R_LARCH_TLS_DESC_PC_HI20
+      - Type: R_LARCH_TLS_DESC_PC_LO12
+      - Type: R_LARCH_TLS_DESC64_PC_LO20
+      - Type: R_LARCH_TLS_DESC64_PC_HI12
+      - Type: R_LARCH_TLS_DESC_HI20
+      - Type: R_LARCH_TLS_DESC_LO12
+      - Type: R_LARCH_TLS_DESC64_LO20
+      - Type: R_LARCH_TLS_DESC64_HI12
+      - Type: R_LARCH_TLS_DESC_LD
+      - Type: R_LARCH_TLS_DESC_CALL
+      - Type: R_LARCH_TLS_LE_HI20_R
+      - Type: R_LARCH_TLS_LE_ADD_R
+      - Type: R_LARCH_TLS_LE_LO12_R
+      - Type: R_LARCH_TLS_LD_PCREL20_S2
+      - Type: R_LARCH_TLS_GD_PCREL20_S2
+      - Type: R_LARCH_TLS_DESC_PCREL20_S2
diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp
index faf855c09cfe86..040860bf905eaf 100644
--- a/llvm/unittests/Object/ELFTest.cpp
+++ b/llvm/unittests/Object/ELFTest.cpp
@@ -77,6 +77,10 @@ TEST(ELFTest, getELFRelocationTypeNameForLoongArch) {
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_TPREL64));
   EXPECT_EQ("R_LARCH_IRELATIVE",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_IRELATIVE));
+  EXPECT_EQ("R_LARCH_TLS_DESC32",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC32));
+  EXPECT_EQ("R_LARCH_TLS_DESC64",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC64));
 
   EXPECT_EQ("R_LARCH_MARK_LA",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_MARK_LA));
@@ -249,6 +253,39 @@ TEST(ELFTest, getELFRelocationTypeNameForLoongArch) {
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_64_PCREL));
   EXPECT_EQ("R_LARCH_CALL36",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_CALL36));
+  EXPECT_EQ("R_LARCH_TLS_DESC_PC_HI20",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_PC_HI20));
+  EXPECT_EQ("R_LARCH_TLS_DESC_PC_LO12",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_PC_LO12));
+  EXPECT_EQ("R_LARCH_TLS_DESC64_PC_LO20",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC64_PC_LO20));
+  EXPECT_EQ("R_LARCH_TLS_DESC64_PC_HI12",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC64_PC_HI12));
+  EXPECT_EQ("R_LARCH_TLS_DESC_HI20",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_HI20));
+  EXPECT_EQ("R_LARCH_TLS_DESC_LO12",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_LO12));
+  EXPECT_EQ("R_LARCH_TLS_DESC64_LO20",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC64_LO20));
+  EXPECT_EQ("R_LARCH_TLS_DESC64_HI12",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC64_HI12));
+  EXPECT_EQ("R_LARCH_TLS_DESC_LD",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_LD));
+  EXPECT_EQ("R_LARCH_TLS_DESC_CALL",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_CALL));
+  EXPECT_EQ("R_LARCH_TLS_LE_HI20_R",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE_HI20_R));
+  EXPECT_EQ("R_LARCH_TLS_LE_ADD_R",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE_ADD_R));
+  EXPECT_EQ("R_LARCH_TLS_LE_LO12_R",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE_LO12_R));
+  EXPECT_EQ("R_LARCH_TLS_LD_PCREL20_S2",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LD_PCREL20_S2));
+  EXPECT_EQ("R_LARCH_TLS_GD_PCREL20_S2",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_GD_PCREL20_S2));
+  EXPECT_EQ(
+      "R_LARCH_TLS_DESC_PCREL20_S2",
+      getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_DESC_PCREL20_S2));
 }
 
 TEST(ELFTest, getELFRelativeRelocationType) {



More information about the llvm-commits mailing list