[PATCH v9 5/6] riscv: Add ifunc helper method to hwprobe.h

enh enh@google.com
Wed Dec 6 18:17:15 GMT 2023


fwiw, this is the one part of the ifunc proposal i haven't aimed for
source compatibility with in bionic --- i'm not _against_ it exactly,
i'm just unconvinced it's much use. and it's trivial to add after the
fact if it does ship in glibc and does actually turn out to be useful.

specifically, my anecdata from Android [both open-source libraries and
apps] is that basically no-one uses ifuncs beyond libc and
compiler-generated fmv ifuncs [though for riscv64 that's still "future
work"], so there's no market for helpers for hand-written ifuncs?

i think i also worry that people aren't going to pay much attention,
and will prefer this even when they have multiple keys to query
because it's a nicer api, and i'm not sure i want to encourage that
kind of thing :-)

On Thu, Nov 30, 2023 at 10:33 AM Evan Green <evan@rivosinc.com> wrote:
>
> Add a little helper method so it's easier to fetch a single value from
> the hwprobe function when used within an ifunc selector.
>
> Signed-off-by: Evan Green <evan@rivosinc.com>
>
> ---
>
> Changes in v9:
>  - Use __inline rather than inline so c89 compiles (build-many-glibcs)
>
> Changes in v7:
>  - Introduced static inline helper (Richard)
>
>  sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h | 25 +++++++++++++++++++++
>  1 file changed, 25 insertions(+)
>
> diff --git a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> index fd3be5a411..ee7eed3960 100644
> --- a/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> +++ b/sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h
> @@ -22,6 +22,7 @@
>
>  #include <features.h>
>  #include <stddef.h>
> +#include <errno.h>
>  #ifdef __has_include
>  # if __has_include (<asm/hwprobe.h>)
>  #  include <asm/hwprobe.h>
> @@ -79,4 +80,28 @@ typedef int (*__riscv_hwprobe_t) (struct riscv_hwprobe *__pairs, size_t __pair_c
>
>  __END_DECLS
>
> +/* Helper function usable from ifunc selectors that probes a single key. */
> +static __inline int
> +__riscv_hwprobe_one(__riscv_hwprobe_t hwprobe_func,
> +                    signed long long int key,
> +                    unsigned long long int *value)
> +{
> +  struct riscv_hwprobe pair;
> +  int rc;
> +
> +  if (!hwprobe_func)
> +    return ENOSYS;
> +
> +  pair.key = key;
> +  rc = hwprobe_func(&pair, 1, 0, NULL, 0);
> +  if (rc)
> +    return rc;
> +
> +  if (pair.key < 0)
> +    return ENOENT;
> +
> +  *value = pair.value;
> +  return 0;
> +}
> +
>  #endif /* sys/hwprobe.h */
> --
> 2.34.1
>


More information about the Libc-alpha mailing list