From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 1881638378C4 for ; Fri, 9 Dec 2022 04:22:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1881638378C4 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-lj1-x229.google.com with SMTP id a7so3708693ljq.12 for ; Thu, 08 Dec 2022 20:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=XGjG566rqALMTdvfaR/WUk4sAnzajaO/LiHWlVzGrSA=; b=bMQAFtye/Lkc81YQxoNDEq/HQm7bN/YklpcBgGLLK6jrvJhCw73gqUGDtSuNTJXPZY tZmV4RloPi6sWZ+P/nyiTL+zrh8QhQK9quiWv5ue3mO6eYvYcIDjRoJ+GeZ3yyK2buP+ a6kGQZHD9z9eoZxt8FmdRKIChkso5OXs0MV3naZM4tkICvG9QFgDaGnmA9LNNPOyLM/k 1ex486WNHXbCoS0H9BC0Chv6NNjvo1ZT9bZUKK62tKFxx6O2LVO4xzysvSJCRoFWXdx6 4nS47X06b5L67jy92htFVeK5bcLiBTcLA2VUWSJImTUQrhncJ8O0+7kl4UOC4P66I75q yNiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XGjG566rqALMTdvfaR/WUk4sAnzajaO/LiHWlVzGrSA=; b=o3jBvaM8HD4CPKBZmDjHD+CFKT+AApRhyMukV3SsdmuNhFYFKpARlE1ruQzpzCIhX7 jriF1GDUkf3kRjGqYNCnN3jOa6WWrtJBa+aeaL9AukvjkorVmo1q6jFkLJhJcRPgdcf0 Y/PvfJCvLO4oi1RUGLa+RlCFInp433KU4kIMe+sCtv6oPZqELe7nJPjJI8UsnT91aSaW lMRYbGHsGmOlURbHcyBjVr8kZV3z8j2qq3ddrCyfFUO5ID3uAa2eBPVdMxXkWjBCZryC pY+rJwP5folBwNqBcQZUbDnKe9XNEeykE9ASzswThmOe0DXImikRoKKiGTjpA0vG6hmI 5V1w== X-Gm-Message-State: ANoB5pnXlBXLuGAYEuNrWn/wJblqfhbLY97uz8Lf4A1LzKFTAcSBdypk p7jK7wuruPDe4Er2EjACt7r14W0Ub6F0/c1vktdJ2A== X-Google-Smtp-Source: AA0mqf5HhNL1UKFU5pdnC6EMYc+IUTP3VCt20RJotcMeFwOC44bFldg2d9swvhl72ncHgVjzkzyBqXfHnnobctX1yys= X-Received: by 2002:a05:651c:1146:b0:26f:a9e1:9181 with SMTP id h6-20020a05651c114600b0026fa9e19181mr29091474ljo.223.1670559776554; Thu, 08 Dec 2022 20:22:56 -0800 (PST) MIME-Version: 1.0 References: <20220118043159.27521-1-vincent.chen@sifive.com> <20220118043159.27521-3-vincent.chen@sifive.com> <76459bf7-10f9-ff70-d217-ed3298b88c4a@rivosinc.com> In-Reply-To: <76459bf7-10f9-ff70-d217-ed3298b88c4a@rivosinc.com> From: Kito Cheng Date: Fri, 9 Dec 2022 12:22:44 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] riscv: Resolve symbols directly for symbols with STO_RISCV_VARIANT_CC. To: Vineet Gupta Cc: Vincent Chen , libc-alpha@sourceware.org, palmer@dabbelt.com, darius@bluespec.com, andrew@sifive.com, dj@redhat.com, greentime.hu@sifive.com, Hsiangkai Wang , Andy Chiu , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , davidlt@rivosinc.com, Arnd Bergmann , Florian Weimer , Nelson Chu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: >As per the ratified psABI v1.0, the V calling convention doesn't allow > use of V reg for functions args, so this is not needed for now. We don't have one for now, but we could expect the future will have one, so I think we could accept that on upstream first? On Fri, Dec 9, 2022 at 12:11 PM Vineet Gupta wrote: > > On 1/17/22 20:31, Vincent Chen wrote: > > 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. > > As per the ratified psABI v1.0, the V calling convention doesn't allow > use of V reg for functions args, so this is not needed for now. > > -Vineet > > > > > Signed-off-by: Hsiangkai Wang > > Signed-off-by: Vincent Chen > > --- > > 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 0735f6b579..9c95544050 100644 > > --- a/elf/elf.h > > +++ b/elf/elf.h > > @@ -3911,6 +3911,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 > > + > > /* 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 d5fdc5bd05..a1a740f381 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..f189fd700a > > --- /dev/null > > +++ b/sysdeps/riscv/dl-dtprocnum.h > > @@ -0,0 +1,21 @@ > > +/* Configuration of lookup functions. RISC-V version. > > + Copyright (C) 2019-2021 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 1d3e2e588c..cdbaca6533 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) > > @@ -305,6 +308,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) >