From patchwork Fri Dec 22 08:31:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mengqinggang X-Patchwork-Id: 182594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp920586dyi; Fri, 22 Dec 2023 00:31:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuDxKA5idqNkR0ZJ8KDMoUqaSbpoB1z8FI+SGXr6UZYpXNCWqalzSB2W3CFvgXR0Ck9Ui5 X-Received: by 2002:a05:6808:218a:b0:3b9:da2c:e5a6 with SMTP id be10-20020a056808218a00b003b9da2ce5a6mr870544oib.32.1703233899669; Fri, 22 Dec 2023 00:31:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703233899; cv=pass; d=google.com; s=arc-20160816; b=tAFX4rfc1FDIgYXRPcVaqRedGGCQzAU+OQCAsWad6y1ctwbk3hrRFneZw1nTRCbibU kImTt+vkt2TVkrWlEO7oVpNUcqt37pQNQB7wYFbTNdjK626ENiar7o4gkvBdVz2HWDYO czq7VSO3k35mSbPyRMH4tAZz1igDi2sWjGJ2F4HAZ+GuQoYVt1hP3x8hGRKIVAYb4pAw gTGDGS9RjnSBKR3BikYjK/1PBRnGo0PyL1lAQO4jciBLWHyIOY2ItG6bh7UbM3aRjc6Q hRdx3z5IyhMNob/GgxWEYBIY1606KZ4BSumKf1S0tYXCTaYAQFEAtXtN9gU/oeZdi4Wg QcTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:arc-filter :dmarc-filter:delivered-to; bh=W4C0+AqFODCOC0Z80QqqFBvAXxwMTTdKzsWdkPC6iWQ=; fh=IjBrBzj0HafC7UFRTZLmdEImc4JDKXFiCrZAu8bdkFw=; b=tQILbOXScwqQq/uFZlQhVQw0IS2h257GJYz1EX2br4/jO5v0R2YxUbBil2JSOsevwn KhiYkEwpI7a38YUgb0/CddcaQEkaiBwlXMvJmjXmW2j21JapWFHhBXZYZSjWAnbO0hzR sxRVHPQhJ2ZH862MLUtxG1VjVLfOJWz1Rd3/Kb/yNAv+mPoGqSu5Qumz2EaUhoVW8RRU cfOmVmdGNqi4hV0y7QK6+/E+TQUb39cWgk9lOizNvyTF7m5KRe6N95BOZPU0Xp+0jwlO MBctlgDgt0NQ5b+x7NjQ7mrx/5d8COnhVovcHzz5KrdYycs+9BMdZAIrQKoXA7DKHxfS VT1g== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u1-20020a0cf1c1000000b0067f3a84123dsi4027217qvl.5.2023.12.22.00.31.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 00:31:39 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D5183858C5E for ; Fri, 22 Dec 2023 08:31:39 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 5E0853858D3C for ; Fri, 22 Dec 2023 08:31:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E0853858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5E0853858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703233889; cv=none; b=mizNpDO1+wKDQehIOkmCFuyRuzytXdIqGVnHkgCIEO0C6MO6jKLZSh1uCo9iMjM/H+AKBo/t9xJbB3QhClONxbM/Q9B7KnTHRfJTpqu9vPlRRio/xRhnTNcd8iA+y1x1WZ7DFfcZf8CqSS4Th+HD0HQ2EbcCq4V1g0BJc2nYwsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703233889; c=relaxed/simple; bh=YY7DtAhrN8H0EeuCyv14d06eJw97Wov+BMJIW10q6rA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=WblHU9Ox1eJniH8/Ykr2B6wQUv1C4htXDHWrL3x5+UE8bIMDX8wLQ9pgWmfeonWK5cIB7vZUyieLcyBg6j9T2SJpayChiiSnfZeop0XWJFvRz1NOTbrsEUk2sfERuvO9DAUcSDCPpfBvYTuu7qSMsLVD3P8Jvmk1OjG8x6hiRXE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.2.6.5]) by gateway (Coremail) with SMTP id _____8AxXOlSSYVlecwDAA--.19453S3; Fri, 22 Dec 2023 16:31:14 +0800 (CST) Received: from 5.5.5 (unknown [10.2.6.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dxjb5RSYVlMFsFAA--.19875S2; Fri, 22 Dec 2023 16:31:13 +0800 (CST) From: mengqinggang To: binutils@sourceware.org Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, liuzhensong@loongson.cn, cailulu@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name, maskray@google.com, luweining@loongson.cn, wanglei@loongson.cn, hejinyang@loongson.cn, mengqinggang Subject: [PATCH] LoongArch: Fix linker generate PLT entry for data symbol Date: Fri, 22 Dec 2023 16:31:12 +0800 Message-Id: <20231222083112.1060582-1-mengqinggang@loongson.cn> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dxjb5RSYVlMFsFAA--.19875S2 X-CM-SenderInfo: 5phqw15lqjwttqj6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBj93XoW7ZryUAr4kAFWrCw15XFWxZrc_yoW8CF4fp3 42yF1aya18J3Z3Grn7uFWrZ3ZxXFZ7Gr42qasxta4Fvrs0qryqqF1FyrZIgF4UJ3yDJFyv vFyvv345uF1kAFbCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv 67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jOb18UUUUU= X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785970189587490711 X-GMAIL-MSGID: 1785970189587490711 With old "medium" code model, we call a function with a pair of PCALAU12I and JIRL instructions. Currently the assembler produces something like: 8: 1a00000c pcalau12i $t0, 0 8: R_LARCH_PCALA_HI20 g c: 4c000181 jirl $ra, $t0, 0 c: R_LARCH_PCALA_LO12 g Before the linker generates a "PLT entry" for data without any diagnostic. If "g" is a data symbol, it may load two instructions in the PLT. For R_LARCH_PCALA_HI20 reloc, linker only generate PLT entry for STT_FUNC and STT_GNU_IFUNC symbol. bfd/ChangeLog: * testsuite/ld-loongarch-elf/libjirl.s: Add function type. * elfnn-loongarch.c (loongarch_elf_check_relocs): Add function condition for R_LARCH_PCALA_HI20 reloc. --- bfd/elfnn-loongarch.c | 6 +++++- ld/testsuite/ld-loongarch-elf/libjirl.s | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c index 87eb65ab9f7..7302930ae01 100644 --- a/bfd/elfnn-loongarch.c +++ b/bfd/elfnn-loongarch.c @@ -762,8 +762,12 @@ loongarch_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, h->non_got_ref = 1; break; + /* For normal cmodel, pcalau12i + addi.d/w used to data. + For first version medium cmodel, pcalau12i + jirl are used to + function call, it need to creat PLT entry for STT_FUNC and + STT_GNU_IFUNC type symbol. */ case R_LARCH_PCALA_HI20: - if (h != NULL) + if (h != NULL && (STT_FUNC == h->type || STT_GNU_IFUNC == h->type)) { /* For pcalau12i + jirl. */ h->needs_plt = 1; diff --git a/ld/testsuite/ld-loongarch-elf/libjirl.s b/ld/testsuite/ld-loongarch-elf/libjirl.s index 4d963870df0..de028c5a44b 100644 --- a/ld/testsuite/ld-loongarch-elf/libjirl.s +++ b/ld/testsuite/ld-loongarch-elf/libjirl.s @@ -1,2 +1,3 @@ +.type func @function pcalau12i $r12, %pc_hi20(func) jirl $r1,$r12, %pc_lo12(func)