compiler-rt: add aarch64 init function for LSE atomics

As reported by Ronald, adding the out-of-line LSE atomics helpers for
aarch64 to compiler-rt was not sufficient to link programs using these,
as they also require a __aarch64_have_lse_atomics global. This is
initialized in compiler-rt's lib/builtins/cpu_model.c, roughly similar
to the x86 CPU model and feature detection in that file.

Since upstream does not yet have a FreeBSD specific implementation for
getting the required information, add a simple one that should work for
now, while I try to get it sorted with the LLVM people.

Reported by:	Ronald Klop <ronald-lists@klop.ws>
Fixes:		cc55ee8009
PR:		257392
MFC after:	2 weeks
This commit is contained in:
Dimitry Andric 2021-09-06 21:23:10 +02:00
parent 292815eac6
commit efe67f33c3
2 changed files with 9 additions and 2 deletions

View file

@ -775,8 +775,14 @@ _Bool __aarch64_have_lse_atomics
#define HWCAP_ATOMICS (1 << 8)
#endif
static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
#if defined(__FreeBSD__)
unsigned long hwcap;
int result = elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
__aarch64_have_lse_atomics = result == 0 && (hwcap & HWCAP_ATOMICS) != 0;
#else
unsigned long hwcap = getauxval(AT_HWCAP);
__aarch64_have_lse_atomics = (hwcap & HWCAP_ATOMICS) != 0;
#endif
}
#endif // defined(__has_include)
#endif // __has_include(<sys/auxv.h>)

View file

@ -146,8 +146,9 @@ SRCF+= floatundisf
SRCF+= floatundixf
.endif
# __cpu_model support, only used on x86
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
# __cpu_model support, only used on aarch64 and x86
.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
${MACHINE_CPUARCH} == "i386"
SRCF+= cpu_model
.endif