[PATCH] RISC-V: Bind defined symbol locally in PIE

Nelson Chu nelson@rivosinc.com
Sun Jul 6 12:10:58 GMT 2025


Okay, looks reasonable to me.  Do you mind adding the following
signed-ff-by at the end of the commit message?  It's because the GNU
copyright issue,
Signed-off-by: your name <your email>

Besides, just some minor stuff...

On Sun, Jul 6, 2025 at 1:01 PM Linsen Zhou <i@lin.moe> wrote:

> 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.
> ---
>  bfd/ChangeLog                                     |  4 ++++
>  bfd/elfnn-riscv.c                                 |  2 +-
>  ld/ChangeLog                                      |  7 +++++++
>  ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp        |  3 +++
>  ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s    |  9 +++++++++
>  ld/testsuite/ld-riscv-elf/pie-bind-locally-b.s    |  8 ++++++++
>  ld/testsuite/ld-riscv-elf/pie-bind-locally-rv32.d | 10 ++++++++++
>  ld/testsuite/ld-riscv-elf/pie-bind-locally-rv64.d | 10 ++++++++++
>  8 files changed, 52 insertions(+), 1 deletion(-)
>  create mode 100644 ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s
>  create mode 100644 ld/testsuite/ld-riscv-elf/pie-bind-locally-b.s
>  create mode 100644 ld/testsuite/ld-riscv-elf/pie-bind-locally-rv32.d
>  create mode 100644 ld/testsuite/ld-riscv-elf/pie-bind-locally-rv64.d
>
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 3f0248717b2..bdc7015f2a6 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,7 @@
> +2025-04-18  Linsen Zhou <i@lin.moe>
> +       * elfnn-riscv.c (RISCV_COPY_INPUT_RELOC): Bind defined symbol
> +       locally in PIE.
> +
>  2025-02-08  Alexandre Oliva <oliva@adacore.com>
>

... I remember we don't need to update the ChangeLog file by ourselves
now.  A new release will auto-generate them from the commit messages, so
just adding them into there should be enough.


>
>         * elfxx-sparc.c (_bfd_sparc_elf_check_relocs): Check for
> diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
> index 790f0397cf5..2fd01299249 100644
> --- a/bfd/elfnn-riscv.c
> +++ b/bfd/elfnn-riscv.c
> @@ -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
> diff --git a/ld/ChangeLog b/ld/ChangeLog
> index 69dad59018f..bcee7fde343 100644
> --- a/ld/ChangeLog
> +++ b/ld/ChangeLog
> @@ -1,3 +1,10 @@
> +2025-04-18  Linsen Zhou <i@lin.moe>
> +
> +       * 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.
> +
>  2025-02-08  Alexandre Oliva <oliva@adacore.com>
>

... Likewise.


>         * testsuite/ld-sparc/got-def.s: New test.
> diff --git a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> index e103df66e11..70c9aa7f66a 100644
> --- a/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> +++ b/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
> @@ -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
> index 00000000000..cc40df88cff
> --- /dev/null
> +++ b/ld/testsuite/ld-riscv-elf/pie-bind-locally-a.s
> @@ -0,0 +1,9 @@
> +       .text
> +       .global _start
> +_start:
> +.L1:   auipc  a0, %got_pcrel_hi(_start)
> +.ifdef __64_bit__
> +       ld      a0, %pcrel_lo(.L1)(a0)
> +.else
> +       lw      a0, %pcrel_lo (.L1)(a0)
> +.endif
>

...
.option pic
la a0, _start

Otherwise looks good to me, thanks.

Nelson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20250706/43ca2651/attachment.htm>


More information about the Binutils mailing list