[compiler-rt] [compiler-rt] simplifying ::ReExec for freebsd. (PR #79711)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 14:15:09 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
Author: David CARLIER (devnexen)
<details>
<summary>Changes</summary>
taking the getauxval route since elf_aux_info is available since FBSD 12.
---
Full diff: https://github.com/llvm/llvm-project/pull/79711.diff
2 Files Affected:
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h (+14)
- (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp (+1-8)
``````````diff
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
index 38439e44f611e6f..b484e5d4fc5a116 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,
``````````
</details>
https://github.com/llvm/llvm-project/pull/79711
More information about the llvm-commits
mailing list