]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
RISC-V: Bind defined symbol locally in PIE
authorLinsen Zhou <i@lin.moe>
Mon, 7 Jul 2025 22:34:18 +0000 (06:34 +0800)
committerNelson Chu <nelson@rivosinc.com>
Tue, 8 Jul 2025 03:10:25 +0000 (11:10 +0800)
Reference commit 1dcb9720d62cd053a72c31881b7724ce9f74332c

bfd/
* elfnn-riscv.c (RISCV_COPY_INPUT_RELOC): Bind defined symbol
locally in PIE.

ld/
* testsuite/ld-riscv-elf/pie-bind-locally-a.s: New test source.
* testsuite/ld-riscv-elf/pie-bind-locally-b.s: Likewise.
* testsuite/ld-riscv-elf/pie-bind-locally-rv32.d: New testcase.
* testsuite/ld-riscv-elf/pie-bind-locally-rv64.d: Likewise.

Signed-off-by: Linsen Zhou <i@lin.moe>
bfd/elfnn-riscv.c
ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/pie-bind-locally-b.s [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/pie-bind-locally-rv32.d [new file with mode: 0644]
ld/testsuite/ld-riscv-elf/pie-bind-locally-rv64.d [new file with mode: 0644]

index 790f0397cf5a7590e9be10c5c915cdee3d596486..2fd0129924954640778a94578e00c9628cc2180e 100644 (file)
@@ -99,7 +99,7 @@
   ((H) != NULL \
    && (H)->dynindx != -1 \
    && (!bfd_link_pic (INFO) \
-       || !SYMBOLIC_BIND ((INFO), (H)) \
+       || !(bfd_link_pie ((INFO)) || SYMBOLIC_BIND ((INFO), (H))) \
        || !(H)->def_regular))
 
 /* True if this is actually a static link, or it is a -Bsymbolic link
index e103df66e11336a9f34deaab6785f34adc264c0a..70c9aa7f66adce9d3b73ab5834b29ec013792018 100644 (file)
@@ -235,6 +235,9 @@ if [istarget "riscv*-*-*"] {
 
     run_dump_test "zicfilp-unlabeled-plt"
 
+    run_dump_test "pie-bind-locally-rv32"
+    run_dump_test "pie-bind-locally-rv64"
+
     # IFUNC testcases.
     # Check IFUNC by single type relocs.
     run_dump_test_ifunc "ifunc-reloc-call-01" rv32 exe
diff --git a/ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s b/ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s
new file mode 100644 (file)
index 0000000..c1ff19b
--- /dev/null
@@ -0,0 +1,5 @@
+       .text
+       .global _start
+_start:
+       .option pic
+       la a0, _start
diff --git a/ld/testsuite/ld-riscv-elf/pie-bind-locally-b.s b/ld/testsuite/ld-riscv-elf/pie-bind-locally-b.s
new file mode 100644 (file)
index 0000000..e5f16cd
--- /dev/null
@@ -0,0 +1,8 @@
+       .section        .data.rel,"aw",%progbits
+       .type   q, %object
+q:
+.ifdef __64_bit__
+       .quad   _start
+.else
+       .word   _start
+.endif
diff --git a/ld/testsuite/ld-riscv-elf/pie-bind-locally-rv32.d b/ld/testsuite/ld-riscv-elf/pie-bind-locally-rv32.d
new file mode 100644 (file)
index 0000000..0133995
--- /dev/null
@@ -0,0 +1,10 @@
+#source: pie-bind-locally-a.s
+#source: pie-bind-locally-b.s
+#as: -march=rv32i -mabi=ilp32
+#ld: -m[riscv_choose_ilp32_emul] -pie
+#readelf: -Wr
+
+Relocation section '\.rela\.dyn' at offset .* contains 2 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[     ]+[0-9a-f]+[    ]+R_RISCV_RELATIVE[ ].*
+[0-9a-f]+[     ]+[0-9a-f]+[    ]+R_RISCV_RELATIVE[ ].*
diff --git a/ld/testsuite/ld-riscv-elf/pie-bind-locally-rv64.d b/ld/testsuite/ld-riscv-elf/pie-bind-locally-rv64.d
new file mode 100644 (file)
index 0000000..6ae627a
--- /dev/null
@@ -0,0 +1,10 @@
+#source: pie-bind-locally-a.s
+#source: pie-bind-locally-b.s
+#as: -march=rv64i -mabi=lp64 -defsym __64_bit__=1
+#ld: -m[riscv_choose_lp64_emul] -pie
+#readelf: -Wr
+
+Relocation section '\.rela\.dyn' at offset .* contains 2 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[     ]+[0-9a-f]+[    ]+R_RISCV_RELATIVE[ ].*
+[0-9a-f]+[     ]+[0-9a-f]+[    ]+R_RISCV_RELATIVE[ ].*