From: Hugo Beauzée-Luyssen <[email protected]>

DATA_ALIGNMENT can exceed DECL_ALIGN when emitting an object.
rs6000_xcoff_section_type_flags only used DECL_ALIGN for the csect,
so the csect symbol could end up placed before its own, more
strongly aligned data.

gcc/ChangeLog:

        * config/rs6000/rs6000.cc (rs6000_xcoff_section_type_flags):
        Also raise the csect alignment to DATA_ALIGNMENT.

Assisted-by: Claude (claude-sonnet-5)
Signed-off-by: Hugo Beauzée-Luyssen <[email protected]>
---
 gcc/config/rs6000/rs6000.cc | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 8cfc8183b83..551843e389b 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -21922,10 +21922,17 @@ rs6000_xcoff_section_type_flags (tree decl, const 
char *name, int reloc)
   else if ((flags & SECTION_CODE) != 0)
     align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT), 32);
   else
-    /* Increase alignment of large objects if not already stricter.  */
-    align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
-                int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
-                ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
+    {
+      /* Increase alignment of large objects if not already stricter.  */
+      align = MAX ((DECL_ALIGN (decl) / BITS_PER_UNIT),
+                  int_size_in_bytes (TREE_TYPE (decl)) > MIN_UNITS_PER_WORD
+                  ? UNITS_PER_FP_WORD : MIN_UNITS_PER_WORD);
+      /* DATA_ALIGNMENT may exceed DECL_ALIGN; match it so the csect
+        isn't more weakly aligned than the data placed inside it.  */
+      align = MAX (align,
+                  DATA_ALIGNMENT (TREE_TYPE (decl), DECL_ALIGN (decl))
+                  / BITS_PER_UNIT);
+    }
 
   return flags | (exact_log2 (align) & SECTION_ENTSIZE);
 }
-- 
2.43.0


Reply via email to