Currently, Binutils still comes with an AVR_TINY linker description file which puts .rodata into RAM so that LDS is applicable for reading such objects.

However, as these devices come with a linearised address model, linker descriptions which put .rodata into flash are much more reasonable. This patch caters for such situations: As .rodata virtual addresses will be offset by 0x4000, respective objects may no more be accessed by LDS.

Moreover, objects with a section attribute won't be accessed by LDS.

Ok for trunk?

Johann

        PR target/78093
        * config/avr/avr.c (avr_decl_maybe_lds_p): New static function.
        (avr_encode_section_info) [TARGET_ABSDATA && AVR_TINY]: Use it.
Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(revision 242544)
+++ config/avr/avr.c	(working copy)
@@ -10102,6 +10102,33 @@ avr_section_type_flags (tree decl, const
 }
 
 
+/* A helper for the next function.  NODE is a decl that is associated with
+   a symbol.  Return TRUE if the respective object may be accessed by LDS.
+   There migth still be other reasons for why LDS is not appropriate.
+   This function is only useful for AVR_TINY. */
+
+static bool
+avr_decl_maybe_lds_p (tree node)
+{
+  if (!node
+      || TREE_CODE (node) != VAR_DECL
+      || DECL_SECTION_NAME (node) != NULL)
+    return false;
+
+  if (TREE_READONLY (node))
+    return true;
+
+  // C++ requires peeling arrays.
+
+  do
+    node = TREE_TYPE (node);
+  while (ARRAY_TYPE == TREE_CODE (node));
+
+  return (node != error_mark_node
+          && !TYPE_READONLY (node));
+}
+
+
 /* Implement `TARGET_ENCODE_SECTION_INFO'.  */
 
 static void
@@ -10193,7 +10220,8 @@ avr_encode_section_info (tree decl, rtx
       if (avr_decl_absdata_p (decl, DECL_ATTRIBUTES (decl))
           || (TARGET_ABSDATA
               && !progmem_p
-              && !addr_attr)
+              && !addr_attr
+              && avr_decl_maybe_lds_p (decl))
           || (addr_attr
               // If addr_attr is non-null, it has an argument.  Peek into it.
               && TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (addr_attr))) < 0xc0))

Reply via email to