[PATCH v4 1/3] riscv: Add Linux hwprobe syscall support

Florian Weimer fweimer@redhat.com
Fri Jul 7 08:15:55 GMT 2023


* Evan Green:

> Add awareness and a thin wrapper function around a new Linux system call
> that allows callers to get architecture and microarchitecture
> information about the CPUs from the kernel. This can be used to
> do things like dynamically choose a memcpy implementation.

I missed before that you intend this for use in IFUNC resolvers, or at
the very least I think I forgot to raise this caveat.

RISC-V is not a HIDDEN_VAR_NEEDS_DYNAMIC_RELOC target, so this is not
completely impossible, but in general, extern function calls in IFUNC
resolvers tend to not work well.  The issue is that the GOT pointer for
a function like __riscv_hwprobe may not have been set up when the
dynamic linker invokes the IFUNC resolver.  There are several ways to
solve this.  You could pass the function pointer to the IFUNC resolver
(which may require a marker symbol and GCC changes).  Or you could a
hidden wrapper function to libc_nonshared.a that checks if the function
pointer to the libc implementation has been set up by a relocation and
uses that, and falls back to a direct system call otherwise.

Thanks,
Florian



More information about the Libc-alpha mailing list