Adding GYP_DEFINES=ASAN to enable ASAN build

BUG=chromium-os:16717
TEST=manual yet

Review URL: http://codereview.chromium.org/7541045

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96772 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/build/common.gypi b/build/common.gypi
index a79a8a07..ee0334ba 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -181,6 +181,11 @@
       # Has no effect if 'clang' is not set as well.
       'clang_use_chrome_plugins%': 0,
 
+      # Enable building with ASAN (Clang's -fasan option).
+      # -fasan only works with clang, but asan=1 implies clang=1
+      # See https://sites.google.com/a/chromium.org/dev/developers/testing/addresssanitizer
+      'asan%': 0,
+
       # Set to 1 compile with -fPIC cflag on linux. This is a must for shared
       # libraries on linux x86-64 and arm, plus ASLR.
       'linux_fpic%': 1,
@@ -306,6 +311,7 @@
     'configuration_policy%': '<(configuration_policy)',
     'safe_browsing%': '<(safe_browsing)',
     'clang_use_chrome_plugins%': '<(clang_use_chrome_plugins)',
+    'asan%': '<(asan)',
     'enable_register_protocol_handler%': '<(enable_register_protocol_handler)',
     'enable_smooth_scrolling%': '<(enable_smooth_scrolling)',
     # Whether to build for Wayland display server
@@ -690,6 +696,10 @@
       ['enable_register_protocol_handler==1', {
         'grit_defines': ['-D', 'enable_register_protocol_handler'],
       }],
+
+      ['asan==1', {
+        'clang%': 1,
+      }],
     ],
   },
   'target_defaults': {
@@ -1543,6 +1553,16 @@
               '-Xclang', '-add-plugin', '-Xclang', '<(clang_add_plugin)',
             ],
           }],
+          ['asan==1', {
+            # Only in the linux section for now, since ASAN doesn't
+            # work on Mac yet.
+            'cflags': [
+              '-fasan -w',
+            ],
+            'ldflags': [
+              '-fasan',
+            ],
+          }],
           ['no_strict_aliasing==1', {
             'cflags': [
               '-fno-strict-aliasing',