From: Fangrui Song <maskray@google.com>
To: liuzhensong <liuzhensong@loongson.cn>
Cc: binutils@sourceware.org, i.swmail@xen0n.name, xry111@xry111.site,
caiyinyu@loongson.cn, chenglulu@loongson.cn,
mengqinggang@loongson.cn, xuchenghua@loongson.cn
Subject: Re: [PATCH v2] LoongArch: ld: Fix bug not generate plt when link a dso
Date: Sun, 21 Aug 2022 22:32:08 -0700 [thread overview]
Message-ID: <CAFP8O3+-MQ88og=YitWRGRqDsgzp1-1ooGfYGM-MAbbj7O7a9g@mail.gmail.com> (raw)
In-Reply-To: <20220822021744.2189051-1-liuzhensong@loongson.cn>
On Sun, Aug 21, 2022 at 7:18 PM liuzhensong <liuzhensong@loongson.cn> wrote:
>
> Fix the bug that can not generate func@plt
> when linking a undefined function with cmodel=medium.
> Add testcase.
>
> bfd/
> elfnn-loongarch.c
> ld/testsuite/ld-loongarch-elf/
> cmodel-libjirl.dd
> cmodel.exp
> libjirl.s
> ---
> bfd/elfnn-loongarch.c | 6 +++
> .../ld-loongarch-elf/cmodel-libjirl.dd | 4 ++
> ld/testsuite/ld-loongarch-elf/cmodel.exp | 37 +++++++++++++++++++
> ld/testsuite/ld-loongarch-elf/libjirl.s | 31 ++++++++++++++++
> 4 files changed, 78 insertions(+)
> create mode 100644 ld/testsuite/ld-loongarch-elf/cmodel-libjirl.dd
> create mode 100644 ld/testsuite/ld-loongarch-elf/cmodel.exp
> create mode 100644 ld/testsuite/ld-loongarch-elf/libjirl.s
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index 8d0f66ea7c1..ed42b8b6770 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -746,6 +746,12 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
> case R_LARCH_PCALA_HI20:
> if (h != NULL)
> {
> + /* For pcalau12i + jirl. */
> + h->needs_plt = 1;
> + if (h->plt.refcount < 0)
> + h->plt.refcount = 0;
> + h->plt.refcount++;
> +
> h->non_got_ref = 1;
> h->pointer_equality_needed = 1;
> }
> diff --git a/ld/testsuite/ld-loongarch-elf/cmodel-libjirl.dd b/ld/testsuite/ld-loongarch-elf/cmodel-libjirl.dd
> new file mode 100644
> index 00000000000..52d3dca8443
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/cmodel-libjirl.dd
> @@ -0,0 +1,4 @@
> +.*file format.*loongarch
> +#...
> +[0-9a-f]+ <func@plt>:
> +#pass
> diff --git a/ld/testsuite/ld-loongarch-elf/cmodel.exp b/ld/testsuite/ld-loongarch-elf/cmodel.exp
> new file mode 100644
> index 00000000000..7ef972a44e5
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/cmodel.exp
> @@ -0,0 +1,37 @@
> +# Expect script for LoongArch ELF linker tests
> +# Copyright (C) 2022 Free Software Foundation, Inc.
> +#
> +# This file is part of the GNU Binutils.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
> +# MA 02110-1301, USA.
> +#
> +
> +if ![istarget loongarch*-*-*] {
> + return
> +}
> +
> +run_ld_link_tests [list \
> + [list \
> + "medium jirl plt" \
> + "-shared" "" \
> + "" \
> + {libjirl.s} \
> + [list \
> + [list objdump -d cmodel-libjirl.dd] \
> + ] \
> + "libjirl.so" \
> + ] \
> + ]
> diff --git a/ld/testsuite/ld-loongarch-elf/libjirl.s b/ld/testsuite/ld-loongarch-elf/libjirl.s
> new file mode 100644
> index 00000000000..5b151203fae
> --- /dev/null
> +++ b/ld/testsuite/ld-loongarch-elf/libjirl.s
> @@ -0,0 +1,31 @@
> + .file "liba.c"
> + .text
> + .align 2
> + .globl foo
> + .type foo, @function
> +foo:
> +.LFB0 = .
> + .cfi_startproc
> + addi.d $r3,$r3,-16
> + .cfi_def_cfa_offset 16
> + st.d $r1,$r3,8
> + stptr.d $r22,$r3,0
> + .cfi_offset 1, -8
> + .cfi_offset 22, -16
> + addi.d $r22,$r3,16
> + .cfi_def_cfa 22, 0
> + pcalau12i $r12, %pc_hi20(func)
> + jirl $r1,$r12, %pc_lo12(func)
> + nop
> + ld.d $r1,$r3,8
> + .cfi_restore 1
> + ldptr.d $r22,$r3,0
> + .cfi_restore 22
> + addi.d $r3,$r3,16
> + .cfi_def_cfa_register 3
> + jr $r1
> + .cfi_endproc
> +.LFE0:
> + .size foo, .-foo
> + .ident "GCC: (GNU) 13.0.0 20220512 (experimental)"
> + .section .note.GNU-stack,"",@progbits
> --
> 2.31.1
>
You may want to remove prologue, epilogue, .ident, .note.GNU-stack,
.cfi_startproc, etc to increase signal-to-noise ratio.
prev parent reply other threads:[~2022-08-22 5:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 2:17 liuzhensong
2022-08-22 5:32 ` Fangrui Song [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFP8O3+-MQ88og=YitWRGRqDsgzp1-1ooGfYGM-MAbbj7O7a9g@mail.gmail.com' \
--to=maskray@google.com \
--cc=binutils@sourceware.org \
--cc=caiyinyu@loongson.cn \
--cc=chenglulu@loongson.cn \
--cc=i.swmail@xen0n.name \
--cc=liuzhensong@loongson.cn \
--cc=mengqinggang@loongson.cn \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).