From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 188013858D32 for ; Mon, 22 Aug 2022 10:16:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 188013858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxX+BpVwNjkUsHAA--.31824S2; Mon, 22 Aug 2022 18:16:13 +0800 (CST) From: liuzhensong To: binutils@sourceware.org Cc: i.swmail@xen0n.name, xry111@xry111.site, maskray@google.com, caiyinyu@loongson.cn, chenglulu@loongson.cn, mengqinggang@loongson.cn, xuchenghua@loongson.cn, liuzhensong Subject: [PATCH v3] LoongArch: ld: Fix bug not generate plt when link a dso Date: Mon, 22 Aug 2022 18:16:07 +0800 Message-Id: <20220822101607.2796251-1-liuzhensong@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxX+BpVwNjkUsHAA--.31824S2 X-Coremail-Antispam: 1UD129KBjvJXoWxGF4DJr1DAF4fZFWkZw15CFg_yoW5Zryfpa sFvF1FkF18X3Z7GF93GFW5Z3Z8JFn7GFy2va43JayIkws8Jry8XF10yrW3JFW5J3yDA3W0 qr1vv345WF1kXaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk214x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK 82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoOJ5UUUUU X-CM-SenderInfo: holx6xphqv003j6o00pqjv00gofq/ X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2022 10:16:17 -0000 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 | 2 + 4 files changed, 49 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]+ : +#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..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) -- 2.31.1