From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7867) id 8DD3E3857034; Wed, 24 Aug 2022 06:27:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DD3E3857034 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: liu & zhensong To: bfd-cvs@sourceware.org Subject: [binutils-gdb] LoongArch: ld: Fix bug not generate plt when link a dso X-Act-Checkin: binutils-gdb X-Git-Author: liuzhensong X-Git-Refname: refs/heads/master X-Git-Oldrev: 044193ebf6a2197a36c75cbc1ec7e77440a37b26 X-Git-Newrev: 42bd5254fb5f52f045796e1d9cce07102881d3b1 Message-Id: <20220824062736.8DD3E3857034@sourceware.org> Date: Wed, 24 Aug 2022 06:27:36 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2022 06:27:36 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D42bd5254fb5f= 52f045796e1d9cce07102881d3b1 commit 42bd5254fb5f52f045796e1d9cce07102881d3b1 Author: liuzhensong Date: Fri Aug 19 15:04:45 2022 +0800 LoongArch: ld: Fix bug not generate plt when link a dso =20 Fix the bug that can not generate func@plt when linking a undefined function with cmodel=3Dmedium. Add testcase. =20 bfd/ * elfnn-loongarch.c ld/testsuite/ld-loongarch-elf/ * cmodel-libjirl.dd * cmodel.exp * libjirl.s Diff: --- bfd/elfnn-loongarch.c | 6 ++++ ld/testsuite/ld-loongarch-elf/cmodel-libjirl.dd | 4 +++ ld/testsuite/ld-loongarch-elf/cmodel.exp | 37 +++++++++++++++++++++= ++++ ld/testsuite/ld-loongarch-elf/libjirl.s | 2 ++ 4 files changed, 49 insertions(+) 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 !=3D NULL) { + /* For pcalau12i + jirl. */ + h->needs_plt =3D 1; + if (h->plt.refcount < 0) + h->plt.refcount =3D 0; + h->plt.refcount++; + h->non_got_ref =3D 1; h->pointer_equality_needed =3D 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]+ : +#pass diff --git a/ld/testsuite/ld-loongarch-elf/cmodel.exp b/ld/testsuite/ld-loo= ngarch-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-loon= garch-elf/libjirl.s new file mode 100644 index 00000000000..4d963870df0 --- /dev/null +++ b/ld/testsuite/ld-loongarch-elf/libjirl.s @@ -0,0 +1,2 @@ +pcalau12i $r12, %pc_hi20(func) +jirl $r1,$r12, %pc_lo12(func)