[PATCH] D67329: Add getauxval() compat for NetBSD

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 11:56:45 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL371758: Add getauxval() compat for NetBSD (authored by kamil, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D67329?vs=219268&id=219963#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67329/new/

https://reviews.llvm.org/D67329

Files:
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_getauxval.h
  compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp


Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_getauxval.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_getauxval.h
+++ compiler-rt/trunk/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.
 //
 //===----------------------------------------------------------------------===//
 
@@ -41,6 +42,23 @@
 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 <dlfcn.h>
+#include <elf.h>
+
+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
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.cpp
@@ -1062,8 +1062,6 @@
 uptr GetPageSize() {
 #if SANITIZER_LINUX && (defined(__x86_64__) || defined(__i386__))
   return EXEC_PAGESIZE;
-#elif SANITIZER_USE_GETAUXVAL
-  return getauxval(AT_PAGESZ);
 #elif SANITIZER_FREEBSD || SANITIZER_NETBSD
 // Use sysctl as sysconf can trigger interceptors internally.
   int pz = 0;
@@ -1072,6 +1070,8 @@
   int rv = internal_sysctl(mib, 2, &pz, &pzl, nullptr, 0);
   CHECK_EQ(rv, 0);
   return (uptr)pz;
+#elif SANITIZER_USE_GETAUXVAL
+  return getauxval(AT_PAGESZ);
 #else
   return sysconf(_SC_PAGESIZE);  // EXEC_PAGESIZE may not be trustworthy.
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67329.219963.patch
Type: text/x-patch
Size: 1996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190912/f43e5e35/attachment.bin>


More information about the llvm-commits mailing list