Skip to content
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

Revert "[compiler-rt] simplifying ::ReExec for freebsd. (#79711)" #82933

Merged
merged 1 commit into from
Feb 25, 2024

Conversation

devnexen
Copy link
Member

This reverts commit 691b12a.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 25, 2024

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

Author: David CARLIER (devnexen)

Changes

This reverts commit 691b12a.


Full diff: https://github.com/llvm/llvm-project/pull/82933.diff

2 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h (-14)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp (+8-1)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
index a22248d5007153..38439e44f611e6 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_getauxval.h
@@ -55,20 +55,6 @@ 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 b3f1fe91f16c58..cccbb4d256df2f 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -934,7 +934,14 @@ u64 MonotonicNanoTime() {
 void ReExec() {
   const char *pathname = "/proc/self/exe";
 
-#  if SANITIZER_NETBSD
+#  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
   static const int name[] = {
       CTL_KERN,
       KERN_PROC_ARGS,

@devnexen devnexen merged commit 529b570 into llvm:main Feb 25, 2024
7 checks passed
Copy link
Collaborator

@DimitryAndric DimitryAndric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, obviously :)

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.

None yet

3 participants