[compiler-rt] [compiler-rt] simplifying ::ReExec for freebsd. (PR #79711)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 14:23:45 PST 2024
https://github.com/devnexen updated https://github.com/llvm/llvm-project/pull/79711
>From 65aa0a563052f29a7096d451dc7074965607a090 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 27 Jan 2024 22:13:06 +0000
Subject: [PATCH] [compiler-rt] simplifying ::ReExec for freebsd.
taking the getauxval route since elf_aux_info is available since FBSD
12.
---
.../lib/sanitizer_common/sanitizer_getauxval.h | 14 ++++++++++++++
.../sanitizer_common/sanitizer_linux_libcdep.cpp | 9 +--------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
index 38439e44f611e6f..a22248d5007153d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
@@ -55,6 +55,20 @@ static inline decltype(AuxInfo::a_v) getauxval(decltype(AuxInfo::a_type) type) {
return 0;
}
+#elif SANITIZER_FREEBSD
+# include <sys/auxv.h>
+
+# define SANITIZER_USE_GETAUXVAL 1
+# define AT_EXECFN AT_EXECPATH
+
+static inline unsigned long getauxval(unsigned long type) {
+ unsigned long buf = 0ul;
+
+ if (elf_aux_info(static_cast<int>(type), &buf, sizeof(buf)))
+ return 0ul;
+ return buf;
+}
+
#endif
#endif // SANITIZER_GETAUXVAL_H
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
index cccbb4d256df2f6..b3f1fe91f16c587 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -934,14 +934,7 @@ u64 MonotonicNanoTime() {
void ReExec() {
const char *pathname = "/proc/self/exe";
-# if SANITIZER_FREEBSD
- for (const auto *aux = __elf_aux_vector; aux->a_type != AT_NULL; aux++) {
- if (aux->a_type == AT_EXECPATH) {
- pathname = static_cast<const char *>(aux->a_un.a_ptr);
- break;
- }
- }
-# elif SANITIZER_NETBSD
+# if SANITIZER_NETBSD
static const int name[] = {
CTL_KERN,
KERN_PROC_ARGS,
More information about the llvm-commits
mailing list