-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20,ADD,LO12}_R relocations #99486
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
wangleiat
merged 8 commits into
main
from
users/wangleiat/spr/lldelfloongarch-add-support-for-r_larch_le_hi20addlo12_r-relocations
Jul 19, 2024
Merged
[lld][ELF][LoongArch] Add support for R_LARCH_LE_{HI20,ADD,LO12}_R relocations #99486
wangleiat
merged 8 commits into
main
from
users/wangleiat/spr/lldelfloongarch-add-support-for-r_larch_le_hi20addlo12_r-relocations
Jul 19, 2024
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
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-lld-elf Author: wanglei (wangleiat) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99486.diff 2 Files Affected:
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index c6ee73f23d471..9466e8b1ce54d 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -11,6 +11,7 @@
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
+#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Support/LEB128.h"
using namespace llvm;
@@ -407,7 +408,9 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
case R_LARCH_TLS_TPREL32:
case R_LARCH_TLS_TPREL64:
case R_LARCH_TLS_LE_HI20:
+ case R_LARCH_TLS_LE_HI20_R:
case R_LARCH_TLS_LE_LO12:
+ case R_LARCH_TLS_LE_LO12_R:
case R_LARCH_TLS_LE64_LO20:
case R_LARCH_TLS_LE64_HI12:
return R_TPREL;
@@ -490,6 +493,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
return R_TLSLD_GOT;
case R_LARCH_TLS_GD_HI20:
return R_TLSGD_GOT;
+ case R_LARCH_TLS_LE_ADD_R:
case R_LARCH_RELAX:
return config->relax ? R_RELAX_HINT : R_NONE;
case R_LARCH_ALIGN:
@@ -617,6 +621,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
case R_LARCH_TLS_LE_LO12:
case R_LARCH_TLS_IE_PC_LO12:
case R_LARCH_TLS_IE_LO12:
+ case R_LARCH_TLS_LE_LO12_R:
case R_LARCH_TLS_DESC_PC_LO12:
case R_LARCH_TLS_DESC_LO12:
write32le(loc, setK12(read32le(loc), extractBits(val, 11, 0)));
@@ -638,6 +643,9 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
case R_LARCH_TLS_DESC_HI20:
write32le(loc, setJ20(read32le(loc), extractBits(val, 31, 12)));
return;
+ case R_LARCH_TLS_LE_HI20_R:
+ write32le(loc, setJ20(read32le(loc), extractBits(val + 0x800, 31, 12)));
+ return;
// Relocs intended for `lu32i.d`.
case R_LARCH_ABS64_LO20:
@@ -707,6 +715,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
// no-op
return;
+ case R_LARCH_TLS_LE_ADD_R:
case R_LARCH_RELAX:
return; // Ignored (for now)
diff --git a/lld/test/ELF/loongarch-tls-le.s b/lld/test/ELF/loongarch-tls-le.s
index a20d7d83bae3f..394c60f67bce8 100644
--- a/lld/test/ELF/loongarch-tls-le.s
+++ b/lld/test/ELF/loongarch-tls-le.s
@@ -1,14 +1,14 @@
# REQUIRES: loongarch
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t.32.o
+# RUN: llvm-mc --filetype=obj --triple=loongarch32 --defsym ELF32=1 %s -o %t.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.64.o
# RUN: ld.lld %t.32.o -o %t.32
# RUN: llvm-nm -p %t.32 | FileCheck --check-prefixes=NM %s
-# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE,LE32 %s
# RUN: ld.lld %t.64.o -o %t.64
-# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE,LE64 %s
# RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
@@ -16,6 +16,10 @@
# ERR: error: relocation R_LARCH_TLS_LE_LO12 against .LANCHOR0 cannot be used with -shared
# ERR: error: relocation R_LARCH_TLS_LE_HI20 against a cannot be used with -shared
# ERR: error: relocation R_LARCH_TLS_LE_LO12 against a cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against .LANCHOR0 cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against .LANCHOR0 cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against a cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against a cannot be used with -shared
# NM: {{0*}}00000008 b .LANCHOR0
# NM: {{0*}}00000800 B a
@@ -26,13 +30,50 @@
# LE-NEXT: ori $a0, $a0, 8
# LE-NEXT: lu12i.w $a1, 0
# LE-NEXT: ori $a1, $a1, 2048
+
+# LE32: add.w $a0, $a0, $tp
+# LE32-NEXT: addi.w $a0, $a0, 8
+# LE32-NEXT: lu12i.w $a0, 1
+# LE32-NEXT: add.w $a0, $a0, $tp
+# LE32-NEXT: addi.w $a0, $a0, -2048
+
+# LE64: add.d $a0, $a0, $tp
+# LE64-NEXT: addi.d $a0, $a0, 8
+# LE64-NEXT: lu12i.w $a0, 1
+# LE64-NEXT: add.d $a0, $a0, $tp
+# LE64-NEXT: addi.d $a0, $a0, -2048
+
# LE-EMPTY:
+.macro add dst, src1, src2, src3
+.ifdef ELF32
+add.w \dst, \src1, \src2, \src3
+.else
+add.d \dst, \src1, \src2, \src3
+.endif
+.endm
+.macro addi dst, src1, src2
+.ifdef ELF32
+addi.w \dst, \src1, \src2
+.else
+addi.d \dst, \src1, \src2
+.endif
+.endm
+
.text
+
_start:
la.tls.le $a0, .LANCHOR0
la.tls.le $a1, a
+lu12i.w $a0, %le_hi20_r(.LANCHOR0)
+add $a0, $a0, $tp, %le_add_r(.LANCHOR0)
+addi $a0, $a0, %le_lo12_r(.LANCHOR0)
+
+lu12i.w $a0, %le_hi20_r(a)
+add $a0, $a0, $tp, %le_add_r(a)
+addi $a0, $a0, %le_lo12_r(a)
+
.section .tbss,"awT",@nobits
.space 8
.LANCHOR0:
|
@llvm/pr-subscribers-lld Author: wanglei (wangleiat) ChangesFull diff: https://github.com/llvm/llvm-project/pull/99486.diff 2 Files Affected:
diff --git a/lld/ELF/Arch/LoongArch.cpp b/lld/ELF/Arch/LoongArch.cpp
index c6ee73f23d471..9466e8b1ce54d 100644
--- a/lld/ELF/Arch/LoongArch.cpp
+++ b/lld/ELF/Arch/LoongArch.cpp
@@ -11,6 +11,7 @@
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
+#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Support/LEB128.h"
using namespace llvm;
@@ -407,7 +408,9 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
case R_LARCH_TLS_TPREL32:
case R_LARCH_TLS_TPREL64:
case R_LARCH_TLS_LE_HI20:
+ case R_LARCH_TLS_LE_HI20_R:
case R_LARCH_TLS_LE_LO12:
+ case R_LARCH_TLS_LE_LO12_R:
case R_LARCH_TLS_LE64_LO20:
case R_LARCH_TLS_LE64_HI12:
return R_TPREL;
@@ -490,6 +493,7 @@ RelExpr LoongArch::getRelExpr(const RelType type, const Symbol &s,
return R_TLSLD_GOT;
case R_LARCH_TLS_GD_HI20:
return R_TLSGD_GOT;
+ case R_LARCH_TLS_LE_ADD_R:
case R_LARCH_RELAX:
return config->relax ? R_RELAX_HINT : R_NONE;
case R_LARCH_ALIGN:
@@ -617,6 +621,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
case R_LARCH_TLS_LE_LO12:
case R_LARCH_TLS_IE_PC_LO12:
case R_LARCH_TLS_IE_LO12:
+ case R_LARCH_TLS_LE_LO12_R:
case R_LARCH_TLS_DESC_PC_LO12:
case R_LARCH_TLS_DESC_LO12:
write32le(loc, setK12(read32le(loc), extractBits(val, 11, 0)));
@@ -638,6 +643,9 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
case R_LARCH_TLS_DESC_HI20:
write32le(loc, setJ20(read32le(loc), extractBits(val, 31, 12)));
return;
+ case R_LARCH_TLS_LE_HI20_R:
+ write32le(loc, setJ20(read32le(loc), extractBits(val + 0x800, 31, 12)));
+ return;
// Relocs intended for `lu32i.d`.
case R_LARCH_ABS64_LO20:
@@ -707,6 +715,7 @@ void LoongArch::relocate(uint8_t *loc, const Relocation &rel,
// no-op
return;
+ case R_LARCH_TLS_LE_ADD_R:
case R_LARCH_RELAX:
return; // Ignored (for now)
diff --git a/lld/test/ELF/loongarch-tls-le.s b/lld/test/ELF/loongarch-tls-le.s
index a20d7d83bae3f..394c60f67bce8 100644
--- a/lld/test/ELF/loongarch-tls-le.s
+++ b/lld/test/ELF/loongarch-tls-le.s
@@ -1,14 +1,14 @@
# REQUIRES: loongarch
-# RUN: llvm-mc --filetype=obj --triple=loongarch32 %s -o %t.32.o
+# RUN: llvm-mc --filetype=obj --triple=loongarch32 --defsym ELF32=1 %s -o %t.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 %s -o %t.64.o
# RUN: ld.lld %t.32.o -o %t.32
# RUN: llvm-nm -p %t.32 | FileCheck --check-prefixes=NM %s
-# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.32 | FileCheck --check-prefixes=LE,LE32 %s
# RUN: ld.lld %t.64.o -o %t.64
-# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE %s
+# RUN: llvm-objdump -d --no-show-raw-insn %t.64 | FileCheck --check-prefixes=LE,LE64 %s
# RUN: not ld.lld -shared %t.32.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
@@ -16,6 +16,10 @@
# ERR: error: relocation R_LARCH_TLS_LE_LO12 against .LANCHOR0 cannot be used with -shared
# ERR: error: relocation R_LARCH_TLS_LE_HI20 against a cannot be used with -shared
# ERR: error: relocation R_LARCH_TLS_LE_LO12 against a cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against .LANCHOR0 cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against .LANCHOR0 cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_HI20_R against a cannot be used with -shared
+# ERR: error: relocation R_LARCH_TLS_LE_LO12_R against a cannot be used with -shared
# NM: {{0*}}00000008 b .LANCHOR0
# NM: {{0*}}00000800 B a
@@ -26,13 +30,50 @@
# LE-NEXT: ori $a0, $a0, 8
# LE-NEXT: lu12i.w $a1, 0
# LE-NEXT: ori $a1, $a1, 2048
+
+# LE32: add.w $a0, $a0, $tp
+# LE32-NEXT: addi.w $a0, $a0, 8
+# LE32-NEXT: lu12i.w $a0, 1
+# LE32-NEXT: add.w $a0, $a0, $tp
+# LE32-NEXT: addi.w $a0, $a0, -2048
+
+# LE64: add.d $a0, $a0, $tp
+# LE64-NEXT: addi.d $a0, $a0, 8
+# LE64-NEXT: lu12i.w $a0, 1
+# LE64-NEXT: add.d $a0, $a0, $tp
+# LE64-NEXT: addi.d $a0, $a0, -2048
+
# LE-EMPTY:
+.macro add dst, src1, src2, src3
+.ifdef ELF32
+add.w \dst, \src1, \src2, \src3
+.else
+add.d \dst, \src1, \src2, \src3
+.endif
+.endm
+.macro addi dst, src1, src2
+.ifdef ELF32
+addi.w \dst, \src1, \src2
+.else
+addi.d \dst, \src1, \src2
+.endif
+.endm
+
.text
+
_start:
la.tls.le $a0, .LANCHOR0
la.tls.le $a1, a
+lu12i.w $a0, %le_hi20_r(.LANCHOR0)
+add $a0, $a0, $tp, %le_add_r(.LANCHOR0)
+addi $a0, $a0, %le_lo12_r(.LANCHOR0)
+
+lu12i.w $a0, %le_hi20_r(a)
+add $a0, $a0, $tp, %le_add_r(a)
+addi $a0, $a0, %le_lo12_r(a)
+
.section .tbss,"awT",@nobits
.space 8
.LANCHOR0:
|
Created using spr 1.3.5-bogner [skip ci]
Created using spr 1.3.5-bogner [skip ci]
SixWeining
approved these changes
Jul 19, 2024
Created using spr 1.3.5-bogner [skip ci]
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.
No description provided.