Static Analysis for Windows Code under Linux

This document will describe how to run Mozilla static check for Windows code under Linux platform by creating a cross-compiler with Dehydra support for Mingw.

We highly recommend you to read the cross compiling manual and the Dehydra build manual before you start the following reading.

Build GCC Corss-compiler with Plugin Support

By default GCC does not support plugins. Dehydra requires patching GCC such that it can load plugins as shared libraries:

# Prepare a directory
mkdir $HOME/dehydra
cd $HOME/dehydra
#Obtain GCC 4.3 sources
tar jxvf gcc-4.3.0.tar.bz2

# Get the patches which enable plugins
cd gcc-4.3.0/
# Create an hg repository. This makes it easy to apply patches, they can be applied manually
hg init .
hg clone .hg/patches
# Apply gty.diff and plugin.diff
# If you have mq setup, do hg qpush -a
(for file in `cat .hg/patches/series`; do cat .hg/patches/$file; done) |patch -p1
cd ..

Now, the Gcc source with plugin supports is ready, we should now build a cross compiler from this source. And the instructions are exactly the same with the one here. Follow that instructions strictly for making a cross compiler.

Build Dehydra for Cross-compiler

Build the Dehydra plugin

Dehydra is a shared library which will be loaded by the above plugin-support gcc. Build Dehydra for a cross compiler has nothing difference with building one for a Linux native compiler. So, please follow this link exactly.

Check the build

make check

If all tests past, you have gotten a workable Dehydra.

Build Treehydra

Build the Treehydra plugin

Building Treehydra for a cross compiler is something tricky. That is because the GCC with plugin support is needed to produce Treehydra shared library. But we just made a Mingw cross compiler, that means it can't produce the correct shared library.

So, we should make a Linux native compiler with plugin support to make Treehydra! This sound crazy, but it may be the only right way to do this.

Just follow this and this to compile both Dehydra and Treehydra shared libraries. And these libraries can be used directly with our cross compiler.

Check the build


make check_treehydra

Run Static Analysis on Mozilla Windows Code

Static analysis is hooked into Mozilla repository from Mozilla 2. You can obtain Mozilla 2 code by:

hg clone

And compose a .mozconfig file for cross-compiling Mozilla with static analysis hooked:

#Specify the cross compile
ac_add_options --enable-application=browser
ac_add_options --host=i686-linux
ac_add_options --target=i686-mingw32
ac_add_options --enable-default-toolkit=cairo-windows
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../mozilla-mingw

# Mozilla trunk uses many Vista only features on Windows, so we should disable some components to make it buildable with mingw32.
ac_add_options  --enable-debug
ac_add_options  --disable-optimize
ac_add_options  --disable-tests
ac_add_options  --disable-embedding-tests
ac_add_options  --disable-installer
ac_add_options  --disable-accessibility

ac_add_options --disable-vista-sdk-requirements
ac_add_options --disable-updater

#change this to where your libIDL-config file locate.
#Config your moztools position

#disable xpcom stdcall calling convention because of gcc 4.3.0 bug

#Specify the CXX and static analysis
#Point CXX to the cross compile g++ with plugin support
ac_add_options --with-static-checking=$HOME/dehydra/dehydra-gcc/

Then, you can start building your Mozilla. The static check will be done when compiling is going on.


You can post any question about static check to the newsgroup and any question about cross compiling to the newsgroup.