[Bug 267752] devel/valgrind: Valgrind fails on programs compiled with -fsanitize=address
Date: Sun, 13 Nov 2022 22:21:34 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=267752 --- Comment #4 from Paul Floyd <pjfloyd@wanadoo.fr> --- 'valgrind' is just a small exe. It modifies the environment to add some LD_PRELOADs and adds an env var called VALGRIND_LAUNCHER. Then it execs the tool (memcheck-amd64-freebsd for instance). The tool code that fails is VG_(debugLog)(1, "main", "Getting launcher's name ...\n"); VG_(name_of_launcher) = VG_(getenv)(VALGRIND_LAUNCHER); if (VG_(name_of_launcher) == NULL) { VG_(printf)("valgrind: You cannot run '%s' directly.\n", argv[0]); VG_(printf)("valgrind: You should use $prefix/bin/valgrind.\n"); VG_(exit)(1); } And here is the launcher code /* Figure out the name of this executable (viz, the launcher), so we can tell stage2. stage2 will use the name for recursive invocations of valgrind on child processes. */ memset(launcher_name, 0, PATH_MAX+1); oid[0] = CTL_KERN; oid[1] = KERN_PROC; oid[2] = KERN_PROC_PATHNAME; oid[3] = getpid(); len = PATH_MAX; r = sysctl(oid, 4, launcher_name, &len, 0, 0); if (r != 0) { fprintf(stderr, "valgrind: warning (non-fatal): " "sysctl(\"kern.proc.pathname\") failed.\n"); fprintf(stderr, "valgrind: continuing, however --trace-children=yes " "will not work.\n"); } /* tediously augment the env: VALGRIND_LAUNCHER=launcher_name */ new_line = malloc(strlen(VALGRIND_LAUNCHER) + 1 + strlen(launcher_name) + 1); if (new_line == NULL) barf("malloc of new_line failed."); strcpy(new_line, VALGRIND_LAUNCHER); strcat(new_line, "="); strcat(new_line, launcher_name); for (j = 0; envp[j]; j++) ; new_env = malloc((j+2) * sizeof(char*)); Does your exe run a bit and then fork/exec? You you set --trace-children=yes (in your valgrind ini file)? I don't know how the sanitized exe is interfering with this, it is all well before the guest even gets loaded. Either the sysctl isn't working correctly or the env var is getting corrupted. -- You are receiving this mail because: You are the assignee for the bug.