aboutsummaryrefslogtreecommitdiff
path: root/lang/gcc12/files/patch-libsanitizer_sanitizer__common_sanitizer__linux__libcdep.cpp
blob: 7f13f85913133d3712d07b3db02f47612b770920 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Patch taken from

https://cgit.freebsd.org/src/commit/?id=96fe7c8ab0f65cf829619abd74ae6c126b21e15f

--- libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp.orig	2022-11-26 09:47:34 UTC
+++ libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
@@ -45,7 +45,9 @@
 
 #if SANITIZER_FREEBSD
 #include <pthread_np.h>
+#include <stdlib.h>
 #include <osreldate.h>
+#include <sys/auxv.h>
 #include <sys/sysctl.h>
 #define pthread_getattr_np pthread_attr_get_np
 #endif
@@ -857,7 +859,14 @@ void ReExec() {
 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,