[RFC PATCH 2/2] x86: Alternative <sys/platform/x86.h> implementation

H.J. Lu hjl.tools@gmail.com
Sun Dec 27 16:38:55 GMT 2020


On Sun, Dec 27, 2020 at 7:24 AM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > You mentioned that the current <sys/platform.h> couldn't be used in
> > IFUNC resolver with BIND_NOW.  Do you have a testcase?
>
> This should do it.
>
> From: Florian Weimer <fweimer@redhat.com>
> Subject: x86: Add tst-ifunc-free
>
> ---
>  sysdeps/x86/Makefile         |  2 +-
>  sysdeps/x86/tst-ifunc-free.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
> index 081cc72e93..ee2ae5f4a8 100644
> --- a/sysdeps/x86/Makefile
> +++ b/sysdeps/x86/Makefile
> @@ -7,7 +7,7 @@ sysdep-dl-routines += dl-get-cpu-features
>  sysdep_headers += sys/platform/x86.h
>
>  tests += tst-get-cpu-features tst-get-cpu-features-static \
> -        tst-cpu-features-cpuinfo tst-cpu-features-supports
> +        tst-cpu-features-cpuinfo tst-cpu-features-supports tst-ifunc-free
>  tests-static += tst-get-cpu-features-static
>  endif
>
> diff --git a/sysdeps/x86/tst-ifunc-free.c b/sysdeps/x86/tst-ifunc-free.c
> new file mode 100644
> index 0000000000..4a140ace0d
> --- /dev/null
> +++ b/sysdeps/x86/tst-ifunc-free.c
> @@ -0,0 +1,49 @@
> +/* IFUNC resolver using CPU_FEATURE_USABLE.
> +   Copyright (C) 2020 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/>.  */
> +
> +#include <stdlib.h>
> +#include <sys/platform/x86.h>
> +
> +static void
> +free_fallback (void *ignored)
> +{
> +}
> +
> +static void
> +free_rtm (void *ignored)
> +{
> +}
> +
> +static void
> +(*ifunc_free (void))(void *)
> +{
> +  if (CPU_FEATURE_USABLE (RTM))
> +    return free_rtm;
> +  else
> +    return free_fallback;
> +}
> +
> +void free (void *) __attribute__ ((ifunc ("ifunc_free")));
> +
> +static int
> +do_test (void)
> +{
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>

Extra glibc (binutils?) changes will be needed to support overriding libc.so
symbols with IFUNC.


-- 
H.J.


More information about the Libc-alpha mailing list