From 2a5acfe43cf9cc9b3cd215d126eb15087eefe0b4 Mon Sep 17 00:00:00 2001
From: Aditya Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 16 Jun 2026 04:36:03 -0500
Subject: [PATCH] Add support to recognise 32 bit core file formats in AIX 7.3

---
 bfd/rs6000-core.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/bfd/rs6000-core.c b/bfd/rs6000-core.c
index 0635960eaee..4ba62965749 100644
--- a/bfd/rs6000-core.c
+++ b/bfd/rs6000-core.c
@@ -151,7 +151,9 @@ typedef union
 
 #ifdef AIX_5_CORE
 # define CORE_DUMPXX_VERSION	267312562
-# define CNEW_IS_CORE_DUMPXX(c) ((c).new_dump.c_version == CORE_DUMPXX_VERSION)
+# define CORE_DUMPXX_VERSION_AIX73	267312561
+# define CNEW_IS_CORE_DUMPXX(c) ((c).new_dump.c_version == CORE_DUMPXX_VERSION || \
+				 (c).new_dump.c_version == CORE_DUMPXX_VERSION_AIX73)
 #else
 # define CNEW_IS_CORE_DUMPXX(c) 0
 #endif
@@ -354,11 +356,21 @@ rs6000coff_core_p (bfd *abfd)
       return NULL;
     }
 
-  /* This isn't the right handler for 64-bit core files on AIX 5.x.  */
+  /* This isn't the right handler for 64-bit core files on AIX 5.x.
+     However, 32-bit processes on AIX 7.x can produce core_dumpxx format
+     cores with version 0xfeeddb1, which we need to handle here.
+     The aix5ppc-core.c handler will catch 64-bit cores.  */
   if (CORE_NEW (core) && CNEW_IS_CORE_DUMPXX (core))
     {
-      bfd_set_error (bfd_error_wrong_format);
-      return NULL;
+      /* Check if this is a 64-bit process core.  */
+      if (CNEW_PROC64 (core.new_dump))
+ {
+   /* Let aix5ppc-core.c handle 64-bit cores.  */
+   bfd_set_error (bfd_error_wrong_format);
+   return NULL;
+ }
+      /* 32-bit process in core_dumpxx format - we can handle this.
+         Continue with normal processing.  */
     }
 
   /* Copy fields from new or old core structure.  */
@@ -371,9 +383,9 @@ rs6000coff_core_p (bfd *abfd)
       c_lsize = CNEW_LSIZE (core.new_dump);
       c_loader = CNEW_LOADER (core.new_dump);
       c_extoff = core.new_dump.c_extctx;
-#ifndef BFD64
       proc64 = CNEW_PROC64 (core.new_dump);
     }
+#ifndef BFD64
   else
     {
       c_flag = core.old.c_flag;
@@ -382,9 +394,9 @@ rs6000coff_core_p (bfd *abfd)
       c_stackend = COLD_STACKEND;
       c_lsize = 0x7ffffff;
       c_loader = (file_ptr) (ptr_to_uint) COLD_LOADER (core.old);
-#endif
       proc64 = 0;
     }
+#endif
 
   if (proc64)
     {
@@ -440,15 +452,18 @@ rs6000coff_core_p (bfd *abfd)
     }
 
   /* Don't check the core file size for a full core, AIX 4.1 includes
-     additional shared library sections in a full core.  */
-  if (!(c_flag & (FULL_CORE | CORE_TRUNC)))
+     additional shared library sections in a full core.
+     Also skip the check for AIX 7.3 32-bit cores in core_dumpxx format,
+     as they may have additional sections beyond c_stack + c_size.  */
+  if (!(c_flag & (FULL_CORE | CORE_TRUNC))
+      && !(CORE_NEW (core) && CNEW_IS_CORE_DUMPXX (core) && !proc64))
     {
       /* If the size is wrong, it means we're misinterpreting something.  */
       if (c_stack + (file_ptr) c_size != statbuf.st_size)
-	{
-	  bfd_set_error (bfd_error_wrong_format);
-	  return NULL;
-	}
+ {
+   bfd_set_error (bfd_error_wrong_format);
+   return NULL;
+ }
     }
 
   /* Sanity check on the c_tab field.  */
-- 
2.51.2

