public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] testsuite, GDC: Update link flags [PR112861].
@ 2024-01-28 15:02 Iain Sandoe
  2024-01-28 15:19 ` Iain Buclaw
  0 siblings, 1 reply; 2+ messages in thread
From: Iain Sandoe @ 2024-01-28 15:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: ro

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

--- 8< ---

The regressions here are because we do not generate a runpath for
the uninstalled libstdc++.  This patch updates the link flags handling
to simplify it.

We need to add options to locate both libgphobos and libstdc++
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 is to add a single -B/-L option for each needed
path.

	PR target/112861

gcc/testsuite/ChangeLog:

	* lib/gdc.exp: Decide on whether to present -B or -L to reference
	the paths to uninstalled libphobos and libstdc++ and use that to
	generate the link flags.
---
 gcc/testsuite/lib/gdc.exp | 40 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/lib/gdc.exp b/gcc/testsuite/lib/gdc.exp
index 3045aa82918..3c284229609 100644
--- a/gcc/testsuite/lib/gdc.exp
+++ b/gcc/testsuite/lib/gdc.exp
@@ -133,6 +133,28 @@ proc gdc_link_flags { paths } {
 	set include_cxx_flags 0
     }
 
+    # We need to add options to locate libgphobos and libstdc++
+    # 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 != "" } {
 	# Path to libgphobos.spec.
 	append flags "-B${gccpath}/libphobos/src "
@@ -143,7 +165,11 @@ proc gdc_link_flags { paths } {
 
 	if { [file exists "${gccpath}/libphobos/src/.libs/libgphobos.a"] \
 	     || [file exists "${gccpath}/libphobos/src/.libs/libgphobos.${shlib_ext}"] } {
-	    append flags "-L${gccpath}/libphobos/src/.libs "
+	    if { $target_wants_B_option } {
+		append flags "-B${gccpath}/libphobos/src/.libs "
+	    } else {
+		append flags "-L${gccpath}/libphobos/src/.libs "
+	    }
 	    append ld_library_path ":${gccpath}/libphobos/src/.libs"
 	}
 	# Static linking is default. If only the shared lib is available adjust
@@ -163,7 +189,11 @@ proc gdc_link_flags { paths } {
 	if $include_cxx_flags {
 	    if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
 		 || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
-		append flags "-L${gccpath}/libstdc++-v3/src/.libs "
+		if { $target_wants_B_option } {
+		    append flags "-B${gccpath}/libstdc++-v3/src/.libs "
+		} else {
+		    append flags "-L${gccpath}/libstdc++-v3/src/.libs "
+		}
 		append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
 	    }
 	}
@@ -173,7 +203,11 @@ proc gdc_link_flags { paths } {
 
 	set libphobos [lookfor_file ${tool_root_dir} libgphobos]
 	if { $libphobos != "" } {
-	    append flags "-B${libphobos} -L${libphobos} "
+	    if { $target_wants_B_option } {
+	      append flags "-B${libphobos} "
+	    } else { 
+	      append flags " -L${libphobos} "
+	    }
 	    append ld_library_path ":${libphobos}"
 	}
 	set libiberty [lookfor_file ${tool_root_dir} libiberty]
-- 
2.39.2 (Apple Git-143)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] testsuite, GDC: Update link flags [PR112861].
  2024-01-28 15:02 [PATCH] testsuite, GDC: Update link flags [PR112861] Iain Sandoe
@ 2024-01-28 15:19 ` Iain Buclaw
  0 siblings, 0 replies; 2+ messages in thread
From: Iain Buclaw @ 2024-01-28 15:19 UTC (permalink / raw)
  To: gcc-patches, iain; +Cc: ro

Excerpts from Iain Sandoe's message of Januar 28, 2024 4:02 pm:
> Tested on i686, x86_64, aarch64 Darwin, x86_64, aarch64 Linux,
> OK for trunk?
> thanks, 
> Iain
> 

OK.

Thanks again!

Iain.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-28 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 15:02 [PATCH] testsuite, GDC: Update link flags [PR112861] Iain Sandoe
2024-01-28 15:19 ` Iain Buclaw

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).