Introduction to Valgrind
        
        
          Valgrind is an instrumentation
          framework for building dynamic analysis tools. There are Valgrind
          tools that can automatically detect many memory management and
          threading bugs, and profile programs in detail. Valgrind can also
          be used to build new tools.
        
        
          ![[Note]](../images/note.png) 
          
            Note
          
          
            Development versions of BLFS may not build or run some packages
            properly if LFS or dependencies have been updated since the most
            recent stable versions of the books.
          
         
        
          Package Information
        
        
        
          Valgrind Dependencies
        
        
          Optional
        
        
          docbook-xml-4.5 (for tests), GDB-16.3 (for tests),
          libaio-0.3.113, LLVM-21.1.2 (with Clang), and
          Which-2.23 (for tests)
        
       
      
        
          Installation of Valgrind
        
        
          Install Valgrind by running the
          following commands:
        
        sed -i 's|/doc/valgrind||' docs/Makefile.in &&
./configure --prefix=/usr \
            --datadir=/usr/share/doc/valgrind-3.26.0 &&
make
        
          To test the results, issue: make
          regtest. The tests may hang forever if GDB-16.3 is not
          installed. Some tests are known to hang also, depending on the
          version of glibc. A few tests can fail in various suites.
          Problematic tests can be disabled by changing the prereq: line in the corresponding
          .vgtest file to prereq: false. For example:
        
        sed -e 's@prereq:.*@prereq: false@' \
    -i {helgrind,drd}/tests/pth_cond_destroy_busy.vgtest
        
          An additional test suite is now available that tests Valgrind with
          every system call provided by the kernel. The test suite is
          designed to test not only glibc and the kernel's conformance to
          standards, but also Valgrind's ability to handle different system
          calls. The test suite does require an internet connection to
          download the tests, and it takes a long time to run (an additional
          20 SBUs and 1.3GB of disk space.) If you wish to run this test
          suite, issue the following command: make ltpchecks. Note that the
          output will show several failures where Valgrind does not currently
          support certain system calls, but the logs for the test suite can
          be found in the auxprogs/auxchecks/ltp-full-20250130/valgrind-ltp-logs
          directory.
        
        
          ![[Note]](../images/note.png) 
          
            Note
          
          
            The OpenMP tests are skipped if
            libgomp has been compiled with --enable-linux-futex (the default). If needed,
            just recompile the libgomp library from the gcc build tree,
            passing --disable-linux-futex to
            configure, storing the library to some place and changing the
            link from /usr/lib/libgomp.so.1 to
            point to the new library.
          
         
        
          Now, as the root user:
        
        make install
       
      
        
          Command Explanations
        
        
          sed -i ...
          docs/Makefile.in : This sed provides for installing
          the documentation in a versioned directory.
        
        
          --enable-lto=yes: This option allows
          building Valgrind with LTO (link time optimization). This produces
          a smaller/faster Valgrind (up to 10%), but build time increases to
          about 5.5 SBU.