Reputation: 4502
To tell the compiler to exclude a function from the address sanitizer, the documentation for both gcc and clang say to use an __attribute__
called no_sanitize
like this:
__attribute__((no_sanitize("address")))
void hidden_from_sanitizer();
But in the wild (e.g. Facebook's folly library), it seems this attribute is called __no_sanitize__
:
__attribute__((__no_sanitize__("address")))
void hidden_from_sanitizer();
GCC and Clang appear to accept both syntaxes, but which should I use? What's the difference? Is wrapping attribute names in double-underscores documented generally somewhere?
Upvotes: 2
Views: 700
Reputation: 110098
GCC documentation says:
You may optionally specify attribute names with ‘__’ preceding and following the name. This allows you to use them in header files without being concerned about a possible macro of the same name. For example, you may use the attribute name
__noreturn__
instead ofnoreturn
.
So you can use the double underscores if you want to be 100% safe in a library header file, or if you know of a name conflict with an existing macro.
Upvotes: 3
Reputation: 131527
These are compiler-specific attributes, not C++ language attributes, which use a different syntax, e.g. [[noreturn]]
or [[maybe_unused]]
.
For compiler-specific features - you have to consult your compiler documentation, and there's no general rule.
Upvotes: 2