From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 72F663858D28 for ; Wed, 3 May 2023 14:46:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72F663858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=linux.vnet.ibm.com Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 343Ei092029537 for ; Wed, 3 May 2023 14:46:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=content-type : message-id : date : subject : to : references : from : in-reply-to : mime-version; s=pp1; bh=At2CJH/4X0LFcat81eQNndQKWt65DsHwCEMdcMu4Vng=; b=msiN+vGzYwQdQ8ix4s3EwuXHFqX/hY4HRzoo2xhmNRlkN/f5CjOXeOVcmyBj2j7CI2bB iy/LnaycVO8jaZIMAYsqPGTeqkEsjEfMUclTjeFWaqUWGSoNgACmvSL+vSjLtoIx/C5b Bz4YyVlw9YburJzYHxqwGjlz4CPoTKMFRrd2kWxH7T4PTSmR42b3fKCVvpFBUow38QUB McuOgoYm8MzOq7E8q8doWniUAWFZAMxkcLup1EgG4c8Mqcxk2N8TG47YTMldJg1h6a+e d2Cfwgk6Xfpx3DtiuZDRPy1ZsRx7zmCaeE2UhGDr1xiuwyXnkp8YZwsrLLiqgNq5rgNA Lw== Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3qbse50hmx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 03 May 2023 14:46:35 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 343C65YD025393 for ; Wed, 3 May 2023 14:46:20 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([9.208.129.120]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3q8tv7mwyb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 03 May 2023 14:46:19 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 343EkIre33489316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 3 May 2023 14:46:18 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7CCC758060 for ; Wed, 3 May 2023 14:46:18 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA09D5805A for ; Wed, 3 May 2023 14:46:17 +0000 (GMT) Received: from [9.163.43.200] (unknown [9.163.43.200]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP for ; Wed, 3 May 2023 14:46:17 +0000 (GMT) Content-Type: multipart/alternative; boundary="------------lfUvmxMSThXJ84kNX6q4GVCZ" Message-ID: Date: Wed, 3 May 2023 20:16:16 +0530 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Fwd: [COMMITTED 1/2] riscv: Resolve symbols directly for symbols with STO_RISCV_VARIANT_CC. To: libc-alpha@sourceware.org References: <20230428140427.13133-1-palmer@rivosinc.com> From: Manjul Mohan In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 0gVL-YllpPn4TSIWr7uZBJ1iW4ixmt78 X-Proofpoint-GUID: 0gVL-YllpPn4TSIWr7uZBJ1iW4ixmt78 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-03_10,2023-05-03_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 impostorscore=0 clxscore=1011 phishscore=0 priorityscore=1501 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305030123 X-Spam-Status: No, score=-17.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: This is a multi-part message in MIME format. --------------lfUvmxMSThXJ84kNX6q4GVCZ Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit > > > From: Hsiangkai Wang > > In some cases, we do not want to go through the resolver for function > calls. For example, functions with vector arguments will use vector > registers to pass arguments. In the resolver, we do not save/restore the > vector argument registers for lazy binding efficiency. To avoid ruining > the vector arguments, functions with vector arguments will not go > through the resolver. > > To achieve the goal, we will annotate the function symbols with > STO_RISCV_VARIANT_CC flag and add DT_RISCV_VARIANT_CC tag in the dynamic > section. In the first pass on PLT relocations, we do not set up to call > _dl_runtime_resolve. Instead, we resolve the functions directly. > > Signed-off-by: Hsiangkai Wang > Signed-off-by: Vincent Chen > Reviewed-by: Palmer Dabbelt > Acked-by: Palmer Dabbelt > Link: > https://inbox.sourceware.org/libc-alpha/20230314162512.35802-1-kito.cheng@sifive.com > Signed-off-by: Palmer Dabbelt > --- > elf/elf.h | 7 +++++++ > manual/platform.texi | 6 ++++++ > sysdeps/riscv/dl-dtprocnum.h | 21 +++++++++++++++++++++ > sysdeps/riscv/dl-machine.h | 26 ++++++++++++++++++++++++++ > 4 files changed, 60 insertions(+) > create mode 100644 sysdeps/riscv/dl-dtprocnum.h > > diff --git a/elf/elf.h b/elf/elf.h > index 94ca23c1bb..4f65b5a32d 100644 > --- a/elf/elf.h > +++ b/elf/elf.h > @@ -3933,6 +3933,13 @@ enum > > #define R_TILEGX_NUM 130 > > +/* RISC-V specific values for the Dyn d_tag field. */ > +#define DT_RISCV_VARIANT_CC (DT_LOPROC + 1) > +#define DT_RISCV_NUM 2 > + > +/* RISC-V specific values for the st_other field. */ > +#define STO_RISCV_VARIANT_CC 0x80 This is causing testcase failures on ppc64le platform. /../elf/elf.h:4013: error: macro STO_RISCV_VARIANT_CC redefined //../elf/elf.h:3941: note: location of previous definition ../elf/elf.h:4023: error: macro DT_RISCV_VARIANT_CC redefined ../elf/elf.h:3937: note: location of previous definition Testcase failures: elf/tst-glibcelf elf/tst-relro-ldso elf/tst-relro-libc > + > /* RISC-V ELF Flags */ > #define EF_RISCV_RVC 0x0001 > #define EF_RISCV_FLOAT_ABI 0x0006 > diff --git a/manual/platform.texi b/manual/platform.texi > index c6ed73cb97..714c07813f 100644 > --- a/manual/platform.texi > +++ b/manual/platform.texi > @@ -121,6 +121,12 @@ when it is not allowed, the priority is set to > medium. > @node RISC-V > @appendixsec RISC-V-specific Facilities > > +Functions that are lazily bound must be compatible with the standard > calling > +convention. When a function is annotated with STO_RISCV_VARIANT_CC, > it means > +this function is not compatible with the standard calling convention. The > +dynamic linker will directly resolve it instead of using the lazy binding > +mechanism. > + > Cache management facilities specific to RISC-V systems that implement > the Linux > ABI are declared in @file{sys/cachectl.h}. > > diff --git a/sysdeps/riscv/dl-dtprocnum.h b/sysdeps/riscv/dl-dtprocnum.h > new file mode 100644 > index 0000000000..281c5aadeb > --- /dev/null > +++ b/sysdeps/riscv/dl-dtprocnum.h > @@ -0,0 +1,21 @@ > +/* Configuration of lookup functions. RISC-V version. > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library 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 > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library. If not, see > + . */ > + > +/* Number of extra dynamic section entries for this architecture. By > + default there are none. */ > +#define DT_THISPROCNUM DT_RISCV_NUM > diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h > index c0c9bd93ad..0e6c0bb155 100644 > --- a/sysdeps/riscv/dl-machine.h > +++ b/sysdeps/riscv/dl-machine.h > @@ -53,6 +53,9 @@ > || (__WORDSIZE == 64 && (type) == R_RISCV_TLS_TPREL64))) \ > | (ELF_RTYPE_CLASS_COPY * ((type) == R_RISCV_COPY))) > > +//* Translate a processor specific dynamic tag to the index in l_info > array. */ > +#define DT_RISCV(x) (DT_RISCV_##x - DT_LOPROC + DT_NUM) > + > /* Return nonzero iff ELF header is compatible with the running host. */ > static inline int __attribute_used__ > elf_machine_matches_host (const ElfW(Ehdr) *ehdr) > @@ -281,6 +284,29 @@ elf_machine_lazy_rel (struct link_map *map, > struct r_scope_elem *scope[], > /* Check for unexpected PLT reloc type. */ > if (__glibc_likely (r_type == R_RISCV_JUMP_SLOT)) > { > + if (__glibc_unlikely (map->l_info[DT_RISCV (VARIANT_CC)] != NULL)) > + { > + /* Check the symbol table for variant CC symbols. */ > + const Elf_Symndx symndx = ELFW(R_SYM) (reloc->r_info); > + const ElfW(Sym) *symtab = > + (const void *)D_PTR (map, l_info[DT_SYMTAB]); > + const ElfW(Sym) *sym = &symtab[symndx]; > + if (__glibc_unlikely (sym->st_other & STO_RISCV_VARIANT_CC)) > + { > + /* Avoid lazy resolution of variant CC symbols. */ > + const struct r_found_version *version = NULL; > + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) > + { > + const ElfW(Half) *vernum = > + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); > + version = &map->l_versions[vernum[symndx] & 0x7fff]; > + } > + elf_machine_rela (map, scope, reloc, sym, version, reloc_addr, > + skip_ifunc); > + return; > + } > + } > + > if (__glibc_unlikely (map->l_mach.plt == 0)) > { > if (l_addr) > -- > 2.40.0 > --------------lfUvmxMSThXJ84kNX6q4GVCZ--