Running Smatch on the Wine source code

Using smatch is described in detail on the "Using Smatch!!!" page.
Note: You may want to use an older gcc (2.95 and 2.96 reportedly work) to compile the smatch gcc.

Running smatch is basicaly a two steps process:

  1. Recompiling Wine with the modified gcc.
  2. Piping the in the previous step generated *.sm files through the smatch scripts
Note: It's highly recommended to disable optimization when compiling. This:
  1. reduces compile time
  2. prevents some functions (like strdup) to be transformed into complex macros

If you decide to do real smatch work on wine you should switch to out of source tree builds so your normal wine build won't interfere with the smatch one. Don't forget to do a "make distclean" in your wine source tree before you start the out of source tree builds.

Here is what I did:
cd $WINESOURCE
make distclean
cd ..
mkdir winebuild
cd winebuild
mkdir smatch wine
cd smatch
cat > doit << EOF
#!/bin/bash
CC="$PATH_TO_SMATCH_GCC/xgcc"
CFLAGS="-B$PATH_TO_SMATCH_GCC --smatch"
LDFLAGS="-B$PATH_TO_SMATCH_GCC"
function mymake() {
    make CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" $*
}
mymake && exit
$WINESOURCE/configure && mymake depend && mymake
EOF
chmod a+x doit
./doit