Testing Mercurial with ASAN

Gregory Szorc gregory.szorc at gmail.com
Tue Sep 4 12:02:08 EDT 2018


On Tue, Sep 4, 2018 at 7:23 AM Yuya Nishihara <yuya at tcha.org> wrote:

> On Fri, 10 Apr 2015 09:53:05 -0700, Bryan O'Sullivan wrote:
> > If you haven't come across the Address Sanitizer that's shipped with
> clang
> > and gcc the past few years, start here:
> > https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer
> >
> > I spent some time building and testing Mercurial against both clang (3.6)
> > and gcc (4.9) ASAN implementations yesterday. The good, and
> > unsurprising-to-me news: t's completely clean right now.
> >
> > Here are some notes, in case anyone wants to reproduce.
> >
> > Normally, ASAN is built directly into an executable. The standard ASAN
> > libraries are thus static libraries, not shared objects. This doesn't
> work
> > with Mercurial at all, as the C routines in Mercurial are loaded as
> shared
> > objects.
>
> I tried ASAN to see if the nodetree bug could be detected. It's gcc 8.2,
> and
> seems working nicely. What I needed is to teach Python to use the standard
> malloc.
>
>   $ cd python
>   $ ./configure --prefix=$HOME/opt/python-2.7.13-asan --without-pymalloc \
>   CFLAGS='-O1 -fsanitize=address -fno-omit-frame-pointer -g -fwrapv
> -fstack-protector-strong -Wall' \
>   LDFLAGS=-lasan
>   $ ASAN_OPTIONS=detect_leaks=0 make
>   $ make install
>
>   $ cd mercurial
>   $ make clean local PYTHON=$HOME/opt/python-2.7.13-asan/bin/python
>   $ cd tests
>   $ $HOME/opt/python-2.7.13-asan/bin/python ./run-tests.py -l
> test-revisions.t
>
> It will report some leaks. I haven't investigated if all of them are false
> positives. To disable the leak detection, set ASAN_OPTIONS=detect_leaks=0.
>

It might be easier to use Python 3 with ASAN: IIRC Python 3 has the
necessary hooks to allow you to inject a custom allocator more easily.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180904/c99bbc6d/attachment.html>


More information about the Mercurial-devel mailing list