Currently, attribute "retain" is ignored since it avoids some
quirks in crtstuff -- which avr doesn't even use.

This renders attribute "used" pretty much useless: A function will
survive till asm, but without the "R" section flag, the linker
will kill the code with --gc-sections.

defaults.h requires .init_array without explaining why.

/* This determines whether or not we support marking sections with
   SHF_GNU_RETAIN flag.  Also require .init_array/.fini_array section
   for constructors and destructors.  */
#ifndef SUPPORTS_SHF_GNU_RETAIN
#if HAVE_GAS_SHF_GNU_RETAIN && HAVE_INITFINI_ARRAY_SUPPORT
#define SUPPORTS_SHF_GNU_RETAIN 1
#else
#define SUPPORTS_SHF_GNU_RETAIN 0
#endif
#endif

Bottom line is that SUPPORTS_SHF_GNU_RETAIN is defined to 0
since avr doesn't use .init_array.

This patch checks whether Binutils support the "R" flag, which
is provided by auto-host.h's HAVE_GAS_SHF_GNU_RETAIN.

If that's the case, avr/elf.h defines SUPPORTS_SHF_GNU_RETAIN to 1,
so that the code from defaults.h is bypassed (tm.h includes avr/elf.h
prior to defaults.h).

Passes without new regressions.

Ok to apply?

diff --git a/gcc/config/avr/elf.h b/gcc/config/avr/elf.h
index d240f8549d7..4520d84da6a 100644
--- a/gcc/config/avr/elf.h
+++ b/gcc/config/avr/elf.h
@@ -18,6 +18,19 @@
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.  */

+/* defaults.h requires HAVE_INITFINI_ARRAY_SUPPORT to be present
+   in order for attribute "retain" to be recognized.  This is due
+   to some quirks in crtstuff.h -- which isn't even used by avr.
+   All we need is that Binutils supports the "R"etain section flag.
+   If that's the case, define SUPPORTS_SHF_GNU_RETAIN so that
+   defaults.h doesn't define it to 0.  */
+#if defined(IN_GCC) && !defined(USED_FOR_TARGET) && !defined(GENERATOR_FILE)
+#include "auto-host.h" /* HAVE_GAS_SHF_GNU_RETAIN */
+#if HAVE_GAS_SHF_GNU_RETAIN
+#undef SUPPORTS_SHF_GNU_RETAIN
+#define SUPPORTS_SHF_GNU_RETAIN 1
+#endif
+#endif

 /* Overriding some definitions from elfos.h for AVR.  */

Reply via email to