cpu_features
cpu_features copied to clipboard
Fix build on FreeBSD/powerpc*
All the tests pass.
FYI x86 implem do support Linux
(or Android
) and FreeBSD
but sources are splitted...
So do we keep the same file "layout" for PowerPC ? or rename the file impl_ppc_linux_or_freebsd.c
note: I don't remember why we split the sources
EDIT:
https://github.com/google/cpu_features/blob/c74a85d64a64594fab865c8fd86865be8ac2bf87/src/impl_x86_freebsd.c#L33-L34
https://github.com/google/cpu_features/blob/c74a85d64a64594fab865c8fd86865be8ac2bf87/src/impl_x86_linux_or_android.c#L32-L33
For FreeBSD
we need to parse /var/run/dmesg.boot
instead of /proc/cpuinfo
and the format is not the same.
So it's definitely not the same way of detecting the features.
Tests "pass" because we create a fake filesystem with /proc/cpuinfo
, but it won't exist on a real FreeBSD
so this patch is incorrect.
While the current implementation with /proc/cpuinfo
is wrong, parsing /var/run/dmesg.boot
is also wrong even if it works. On FreeBSD you need to use elf_aux_info()
to get CPU capabilities. It works similarly to Linux's getauxval()
.
While the current implementation with
/proc/cpuinfo
is wrong, parsing/var/run/dmesg.boot
is also wrong even if it works. On FreeBSD you need to useelf_aux_info()
to get CPU capabilities. It works similarly to Linuxs
getauxval()`.
Ah! Thx a lot for the information. I was unaware of elf_aux_info()
.
We'll look into this. @pkubaj do you know if the function is always available or if it needs dynamic loading as for android?
This function is available without dynamic loading. You just need FreeBSD 12.0 or newer and include sys/auxv.h
. An example of using it would be https://github.com/zlib-ng/zlib-ng/pull/1340/files
Pull request rebased and fixed, It currently builds on the support added in https://github.com/google/cpu_features/commit/89a3f0358a32268d1870a2e35e2a13b49ab7f126, which adds support for using elf_aux_info()
on FreeBSD. Currently list_cpu_features
correctly lists architecture and CPU features, It does not list CPU model, microarchitecture etc., due to no AT_PLATFORM on FreeBSD.
@kgotlinux, could you please add src/impl_ppc_freebsd.c
file to BUILD.bazel
: https://github.com/google/cpu_features/blob/main/BUILD.bazel#L237
https://github.com/google/cpu_features/blob/main/BUILD.bazel#L302
and make sure the following command will work fine?
bazel run list_cpu_features
@kgotlinux can you clang format the c
file?
EDIT: never mind, I'll do it.
@gchatelet, I see bug
and compilation error
labels, but we didn't have support FreeBSD powerpc at all, so I would say this is new architecture support for FreeBSD.
@gchatelet, I see
bug
andcompilation error
labels, but we didn't have support FreeBSD powerpc at all, so I would say this is new architecture support for FreeBSD.
Fair enough, thx for noticing. Let's try to add CI support for this patch before merging.
@Mizux would you have a bit of time to add CI for FreeBSD / Power ?