Commit 37d6f666 by Wei Mi Committed by Dodji Seketeli

Initial import of asan from the Google branch

This patch imports the initial state of asan as it was in the
Google branch.

It provides basic infrastructure for asan to instrument memory
accesses on the heap, at -O3.  Note that it supports neither stack nor
global variable protection.

The rest of the patches of the set is intended to further improve this
base.

gcc/ChangeLog

	* Makefile.in: Add asan.c and its dependencies.
	* common.opt: Add -faddress-sanitizer option.
	* invoke.texi: Document the new flag.
	* passes.c: Add the asan pass.
	* toplev.c (compile_file): Call asan_finish_file.
	* asan.c: New file.
	* asan.h: New file.
	* tree-pass.h: Declare pass_asan.

Co-Authored-By: Diego Novillo <dnovillo@google.com>
Co-Authored-By: Dodji Seketeli <dodji@redhat.com>

From-SVN: r193432
parent abfc7377
2012-11-12 Wei Mi <wmi@google.com>
Diego Novillo <dnovillo@google.com>
Dodji Seketeli <dodji@redhat.com>
* Makefile.in: Add asan.c and its dependencies.
* common.opt: Add -faddress-sanitizer option.
* invoke.texi: Document the new flag.
* passes.c: Add the asan pass.
* toplev.c (compile_file): Call asan_finish_file.
* asan.c: New file.
* asan.h: New file.
* tree-pass.h: Declare pass_asan.
2012-11-12 Tobias Burnus <burnus@net-b.de>
* diagnostic.c (diagnostic_append_note): Also call va_end when
......@@ -1349,6 +1349,7 @@ OBJS = \
tracer.o \
trans-mem.o \
tree-affine.o \
asan.o \
tree-call-cdce.o \
tree-cfg.o \
tree-cfgcleanup.o \
......@@ -2207,6 +2208,10 @@ stor-layout.o : stor-layout.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(TREE_H) $(PARAMS_H) $(FLAGS_H) $(FUNCTION_H) $(EXPR_H) $(RTL_H) \
$(GGC_H) $(TM_P_H) $(TARGET_H) langhooks.h $(REGS_H) gt-stor-layout.h \
$(DIAGNOSTIC_CORE_H) $(CGRAPH_H) $(TREE_INLINE_H) $(TREE_DUMP_H) $(GIMPLE_H)
asan.o : asan.c asan.h $(CONFIG_H) pointer-set.h \
$(SYSTEM_H) $(TREE_H) $(GIMPLE_H) \
output.h $(DIAGNOSTIC_H) coretypes.h $(TREE_DUMP_H) $(FLAGS_H) \
tree-pretty-print.h
tree-ssa-tail-merge.o: tree-ssa-tail-merge.c \
$(SYSTEM_H) $(CONFIG_H) coretypes.h $(TM_H) $(BITMAP_H) \
$(FLAGS_H) $(TM_P_H) $(BASIC_BLOCK_H) \
......
This diff is collapsed. Click to expand it.
/* AddressSanitizer, a fast memory error detector.
Copyright (C) 2011 Free Software Foundation, Inc.
Contributed by Kostya Serebryany <kcc@google.com>
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef TREE_ASAN
#define TREE_ASAN
extern void asan_finish_file(void);
#endif /* TREE_ASAN */
......@@ -837,6 +837,10 @@ fargument-noalias-anything
Common Ignore
Does nothing. Preserved for backward compatibility.
faddress-sanitizer
Common Report Var(flag_asan)
Enable AddressSanitizer, a memory error detector
fasynchronous-unwind-tables
Common Report Var(flag_asynchronous_unwind_tables) Optimization
Generate unwind tables that are exact at each instruction boundary
......
......@@ -354,9 +354,10 @@ Objective-C and Objective-C++ Dialects}.
@item Optimization Options
@xref{Optimize Options,,Options that Control Optimization}.
@gccoptlist{-falign-functions[=@var{n}] -falign-jumps[=@var{n}] @gol
-falign-labels[=@var{n}] -falign-loops[=@var{n}] -fassociative-math @gol
-fauto-inc-dec -fbranch-probabilities -fbranch-target-load-optimize @gol
-fbranch-target-load-optimize2 -fbtr-bb-exclusive -fcaller-saves @gol
-falign-labels[=@var{n}] -falign-loops[=@var{n}] -faddress-sanitizer @gol
--fassociative-math fauto-inc-dec -fbranch-probabilities @gol
--fbranch-target-load-optimize fbranch-target-load-optimize2 @gol
--fbtr-bb-exclusive -fcaller-saves @gol
-fcheck-data-deps -fcombine-stack-adjustments -fconserve-stack @gol
-fcompare-elim -fcprop-registers -fcrossjumping @gol
-fcse-follow-jumps -fcse-skip-blocks -fcx-fortran-rules @gol
......@@ -6848,6 +6849,12 @@ assumptions based on that.
The default is @option{-fzero-initialized-in-bss}.
@item -faddress-sanitizer
Enable AddressSanitizer, a fast memory error detector.
Memory access instructions will be instrumented to detect
out-of-bounds and use-after-free bugs. So far only heap bugs will be detected.
See @uref{http://code.google.com/p/address-sanitizer/} for more details.
@item -fmudflap -fmudflapth -fmudflapir
@opindex fmudflap
@opindex fmudflapth
......
......@@ -1456,6 +1456,7 @@ init_optimization_passes (void)
NEXT_PASS (pass_split_crit_edges);
NEXT_PASS (pass_pre);
NEXT_PASS (pass_sink_code);
NEXT_PASS (pass_asan);
NEXT_PASS (pass_tree_loop);
{
struct opt_pass **p = &pass_tree_loop.pass.sub;
......
......@@ -72,6 +72,7 @@ along with GCC; see the file COPYING3. If not see
#include "value-prof.h"
#include "alloc-pool.h"
#include "tree-mudflap.h"
#include "asan.h"
#include "gimple.h"
#include "tree-ssa-alias.h"
#include "plugin.h"
......@@ -570,6 +571,10 @@ compile_file (void)
if (flag_mudflap)
mudflap_finish_file ();
/* File-scope initialization for AddressSanitizer. */
if (flag_asan)
asan_finish_file ();
output_shared_constant_pool ();
output_object_blocks ();
finish_tm_clone_pairs ();
......
......@@ -259,6 +259,7 @@ struct register_pass_info
extern struct gimple_opt_pass pass_mudflap_1;
extern struct gimple_opt_pass pass_mudflap_2;
extern struct gimple_opt_pass pass_asan;
extern struct gimple_opt_pass pass_lower_cf;
extern struct gimple_opt_pass pass_refactor_eh;
extern struct gimple_opt_pass pass_lower_eh;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment