Skip to content

[BinaryFormat][LoongArch] Define psABI v2.20 relocs #73345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

SixWeining
Copy link
Contributor

psABI v2.20 added R_LARCH_CALL36 and removed R_LARCH_DELETE / R_LARCH_CFA.

R_LARCH_CALL36 was designed for function call on medium code model where the 2 instructions (pcaddu18i + jirl) must be adjacent.

psABI v2.20 added R_LARCH_CALL36 and removed R_LARCH_DELETE / R_LARCH_CFA.

R_LARCH_CALL36 was designed for function call on medium code model
where the 2 instructions (pcaddu18i + jirl) must be adjacent.
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Lu Weining (SixWeining)

Changes

psABI v2.20 added R_LARCH_CALL36 and removed R_LARCH_DELETE / R_LARCH_CFA.

R_LARCH_CALL36 was designed for function call on medium code model where the 2 instructions (pcaddu18i + jirl) must be adjacent.


Full diff: https://github.com/llvm/llvm-project/pull/73345.diff

3 Files Affected:

  • (modified) llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def (+10-2)
  • (modified) llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test (+2-4)
  • (modified) llvm/unittests/Object/ELFTest.cpp (+2-4)
diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
index 02bce3c71712743..df3a342151fb361 100644
--- a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
+++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def
@@ -109,12 +109,20 @@ ELF_RELOC(R_LARCH_RELAX,            100)
 //
 // Spec addition: https://github.com/loongson/la-abi-specs/pull/1
 // Binutils commit 57a930e3bfe4b2c7fd6463ed39311e1938513138
-ELF_RELOC(R_LARCH_DELETE,      101)
+// Note that the 101 and 104 relocation numbers are defined as R_LARCH_DELETE
+// and R_LARCH_CFA respectively in psABI 2.10. But they are marked as reserved
+// in psABI v2.20 because they were proved not necessary to be exposed outside
+// of the linker.
 ELF_RELOC(R_LARCH_ALIGN,       102)
 ELF_RELOC(R_LARCH_PCREL20_S2,  103)
-ELF_RELOC(R_LARCH_CFA,         104)
 ELF_RELOC(R_LARCH_ADD6,        105)
 ELF_RELOC(R_LARCH_SUB6,        106)
 ELF_RELOC(R_LARCH_ADD_ULEB128, 107)
 ELF_RELOC(R_LARCH_SUB_ULEB128, 108)
 ELF_RELOC(R_LARCH_64_PCREL,    109)
+
+// Relocs added in ELF for the LoongArch™ Architecture v20231102, part of the
+// v2.20 LoongArch ABI specs.
+//
+// Spec addition: https://github.com/loongson/la-abi-specs/pull/4
+ELF_RELOC(R_LARCH_CALL36, 110)
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 e32dc893fa7985d..55a3e645b883cb5 100644
--- a/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test
+++ b/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test
@@ -93,15 +93,14 @@
 # CHECK: Type: R_LARCH_TLS_GD_HI20 (98)
 # CHECK: Type: R_LARCH_32_PCREL (99)
 # CHECK: Type: R_LARCH_RELAX (100)
-# CHECK: Type: R_LARCH_DELETE (101)
 # CHECK: Type: R_LARCH_ALIGN (102)
 # CHECK: Type: R_LARCH_PCREL20_S2 (103)
-# CHECK: Type: R_LARCH_CFA (104)
 # CHECK: Type: R_LARCH_ADD6 (105)
 # CHECK: Type: R_LARCH_SUB6 (106)
 # CHECK: Type: R_LARCH_ADD_ULEB128 (107)
 # CHECK: Type: R_LARCH_SUB_ULEB128 (108)
 # CHECK: Type: R_LARCH_64_PCREL (109)
+# CHECK: Type: R_LARCH_CALL36 (110)
 
 --- !ELF
 FileHeader:
@@ -202,12 +201,11 @@ Sections:
       - Type: R_LARCH_TLS_GD_HI20
       - Type: R_LARCH_32_PCREL
       - Type: R_LARCH_RELAX
-      - Type: R_LARCH_DELETE
       - Type: R_LARCH_ALIGN
       - Type: R_LARCH_PCREL20_S2
-      - Type: R_LARCH_CFA
       - Type: R_LARCH_ADD6
       - Type: R_LARCH_SUB6
       - Type: R_LARCH_ADD_ULEB128
       - Type: R_LARCH_SUB_ULEB128
       - Type: R_LARCH_64_PCREL
+      - Type: R_LARCH_CALL36
diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp
index 50b1df124a4a58c..faf855c09cfe86e 100644
--- a/llvm/unittests/Object/ELFTest.cpp
+++ b/llvm/unittests/Object/ELFTest.cpp
@@ -233,14 +233,10 @@ TEST(ELFTest, getELFRelocationTypeNameForLoongArch) {
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_32_PCREL));
   EXPECT_EQ("R_LARCH_RELAX",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_RELAX));
-  EXPECT_EQ("R_LARCH_DELETE",
-            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_DELETE));
   EXPECT_EQ("R_LARCH_ALIGN",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ALIGN));
   EXPECT_EQ("R_LARCH_PCREL20_S2",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_PCREL20_S2));
-  EXPECT_EQ("R_LARCH_CFA",
-            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_CFA));
   EXPECT_EQ("R_LARCH_ADD6",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ADD6));
   EXPECT_EQ("R_LARCH_SUB6",
@@ -251,6 +247,8 @@ TEST(ELFTest, getELFRelocationTypeNameForLoongArch) {
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_SUB_ULEB128));
   EXPECT_EQ("R_LARCH_64_PCREL",
             getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_64_PCREL));
+  EXPECT_EQ("R_LARCH_CALL36",
+            getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_CALL36));
 }
 
 TEST(ELFTest, getELFRelativeRelocationType) {

@SixWeining SixWeining merged commit c3a9c90 into llvm:main Dec 5, 2023
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Dec 2, 2024
Including e_machine, e_flags and relocation types.

References:

  Loongson documentation:
    https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc

  LLVM reviews / commits:
    https://reviews.llvm.org/D134601
    https://reviews.llvm.org/D115859
    https://reviews.llvm.org/D131467
    https://reviews.llvm.org/D152184
    llvm/llvm-project#73345
    llvm/llvm-project#77039

  Binutils commits:
    6d13722a97cee3fd397e116bde3bcedbb1e220be
    9801120721c3a702ce3bd50433ef920f92a83502
    57a930e3bfe4b2c7fd6463ed39311e1938513138

Reviewed by:	markj, emaste
Pull Request:	#1532
leecheechen pushed a commit to leecheechen/llvm-project that referenced this pull request Jun 9, 2025
…llvm#73345)

R_LARCH_CALL36 was designed for function call on medium code model where
the 2 instructions (pcaddu18i + jirl) must be adjacent.

(cherry picked from commit c3a9c90)
Change-Id: I0c542c9ad57a0f657039b266e353f41e684054fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants