From patchwork Tue Oct 15 17:01:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 98965 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE7E73858D38 for ; Tue, 15 Oct 2024 17:01:37 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from out203-205-221-153.mail.qq.com (out203-205-221-153.mail.qq.com [203.205.221.153]) by sourceware.org (Postfix) with UTF8SMTPS id B22A93858D26 for ; Tue, 15 Oct 2024 17:01:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B22A93858D26 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cyyself.name ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B22A93858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=203.205.221.153 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729011676; cv=none; b=jjksvgRAFTLqilfNQUL0v/Az+6o5FnFIIu06m937OzVLqv8r1PBMHIvmjylmenkmdO7pqFlNQ0/HSWiuLTIBK+0OOKXu876KlKsY52kw+Tz0yJZMFzNezsM1c7sYCoZ3AC8LPil6EWlQKKwb846m4MgBQBQ9k99laV1q8defV3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729011676; c=relaxed/simple; bh=T9Bp63i/vijVoOxHvXxjeJFctwgdv1mpWTXNRl0XXdw=; h=DKIM-Signature:Message-ID:From:To:Subject:Date:MIME-Version; b=l55S/j/73DPb6iJMC/FfGR9ArBVFHIG8NbDWOXOe2IBT0UDCgs65ovAv5xTqL6/QXyIdOJavXF5djNDrPV2j0UeylbRyml1tzBY1GDSCMW79RKjhigPq3rP/5kclOqdHvLio1JcKcQftd+ZCXrGJxL53yu5Oni2N6uWiXRAjNEM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1729011670; bh=adSUQ4z2BCW3pFx/TfrR4GWxZmPflU+aWF5UnahRGIg=; h=From:To:Cc:Subject:Date; b=mtOfUVlDga3XZvyxpaSmanta+V0KhozAN30rWMRfmqlBG0bMkBb4UrYPeokhMvsHX hRyc4fJ5Q4ftqX7Wm1vdGaGefbD6kIwUcKiDeZxdFd6iQGPFR3EvyL8OWe0KVJXF5y 8AANxdgF8uwtkvMeXXlJk+7NrvjEr//mlO3toWUQ= Received: from cyy-pc.lan ([240e:379:224e:6200:46fa:4c95:3ace:1c9d]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 44B9804; Wed, 16 Oct 2024 01:01:04 +0800 X-QQ-mid: xmsmtpt1729011664tm6ddfanm Message-ID: X-QQ-XMAILINFO: Mdc3TkmnJyI/fJsubysNhJM4Cbcyzd7cL5b1rf1wu+STM6ehyKyQ/kjwQZ6YjK OxfQzZsCkZ+pVteX+1r71dE+V9nhLOqceuo1vbNTmcuJ8KnUGFiNh6XceIlR4+juLEJCTPom/CaN ITH7+uHFvMNMyYRDvBIBGKDKVLXz+T8OnaRl84NQEcxWTg+e5wye+j1F8W6dX0mkcFh7uBPhX4s3 2ptyTiz2hevoRpIHOQYsV0nN9bjuXt56J8ikXBNKIlAji80RYiCTMk5BFYHQ9ONRbw1AqKpWIlfV hA2Ub/fO0dJvdvt9WmFmTazSg+9ZICvuQE2WGevKXgVcITn6olwdta1M+csJMIriHGVZXU8LwwnD nVfV3IGM7ewqfJw8I3DaMLNNTqjsNnJrlqceKsKAxoY6G2s6U9csBcek3avVev/7LH9AR05JhUW8 JJ29lM8e8pvc08yXugEfC/sD690BIfwBXZwVw0FFj46soL/NBEkjssRE7ePPihKua4DGaMXrnYvi HmMyT6iy7aBqJFlQao9BiMH67MxP7pV61AB2NnSDTIMt/mD9P7QGe4RKhJ8PUiMoJHHI91hIccAt w/JW1RcheRlrdKeu6/xUyHrRNgRCPG7pBLf2CXvo2/LGsFWGpzydosHzLJwo3erBZhW72urfqVMI pUpfOG1FMgx2BvyjSdNIOzlLFsaeT4Rfz/a93TAc+A4zGE72pdilIokPqGRSiF3395oXLX07GNBV kbaTJuYW12nfdDPclcHluWv22xRq8uaYR+GqG+VKaQdbwkd3ETFKzfPEFrLDyhOPi/xl/2jv5smz wvBYGf2p6tG/oYkaB9ySldabLNrpwN5Iwhg5eGO9gb9475Om7Cz0+voggioAEZV59/jNK9BVUUVh pU3SqGe/thGJ85LOcYjTEKgAZ6X2VrR3ffeaLbAroU3aq9+OcTXCRVVBf+UcofGLds4ylO9HxVrw QHL588I1RjcUZTGsu+eYsbS6A7MWEWY2lCFI1dy8k= X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: Yangyu Chen To: libc-alpha@sourceware.org Cc: Palmer Dabbelt , Kito Cheng , Vincent Chen , Andreas Schwab , Yangyu Chen Subject: [PATCH v2] RISC-V: Fix IFUNC resolver cannot access gp pointer Date: Wed, 16 Oct 2024 01:01:02 +0800 X-OQ-MSGID: <20241015170102.3531554-1-cyy@cyyself.name> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, HELO_DYNAMIC_IPADDR, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_PASS, TXREP 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org In some cases, an IFUNC resolver may need to access the gp pointer to resolve the function address. Such an object may have l_relocated == 0. In this case, the GP register will not be set up. Thus, the IFUNC resolver cannot access the gp pointer. This patch fixes this issue by relaxing the check of l_relocated in elf_machine_runtime_setup. As for the original Bug 31317, since the static-linked executable has already set up the gp pointer, we don't need to execute the code to set up the gp pointer again. I have also reproduced and checked Bug 31317, this patch can fix the issue. Closes: BZ #32269 Fixes: 96d1b9ac23 ("RISC-V: Fix the static-PIE non-relocated object check") Signed-off-by: Yangyu Chen --- sysdeps/riscv/dl-machine.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h index b2f28697f7..10a36d6701 100644 --- a/sysdeps/riscv/dl-machine.h +++ b/sysdeps/riscv/dl-machine.h @@ -348,7 +348,8 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], gotplt[1] = (ElfW(Addr)) l; } - if (l->l_type == lt_executable && l->l_relocated) +#ifdef SHARED + if (l->l_type == lt_executable) { /* The __global_pointer$ may not be defined by the linker if the $gp register does not be used to access the global variable @@ -368,6 +369,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[], : "r" (ref->st_value) ); } +#endif #endif return lazy; }