On 05/05/2016 01:10 PM, Aldy Hernandez wrote:
You can leave the attributes enabled unconditionally. GCC ignores unknown
attributes, so the old compiler compiling the attributed source will behave as
usual.
However, you will get an "unknown attribute ignored" warning with -Wall, but you
can easily silence that particular warning just for the wrapper:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
static inline void
__attribute__((SOME_POSSIBLY_UNKNOWN_ATTRIBUTE))
wrapper_function (void)
{
}
#pragma GCC diagnostic pop
Another option is:
1. Define attribute as a macro:
#ifdef __PLUGIN_LOADED__
# define PLUGIN_ATTRIBUTE __attribute__((SOME_ATTRIBUTE))
#else
# define PLUGIN_ATTRIBUTE /* nothing */
#endif
...
static inline void
PLUGIN_ATTRIBUTE
wrapper_function (void)
{
}
2. Define __PLUGIN_LOADED__ from PLUGIN_START_UNIT event:
static void
start_unit(void* /*event_data*/, void* /*data*/)
{
gcc_assert(parse_in);
cpp_define(parse_in, "__PLUGIN_LOADED__=1");
}
int
plugin_init(plugin_name_args* plugin_info, plugin_gcc_version* version)
{
...
register_callback(plugin_name, PLUGIN_START_UNIT, start_unit, nullptr);
...
}