https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125182

John Baldwin <jhb at FreeBSD dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jhb at FreeBSD dot org

--- Comment #12 from John Baldwin <jhb at FreeBSD dot org> ---
(In reply to Wilco from comment #9)
> It should be easy to add the 
> 
> #if __has_include(<asm/hwcap.h>)
> 
> back in if that is what worked in the past (or use __gnu_linux__).
> 
> Should there be a #elif that includes a different header for FreeBSD? Does
> it support the ABI for ifuncs?
> 
> How is the similar issue resolved for libgcc/config/aarch64/lse-init.c?

Mark pointed me here.  I am not the primary maintainer of aarch64 support in
FreeBSD, but I am familiar with some of the details.  From what I can tell,
lse-init.c doesn't handle FreeBSD either.  FreeBSD does have ifunc support for
aarch64, and its ABI is compatible with what cpuinfo.c expects.  On
FreeBSD/aarch64, ifunc resolvers are passed the value of AT_HWCAP in the first
argument (ored with _IFUNC_ARG_HWCAP), and a pointer to an __ifunc_arg_t object
with the same layout as that used in cpuinfo.c as the second argument.

The various HWCAP_* constants are defined on FreeBSD in <machine/elf.h> which
is included by other headers such as <sys/auxv.h> and <sys/elf.h>.

For lse-init.c, FreeBSD's <sys/auxv.h> defines a function elf_aux_info which is
similar in spirit to __getauxval() though the calling convention is slightly
different, I think the equivalent would be:

#include <sys/auxv.h>
#include <sys/elf.h>

static void __attribute__((constructor (90)))
init_have_lse_atomics (void)
{
  unsigned long hwcap;
  if (elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)) == 0)
    __arch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
}

For cpuinfo.c, I think the main thing you'd have to deal with to support
FreeBSD is that you can't assume a fixed value for AT_* (or at least not the
same value used on Linux), and the calls to __getauxval would use elf_aux_info
instead.

If it would be helpful I could come up with an initial patch for FreeBSD
support, but I might need a pointer to a test if you have one for both the
lse-init.c bits and cpuinfo.c bits.  I'll also happily defer to you on how you
would prefer to handle the AT_HWCAP* values being different on different
systems.

Reply via email to