https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99587
--- Comment #4 from Florian Weimer <fw at gcc dot gnu.org> ---
For retain, something along these lines might work:
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index c1f652d1dc9..cdae464ab8a 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -329,8 +329,10 @@ const struct attribute_spec c_common_attribute_table[] =
handle_used_attribute, NULL },
{ "unused", 0, 0, false, false, false, false,
handle_unused_attribute, NULL },
+#if SUPPORTS_SHF_GNU_RETAIN
{ "retain", 0, 0, true, false, false, false,
handle_retain_attribute, NULL },
+#endif
{ "externally_visible", 0, 0, true, false, false, false,
handle_externally_visible_attribute, NULL },
{ "no_reorder", 0, 0, true, false, false, false,
In other cases, it's more difficult because those are subtarget-dependent.
It's not particularly useful to know that a particular source code base of GCC
knows about the attribute in principle, if built for the right target and with
the right binutils/glibc versions etc. A programmer can already use a version
check for that. __has_attribute and __has_builtin are only useful if they
reflect the current GCC build and its target flags.