+#include <sys/systemcfg.h>
+
+/* Borrowed from <sys/inttypes.h> on recent AIX versions. */
+typedef unsigned long ptr_to_uint;
+
+#define core_hdr(bfd) ((CoreHdr *) bfd->tdata.any)
+
+/* AIX 4.1 changed the names and locations of a few items in the core file.
+ AIX 4.3 defined an entirely new structure, core_dumpx, but kept support for
+ the previous 4.1 structure, core_dump.
+
+ AIX_CORE_DUMPX_CORE is defined (by configure) on AIX 4.3+, and
+ CORE_VERSION_1 is defined (by AIX core.h) as 2 on AIX 4.3+ and as 1 on AIX
+ 4.1 and 4.2. AIX pre-4.1 (aka 3.x) either doesn't define CORE_VERSION_1
+ or else defines it as 0. */
+
+#if defined(CORE_VERSION_1) && !CORE_VERSION_1
+# undef CORE_VERSION_1
+#endif
+
+/* The following union and macros allow this module to compile on all AIX
+ versions and to handle both core_dumpx and core_dump on 4.3+. CNEW_*()
+ and COLD_*() macros respectively retrieve core_dumpx and core_dump
+ values. */
+
+/* Union of 32-bit and 64-bit versions of ld_info. */
+
+typedef union
+{
+#if defined (__ld_info32) || defined (__ld_info64)
+ struct __ld_info32 l32;
+ struct __ld_info64 l64;
+#else
+ struct ld_info l32;
+ struct ld_info l64;
+#endif
+} LdInfo;
+
+/* Union of old and new core dump structures. */
+
+typedef union
+{
+#ifdef AIX_CORE_DUMPX_CORE
+ struct core_dumpx new_dump; /* New AIX 4.3+ core dump. */
+#else
+ struct core_dump new_dump; /* For simpler coding. */
+#endif
+#ifndef BFD64 /* Use old only if gdb is 32-bit. */
+ struct core_dump old; /* Old AIX 4.2- core dump, still used on
+ 4.3+ with appropriate SMIT config. */
+#endif
+} CoreHdr;
+
+/* Union of old and new vm_info structures. */
+
+#ifdef CORE_VERSION_1
+typedef union
+{
+#ifdef AIX_CORE_DUMPX_CORE
+ struct vm_infox new_dump;
+#else
+ struct vm_info new_dump;
+#endif
+#ifndef BFD64
+ struct vm_info old;
+#endif
+} VmInfo;
+#endif
+
+/* Return whether CoreHdr C is in new or old format. */
+
+#ifdef AIX_CORE_DUMPX_CORE
+# ifndef BFD64
+# define CORE_NEW(c) (!(c).old.c_entries)
+# else
+# define CORE_NEW(c) 1
+# endif
+#else
+# define CORE_NEW(c) 0
+#endif
+
+/* Return whether CoreHdr C usese core_dumpxx structure.
+
+ FIXME: the core file format version number used here definitely indicates
+ that struct core_dumpxx should be used to represent the core file header,
+ but that may not be the only such format version number. */
+
+#ifdef AIX_5_CORE
+# define CORE_DUMPXX_VERSION 267312562
+# define CNEW_IS_CORE_DUMPXX(c) ((c).new_dump.c_version == CORE_DUMPXX_VERSION)
+#else
+# define CNEW_IS_CORE_DUMPXX(c) 0
+#endif
+
+/* Return the c_stackorg field from struct core_dumpx C. */
+
+#ifdef AIX_CORE_DUMPX_CORE
+# define CNEW_STACKORG(c) (c).c_stackorg
+#else
+# define CNEW_STACKORG(c) 0
+#endif
+
+/* Return the offset to the loader region from struct core_dump C. */
+
+#ifdef AIX_CORE_DUMPX_CORE
+# define CNEW_LOADER(c) (c).c_loader
+#else
+# define CNEW_LOADER(c) 0
+#endif
+
+/* Return the offset to the loader region from struct core_dump C. */
+
+#define COLD_LOADER(c) (c).c_tab
+
+/* Return the c_lsize field from struct core_dumpx C. */
+
+#ifdef AIX_CORE_DUMPX_CORE
+# define CNEW_LSIZE(c) (c).c_lsize
+#else
+# define CNEW_LSIZE(c) 0
+#endif