From: DJ Delorie via Libc-alpha <libc-alpha@sourceware.org>
To: Hsiangkai Wang <kai.wang@sifive.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH] riscv: Resolve symbols directly for symbols with STO_RISCV_VARIANT_CC.
Date: Thu, 28 Oct 2021 20:20:44 -0400 [thread overview]
Message-ID: <xnbl38adgj.fsf@greed.delorie.com> (raw)
In-Reply-To: <1628480827-366232-1-git-send-email-kai.wang@sifive.com>
This patch looks good to me and follows the spec as committed. I think
it's good to have a "we can't trust the ABI" bit that bypasses all the
problems with lazy relocation and ABI registers.
However, it no longer compiles due to 490e6c62aa31a8aa5c4a059f6e646ede121edf0a
https://sourceware.org/pipermail/libc-alpha/2021-October/131680.html
https://patchwork.sourceware.org/project/glibc/patch/20211006050935.1311740-1-maskray@google.com/
Speficially, this function changed parameters:
-elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
- const ElfW(Sym) *sym, const struct r_found_version *version,
+elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
+ const ElfW(Rela) *reloc, const ElfW(Sym) *sym,
+ const struct r_found_version *version,
void *const reloc_addr, int skip_ifunc)
Hsiangkai Wang <kai.wang@sifive.com> writes:
> +/* RISC-V specific values for the Dyn d_tag field. */
> +#define DT_RISCV_VARIANT_CC (DT_LOPROC + 1)
> +#define DT_RISCV_NUM 2
This matches the spec, ok. I note that (DT_LOPROC) is left unused, so
while there is only one DT_* tag, the "number" of used tags is 2, with
the first tag left undefined.
> +/* RISC-V specific values for the st_other field. */
> +#define STO_RISCV_VARIANT_CC 0x80
This matches the spec, ok.
> diff --git a/sysdeps/riscv/dl-dtprocnum.h b/sysdeps/riscv/dl-dtprocnum.h
> new file mode 100644
> index 0000000..f189fd7
> --- /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
> + <https://www.gnu.org/licenses/>. */
> +
> +/* Number of extra dynamic section entries for this architecture. By
> + default there are none. */
> +#define DT_THISPROCNUM DT_RISCV_NUM
Ok.
> diff --git a/sysdeps/riscv/dl-machine.h b/sysdeps/riscv/dl-machine.h
> +/* Translate a processor specific dynamic tag to the index in l_info array. */
> +#define DT_RISCV(x) (DT_RISCV_##x - DT_LOPROC + DT_NUM)
Ok.
> @@ -299,6 +302,29 @@ elf_machine_lazy_rel (struct link_map *map, ElfW(Addr) l_addr,
> /* 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))
> + {
If the object MAY have CC's...
> + /* 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];
Find the symbol we're relocating against; we already know reloc is not NULL.
> + if (__glibc_unlikely (sym->st_other & STO_RISCV_VARIANT_CC))
> + {
and if it IS a CC type..
> + /* 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, reloc, sym, version, reloc_addr,
> + skip_ifunc);
THEN we relocate it now
> + return;
> + }
> + }
> +
Else we continue to keep it lazy.
(conveniently, this code is the same as aarch64's)
> if (__glibc_unlikely (map->l_mach.plt == 0))
> {
> if (l_addr)
prev parent reply other threads:[~2021-10-29 0:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-09 3:47 [PATCH] riscv: Resolve symbols directly for symbols with STO_RISCV_VARIANT_CC Hsiangkai Wang
2021-08-11 22:11 ` Palmer Dabbelt
2021-08-11 22:51 ` Jessica Clarke
2021-08-11 23:00 ` Jim Wilson
2021-08-11 23:21 ` Palmer Dabbelt
2021-08-11 23:32 ` Jessica Clarke
2021-08-11 23:52 ` Palmer Dabbelt
2021-08-12 0:54 ` Jessica Clarke
2021-10-25 21:08 ` Jim Wilson
2021-12-02 20:21 ` Palmer Dabbelt
2021-12-02 21:06 ` Jessica Clarke
2021-12-02 21:09 ` Andrew Waterman
2021-12-02 21:44 ` Florian Weimer via Libc-alpha
2021-12-02 22:08 ` Jessica Clarke
2021-10-29 0:20 ` DJ Delorie via Libc-alpha [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xnbl38adgj.fsf@greed.delorie.com \
--to=libc-alpha@sourceware.org \
--cc=dj@redhat.com \
--cc=kai.wang@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).