Skip to content

Commit

Permalink
Fix build on FreeBSD/powerpc64 (#5572)
Browse files Browse the repository at this point in the history
* Fix build on FreeBSD/powerpc64

FreeBSD doesn't use getauxval, but elf_aux_info.

* Make the conditional only work Linux and FreeBSD

* Make the conditional only for FreeBSD and Linux
  • Loading branch information
pkubaj committed Dec 23, 2020
1 parent 8a0f4a1 commit 890a519
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Target.cpp
Expand Up @@ -10,7 +10,11 @@
#include "Util.h"
#include "WasmExecutor.h"

#if defined(__powerpc__) && defined(__linux__)
#if defined(__powerpc__) && (defined(__FreeBSD__) || defined(__linux__))
#if defined(__FreeBSD__)
#include <machine/cpu.h>
#include <sys/elf_common.h>
#endif
// This uses elf.h and must be included after "LLVM_Headers.h", which
// uses llvm/support/Elf.h.
#include <sys/auxv.h>
Expand Down Expand Up @@ -83,11 +87,17 @@ Target calculate_host_target() {
#if defined(__arm__) || defined(__aarch64__)
Target::Arch arch = Target::ARM;
#else
#if defined(__powerpc__) && defined(__linux__)
#if defined(__powerpc__) && (defined(__FreeBSD__) || defined(__linux__))
Target::Arch arch = Target::POWERPC;

#if defined(__linux__)
unsigned long hwcap = getauxval(AT_HWCAP);
unsigned long hwcap2 = getauxval(AT_HWCAP2);
#elif defined(__FreeBSD__)
unsigned long hwcap, hwcap2;
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
#endif
bool have_altivec = (hwcap & PPC_FEATURE_HAS_ALTIVEC) != 0;
bool have_vsx = (hwcap & PPC_FEATURE_HAS_VSX) != 0;
bool arch_2_07 = (hwcap2 & PPC_FEATURE2_ARCH_2_07) != 0;
Expand Down

0 comments on commit 890a519

Please sign in to comment.