Skip to content

Commit

Permalink
Avoid getauxval on mobile, fix warnings on GCC
Browse files Browse the repository at this point in the history
Summary: While `getauxval` is documented to exist and be usable on Android at API level 18 and higher it is not usable in all cases. Avoid this call unless compiling for non-mobile Linux.

Differential Revision: D59371173

fbshipit-source-id: 1a1e08c6a3cc731f896f1cda6fc40fe22a8fd801
  • Loading branch information
Michael van der Westhuizen authored and facebook-github-bot committed Jul 5, 2024
1 parent 19e4d49 commit ac93e22
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions folly/ElfHwCaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include <cstdint>
#include <cstring>

#if defined(__linux__)
#include <sys/auxv.h> // @manual
#endif

#include <folly/Portability.h>
#include <folly/Preprocessor.h>

#if defined(__linux__) && !FOLLY_MOBILE
#include <sys/auxv.h> // @manual
#endif

namespace folly {

/**
Expand All @@ -47,16 +47,14 @@ namespace folly {
* auxiliary vector entries. If you wish to use the class from an ifunc
* resolver you should pass the hwcap and hwcap2 values received by your
* resolver to the constructor.
*
* This class is safe for use on Android API level 18 or higher (early 2013).
*/
class ElfHwCaps {
public:
FOLLY_ALWAYS_INLINE ElfHwCaps(uint64_t hwcap, uint64_t hwcap2)
: hwcap_(hwcap), hwcap2_(hwcap2) {}

FOLLY_ALWAYS_INLINE ElfHwCaps() {
#if defined(__linux__)
#if defined(__linux__) && !FOLLY_MOBILE
hwcap_ = getauxval(AT_HWCAP);
hwcap2_ = getauxval(AT_HWCAP2);
#endif
Expand Down Expand Up @@ -139,8 +137,15 @@ class ElfHwCaps {
#undef FOLLY_DETAIL_HWCAP_X

private:
// GCC would not warn about maybe unused here, but will warn
// about the ignored attribute.
#if defined(__clang__)
uint64_t hwcap_ [[maybe_unused]] = 0;
uint64_t hwcap2_ [[maybe_unused]] = 0;
#else
uint64_t hwcap_ = 0;
uint64_t hwcap2_ = 0;
#endif
};

} // namespace folly

0 comments on commit ac93e22

Please sign in to comment.