Visit Mozilla.org

Dehydra GCC

From MDC

Contents

[edit] Prerequisites

  • Mercurial 1.0 is needed to access source repositories. Make sure that the mq extension is enabled
  • SpiderMonkey 1.7 or newer provides scripting capabilities for Dehydra (trunk is preferred).
  • GCC 4.3 on Linux, Apple GCC 4.2 Preview 1 on OSX
    • May need libgmp >= 4.2.2 on Linux
  • XCode 3.0 and OSX 10.5 (mac only)

[edit] Building GCC with plugin support on Linux

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

# Prepare a directory to build GCC and Dehydra in
mkdir $HOME/gcc-dehydra
cd $HOME/gcc-dehydra
#Obtain GCC 4.3 sources
wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.0/gcc-4.3.0.tar.bz2
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 http://hg.mozilla.org/users/tglek_mozilla.com/gcc-moz-plugin-mq .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 .. 

# Compile GCC and install it into $HOME/gcc-dehydra/gcc/
mkdir gcc-build
cd gcc-build
../gcc-4.3.0/configure --without-libstdcxx --enable-checking --disable-bootstrap CFLAGS="-g3 -O0" --enable-languages=c,c++ --enable-__cxa_atexit --prefix=$PWD/../installed
(on x86_64, use ../gcc-4.3.0/configure --without-libstdcxx --enable-checking --disable-bootstrap CFLAGS="-g3 -O0 -m64" --enable-languages=c,c++ --disable-multilib --enable-__cxa_atexit --prefix=$PWD/../installed )
make
make install
cd ..

[edit] Building GCC with plugin support on OSX

# Prepare a directory to build GCC and Dehydra in
mkdir $HOME/gcc-dehydra
cd $HOME/gcc-dehydra
# Obtain Apple GCC 4.2 prerelease sources
wget http://www.opensource.apple.com/darwinsource/tarballs/other/gcc_42-5531.tar.gz
tar zxvf gcc_42-5531.tar.gz
# Obtain and apply only the plugin patch (bug 428593)
cd gcc_42-5531
wget --no-check-certificate https://bugzilla.mozilla.org/attachment.cgi?id=318962 -O plugin.diff
patch -p1 < plugin.diff
# Compile and install GCC Apple way
# You may need to "sudo port deactivate texinfo" if applicable as it seems to interfere with the build
make install
# Make Apple-style build friendlier for dehydra
ditto dst/usr ../installed
cd ..
ln -s gcc_42-5531/obj/obj-i686-i686 gcc-build

[edit] Building Dehydra

Building Dehydra requires a standalone SpiderMonkey library, version 1.7 or higher (the current SpiderMonkey trunk is preferred). The SpiderMonkey built for Firefox or other Mozilla product is not suitable. See SpiderMonkey_Build_Documentation for how to build SpiderMonkey.

We'll assume here that your SpiderMonkey build is in $MOZILLA_CENTRAL/src/js, it's a BUILD_OPT=1 build, and you're on linux.

Dehydra releases can be found on the Mozilla ftp site, however it is recommended to get the latest Dehydra sources by checking out from Mercurial.

cd $HOME/gcc-dehydra
hg clone http://hg.mozilla.org/users/tglek_mozilla.com/dehydra-gcc/
cd dehydra-gcc
./configure \
  --js-libs=$MOZILLA_CENTRAL/js/src/Linux_All_OPT.OBJ \ 
  --js-include=$MOZILLA_CENTRAL/js/src  
make

# run dehydra-gcc tests
make check

[edit] Usage

Dehydra checking can be performed directly within the Mozilla build. To enable static checking of a Mozilla build, see Building with static checking.

To run Dehydra manually using G++, add the -fplugin and -fplugin-arg flags to specify the location of the Dehydra plugin and the location of the analysis script:

$HOME/gcc-dehydra/installed/bin/g++ -quiet -fplugin=$HOME/gcc-dehydra/dehydra-gcc/gcc_dehydra.so -fplugin-arg=$DEHYDRA_SCRIPT \
  -fshort-wchar $CPPFILE -S -o /dev/null

For example, in the tests directory created by the installation procedure, I can run a Dehydra script 'a.js' on a Mozilla file like this:

../../gcc-build/gcc/cc1plus -quiet -fplugin=../gcc_dehydra.so \
-fplugin-arg=a.js -fshort-wchar -fpreprocessed \
/home/dmandelin/builds/dehydra-gcc/browser/app/nsBrowserApp.ii -o /dev/null

The -fshort-wchar is required for running against Firefox, but not necessarily for other codebases.

[edit] Writing analysis scripts

See wikimo:Dehydra API.

[edit] See Also