Bug 55397 - [asan] -faddress-sanitizer should define a CPP macro
Summary: [asan] -faddress-sanitizer should define a CPP macro
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-19 20:59 UTC by H.J. Lu
Modified: 2012-11-22 10:02 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Comment 1 Konstantin Serebryany 2012-11-20 05:13:27 UTC
Note that this will be incompatible with what clang uses
(http://clang.llvm.org/docs/AddressSanitizer.html#has_feature)
Clang will never use a CPP macro (I've lost this battle a year ago). 

Just FYI. I don't know how much compatibility we want and can achieve.
Comment 2 Andrew Pinski 2012-11-20 05:23:29 UTC
(In reply to comment #1)
> Note that this will be incompatible with what clang uses
> (http://clang.llvm.org/docs/AddressSanitizer.html#has_feature)
> Clang will never use a CPP macro (I've lost this battle a year ago). 
> 
> Just FYI. I don't know how much compatibility we want and can achieve.

has feature will most likely not be implemented in GCC so CPP macro is correct for GCC.  If clang wants to have a non-standard way of doing CPP macro for features, that is up to them.
Comment 3 Konstantin Serebryany 2012-11-20 05:30:59 UTC
FTR: my conversation with clang on this topic. 
http://comments.gmane.org/gmane.comp.compilers.clang.scm/42610

From Diego: 
I don't know of any current effort in this area for GCC.  If 
__has_feature() is desirable, patches documenting and implementing it 
would be welcome.  The GCC pre-processor is jointly maintained by all 
the FE maintainers.  I would start there.


If we end up implementing a macro, may I ask it to be named ADDRESS_SANITIZER? 
This name is already used in a few places (Chromium, WebKit, etc).
Comment 4 H.J. Lu 2012-11-20 05:37:18 UTC
(In reply to comment #3)
> 
> If we end up implementing a macro, may I ask it to be named ADDRESS_SANITIZER? 
> This name is already used in a few places (Chromium, WebKit, etc).

It should have `_' prefix.
Comment 5 Konstantin Serebryany 2012-11-20 05:46:06 UTC
Then it should probably *not* be named _ADDRESS_SANITIZER 
(imagine a user trying to understand why ADDRESS_SANITIZER works for him 
with clang, where he added -DADDRESS_SANITIZER=1 manually, and dpoes not work with gcc where he saw the documentation saying about _ADDRESS_SANITIZER)

Maybe something with GCC in the name?  _GCC_ADDRESS_SANITIZER?
Comment 6 hjl@gcc.gnu.org 2012-11-21 20:21:02 UTC
Author: hjl
Date: Wed Nov 21 20:20:42 2012
New Revision: 193704

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193704
Log:
Define __SANITIZE_ADDRESS__ for -fsanitize=address

	PR c/55397
	* cppbuiltin.c (define_builtin_macros_for_compilation_flags):
	Define __SANITIZE_ADDRESS__ for flag_asan.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cppbuiltin.c
Comment 7 H.J. Lu 2012-11-21 20:28:52 UTC
Fixed.