public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@wdc.com>
To: gcc-patches@gcc.gnu.org
Cc: Jeff Law <law@redhat.com>, Mike Stump <mikestump@comcast.net>,
	 Chung-Lin Tang <cltang@codesourcery.com>,
	 Ian Lance Taylor <iant@golang.org>,
	libffi-discuss@sourceware.org
Subject: [PATCH v4 GCC 3/5] libffi/test: Make `libffi-init' use $CC_FOR_TARGET
Date: Sat, 4 Apr 2020 00:01:25 +0100 (BST)	[thread overview]
Message-ID: <alpine.LFD.2.21.2004031747300.461@redsun52.ssa.fujisawa.hgst.com> (raw)
In-Reply-To: <alpine.LFD.2.21.2004031338210.461@redsun52.ssa.fujisawa.hgst.com>

Update code in `libffi-init' to use $CC_FOR_TARGET in determining the 
value of $ld_library_path, as using a different compiler location from 
one actually used in testing may have odd consequences.

As this obviously loses the setting of $gccdir provide a replacement way 
to determine the directory if feasible, however prefer the location of 
shared libgcc over static libgcc.  This helps in configurations where 
shared libgcc is, unlike libgcc, a location that is not specific to the 
compiler version, a common scenario.  It does not address the scenario 
however where there is a shared libgcc symlink installed pointing to the 
actual run-time library installed elsewhere; this would have to be dealt 
with in a board description file specific to the installation.

Use `remote_exec host' rather than `exec' to invoke the compiler so as 
to support remote configurations and also avoid the latter procedure's 
path length limitation that prevents execution in some actual scenarios.

As using `remote_exec host' precludes the use of our existing file name 
globbing to examine directory contents reuse, with minor modifications 
needed to adjust to our structure, the piece I previously contributed to 
GCC with commit d42b84f427e4 ("testsuite: Fix run-time tracking down 
of `libgcc_s'").

	libffi/
	* testsuite/lib/libffi.exp (libffi-init): Use CC_FOR_TARGET.
	Update the determination of `ld_library_path' accordingly.
---
This is a backport of combined upstream libffi changes as recorded here: 
<https://sourceware.org/pipermail/libffi-discuss/2020/002505.html> and 
here: <https://sourceware.org/pipermail/libffi-discuss/2020/002506.html> 
(there's no point to introduce indentation breakage only to fix it with 
the next change).

New change in v4.
---
 libffi/testsuite/lib/libffi.exp |   72 ++++++++++++++++++++++++++++++----------
 1 file changed, 54 insertions(+), 18 deletions(-)

gcc-test-libffi-init-compiler.diff
Index: gcc/libffi/testsuite/lib/libffi.exp
===================================================================
--- gcc.orig/libffi/testsuite/lib/libffi.exp
+++ gcc/libffi/testsuite/lib/libffi.exp
@@ -99,7 +99,7 @@ proc libffi-init { args } {
     global blddirffi
     global objdir
     global blddircxx
-    global TOOL_OPTIONS
+    global CC_FOR_TARGET
     global tool
     global libffi_include
     global libffi_link_flags
@@ -114,26 +114,62 @@ proc libffi-init { args } {
 
     set compiler_vendor "gnu"
 
-    set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
-    if {$gccdir != ""} {
-	set gccdir [file dirname $gccdir]
-    }
-    verbose "gccdir $gccdir"
+    if { [string match $compiler_vendor "gnu"] } {
+	if [info exists CC_FOR_TARGET] then {
+	    set compiler "$CC_FOR_TARGET"
+	    set libgcc_a_x [remote_exec host "$compiler" \
+			    "-print-file-name=libgcc.a"]
+	    if { [lindex $libgcc_a_x 0] == 0 } {
+		set gccdir [file dirname [lindex $libgcc_a_x 1]]
+	    } else {
+		set gccdir ""
+	    }
+	} else {
+	    set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
+	    if {$gccdir != ""} {
+		set gccdir [file dirname $gccdir]
+	    }
+	    set compiler "${gccdir}/xgcc"
+	}
+	verbose "gccdir $gccdir"
 
-    set ld_library_path "."
-    append ld_library_path ":${gccdir}"
+	set shlib_ext [get_shlib_extension]
+	set libgcc_s_x [remote_exec host "$compiler" \
+			"-print-file-name=libgcc_s.${shlib_ext}"]
+	if { [lindex $libgcc_s_x 0] == 0 } {
+	    set libgcc_dir [file dirname [lindex $libgcc_s_x 1]]
+	} else {
+	    set libgcc_dir $gccdir
+	}
+	verbose "libgcc_dir $libgcc_dir"
 
-    set compiler "${gccdir}/xgcc"
-    if { [is_remote host] == 0 && [which $compiler] != 0 } {
-	foreach i "[exec $compiler --print-multi-lib]" {
-	    set mldir ""
-	    regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
-	    set mldir [string trimright $mldir "\;@"]
-	    if { "$mldir" == "." } {
-		continue
+	set ld_library_path "."
+	append ld_library_path ":${gccdir}"
+
+	set multi_dir_x [remote_exec host "$compiler" "-print-multi-directory"]
+	set multi_lib_x [remote_exec host "$compiler" "-print-multi-lib"]
+	if { [lindex $multi_dir_x 0] == 0 && [lindex $multi_lib_x 0] == 0 } {
+	    set multi_dir [string trim [lindex $multi_dir_x 1]]
+	    set multi_lib [string trim [lindex $multi_lib_x 1]]
+	    if { "$multi_dir" == "." } {
+		set multi_root "$libgcc_dir"
+	    } else {
+		set multi_match [string last "/$multi_dir" "$libgcc_dir"]
+		if { "$multi_match" >= 0 } {
+		    set multi_root [string range "$libgcc_dir" \
+				    0 [expr $multi_match - 1]]
+		} else {
+		    set multi_lib ""
+		}
 	    }
-	    if { [llength [glob -nocomplain ${gccdir}/${mldir}/libgcc_s*.so.*]] >= 1 } {
-		append ld_library_path ":${gccdir}/${mldir}"
+	    foreach i "$multi_lib" {
+		set mldir ""
+		regexp -- "\[a-z0-9=_/\.-\]*;" $i mldir
+		set mldir [string trimright $mldir "\;@"]
+		if { "$mldir" == "$multi_dir" } {
+		    continue
+		}
+		append ld_library_path ":${multi_root}/${mldir}"
 	    }
 	}
     }

      parent reply	other threads:[~2020-04-03 23:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.LFD.2.21.2004031338210.461@redsun52.ssa.fujisawa.hgst.com>
2020-04-03 23:01 ` [PATCH v4 GCC 2/5] libffi/test: Fix compilation for build sysroot Maciej W. Rozycki
2020-04-06 18:06   ` Jeff Law
2020-04-06 20:21     ` Maciej W. Rozycki
2020-04-03 23:01 ` Maciej W. Rozycki [this message]

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=alpine.LFD.2.21.2004031747300.461@redsun52.ssa.fujisawa.hgst.com \
    --to=macro@wdc.com \
    --cc=cltang@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iant@golang.org \
    --cc=law@redhat.com \
    --cc=libffi-discuss@sourceware.org \
    --cc=mikestump@comcast.net \
    /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).