freebsd-ports/lang/gcc11/files/patch-libsanitizer_sanitizer__common_sanitizer__linux__libcdep.cpp
Lorenzo Salvadore a051e5a32d
lang/gcc11: Re-execute program with ASLR disabled when necessary
Software compiled with -fsanitize=address needs ASLR to be disabled to
run successfully.

Add patches taken from the commits listed below that improve ASLR
detection and re-execute the program with ASLR disabled if necessary.

https://cgit.freebsd.org/src/commit/?id=7cafe89f9ce33effe6e471b185339d413da1ca46
https://cgit.freebsd.org/src/commit/?id=930a7c2ac67e1e8e511aa1d0a31a16c632060ebb
https://cgit.freebsd.org/src/commit/?id=96fe7c8ab0f65cf829619abd74ae6c126b21e15f

PR:		267751
2022-12-03 18:24:17 +01:00

33 lines
912 B
C++

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,