[PATCH] Support -fsanitize=leak

Jakub Jelinek jakub@redhat.com
Mon Nov 18 15:11:00 GMT 2013


On Fri, Nov 15, 2013 at 12:34:14PM -0800, Ian Lance Taylor wrote:
> On Fri, Nov 15, 2013 at 11:41 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> >
> > This patch adds support for -fsanitize=leak and -static-liblsan options.
> > If combined with -fsanitize=address, it does nothing, otherwise it links
> > in liblsan, a new shared+static library (on x86_64-linux only so far,
> > the code isn't 32-bit ready apparently).
> >
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> Documentation?

Here it is, as incremental patch:

2013-11-18  Jakub Jelinek  <jakub@redhat.com>

	* doc/invoke.texi (-static-liblsan, -fsanitize=leak): Document.

--- gcc/doc/invoke.texi.jj	2013-11-18 09:59:09.000000000 +0100
+++ gcc/doc/invoke.texi	2013-11-18 14:57:12.240073775 +0100
@@ -454,7 +454,7 @@ Objective-C and Objective-C++ Dialects}.
 @gccoptlist{@var{object-file-name}  -l@var{library} @gol
 -nostartfiles  -nodefaultlibs  -nostdlib -pie -rdynamic @gol
 -s  -static -static-libgcc -static-libstdc++ @gol
--static-libasan -static-libtsan -static-libubsan @gol
+-static-libasan -static-libtsan -static-liblsan -static-libubsan @gol
 -shared -shared-libgcc  -symbolic @gol
 -T @var{script}  -Wl,@var{option}  -Xlinker @var{option} @gol
 -u @var{symbol}}
@@ -5259,6 +5259,13 @@ Memory access instructions will be instr
 data race bugs.
 See @uref{http://code.google.com/p/data-race-test/wiki/ThreadSanitizer} for more details.
 
+@item -fsanitize=leak
+Enable LeakSanitizer, a memory leak detector.
+This option only matters for linking of executables and if neither
+@option{-fsanitize=address} nor @option{-fsanitize=thread} is used.  In that
+case it will link the executable against a library that overrides @code{malloc}
+and other allocator functions.
+
 @item -fsanitize=undefined
 Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector
 Various computations will be instrumented to detect undefined behavior
@@ -10181,6 +10188,15 @@ option is not used, then this links agai
 driver to link @file{libtsan} statically, without necessarily linking
 other libraries statically.
 
+@item -static-liblsan
+When the @option{-fsanitize=leak} option is used to link a program,
+the GCC driver automatically links against @option{liblsan}.  If
+@file{liblsan} is available as a shared library, and the @option{-static}
+option is not used, then this links against the shared version of
+@file{liblsan}.  The @option{-static-liblsan} option directs the GCC
+driver to link @file{liblsan} statically, without necessarily linking
+other libraries statically.
+
 @item -static-libubsan
 When the @option{-fsanitize=undefined} option is used to link a program,
 the GCC driver automatically links against @option{libubsan}.  If


	Jakub



More information about the Gcc-patches mailing list