cpu_features icon indicating copy to clipboard operation
cpu_features copied to clipboard

Fix build on FreeBSD/powerpc*

Open kgotlinux opened this issue 2 years ago • 10 comments

All the tests pass.

kgotlinux avatar Feb 21 '23 18:02 kgotlinux

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

Mizux avatar Feb 22 '23 10:02 Mizux

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.

gchatelet avatar Feb 22 '23 10:02 gchatelet

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().

pkubaj avatar Feb 23 '23 11:02 pkubaj

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 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?

gchatelet avatar Feb 23 '23 12:02 gchatelet

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

pkubaj avatar Feb 23 '23 13:02 pkubaj

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 avatar Sep 20 '23 20:09 kgotlinux

@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 

toor1245 avatar Sep 23 '23 00:09 toor1245

@kgotlinux can you clang format the c file?

EDIT: never mind, I'll do it.

gchatelet avatar Sep 25 '23 07:09 gchatelet

@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.

toor1245 avatar Sep 25 '23 09:09 toor1245

@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.

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 ?

gchatelet avatar Sep 25 '23 09:09 gchatelet