Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenBSD Arm64 support #367

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

load("@bazel_skylib//lib:selects.bzl", "selects")
load("//:bazel/platforms.bzl", "PLATFORM_CPU_ARM", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_MIPS", "PLATFORM_CPU_PPC", "PLATFORM_CPU_RISCV32", "PLATFORM_CPU_RISCV64", "PLATFORM_CPU_X86_64")
load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS", "PLATFORM_OS_LINUX", "PLATFORM_OS_FREEBSD", "PLATFORM_OS_ANDROID")
load("//:bazel/platforms.bzl", "PLATFORM_OS_MACOS", "PLATFORM_OS_LINUX", "PLATFORM_OS_FREEBSD", "PLATFORM_OS_OPENBSD", "PLATFORM_OS_ANDROID")

package(
default_visibility = ["//visibility:public"],
Expand Down Expand Up @@ -170,13 +170,14 @@ cc_library(
name = "hwcaps",
srcs = [
"src/hwcaps.c",
"src/hwcaps_freebsd.c",
"src/hwcaps_freebsd_or_openbsd.c",
"src/hwcaps_linux_or_android.c",
],
copts = C99_FLAGS,
defines = selects.with_or({
PLATFORM_OS_MACOS: ["HAVE_DLFCN_H"],
PLATFORM_OS_FREEBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
PLATFORM_OS_OPENBSD: ["HAVE_STRONG_ELF_AUX_INFO"],
PLATFORM_OS_LINUX: ["HAVE_STRONG_GETAUXVAL"],
PLATFORM_OS_ANDROID: ["HAVE_STRONG_GETAUXVAL"],
"//conditions:default": [],
Expand All @@ -195,7 +196,7 @@ cc_library(
testonly = 1,
srcs = [
"src/hwcaps.c",
"src/hwcaps_freebsd.c",
"src/hwcaps_freebsd_or_openbsd.c",
"src/hwcaps_linux_or_android.c",
"test/hwcaps_for_testing.cc",
],
Expand Down Expand Up @@ -230,7 +231,7 @@ cc_library(
"src/impl_aarch64_linux_or_android.c",
"src/impl_aarch64_macos_or_iphone.c",
"src/impl_aarch64_windows.c",
"src/impl_aarch64_freebsd.c",
"src/impl_aarch64_freebsd_or_openbsd.c",
],
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
Expand Down Expand Up @@ -295,7 +296,7 @@ cc_library(
"src/impl_aarch64_linux_or_android.c",
"src/impl_aarch64_macos_or_iphone.c",
"src/impl_aarch64_windows.c",
"src/impl_aarch64_freebsd.c",
"src/impl_aarch64_freebsd_or_openbsd.c",
],
PLATFORM_CPU_MIPS: ["src/impl_mips_linux_or_android.c"],
PLATFORM_CPU_PPC: ["src/impl_ppc_linux.c"],
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ if(UNIX)
add_library(unix_based_hardware_detection OBJECT
${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h
${PROJECT_SOURCE_DIR}/src/hwcaps_linux_or_android.c
${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd.c
${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd_or_openbsd.c
${PROJECT_SOURCE_DIR}/src/hwcaps.c
)
setup_include_and_definitions(unix_based_hardware_detection)
Expand Down
2 changes: 2 additions & 0 deletions bazel/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ PLATFORM_OS_LINUX = ("@platforms//os:linux")
PLATFORM_OS_ANDROID = ("@platforms//os:android")

PLATFORM_OS_FREEBSD = ("@platforms//os:freebsd")

PLATFORM_OS_OPENBSD = ("@platforms//os:openbsd")
4 changes: 4 additions & 0 deletions include/cpu_features_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
#define CPU_FEATURES_OS_FREEBSD
#endif

#if defined(__OpenBSD__)
#define CPU_FEATURES_OS_OPENBSD
#endif

#if defined(__ANDROID__)
#define CPU_FEATURES_OS_ANDROID
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/hwcaps_freebsd.c → src/hwcaps_freebsd_or_openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_OS_FREEBSD
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)

#include "internal/hwcaps.h"

Expand Down Expand Up @@ -47,8 +47,8 @@ const char *CpuFeatures_GetPlatformPointer(void) { return NULL; }
const char *CpuFeatures_GetBasePlatformPointer(void) { return NULL; }

#else
#error "FreeBSD needs support for elf_aux_info"
#error "FreeBSD / OpenBSD needs support for elf_aux_info"
#endif // HAVE_STRONG_ELF_AUX_INFO

#endif // CPU_FEATURES_TEST
#endif // CPU_FEATURES_OS_FREEBSD
#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD
8 changes: 4 additions & 4 deletions src/impl_aarch64_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) || \
defined(CPU_FEATURES_OS_ANDROID))
#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || \
defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID))
#if (defined(CPU_FEATURES_COMPILER_GCC) || defined(CPU_FEATURES_COMPILER_CLANG))

#include "internal/cpuid_aarch64.h"
Expand All @@ -35,6 +35,6 @@ uint64_t GetMidrEl1(void) {
#error "Unsupported compiler, aarch64 cpuid requires either GCC or Clang."
#endif // (defined(CPU_FEATURES_COMPILER_GCC) ||
// defined(CPU_FEATURES_COMPILER_CLANG))
#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
// || defined(CPU_FEATURES_OS_ANDROID))
#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
// || defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID))
#endif // CPU_FEATURES_ARCH_AARCH64
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#ifdef CPU_FEATURES_OS_FREEBSD
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)

#include "cpuinfo_aarch64.h"
#include "impl_aarch64__base_implementation.inl"
Expand All @@ -42,5 +42,5 @@ Aarch64Info GetAarch64Info(void) {
return info;
}

#endif // CPU_FEATURES_OS_FREEBSD
#endif // CPU_FEATURES_OS_FREEBSD || CPU_FEATURES_OS_OPENBSD
#endif // CPU_FEATURES_ARCH_AARCH64
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_link_libraries(stack_line_reader_for_test string_view filesystem_for_test
add_library(all_libraries
../src/hwcaps.c
../src/hwcaps_linux_or_android.c
../src/hwcaps_freebsd.c
../src/hwcaps_freebsd_or_openbsd.c
../src/stack_line_reader.c)
target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)

Expand Down Expand Up @@ -81,7 +81,7 @@ if(PROCESSOR_IS_AARCH64)
../src/impl_aarch64_linux_or_android.c
../src/impl_aarch64_windows.c
../src/impl_aarch64_macos_or_iphone.c
../src/impl_aarch64_freebsd.c
../src/impl_aarch64_freebsd_or_openbsd.c
)
if(APPLE)
target_compile_definitions(cpuinfo_aarch64_test PUBLIC CPU_FEATURES_MOCK_SYSCTL_AARCH64)
Expand Down
14 changes: 7 additions & 7 deletions test/cpuinfo_aarch64_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
#if defined(CPU_FEATURES_OS_WINDOWS)
#include "internal/windows_utils.h"
#endif // CPU_FEATURES_OS_WINDOWS
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
#include "internal/cpuid_aarch64.h"
#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)

namespace cpu_features {
class FakeCpuAarch64 {
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
public:
uint64_t GetMidrEl1() const { return _midr_el1; }

Expand Down Expand Up @@ -89,7 +89,7 @@ static FakeCpuAarch64& cpu() {
}

// Define OS dependent mock functions
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD) || defined(CPU_FEATURES_OS_LINUX)
extern "C" uint64_t GetMidrEl1(void) { return cpu().GetMidrEl1(); }
#elif defined(CPU_FEATURES_OS_MACOS)
extern "C" bool GetDarwinSysCtlByName(const char* name) {
Expand Down Expand Up @@ -137,7 +137,7 @@ TEST_F(CpuidAarch64Test, Aarch64FeaturesEnum) {
}

// AT_HWCAP tests
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
TEST_F(CpuidAarch64Test, FromHardwareCap) {
ResetHwcaps();
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
Expand Down Expand Up @@ -205,7 +205,7 @@ TEST_F(CpuidAarch64Test, FromHardwareCap2) {
EXPECT_FALSE(info.features.dgh);
EXPECT_FALSE(info.features.rng);
}
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)

// OS dependent tests
#if defined(CPU_FEATURES_OS_LINUX)
Expand Down Expand Up @@ -415,7 +415,7 @@ TEST_F(CpuidAarch64Test, WINDOWS_AARCH64_RPI4) {
EXPECT_FALSE(info.features.jscvt);
EXPECT_FALSE(info.features.lrcpc);
}
#elif defined(CPU_FEATURES_OS_FREEBSD)
#elif defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_OPENBSD)
TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) {
ResetHwcaps();
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_CPUID, 0);
Expand Down