https://gcc.gnu.org/g:70be268cd45fd836f3606afc66d5c83f9c4b5e74

commit r15-10486-g70be268cd45fd836f3606afc66d5c83f9c4b5e74
Author: Georg-Johann Lay <[email protected]>
Date:   Thu Nov 6 20:20:49 2025 +0100

    AVR: target/122516: Make attribute "retain" work.
    
    Due to some quirks in crtstuff.c, attribute "retain" requires
    some features that avr doesn't implement -- even though it
    doesnt't even use crtstuff.  This patch works around that.
    
            PR target/122516
    gcc/
            * config/avr/elf.h (SUPPORTS_SHF_GNU_RETAIN): Define if
            HAVE_GAS_SHF_GNU_RETAIN.
    
    (cherry picked from commit d5ede6fff1ff19738d60350856ab852522809068)

Diff:
---
 gcc/config/avr/elf.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/gcc/config/avr/elf.h b/gcc/config/avr/elf.h
index d240f8549d79..e0f8a8770ba3 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