Ping.

On 2026-06-13 10:09 a.m., John David Anglin wrote:
> Tested on hppa64-hp-hpux11.11.
> 
> Okay?
> 
> Dave
> ---
> 
> libgfortran: Fix caf tests on HP-UX
> 
> On HP-UX, shm_open parses the name argument directly through file
> system checks.  As a result, we need a name that specifies a directory
> with read, write and execute permisions.  This differs from linux
> where the name specifies the shared memory object to be created or
> opened, and the shared object is identified by a name of the form
> /somename.
> 
> We also limit the size of the shared objects to 1 GB on HP-UX.
> The maximum JFS file size is 2 GB - 1 with the default nolargefiles
> option in HP-UX 11.
> 
> Finally, we need to compile and link tests with the -pthread option
> to ensure they are linked against libpthread.
> 
> 2026-06-13  John David Anglin  <[email protected]>
> 
> libgfortran/ChangeLog:
> 
>       * caf/shmem/shared_memory.c (SHM_NAME_FMTD, SHM_NAME_FMTS): Define.
>       (shared_memory_init) Use SHM_NAME_FMTD format to generate
>       shm_name.
>       (shared_memory_cleanup): Use SHM_NAME_FMTS to generate shm_name.
>       * caf/shmem/supervisor.c (get_memory_size_from_envvar): Use
>       1 GB on 64-bit Windows and HP-UX.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gfortran.dg/coarray/caf.exp: Run test with -pthread option.
> 
> diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp 
> b/gcc/testsuite/gfortran.dg/coarray/caf.exp
> index bb4fb53050e..59aa9d6150e 100644
> --- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
> +++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
> @@ -120,7 +120,7 @@ foreach test [lsort [glob -nocomplain 
> $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]]
>          foreach flags $option_list {
>              verbose "Testing $nshort (libcaf_shmem), $flags" 1
>              set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem"
> -            if { [istarget *-*-freebsd*] } {
> +            if { [istarget *-*-freebsd*] || [istarget *-*-hpux*] } {
>                  dg-test $test "-fcoarray=lib -pthread $flags -lcaf_shmem" {}
>              } else {
>                  if { [istarget *-linux*] } {
> diff --git a/libgfortran/caf/shmem/shared_memory.c 
> b/libgfortran/caf/shmem/shared_memory.c
> index a42b0963697..6cf0c80eeb6 100644
> --- a/libgfortran/caf/shmem/shared_memory.c
> +++ b/libgfortran/caf/shmem/shared_memory.c
> @@ -122,6 +122,17 @@ shared_memory_prepare (shared_memory_act *)
>    asm volatile ("" ::: "memory");
>  }
>  
> +#if defined(__hpux__)
> +/* On HP-UX, shm_open parses the name argument directly through file
> +   system checks.  We need to provide a file path inside a globally
> +   writeable directory.  */
> +#define SHM_NAME_FMTD "/tmp/gfor-shm-%d"
> +#define SHM_NAME_FMTS "/tmp/gfor-shm-%s"
> +#else
> +#define SHM_NAME_FMTD "/gfor-shm-%d"
> +#define SHM_NAME_FMTS "/gfor-shm-%s"
> +#endif
> +
>  #define SHM_NAME_MAX 255
>  
>  /* Initialize the memory with one page, the shared metadata of the
> @@ -140,7 +151,7 @@ shared_memory_init (shared_memory_act *mem, size_t size)
>        int n = sscanf (env_val, "%d", &ppid);
>        assert (n == 1);
>      }
> -  snprintf (shm_name, SHM_NAME_MAX, "/gfor-shm-%d", ppid);
> +  snprintf (shm_name, SHM_NAME_MAX, SHM_NAME_FMTD, ppid);
>    if (base)
>      {
>        int n = sscanf (base, "%p", &base_ptr);
> @@ -286,7 +297,8 @@ shared_memory_cleanup (shared_memory_act *mem)
>      {
>        char shm_name[SHM_NAME_MAX];
>  
> -      snprintf (shm_name, SHM_NAME_MAX, "/gfor-shm-%s", 
> shared_memory_get_env ());
> +      snprintf (shm_name, SHM_NAME_MAX, SHM_NAME_FMTS,
> +             shared_memory_get_env ());
>        /* Only the supervisor is to delete the shm-file.  */
>        res = shm_unlink (shm_name);
>        if (res == -1)
> diff --git a/libgfortran/caf/shmem/supervisor.c 
> b/libgfortran/caf/shmem/supervisor.c
> index aa692a6551d..0836b89d99f 100644
> --- a/libgfortran/caf/shmem/supervisor.c
> +++ b/libgfortran/caf/shmem/supervisor.c
> @@ -134,11 +134,11 @@ get_memory_size_from_envvar (void)
>        if (sizeof (size_t) == 4)
>       sz = ((size_t) 1) << 28;
>        else
> -#ifndef WIN32
> -     sz = ((size_t) 1) << 34;
> -#else
> -     /* Use 1GB on Windows.  */
> +#if defined(WIN32) || defined(__hpux__)
> +     /* Use 1GB on Windows and HP-UX.  */
>       sz = ((size_t) 1) << 30;
> +#else
> +     sz = ((size_t) 1) << 34;
>  #endif
>      }
>    return sz;


-- 
John David Anglin  [email protected]

Reply via email to