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 472EC385AC12 for ; Mon, 22 Aug 2022 02:18:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 472EC385AC12 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 AQAAf8DxReJV5wJjJyMHAA--.31792S2; Mon, 22 Aug 2022 10:18:01 +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 v2] LoongArch: ld: Fix bug not generate plt when link a dso Date: Mon, 22 Aug 2022 10:17:44 +0800 Message-Id: <20220822021744.2189051-1-liuzhensong@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxReJV5wJjJyMHAA--.31792S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWw4kJFWrKFWrtF1fGF15Arb_yoWrJw4xpa 4qvF1FkF48X3Z7WF93GFW5Z3Z8JFn7GFy2qa43tay0kws8Gry8XF1vyrW3JFW5J3yDA3Wj vr1vva45WF4kXw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkS14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r 4UJVWxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2Wl Yx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbV WUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK6svP MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUoOJ5UUUUU 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 02:18:05 -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 | 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]+ : +#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