diff options
author | Jakub Jelinek <jakub@redhat.com> | 2013-11-22 22:13:08 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2013-11-22 22:13:08 +0100 |
commit | 9065ada9b5fa30d47ec723fbfbbeaad1082035cb (patch) | |
tree | 1e351f73c04f7b8ee40bc54557ac53f5b8b0aa2a /gcc | |
parent | 2e5189c83a2b2c6f3fff04f9d8f6c1b1a869b915 (diff) | |
download | gcc-9065ada9b5fa30d47ec723fbfbbeaad1082035cb.zip gcc-9065ada9b5fa30d47ec723fbfbbeaad1082035cb.tar.gz gcc-9065ada9b5fa30d47ec723fbfbbeaad1082035cb.tar.bz2 |
re PR sanitizer/59061 (Port leaksanitizer)
PR sanitizer/59061
* common.opt (static-liblsan): Add.
* config/gnu-user.h (STATIC_LIBLSAN_LIBS, STATIC_LIBUBSAN_LIBS):
Define.
* flag-types.h (enum sanitize_code): Add SANITIZE_LEAK. Renumber
SANITIZE_SHIFT, SANITIZE_DIVIDE, SANITIZE_UNREACHABLE, SANITIZE_VLA,
SANITIZE_RETURN.
* opts.c (common_handle_option): Handle -fsanitize=leak.
* gcc.c (ADD_STATIC_LIBLSAN_LIBS, LIBLSAN_SPEC): Define.
(LIBUBSAN_SPEC): Don't test LIBUBSAN_EARLY_SPEC.
(LIBUBSAN_EARLY_SPEC): Remove.
(SANITIZER_EARLY_SPEC): Don't do anything for libubsan.
(SANITIZER_SPEC): Add -fsanitize=leak handling.
(sanitize_spec_function): Handle %sanitize(leak).
* doc/invoke.texi (-static-liblsan, -fsanitize=leak): Document.
* c-c++-common/asan/no-redundant-instrumentation-7.c: Fix
cleanup-tree-dump directive.
* configure.tgt: Set LSAN_SUPPORTED=yes for x86_64-linux.
* configure.ac (LSAN_SUPPORTED): New AM_CONDITIONAL.
* configure: Regenerated.
* lsan/Makefile.am (toolexeclib_LTLIBRARIES, lsan_files,
liblsan_la_SOURCES, liblsan_la_LIBADD, liblsan_la_LDFLAGS): Add.
* lsan/Makefile.in: Regenerated.
From-SVN: r205290
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/common.opt | 3 | ||||
-rw-r--r-- | gcc/config/gnu-user.h | 8 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 18 | ||||
-rw-r--r-- | gcc/flag-types.h | 14 | ||||
-rw-r--r-- | gcc/gcc.c | 35 | ||||
-rw-r--r-- | gcc/opts.c | 1 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c | 2 |
9 files changed, 85 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0757d15..f298c0b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,21 @@ +2013-11-22 Jakub Jelinek <jakub@redhat.com> + + PR sanitizer/59061 + * common.opt (static-liblsan): Add. + * config/gnu-user.h (STATIC_LIBLSAN_LIBS, STATIC_LIBUBSAN_LIBS): + Define. + * flag-types.h (enum sanitize_code): Add SANITIZE_LEAK. Renumber + SANITIZE_SHIFT, SANITIZE_DIVIDE, SANITIZE_UNREACHABLE, SANITIZE_VLA, + SANITIZE_RETURN. + * opts.c (common_handle_option): Handle -fsanitize=leak. + * gcc.c (ADD_STATIC_LIBLSAN_LIBS, LIBLSAN_SPEC): Define. + (LIBUBSAN_SPEC): Don't test LIBUBSAN_EARLY_SPEC. + (LIBUBSAN_EARLY_SPEC): Remove. + (SANITIZER_EARLY_SPEC): Don't do anything for libubsan. + (SANITIZER_SPEC): Add -fsanitize=leak handling. + (sanitize_spec_function): Handle %sanitize(leak). + * doc/invoke.texi (-static-liblsan, -fsanitize=leak): Document. + 2013-11-22 Aldy Hernandez <aldyh@redhat.com> Jakub Jelinek <jakub@redhat.com> diff --git a/gcc/common.opt b/gcc/common.opt index 2216d6e..a7af636 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2654,6 +2654,9 @@ Driver static-libtsan Driver +static-liblsan +Driver + static-libubsan Driver diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index 6f69158..157e147 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -134,3 +134,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see /* Additional libraries needed by -static-libtsan. */ #undef STATIC_LIBTSAN_LIBS #define STATIC_LIBTSAN_LIBS "-ldl -lpthread" + +/* Additional libraries needed by -static-liblsan. */ +#undef STATIC_LIBLSAN_LIBS +#define STATIC_LIBLSAN_LIBS "-ldl -lpthread" + +/* Additional libraries needed by -static-libubsan. */ +#undef STATIC_LIBUBSAN_LIBS +#define STATIC_LIBUBSAN_LIBS "-ldl -lpthread" diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 7048b0b..0708836 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -455,7 +455,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}} @@ -5269,6 +5269,13 @@ Memory access instructions will be instrumented to detect 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 @@ -10227,6 +10234,15 @@ option is not used, then this links against the shared version of 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 diff --git a/gcc/flag-types.h b/gcc/flag-types.h index 1d85a9a..5ba9097 100644 --- a/gcc/flag-types.h +++ b/gcc/flag-types.h @@ -206,13 +206,15 @@ enum sanitize_code { SANITIZE_ADDRESS = 1 << 0, /* ThreadSanitizer. */ SANITIZE_THREAD = 1 << 1, + /* LeakSanitizer. */ + SANITIZE_LEAK = 1 << 2, /* UndefinedBehaviorSanitizer. */ - SANITIZE_SHIFT = 1 << 2, - SANITIZE_DIVIDE = 1 << 3, - SANITIZE_UNREACHABLE = 1 << 4, - SANITIZE_VLA = 1 << 5, - SANITIZE_NULL = 1 << 6, - SANITIZE_RETURN = 1 << 7, + SANITIZE_SHIFT = 1 << 3, + SANITIZE_DIVIDE = 1 << 4, + SANITIZE_UNREACHABLE = 1 << 5, + SANITIZE_VLA = 1 << 6, + SANITIZE_NULL = 1 << 7, + SANITIZE_RETURN = 1 << 8, SANITIZE_UNDEFINED = SANITIZE_SHIFT | SANITIZE_DIVIDE | SANITIZE_UNREACHABLE | SANITIZE_VLA | SANITIZE_NULL | SANITIZE_RETURN }; @@ -578,6 +578,22 @@ proper position among the other output files. */ #define LIBTSAN_EARLY_SPEC "" #endif +#ifndef LIBLSAN_SPEC +#ifdef STATIC_LIBLSAN_LIBS +#define ADD_STATIC_LIBLSAN_LIBS \ + " %{static-liblsan:" STATIC_LIBLSAN_LIBS "}" +#else +#define ADD_STATIC_LIBLSAN_LIBS +#endif +#ifdef HAVE_LD_STATIC_DYNAMIC +#define LIBLSAN_SPEC "%{!shared:%{static-liblsan:" LD_STATIC_OPTION \ + "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ + ADD_STATIC_LIBLSAN_LIBS "}" +#else +#define LIBLSAN_SPEC "%{!shared:-llsan" ADD_STATIC_LIBLSAN_LIBS "}" +#endif +#endif + #ifndef LIBUBSAN_SPEC #ifdef STATIC_LIBUBSAN_LIBS #define ADD_STATIC_LIBUBSAN_LIBS \ @@ -585,9 +601,7 @@ proper position among the other output files. */ #else #define ADD_STATIC_LIBUBSAN_LIBS #endif -#ifdef LIBUBSAN_EARLY_SPEC -#define LIBUBSAN_SPEC ADD_STATIC_LIBUBSAN_LIBS -#elif defined(HAVE_LD_STATIC_DYNAMIC) +#ifdef HAVE_LD_STATIC_DYNAMIC #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ ADD_STATIC_LIBUBSAN_LIBS @@ -596,10 +610,6 @@ proper position among the other output files. */ #endif #endif -#ifndef LIBUBSAN_EARLY_SPEC -#define LIBUBSAN_EARLY_SPEC "" -#endif - /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is included. */ #ifndef LIBGCC_SPEC @@ -723,8 +733,7 @@ proper position among the other output files. */ #ifndef SANITIZER_EARLY_SPEC #define SANITIZER_EARLY_SPEC "\ %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \ - %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \ - %{%:sanitize(undefined):" LIBUBSAN_EARLY_SPEC "}}}" + %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "}}}" #endif /* Linker command line options for -fsanitize= late on the command line. */ @@ -735,7 +744,8 @@ proper position among the other output files. */ %{%:sanitize(thread):%e-fsanitize=address is incompatible with -fsanitize=thread}}\ %{%:sanitize(thread):" LIBTSAN_SPEC "\ %{!pie:%{!shared:%e-fsanitize=thread linking must be done with -pie or -shared}}}\ - %{%:sanitize(undefined):" LIBUBSAN_SPEC "}}}" + %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\ + %{%:sanitize(leak):" LIBLSAN_SPEC "}}}" #endif /* This is the spec to use, once the code for creating the vtable @@ -8123,7 +8133,10 @@ sanitize_spec_function (int argc, const char **argv) return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL; if (strcmp (argv[0], "undefined") == 0) return (flag_sanitize & SANITIZE_UNDEFINED) ? "" : NULL; - + if (strcmp (argv[0], "leak") == 0) + return ((flag_sanitize + & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD)) + == SANITIZE_LEAK) ? "" : NULL; return NULL; } @@ -1450,6 +1450,7 @@ common_handle_option (struct gcc_options *opts, { { "address", SANITIZE_ADDRESS, sizeof "address" - 1 }, { "thread", SANITIZE_THREAD, sizeof "thread" - 1 }, + { "leak", SANITIZE_LEAK, sizeof "leak" - 1 }, { "shift", SANITIZE_SHIFT, sizeof "shift" - 1 }, { "integer-divide-by-zero", SANITIZE_DIVIDE, sizeof "integer-divide-by-zero" - 1 }, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9a66cbf..12d2c90 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-11-22 Jakub Jelinek <jakub@redhat.com> + + * c-c++-common/asan/no-redundant-instrumentation-7.c: Fix + cleanup-tree-dump directive. + 2013-11-22 Jan Hubicka <jh@suse.cz> * gcc.dg/20081223-1.c: Add -ffat-lto-objects. diff --git a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c index 075e9cf..bf40a03 100644 --- a/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c +++ b/gcc/testsuite/c-c++-common/asan/no-redundant-instrumentation-7.c @@ -20,4 +20,4 @@ foo (int *a, char *b, char *c) /* { dg-final { scan-tree-dump-times "__builtin___asan_report_load" 6 "asan0" } } */ /* { dg-final { scan-tree-dump-not "__builtin___asan_report_store" "asan0" } } */ -/* { dg-final { cleanup-tree-dump "asan" } } */ +/* { dg-final { cleanup-tree-dump "asan0" } } */ |