From 96fe7c8ab0f65cf829619abd74ae6c126b21e15f Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Wed, 19 Jan 2022 13:08:18 -0500 Subject: [PATCH] compiler-rt: support ReExec() on FreeBSD Based on getMainExecutable() in llvm/lib/Support/Unix/Path.inc. This will need a little more work for an upstream change as it must support older FreeBSD releases that lack elf_aux_info() / AT_EXEC_PATH. No objection: dim MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33934 --- .../lib/sanitizer_common/sanitizer_linux_libcdep.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp index 7ce9e25da34..59f8d5d1fec 100644 --- a/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp +++ b/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp @@ -46,7 +46,9 @@ #if SANITIZER_FREEBSD #include +#include #include +#include #include #define pthread_getattr_np pthread_attr_get_np // The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before @@ -865,7 +867,14 @@ u64 MonotonicNanoTime() { void ReExec() { const char *pathname = "/proc/self/exe"; -#if SANITIZER_NETBSD +#if SANITIZER_FREEBSD + char exe_path[PATH_MAX]; + if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) { + char link_path[PATH_MAX]; + if (realpath(exe_path, link_path)) + pathname = link_path; + } +#elif SANITIZER_NETBSD static const int name[] = { CTL_KERN, KERN_PROC_ARGS,