From 5c357ef1546e5091a5b5e6ca8aa538c75b1d069d Mon Sep 17 00:00:00 2001
From: Mark Allen <markalle@us.ibm.com>
Date: Tue, 30 Mar 2021 17:35:54 -0400
Subject: [PATCH] [mpich romio d97c4ee] romio: ensure config headers are
 included first

> Pulled in from mpich romio, branch "main".
> Their commit message is below.
>
> This is part of a batch of commits from the
> following set of PRs:
>  *  https://github.com/pmodels/mpich/pull/4943
>     -- darray fix which contains a flatten fix
>         73a3eba
>         c4b5762
>  *  https://github.com/pmodels/mpich/pull/4995
>     -- write strided fix
>         bbb5210
>  *  https://github.com/pmodels/mpich/pull/5100
>     -- build fix for -Wpedantic
>         ad0e435
>  *  https://github.com/pmodels/mpich/pull/5099
>     -- build fix, they had let file-system=...gpfs bit rot
>         e1d42af
>         313289a
>         83bbb82
>  *  https://github.com/pmodels/mpich/pull/5150
>     -- build fix, configure-related _GNU_SOURCE
>         a712b56
>         5a036e7
>  *  https://github.com/pmodels/mpich/pull/5184
>     -- build fix, continuation of _GNU_SOURCE fix
>         d97c4ee

There was a problem with romio's use of MPL and the include order
sometimes having system files before the config files generated
by configure.  So for example at configure time _GNU_SOURCE was
used and thus configure concluded that aligned_memory() was
already declared, but then later in romio sometimes stdlib.h or
similar sys includes were coming before mplconfig.h and maybe
even before romioconf.h.

My understanding of the design described by hzhou is that
universlaly putting the config files at the top is the best
solution to this ordering.

All over the romio code they seem to use adio.h as their top
level include, which has romioconf.h as its first include.
So in this PR I'm moved adio.h to the top of a few more files.

And I also made romioconf.h include mplconfig.h as its first
include.  Otherwise what we have for romio's use of MPL is

adio.h:
  includes romioconf.h  <-- we're relying on _GNU_SOURCE being here too
  includes many things including system files
  includes adioi.h
    includes mpl.h
      includes mplconfig.h with _GNU_SOURCE

so having _GNU_SOURCE down in mplconfig.h doesn't really
ensure it's in front of the system files unless we can
rely on it being there in romioconf.h (Maybe we can? I'm not
sure).  Anyway as long as the top level romioconf.h knows
it's consuming MPL it can put mplconfig.h at its top and then
all the rest of the romio code only needs to follow the rule
of putting adio.h first and then both romio and mpl will get
their config settings included at the top

Signed-off-by: Mark Allen <markalle@us.ibm.com>
---
 3rd-party/romio341/adio/ad_lustre/ad_lustre.h        | 2 +-
 3rd-party/romio341/adio/ad_panfs/ad_panfs.h          | 2 +-
 3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_dtype.c | 2 +-
 3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_list.c  | 2 +-
 3rd-party/romio341/adio/ad_xfs/ad_xfs.h              | 2 +-
 3rd-party/romio341/configure.ac                      | 1 +
 3rd-party/romio341/mpi-io/fortran/deletef.c          | 2 +-
 3rd-party/romio341/mpi-io/fortran/get_viewf.c        | 2 +-
 3rd-party/romio341/mpi-io/fortran/openf.c            | 2 +-
 3rd-party/romio341/mpi-io/fortran/set_viewf.c        | 2 +-
 10 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/3rd-party/romio341/adio/ad_lustre/ad_lustre.h b/3rd-party/romio341/adio/ad_lustre/ad_lustre.h
index 7b54b0ffa8..0190d7628b 100644
--- a/3rd-party/romio341/adio/ad_lustre/ad_lustre.h
+++ b/3rd-party/romio341/adio/ad_lustre/ad_lustre.h
@@ -9,6 +9,7 @@
 /* temp*/
 #define HAVE_ASM_TYPES_H 1
 
+#include "adio.h"
 #define _GNU_SOURCE 1
 #include <stdlib.h>
 #include <sys/types.h>
@@ -30,7 +31,6 @@
 
 #include <sys/ioctl.h>
 
-#include "adio.h"
 #include "ad_tuning.h"
 
 #ifdef HAVE_LUSTRE_LUSTRE_USER_H
diff --git a/3rd-party/romio341/adio/ad_panfs/ad_panfs.h b/3rd-party/romio341/adio/ad_panfs/ad_panfs.h
index ee68edc08b..e6af35e78d 100644
--- a/3rd-party/romio341/adio/ad_panfs/ad_panfs.h
+++ b/3rd-party/romio341/adio/ad_panfs/ad_panfs.h
@@ -6,10 +6,10 @@
 #ifndef AD_PANFS_H_INCLUDED
 #define AD_PANFS_H_INCLUDED
 
+#include "adio.h"
 #include <unistd.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include "adio.h"
 
 #ifndef NO_AIO
 #ifdef AIO_SUN
diff --git a/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_dtype.c b/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_dtype.c
index fa50e317cf..491af6d385 100644
--- a/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_dtype.c
+++ b/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_dtype.c
@@ -3,8 +3,8 @@
  *     See COPYRIGHT in top-level directory
  */
 
-#include <assert.h>
 #include "adio.h"
+#include <assert.h>
 #include "adio_extern.h"
 #include "ad_pvfs2.h"
 #include "ad_pvfs2_io.h"
diff --git a/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_list.c b/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_list.c
index 933efdda5e..8030f2a917 100644
--- a/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_list.c
+++ b/3rd-party/romio341/adio/ad_pvfs2/ad_pvfs2_io_list.c
@@ -3,8 +3,8 @@
  *     See COPYRIGHT in top-level directory
  */
 
-#include <assert.h>
 #include "adio.h"
+#include <assert.h>
 #include "adio_extern.h"
 #include "ad_pvfs2.h"
 #include "ad_pvfs2_io.h"
diff --git a/3rd-party/romio341/adio/ad_xfs/ad_xfs.h b/3rd-party/romio341/adio/ad_xfs/ad_xfs.h
index d082fe09f4..f37028ea2c 100644
--- a/3rd-party/romio341/adio/ad_xfs/ad_xfs.h
+++ b/3rd-party/romio341/adio/ad_xfs/ad_xfs.h
@@ -6,10 +6,10 @@
 #ifndef AD_XFS_H_INCLUDED
 #define AD_XFS_H_INCLUDED
 
+#include "adio.h"
 #include <unistd.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include "adio.h"
 
 #if defined(MPISGI)
 #include "xfs/xfs_fs.h"
diff --git a/3rd-party/romio341/configure.ac b/3rd-party/romio341/configure.ac
index 6aaea10376..b0dad8f5a0 100644
--- a/3rd-party/romio341/configure.ac
+++ b/3rd-party/romio341/configure.ac
@@ -68,6 +68,7 @@ AH_TOP([/*
  */
 #ifndef ROMIOCONF_H_INCLUDED
 #define ROMIOCONF_H_INCLUDED
+#include <mplconfig.h>
 
 #include "romioconf-undefs.h"
 ])
diff --git a/3rd-party/romio341/mpi-io/fortran/deletef.c b/3rd-party/romio341/mpi-io/fortran/deletef.c
index a4272aee5e..8cc9eeeb3e 100644
--- a/3rd-party/romio341/mpi-io/fortran/deletef.c
+++ b/3rd-party/romio341/mpi-io/fortran/deletef.c
@@ -3,10 +3,10 @@
  *     See COPYRIGHT in top-level directory
  */
 
+#include "adio.h"
 #ifdef _UNICOS
 #include <fortran.h>
 #endif
-#include "adio.h"
 #include "mpio.h"
 
 
diff --git a/3rd-party/romio341/mpi-io/fortran/get_viewf.c b/3rd-party/romio341/mpi-io/fortran/get_viewf.c
index 38e64875cf..ada465a765 100644
--- a/3rd-party/romio341/mpi-io/fortran/get_viewf.c
+++ b/3rd-party/romio341/mpi-io/fortran/get_viewf.c
@@ -3,10 +3,10 @@
  *     See COPYRIGHT in top-level directory
  */
 
+#include "adio.h"
 #ifdef _UNICOS
 #include <fortran.h>
 #endif
-#include "adio.h"
 #include "mpio.h"
 
 
diff --git a/3rd-party/romio341/mpi-io/fortran/openf.c b/3rd-party/romio341/mpi-io/fortran/openf.c
index af88b5b692..8067a2791a 100644
--- a/3rd-party/romio341/mpi-io/fortran/openf.c
+++ b/3rd-party/romio341/mpi-io/fortran/openf.c
@@ -3,10 +3,10 @@
  *     See COPYRIGHT in top-level directory
  */
 
+#include "adio.h"
 #ifdef _UNICOS
 #include <fortran.h>
 #endif
-#include "adio.h"
 #include "mpio.h"
 
 
diff --git a/3rd-party/romio341/mpi-io/fortran/set_viewf.c b/3rd-party/romio341/mpi-io/fortran/set_viewf.c
index 206a7da942..1ea4bedd42 100644
--- a/3rd-party/romio341/mpi-io/fortran/set_viewf.c
+++ b/3rd-party/romio341/mpi-io/fortran/set_viewf.c
@@ -3,10 +3,10 @@
  *     See COPYRIGHT in top-level directory
  */
 
+#include "adio.h"
 #ifdef _UNICOS
 #include <fortran.h>
 #endif
-#include "adio.h"
 #include "mpio.h"
 
 
-- 
GitLab