Skip to content

[compiler-rt] simplifying ::ReExec for freebsd. #79711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

devnexen
Copy link
Member

taking the getauxval route since elf_aux_info is available since FBSD 12.

@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David CARLIER (devnexen)

Changes

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 --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,

Copy link

github-actions bot commented Jan 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

taking the getauxval route since elf_aux_info is available since FBSD
12.
@devnexen devnexen merged commit 691b12a into llvm:main Feb 16, 2024
@DimitryAndric
Copy link
Collaborator

This should be reverted, 7440e4e implemented ReExec without using elf_aux_info, since that is intercepted already, and this will lead to segfaults. See also freebsd/freebsd-src@4c9a0adad1826

devnexen added a commit to devnexen/llvm-project that referenced this pull request Feb 25, 2024
devnexen added a commit that referenced this pull request Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants