Skip to content

Commit 96fe7c8

Browse files
committed
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
1 parent 867b4de commit 96fe7c8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646

4747
#if SANITIZER_FREEBSD
4848
#include <pthread_np.h>
49+
#include <stdlib.h>
4950
#include <osreldate.h>
51+
#include <sys/auxv.h>
5052
#include <sys/sysctl.h>
5153
#define pthread_getattr_np pthread_attr_get_np
5254
// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
@@ -865,7 +867,14 @@ u64 MonotonicNanoTime() {
865867
void ReExec() {
866868
const char *pathname = "/proc/self/exe";
867869

868-
#if SANITIZER_NETBSD
870+
#if SANITIZER_FREEBSD
871+
char exe_path[PATH_MAX];
872+
if (elf_aux_info(AT_EXECPATH, exe_path, sizeof(exe_path)) == 0) {
873+
char link_path[PATH_MAX];
874+
if (realpath(exe_path, link_path))
875+
pathname = link_path;
876+
}
877+
#elif SANITIZER_NETBSD
869878
static const int name[] = {
870879
CTL_KERN,
871880
KERN_PROC_ARGS,

0 commit comments

Comments
 (0)