From 3a1720af1d7f43edc5b214cde0be11bfb94d077e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 23 Oct 2019 17:52:22 +0000 Subject: Vendor import of stripped compiler-rt trunk r375505, the last commit before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505 --- lib/sanitizer_common/sanitizer_getauxval.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lib/sanitizer_common/sanitizer_getauxval.h') diff --git a/lib/sanitizer_common/sanitizer_getauxval.h b/lib/sanitizer_common/sanitizer_getauxval.h index cbd1af12c04f..86ad3a5e2c2a 100644 --- a/lib/sanitizer_common/sanitizer_getauxval.h +++ b/lib/sanitizer_common/sanitizer_getauxval.h @@ -9,6 +9,7 @@ // Common getauxval() guards and definitions. // getauxval() is not defined until glibc version 2.16, or until API level 21 // for Android. +// Implement the getauxval() compat function for NetBSD. // //===----------------------------------------------------------------------===// @@ -16,15 +17,10 @@ #define SANITIZER_GETAUXVAL_H #include "sanitizer_platform.h" +#include "sanitizer_glibc_version.h" #if SANITIZER_LINUX || SANITIZER_FUCHSIA -# include - -# ifndef __GLIBC_PREREQ -# define __GLIBC_PREREQ(x, y) 0 -# endif - # if __GLIBC_PREREQ(2, 16) || (SANITIZER_ANDROID && __ANDROID_API__ >= 21) || \ SANITIZER_FUCHSIA # define SANITIZER_USE_GETAUXVAL 1 @@ -38,10 +34,26 @@ // The weak getauxval definition allows to check for the function at runtime. // This is useful for Android, when compiled at a lower API level yet running // on a more recent platform that offers the function. -extern "C" SANITIZER_WEAK_ATTRIBUTE -unsigned long getauxval(unsigned long type); // NOLINT +extern "C" SANITIZER_WEAK_ATTRIBUTE unsigned long getauxval(unsigned long type); # endif -#endif // SANITIZER_LINUX || SANITIZER_FUCHSIA +#elif SANITIZER_NETBSD + +#define SANITIZER_USE_GETAUXVAL 1 + +#include +#include + +static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) { + for (const AuxInfo *aux = (const AuxInfo *)_dlauxinfo(); + aux->a_type != AT_NULL; ++aux) { + if (type == aux->a_type) + return aux->a_v; + } + + return 0; +} + +#endif #endif // SANITIZER_GETAUXVAL_H -- cgit v1.2.3