[sanitizer] Fix nolibc unittests broken by r346215
authorVitaly Buka <vitalybuka@google.com>
Tue, 6 Nov 2018 19:23:22 +0000 (19:23 +0000)
committerVitaly Buka <vitalybuka@google.com>
Tue, 6 Nov 2018 19:23:22 +0000 (19:23 +0000)
Subscribers: kubamracek, krytarowski, fedor.sergeev, llvm-commits

Differential Revision: https://reviews.llvm.org/D54163

llvm-svn: 346258

compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc

index 592f424f7198da2ae69ef2da6a17c67bff3ab31a..7c3da0cb61cf6ec00c604bdca9e17e1da9baf73d 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "sanitizer_common.h"
 #include "sanitizer_flags.h"
-#include "sanitizer_getauxval.h"
 #include "sanitizer_internal_defs.h"
 #include "sanitizer_libc.h"
 #include "sanitizer_linux.h"
@@ -629,35 +628,7 @@ char **GetEnviron() {
   return envp;
 }
 
-void ReExec() {
-  const char *pathname = "/proc/self/exe";
-
-#if SANITIZER_NETBSD
-  static const int name[] = {
-    CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME,
-  };
-  char path[400];
-  uptr len;
-
-  len = sizeof(path);
-  if (internal_sysctl(name, ARRAY_SIZE(name), path, &len, NULL, 0) != -1)
-    pathname = path;
-#elif SANITIZER_SOLARIS
-  pathname = getexecname();
-  CHECK_NE(pathname, NULL);
-#elif SANITIZER_USE_GETAUXVAL
-  // Calling execve with /proc/self/exe sets that as $EXEC_ORIGIN. Binaries that
-  // rely on that will fail to load shared libraries. Query AT_EXECFN instead.
-  pathname = reinterpret_cast<const char *>(getauxval(AT_EXECFN));
-#endif
-
-  uptr rv = internal_execve(pathname, GetArgv(), GetEnviron());
-  int rverrno;
-  CHECK_EQ(internal_iserror(rv, &rverrno), true);
-  Printf("execve failed, errno %d\n", rverrno);
-  Die();
-}
-#endif
+#endif  // !SANITIZER_OPENBSD
 
 #if !SANITIZER_SOLARIS
 enum MutexState {
index 7859557c82d7305ea2d7468142641ad1f44a9720..84da23e3fad922f2241d60e1d44f534456c3db55 100644 (file)
@@ -23,6 +23,7 @@
 #include "sanitizer_file.h"
 #include "sanitizer_flags.h"
 #include "sanitizer_freebsd.h"
+#include "sanitizer_getauxval.h"
 #include "sanitizer_linux.h"
 #include "sanitizer_placement_new.h"
 #include "sanitizer_procmaps.h"
@@ -806,6 +807,40 @@ u64 MonotonicNanoTime() {
 }
 #endif  // SANITIZER_LINUX && !SANITIZER_GO
 
+#if !SANITIZER_OPENBSD
+void ReExec() {
+  const char *pathname = "/proc/self/exe";
+
+#if SANITIZER_NETBSD
+  static const int name[] = {
+      CTL_KERN,
+      KERN_PROC_ARGS,
+      -1,
+      KERN_PROC_PATHNAME,
+  };
+  char path[400];
+  uptr len;
+
+  len = sizeof(path);
+  if (internal_sysctl(name, ARRAY_SIZE(name), path, &len, NULL, 0) != -1)
+    pathname = path;
+#elif SANITIZER_SOLARIS
+  pathname = getexecname();
+  CHECK_NE(pathname, NULL);
+#elif SANITIZER_USE_GETAUXVAL
+  // Calling execve with /proc/self/exe sets that as $EXEC_ORIGIN. Binaries that
+  // rely on that will fail to load shared libraries. Query AT_EXECFN instead.
+  pathname = reinterpret_cast<const char *>(getauxval(AT_EXECFN));
+#endif
+
+  uptr rv = internal_execve(pathname, GetArgv(), GetEnviron());
+  int rverrno;
+  CHECK_EQ(internal_iserror(rv, &rverrno), true);
+  Printf("execve failed, errno %d\n", rverrno);
+  Die();
+}
+#endif  // !SANITIZER_OPENBSD
+
 } // namespace __sanitizer
 
 #endif