From patchwork Mon May 6 04:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hau Hsu X-Patchwork-Id: 89513 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 C325D3858C98 for ; Mon, 6 May 2024 04:46:10 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 2FD2F3858D1E for ; Mon, 6 May 2024 04:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2FD2F3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2FD2F3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714970737; cv=none; b=bfz4x3/O/CFGTZCiNrWyJIogp8JkKdDnj8QTJ9Yy+cHr1XffuOhQgFABdY3RzvqwKq7WsvxMxmJsILUNzNnjnA1ryRGskGFPSnM3w1IbbpKHLSeQQOF80qXhtZMwQ9DUh345uB/J0KkwEISycxN76KaXSiwBgyPRwfwmFlsBhTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714970737; c=relaxed/simple; bh=chKkHEfUdkShlmPmkKliPhLd9k9cTUbOja7G/5yQ0dY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FYEVbYDA3vRQtVmZ8IgRM394+TIDG3CTbrToZ2gXEdrIXDacB+YqYOAo8Mk4eukn174bwEddKsbWkkP+ggFUWQCmMfiGpZO0r7WpZCxvS1bwhfkgRBAODZ9oXczGDlRI0a+0DtE7D4c2tkc6lS1HJb1FXhaMynV/r8q4vUGmOtA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1edfc57ac0cso4041095ad.3 for ; Sun, 05 May 2024 21:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1714970734; x=1715575534; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=KFdIGhBkb536R1DHpdVlXxEoy9Z1hrQzR0F8HHdBnbE=; b=GhotsEHUf3jVJkq4y10O//iMbSQu5FdZeFjdPkzC0MTptsybv0e1e4kIual2hLdThk aiev+Mn7nT4oOIbM9F/vGVb7qFmDWTp8zU5C8D5vmtaNWf9NMVx5ZBXK3FWyPCSqFTY8 3kyz+ugjg4jL/3gaMlLjdoPfWcEXiT8PNPBBcIkP31mOLMW+b4zE9MdqRNAWADyfOhUz sTeWU8O7wBVdmsSQD4UA4ghOZ58vTdfg60KgmElxg/QqeXHmEuh8lUJTYYN436ALHR7l 18+EwqEQbgsZdNmWXc22p2gXHA4bdwmerwQfHe4cJthdFy5Sk/yDsBo1SjD+NpYCxMJv VmMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714970734; x=1715575534; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KFdIGhBkb536R1DHpdVlXxEoy9Z1hrQzR0F8HHdBnbE=; b=avNa377j4Bs/5xdyuptyxLsyIK2jnf0kI9HizfuK4wp28wpcXk/4eh3b6mkJaFyt9L YNZBTgbaqRVMrnn0ZvsTO3CKh67qiML/pvqTRBVM66Y73LiziHVLckKLWhtDCpTXXsr6 q6O8Y9MkkQJEIxF/7DGgYUiM4zpPMD8dOcrCyU+VqnoV9GQ5A06QYJuwBdOInvVGWST6 ZFy2VVgY0dP6iU5Ei9Ti/gY2MG+qvcD4IzpxDbXtiJD4DlgG+G6JhOBt1imHFvrHD8Q1 +vgprsEWKUGg8XML+s8GTbEu/jT4ZVNNkj7N+81SFu0lZhmEt66S+QJtYr8dZWWsesvj 4itA== X-Gm-Message-State: AOJu0YzDD2fzXdNHEbnpM39Amxd+q3FWA/ienP9JgSqzpoDhEy78EcLQ OUQ0buYX3kTNoFrQyKh3N0SGT5xSvZaDBqIbdK3HUUs624x6D5ZUt/B98w+sL1/qlTvueceh2Fb KHNbhjoPUWXxLVp68yGGZt+yu9ull4mJzQOyXixesVaZJ0c5/bhg42iJVVdjjLNLC8rShF7EDrX nr8WdVXemM68wkwrpzvsSTPcxTI4xQmxOHIbG0 X-Google-Smtp-Source: AGHT+IEa0Otm7XFCDilOX0FLkmTOROTUJn1aH3mDaOiF4ysdrfSq/0wnfsLC4t4Ts9MOTOacFexlnQ== X-Received: by 2002:a17:902:7288:b0:1e3:e1e8:bb5 with SMTP id d8-20020a170902728800b001e3e1e80bb5mr8191229pll.28.1714970733894; Sun, 05 May 2024 21:45:33 -0700 (PDT) Received: from sw05.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id s11-20020a170902ea0b00b001e3e081d07esm7304810plg.179.2024.05.05.21.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 May 2024 21:45:33 -0700 (PDT) From: Hau Hsu To: binutils@sourceware.org, kito.cheng@gmail.com, hau.hsu@sifive.com Subject: [PATCH 1/2] riscv: Add POINTER_LOCAL_IFUNC_P/PLT_LOCAL_IFUNC_P Date: Mon, 6 May 2024 12:45:19 +0800 Message-Id: <20240506044520.2780464-1-hau.hsu@sifive.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: 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+patchwork=sourceware.org@sourceware.org Add POINTER_LOCAL_IFUNC_P which returns TRUE for pointer reference to local IFUNC symbol. Add PLT_LOCAL_IFUNC_P which returns TRUE for PLT reference to local IFUNC symbol. Copied from x86 commit: cf1070f1a1ca1f8be1cd88aa6ece55a25e6a887b --- bfd/elfnn-riscv.c | 11 ++--------- bfd/elfxx-riscv.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 95abf2d10e2..3a30b7a4bd9 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -2373,9 +2373,7 @@ riscv_elf_relocate_section (bfd *output_bfd, outrel.r_offset += input_section->output_section->vma + input_section->output_offset; - if (h->dynindx == -1 - || h->forced_local - || bfd_link_executable (info)) + if (POINTER_LOCAL_IFUNC_P (info, h)) { info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"), @@ -3272,12 +3270,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd, bfd_put_NN (output_bfd, sec_addr (plt), loc); rela.r_offset = got_address; - - if (h->dynindx == -1 - || ((bfd_link_executable (info) - || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) - && h->def_regular - && h->type == STT_GNU_IFUNC)) + if (PLT_LOCAL_IFUNC_P (info, h)) { info->callbacks->minfo (_("Local IFUNC function `%s' in %pB\n"), h->root.root.string, diff --git a/bfd/elfxx-riscv.h b/bfd/elfxx-riscv.h index 49be71746b9..9efac27864c 100644 --- a/bfd/elfxx-riscv.h +++ b/bfd/elfxx-riscv.h @@ -27,6 +27,20 @@ #define RISCV_UNKNOWN_VERSION -1 +/* TRUE if this is a pointer reference to a local IFUNC. */ +#define POINTER_LOCAL_IFUNC_P(INFO, H) \ + ((H)->dynindx == -1 \ + || (H)->forced_local \ + || bfd_link_executable (INFO)) + +/* TRUE if this is a PLT reference to a local IFUNC. */ +#define PLT_LOCAL_IFUNC_P(INFO, H) \ + ((H)->dynindx == -1 \ + || ((bfd_link_executable (INFO) \ + || ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT) \ + && (H)->def_regular \ + && (H)->type == STT_GNU_IFUNC)) + struct riscv_elf_params { /* Whether to relax code sequences to GP-relative addressing. */