Bug 464476

Summary: Firefox fails to start under Valgrind
Product: [Developer tools] valgrind Reporter: Paul Floyd <pjfloyd>
Component: memcheckAssignee: Paul Floyd <pjfloyd>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 3.21 GIT   
Target Milestone: ---   
Platform: Compiled Sources   
OS: FreeBSD   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Paul Floyd 2023-01-18 20:14:59 UTC
Runs and quickly exits with

Couldn't load XPCOM.
Comment 1 Paul Floyd 2023-01-18 20:20:08 UTC
There problem is with sysctl kern.proc.pathname.PID

This is used to determine the full path of firefox, but when it runs under valgrind it returns the path to valgrind instead.

firefox then looks in the valgrind directory for dependentlibs.list and fails to find it.
Comment 2 Paul Floyd 2023-01-19 08:30:24 UTC
A bit trickier than I thought since firefox is a symlink and I need to first resolve the symlink.

We don't have a VG_(lstat) as far as I can see.
Comment 3 Paul Floyd 2023-01-20 07:38:23 UTC
Almost there. 

I use VG_(find_executable)(VG_(args_the_exename)) then check if it is a link and if so call VG_(readlink)(exe_name, out, VKI_PATH_MAX);

But readlink doesn't resolve relative paths to absolute paths.
Comment 4 Paul Floyd 2023-01-21 20:30:30 UTC
Running firefox under memcheck to close this item !

commit 5d387642049bf366d913f572269f8bf16627ac10
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Sat Jan 21 17:55:09 2023 +0100

    Bug 464476 - Firefox fails to start under Valgrind
    
    On FreeBSD, Firefox uses the kern.proc.pathname.PID sysctl
    to get the binary path (where PID can be the actual pid
    or -1). The user path is /usr/local/bin/firefox which is
    a symlink to /usr/local/lib/firefox/firefox.
    
    This was failing because we were not handling this MIB.
    That meant that the sysctl returned the path for the
    binary of the running tool (e.g.,
    /home/paulf/scratch/valgrind/memcheck/memcheck-amd64-freebsd).
    Firefox looks for files in the same directory.
    Since it was the wrong directory it failed to find them and
    exited.
    
    I also noticed a lot of _umtx_op errors. On analysis they
    are spurious. The wake ops take an "obj" argument, a pointer
    to a variable. They only use the address as a key for
    lookups and don't read the contents.