public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Toon Moene <toon@moene.org>
To: gfortran <fortran@gcc.gnu.org>
Subject: Fwd: [PATCH] testsuite, gfortan: Update link flags [PR112862].
Date: Sun, 28 Jan 2024 16:22:35 +0100	[thread overview]
Message-ID: <f1a12f51-1e9a-4c42-ae27-fcaa34c756de@moene.org> (raw)
In-Reply-To: <20240128150308.21141-1-iain@sandoe.co.uk>




-------- Forwarded Message --------
Subject: [PATCH] testsuite, gfortan: Update link flags [PR112862].
Date: Sun, 28 Jan 2024 15:03:08 +0000
From: Iain Sandoe <iains.gcc@gmail.com>
Reply-To: iain@sandoe.co.uk
To: gcc-patches@gcc.gnu.org
CC: ro@CeBiTec.Uni-Bielefeld.DE

Tested on i686, x86_64, aarch64 Darwin, x86_64, aarch64 Linux,
OK for trunk?
thanks, Iain

--- 8< ---

The regressions here are caused by two issues:
1. In some cases there is no generated runpath for libatomic
2. In other cases there are duplicate paths.

This patch simplifies the addition of the options in the main
gfortran exp and removes the duplicates elewhere.

We need to add options to locate libgfortran and the dependent libs
libquadmath (supporting REAL*16) and libatomic (supporting operations
used by coarrays).  Usually '-L' options are added to point to the
relevant directories for the uninstalled libraries.

In cases where libraries are available as both shared and convenience
some additional checks are made.

For some targets -static-xxxx options are handled by specs substitution
and need a '-B' option rather than '-L'.  For Darwin, when embedded
runpaths are in use (the default for all versions after macOS 10.11),
'-B' is also needed to provide the runpath.

When '-B' is used, this results in a '-L' for each path that exists (so
that appending a '-L' as well is a needless duplicate).  There are also
cases where tools warn for duplicates, leading to spurious fails.

	PR target/112862

gcc/testsuite/ChangeLog:

	* gfortran.dg/coarray/caf.exp: Remove duplicate additions of
	libatomic handling.
	* gfortran.dg/dg.exp: Likewise.
	* lib/gfortran.exp: Decide on whether to present -B or -L to
	reference the paths to uninstalled libgfortran, libqadmath and
	libatomic and use that to generate the link flags.
---
  gcc/testsuite/gfortran.dg/coarray/caf.exp | 16 +----
  gcc/testsuite/gfortran.dg/dg.exp          | 20 -------
  gcc/testsuite/lib/gfortran.exp            | 73 +++++++++++++++--------
  3 files changed, 51 insertions(+), 58 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp 
b/gcc/testsuite/gfortran.dg/coarray/caf.exp
index dae46bd92fa..31c13cd34e5 100644
--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
@@ -70,18 +70,6 @@ proc dg-compile-aux-modules { args } {
      }
  }
  -# Add -latomic only where supported.  Assume built-in support elsewhere.
-set maybe_atomic_lib ""
-if [check_effective_target_libatomic_available] {
-    if ![is_remote host] {
-	if [info exists TOOL_OPTIONS] {
-	    set maybe_atomic_lib "[atomic_link_flags [get_multilibs 
${TOOL_OPTIONS}]]"
-	} else {
-	    set maybe_atomic_lib "[atomic_link_flags [get_multilibs]]"
-	}
-    }
-}
-
  # Main loop.
  foreach test [lsort [glob -nocomplain 
$srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]] {
      # If we're only testing specific files and this isn't one of them, 
skip it.
@@ -105,14 +93,14 @@ foreach test [lsort [glob -nocomplain 
$srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]]
      foreach flags $option_list {
  	verbose "Testing $nshort (single), $flags" 1
          set gfortran_aux_module_flags "-fcoarray=single $flags"
-	dg-test $test "-fcoarray=single $flags" $maybe_atomic_lib
+	dg-test $test "-fcoarray=single $flags" {}
  	cleanup-modules ""
      }
       foreach flags $option_list {
  	verbose "Testing $nshort (libcaf_single), $flags" 1
          set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_single"
-	dg-test $test "-fcoarray=lib $flags -lcaf_single" $maybe_atomic_lib
+	dg-test $test "-fcoarray=lib $flags -lcaf_single" {}
  	cleanup-modules ""
      }
  }
diff --git a/gcc/testsuite/gfortran.dg/dg.exp 
b/gcc/testsuite/gfortran.dg/dg.exp
index f936fd38644..7a9cb89c194 100644
--- a/gcc/testsuite/gfortran.dg/dg.exp
+++ b/gcc/testsuite/gfortran.dg/dg.exp
@@ -54,27 +54,7 @@ proc dg-compile-aux-modules { args } {
      }
  }
  -# coarray tests might need libatomic.  Assume that it is either not 
needed or
-# provided by builtins if it's not available.
-set maybe_atomic_lib ""
-if [check_effective_target_libatomic_available] {
-    if ![is_remote host] {
-	if [info exists TOOL_OPTIONS] {
-	    set maybe_atomic_lib "[atomic_link_flags [get_multilibs 
${TOOL_OPTIONS}]]"
-	} else {
-	    set maybe_atomic_lib "[atomic_link_flags [get_multilibs]]"
-	}
-    } else {
-        set maybe_atomic_lib ""
-    }
-}
-
  set all_flags $DEFAULT_FFLAGS
-if { $maybe_atomic_lib != "" } {
-   foreach f $maybe_atomic_lib {
-     lappend all_flags $f
-   }
-}
   # Main loop.
  gfortran-dg-runtest [lsort \
diff --git a/gcc/testsuite/lib/gfortran.exp b/gcc/testsuite/lib/gfortran.exp
index c3e258b410b..1ccb81ccec5 100644
--- a/gcc/testsuite/lib/gfortran.exp
+++ b/gcc/testsuite/lib/gfortran.exp
@@ -79,6 +79,7 @@ proc gfortran_link_flags { paths } {
      global ld_library_path
      global GFORTRAN_UNDER_TEST
      global shlib_ext
+    global ENABLE_DARWIN_AT_RPATH
       set gccpath ${paths}
      set libio_dir ""
@@ -87,39 +88,63 @@ proc gfortran_link_flags { paths } {
      set shlib_ext [get_shlib_extension]
      verbose "shared lib extension: $shlib_ext"
  +    # We need to add options to locate libgfortran and the dependent libs
+    # libquadmath (supporting REAL*16) and libatomic (supporting operations
+    # used by coarrays).  Usually '-L' options are added to point to the
+    # relevant directories for the uninstalled libraries.
+
+    # In cases where libraries are available as both shared and convenience
+    # some additional checks are made.
+
+    # For some targets -static-xxxx options are handled by specs 
substitution
+    # and need a '-B' option rather than '-L'.  For Darwin, when embedded
+    # runpaths are in use (the default for all versions after macOS 10.11),
+    # '-B' is also needed to provide the runpath.
+    # When '-B' is used, this results in a '-L' for each path that 
exists (so
+    # that appending a '-L' as well is a needless duplicate).  There 
are also
+    # cases where tools warn for duplicates, leading to spurious fails.
+    # Therefore the objective of the code below is to add just one '-L' or
+    # '-B' for each of the libraries.
+
+    set target_wants_B_option 0
+    if { [istarget *-*-darwin9* ] || [istarget *-*-darwin\[12\]* ] } {
+      set target_wants_B_option 1
+    }
+
      if { $gccpath != "" } {
-      if [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] {
-          # Some targets use libgfortran.a%s in their specs, so they 
need a -B option
-          # for uninstalled testing.
-          append flags "-B${gccpath}/libgfortran/.libs "
-          append flags "-L${gccpath}/libgfortran/.libs "
-          append ld_library_path ":${gccpath}/libgfortran/.libs"
-      }
-      if [file exists 
"${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] {
-	  append flags "-L${gccpath}/libgfortran/.libs "
-	  append ld_library_path ":${gccpath}/libgfortran/.libs"
-      }
        if [file exists "${gccpath}/libgfortran/libgforbegin.a"] {
            append flags "-L${gccpath}/libgfortran "
        }
-      if [file exists 
"${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] {
-	  append flags "-L${gccpath}/libatomic/.libs "
-	  append ld_library_path ":${gccpath}/libatomic/.libs"
+      if { [file exists "${gccpath}/libgfortran/.libs/libgfortran.a"] ||
+	 [file exists "${gccpath}/libgfortran/.libs/libgfortran.${shlib_ext}"] } {
+	if { $target_wants_B_option } {
+          append flags "-B${gccpath}/libgfortran/.libs "
+	} else {
+          append flags "-L${gccpath}/libgfortran/.libs "
+	}
+	append ld_library_path ":${gccpath}/libgfortran/.libs"
        }
-      if [file exists "${gccpath}/libatomic/libatomic.a"] {
-          append flags "-L${gccpath}/libatomic "
+
+      if { [file exists "${gccpath}/libatomic/.libs/libatomic.a"] ||
+	 [file exists "${gccpath}/libatomic/.libs/libatomic.${shlib_ext}"] } {
+	if { $target_wants_B_option } {
+          append flags "-B${gccpath}/libatomic/.libs "
+	} else {
+          append flags "-L${gccpath}/libatomic/.libs "
+	}
+	append ld_library_path ":${gccpath}/libatomic/.libs"
        }
-      if [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] {
-          # Some targets use libquadmath.a%s in their specs, so they 
need a -B option
-          # for uninstalled testing.
+
+      if { [file exists "${gccpath}/libquadmath/.libs/libquadmath.a"] ||
+	 [file exists "${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] } {
+	if { $target_wants_B_option } {
            append flags "-B${gccpath}/libquadmath/.libs "
+	} else {
            append flags "-L${gccpath}/libquadmath/.libs "
-          append ld_library_path ":${gccpath}/libquadmath/.libs"
-      }
-      if [file exists 
"${gccpath}/libquadmath/.libs/libquadmath.${shlib_ext}"] {
-	  append flags "-L${gccpath}/libquadmath/.libs "
-	  append ld_library_path ":${gccpath}/libquadmath/.libs"
+	}
+	append ld_library_path ":${gccpath}/libquadmath/.libs"
        }
+
        if [file exists "${gccpath}/libiberty/libiberty.a"] {
            append flags "-L${gccpath}/libiberty "
        }
-- 
2.39.2 (Apple Git-143)


       reply	other threads:[~2024-01-28 15:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240128150308.21141-1-iain@sandoe.co.uk>
2024-01-28 15:22 ` Toon Moene [this message]
2024-01-28 15:35   ` FX Coudert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1a12f51-1e9a-4c42-ae27-fcaa34c756de@moene.org \
    --to=toon@moene.org \
    --cc=fortran@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).