aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorJim Wilson <jimw@sifive.com>2019-10-17 15:38:27 -0700
committerJim Wilson <jimw@sifive.com>2019-10-17 15:38:27 -0700
commit330a6637a53d4b6694c9f8fa04155d4366453621 (patch)
tree160e5582b61fedb210bda098844ebc0a45b0c2ec /ld
parentc5adaa1921c34d2b9711ec7cecd3cb4a253620db (diff)
downloadgdb-330a6637a53d4b6694c9f8fa04155d4366453621.zip
gdb-330a6637a53d4b6694c9f8fa04155d4366453621.tar.gz
gdb-330a6637a53d4b6694c9f8fa04155d4366453621.tar.bz2
RISC-V: Report unresolved relocation error via linker's callback function.
Two patches from Nelson Chu. It is better to use the linker's callback functions to handle the link time error when relocating. The unresolved relocation error can be regarded as an unsupported relocation. To make user easier to understand different errors, we need to extend the current error message format of the callback function since the format is fixed. bfd/ * elfnn-riscv.c (riscv_elf_relocate_section): Use asprintf to extend the error message if needed, and then store the result into the `msg_buf`. Finally, remember to free the unused `msg_buf`. All error message for the dangerous relocation should be set before we call the callback function. If we miss the error message since linker runs out of memory, we should set the default error message for the error. ld/ * testsuite/ld-riscv-elf/lib-nopic-01a.s: Create the shared library lib-nopic-01a.so, it will be linked with lib-nopic-01b.s. * testsuite/ld-riscv-elf/lib-nopic-01b.s: Add new test for the unresolved relocation. Link the non-pic code into a shared library may cause the error. * testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise. * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run the new test only when the shared library is supported. R_RISCV_CALL, R_RISCV_JAL and R_RISCV_RVC_JUMP are pc-relative relocation. For now, we do not allow the object with these relocation links into a shared library since the referenced symbols may be loaded to the places that too far from the pc. We can improve the error message for these unsupported relocation to notice user that they should recompile their code with `fPIC`. bfd/ * elfnn-riscv.c (riscv_elf_relocate_section): Report the error message that user should recompile their code with `fPIC` when linking non-pic code into shared library. ld/ * testsuite/ld-riscv-elf/lib-nopic-01b.d: Update the error message. Change-Id: Ib3347a0a6fa1c2b20a9647c314d5bec2c322ff04
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog13
-rw-r--r--ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp7
-rw-r--r--ld/testsuite/ld-riscv-elf/lib-nopic-01a.s9
-rw-r--r--ld/testsuite/ld-riscv-elf/lib-nopic-01b.d5
-rw-r--r--ld/testsuite/ld-riscv-elf/lib-nopic-01b.s9
5 files changed, 43 insertions, 0 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index f51e646..8fc2cee 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,16 @@
+2019-10-17 Nelson Chu <nelson.chu@sifive.com>
+
+ * testsuite/ld-riscv-elf/lib-nopic-01b.d: Update the error message.
+
+ * testsuite/ld-riscv-elf/lib-nopic-01a.s: Create the shared library
+ lib-nopic-01a.so, it will be linked with lib-nopic-01b.s.
+ * testsuite/ld-riscv-elf/lib-nopic-01b.s: Add new test for the
+ unresolved relocation. Link the non-pic code into a shared library
+ may cause the error.
+ * testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise.
+ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run the new test only when
+ the shared library is supported.
+
2019-10-16 Alan Modra <amodra@gmail.com>
PR 13616
diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
index c994a57..0a7ac59 100644
--- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
+++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
@@ -71,4 +71,11 @@ if [istarget "riscv*-*-*"] {
[list "readelf --syms gp-test.sd"] \
"gp-test-${abi}"]]
}
+
+ run_ld_link_tests {
+ { "Link non-pic code into a shared library (setup)"
+ "-shared" "" "" {lib-nopic-01a.s}
+ {} "lib-nopic-01a.so" }
+ }
+ run_dump_test "lib-nopic-01b"
}
diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s b/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
new file mode 100644
index 0000000..c95cda0
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
@@ -0,0 +1,9 @@
+ .option nopic
+ .text
+ .align 1
+ .globl func1
+ .type func1, @function
+func1:
+ call func2
+ jr ra
+ .size func1, .-func1
diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
new file mode 100644
index 0000000..0d758a4
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
@@ -0,0 +1,5 @@
+#name: link non-pic code into a shared library
+#source: lib-nopic-01b.s
+#as:
+#ld: -shared tmpdir/lib-nopic-01a.so
+#error: .*relocation R_RISCV_CALL against `func1' can not be used when making a shared object; recompile with -fPIC
diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s
new file mode 100644
index 0000000..97fe137
--- /dev/null
+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s
@@ -0,0 +1,9 @@
+ .option nopic
+ .text
+ .align 1
+ .globl func2
+ .type func2, @function
+func2:
+ call func1
+ jr ra
+ .size func2, .-func2