Go to file
Dodji Seketeli bdcbe80c52 [asan] Avoid instrumenting duplicated memory access in the same basic block
Like what Address Sanitizer does in LLVM, this patch avoids instrumented
duplicated memory accesses in the same basic blocks.

The approach taken is very conservative, to keep the pass simple, for
a start.

A memory access is considered to be a pair made of an expression tree
representing the beginning of the memory region that is accessed and
a the size of the access, in byte.  For now that size is either 1, 2,
4, 8 or 16 bytes.

The patch builds a hash table of the memory accesses that have been
instrumented in the current basic block.  Then it walks the gimple
statements of the current basic block.  For each statement, it tests
if the memory regions it references have already been instrumented.
If not, the statement is instrumented and each memory references that
are actually instrumented are added to the hash table.  When a memory
region is accessed (usually through builtin functions like memset),
then what gets added to the hash table is actually two memory
accesses: one for the beginning of the region, and the other for the
its end.

When the patch crosses a function call that is not a built-in function
that we ought to instrument, the hash table is cleared, because that
function call can possibly e.g free some memory that was instrumented.

Likewise, when a new basic block is visited, the hash table is
cleared.  I guess we could be smarter than just unconditionally
clearing the hash table in this later case, but this is what asan@llvm
does, and for now, I thought starting in a conservative manner might
have some value.

The hash table is destroyed at the end of the pass.

Bootstrapped and tested against trunk on x86-64-unknown-linux-gnu.

gcc/
	* Makefile.in (asan.o): Add new dependency on hash-table.h
	* asan.c (struct asan_mem_ref, struct mem_ref_hasher): New types.
	(asan_mem_ref_init, asan_mem_ref_get_end, get_mem_ref_hash_table)
	(has_stmt_been_instrumented_p, empty_mem_ref_hash_table)
	(free_mem_ref_resources, has_mem_ref_been_instrumented)
	(has_stmt_been_instrumented_p, update_mem_ref_hash_table)
	(get_mem_ref_of_assignment): New functions.
	(get_mem_refs_of_builtin_call): Extract from
	instrument_builtin_call and tweak a little bit to make it fit with
	the new signature.
	(instrument_builtin_call): Use the new
	get_mem_refs_of_builtin_call.  Use gimple_call_builtin_p instead
	of is_gimple_builtin_call.
	(instrument_derefs, instrument_mem_region_access): Insert the
	instrumented memory reference into the hash table.
	(maybe_instrument_assignment): Renamed instrument_assignment into
	this, and change it to advance the iterator when instrumentation
	actually happened and return true in that case.  This makes it
	homogeneous with maybe_instrument_assignment, and thus give a
	chance to callers to be more 'regular'.
	(transform_statements): Clear the memory reference hash table
	whenever we enter a new BB, when we cross a function call, or when
	we are done transforming statements.  Use
	maybe_instrument_assignment instead of instrumentation.  No more
	need to special case maybe_instrument_assignment and advance the
	iterator after calling it; it's now handled just like
	maybe_instrument_call.  Update comment.

gcc/testsuite/

	* c-c++-common/asan/no-redundant-instrumentation-1.c: New test.
	* testsuite/c-c++-common/asan/no-redundant-instrumentation-2.c: Likewise.
	* testsuite/c-c++-common/asan/no-redundant-instrumentation-3.c: Likewise.
	* testsuite/c-c++-common/asan/inc.c: Likewise.

From-SVN: r196008
2013-02-13 11:32:26 +01:00
INSTALL
boehm-gc
config
contrib update-copyright.py: Add libdecnumber to the default list. 2013-02-06 22:10:25 +00:00
fixincludes
gcc [asan] Avoid instrumenting duplicated memory access in the same basic block 2013-02-13 11:32:26 +01:00
gnattools
include Sync plugin-api.h with the copy in binutils. Please see: 2013-02-11 19:42:25 +00:00
intl
libada Fix typo in ChangeLog 2013-02-13 11:30:32 +01:00
libatomic
libbacktrace
libcpp
libdecnumber Update copyright in libdecnumber. 2013-02-06 22:09:24 +00:00
libffi ffi.c (ffi_prep_cif_machdep): Fix case where DOUBLE equal LONGDOUBLE. 2013-02-06 18:32:41 +01:00
libgcc re PR target/54222 ([avr] Implement fixed-point support) 2013-02-12 14:55:16 +00:00
libgfortran re PR fortran/55978 (class_optional_2.f90 -Os fails) 2013-02-06 20:39:35 +01:00
libgo re PR go/56171 (syscall FAILs on Solaris) 2013-02-11 19:03:04 +00:00
libgomp
libiberty re PR other/56245 (-fsanitize=address miscompiles GCC) 2013-02-09 19:41:00 +01:00
libitm re PR libitm/55693 (libitm.c++/eh-1.C execution test fails on darwin from r193271) 2013-02-11 23:30:10 +00:00
libjava
libmudflap
libobjc
libquadmath Revert libquadmath and libssp copyright patches. 2013-02-06 22:03:54 +00:00
libsanitizer configure.tgt: Disable build on darwin9 and earlier. 2013-02-11 23:13:37 +00:00
libssp Revert libquadmath and libssp copyright patches. 2013-02-06 22:03:54 +00:00
libstdc++-v3 cstdlib (at_quick_exit, quick_exit): Provide in C++11 mode. 2013-02-12 12:01:14 +00:00
lto-plugin
maintainer-scripts
zlib
.gitignore
ABOUT-NLS
COPYING
COPYING.LIB
COPYING.RUNTIME
COPYING3
COPYING3.LIB
ChangeLog
ChangeLog.tree-ssa
MAINTAINERS
Makefile.def
Makefile.in
Makefile.tpl
README
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
depcomp
install-sh
libtool-ldflags
libtool.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
missing
mkdep
mkinstalldirs
move-if-change
symlink-tree
ylwrap

README

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.