Index: lib/sanitizer_common/sanitizer_linux.cc =================================================================== --- lib/sanitizer_common/sanitizer_linux.cc +++ lib/sanitizer_common/sanitizer_linux.cc @@ -49,6 +49,7 @@ #include #if SANITIZER_FREEBSD +#include #include extern "C" { // must be included after and on @@ -655,10 +656,19 @@ static uptr proc_self_exe_cache_len = 0; uptr ReadBinaryName(/*out*/char *buf, uptr buf_len) { +#if SANITIZER_FREEBSD + const int Mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; + size_t Size = buf_len; + bool IsErr = (sysctl(Mib, 4, buf, &Size, NULL, 0) != 0); + int readlink_error = IsErr ? errno : 0; + uptr module_name_len = Size; +#else uptr module_name_len = internal_readlink( "/proc/self/exe", buf, buf_len); int readlink_error; - if (internal_iserror(module_name_len, &readlink_error)) { + bool IsErr = internal_iserror(module_name_len, &readlink_error); +#endif + if (IsErr) { if (proc_self_exe_cache_len) { // If available, use the cached module name. CHECK_LE(proc_self_exe_cache_len, buf_len);