-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
This file contains hidden or 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
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.
@llvm/pr-subscribers-llvm-binary-utilities Author: Lu Weining (SixWeining) ChangespsABI 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:
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) {
|
MaskRay
approved these changes
Dec 4, 2023
haowuge
added a commit
to haowuge/freebsd-src
that referenced
this pull request
Dec 2, 2024
adds necessary definitions for LoongArch ELF files, including e_machine, e_flags and relocation types. reference: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc 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
haowuge
added a commit
to haowuge/freebsd-src
that referenced
this pull request
Dec 2, 2024
adds necessary definitions for LoongArch ELF files, including e_machine, e_flags and relocation types. reference: https://github.com/loongson/la-abi-specs/blob/release/laelf.adoc 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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.