aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorLulu Cai <cailulu@loongson.cn>2024-09-30 16:08:59 +0800
committerliuzhensong <liuzhensong@loongson.cn>2024-10-17 21:01:52 +0800
commit4cb77761d68791aa3fd9e7c0ec37fce86a4661f3 (patch)
tree4f42397fc534c700475a7b6134742985fade00d6 /ld
parent7721dcad5c61b0ba7cc673958ae06315dc2ffa28 (diff)
downloadgdb-4cb77761d68791aa3fd9e7c0ec37fce86a4661f3.zip
gdb-4cb77761d68791aa3fd9e7c0ec37fce86a4661f3.tar.gz
gdb-4cb77761d68791aa3fd9e7c0ec37fce86a4661f3.tar.bz2
LoongArch: Check PC-relative relocations for shared libraries
Building shared libraries should not be allowed for PC-relative relocations against external symbols. Currently LoongArch has no corresponding checks and silently generates wrong shared libraries. However, In the first version of the medium cmodel, pcalau12i+jirl was used for function calls, in which case PC-relative relocations were allowed.
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d5
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s8
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d5
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s9
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d5
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s8
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d5
-rw-r--r--ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s9
-rw-r--r--ld/testsuite/ld-loongarch-elf/data-plt.s1
-rw-r--r--ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp4
10 files changed, 59 insertions, 0 deletions
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
new file mode 100644
index 0000000..6ecefd1
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.d
@@ -0,0 +1,5 @@
+#name: PC-relative relocation making shared
+#source: bad_pcala_hi20_global.s
+#target: [check_shared_lib_support]
+#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
+#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s
new file mode 100644
index 0000000..d8189e4
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_global.s
@@ -0,0 +1,8 @@
+ .hidden global_a
+ .text
+ .align 2
+main:
+ # Symbols defined .hidden are bound local and
+ # the linker should differenciate them.
+ la.pcrel $a0, global_a
+ la.pcrel $a0, global_b
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d
new file mode 100644
index 0000000..cefc42c
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.d
@@ -0,0 +1,5 @@
+#name: PC-relative relocation making shared
+#source: bad_pcala_hi20_weak.s
+#target: [check_shared_lib_support]
+#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
+#error: .*: relocation R_LARCH_PCALA_HI20 against `global_b` can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s
new file mode 100644
index 0000000..73c6ec5
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcala_hi20_weak.s
@@ -0,0 +1,9 @@
+ .hidden global_a
+ .weak global_b
+ .text
+ .align 2
+main:
+ # Symbols defined .hidden are bound local and
+ # the linker should differenciate them.
+ la.pcrel $a0, global_a
+ la.pcrel $a0, global_b
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d
new file mode 100644
index 0000000..8e063df
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.d
@@ -0,0 +1,5 @@
+#name: PC-relative relocation making shared
+#source: bad_pcrel20_s2_global.s
+#target: [check_shared_lib_support]
+#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
+#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s
new file mode 100644
index 0000000..39cedbd
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_global.s
@@ -0,0 +1,8 @@
+ .hidden global_a
+ .text
+ .align 2
+main:
+ # Symbols defined .hidden are bound local and
+ # the linker should differenciate them.
+ pcaddi $a0, %pcrel_20(global_a)
+ pcaddi $a0, %pcrel_20(global_b)
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d
new file mode 100644
index 0000000..605df24
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.d
@@ -0,0 +1,5 @@
+#name: PC-relative relocation making shared
+#source: bad_pcrel20_s2_weak.s
+#target: [check_shared_lib_support]
+#ld: -shared --defsym global_a=0x10 --defsym global_b=0x20
+#error: .*: relocation R_LARCH_PCREL20_S2 against `global_b` can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s
new file mode 100644
index 0000000..82faa5b
--- /dev/null
+++ b/ld/testsuite/ld-loongarch-elf/bad_pcrel20_s2_weak.s
@@ -0,0 +1,9 @@
+ .hidden global_a
+ .weak global_b
+ .text
+ .align 2
+main:
+ # Symbols defined .hidden are bound local and
+ # the linker should differenciate them.
+ pcaddi $a0, %pcrel_20(global_a)
+ pcaddi $a0, %pcrel_20(global_b)
diff --git a/ld/testsuite/ld-loongarch-elf/data-plt.s b/ld/testsuite/ld-loongarch-elf/data-plt.s
index faff052..6c1a8ea 100644
--- a/ld/testsuite/ld-loongarch-elf/data-plt.s
+++ b/ld/testsuite/ld-loongarch-elf/data-plt.s
@@ -2,6 +2,7 @@
# R_LARCH_PCALA_HI20 only need to generate PLT entry for function symbols.
.text
.globl a
+ .hidden a
.data
.align 2
diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
index 6bef97c2..4e0068d 100644
--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
+++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp
@@ -166,6 +166,10 @@ if [istarget "loongarch64-*-*"] {
run_dump_test "relr-got-shared"
run_dump_test "relr-text-shared"
run_dump_test "abssym_shared"
+ run_dump_test "bad_pcala_hi20_global"
+ run_dump_test "bad_pcala_hi20_weak"
+ run_dump_test "bad_pcrel20_s2_global"
+ run_dump_test "bad_pcrel20_s2_weak"
}
if [check_pie_support] {