From:
4824ed41ba7cd63e60fd9f8769a58b79935a90d1 - libffi: Integrate testsuite with GCC 
testsuite
a0673ec5f9236dca6ada23f28343c591ccd575e4 - Testsuite: allow non-installed 
testing on darwin
967d4171b2eb0557e86ba28996423353f0f1b141 - libffi: Consider 
'--with-build-sysroot=[...]' for target libraries' build-tree testing (instead 
of build-time 'CC' etc.) [PR109951]

libffi/ChangeLog:
        PR libffi/117635
        * testsuite/lib/libffi.exp (load_gcc_lib): Load library from GCC
        testsuite.
        Load target-supports.exp and target-supports-dg.exp.
        (libffi-init): Use libraries in GCC build tree.
        Pass correct flags on darwin.
        (libffi_target_compile): If '--with-build-sysroot=[...]' was
        specified, use it for build-tree testing. Link with
        -shared-libgcc -lstdc++ for C++ sources.

Signed-off-by: Pietro Monteiro <[email protected]>
---
 libffi/testsuite/lib/libffi.exp | 45 ++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 17 deletions(-)

diff --git a/libffi/testsuite/lib/libffi.exp b/libffi/testsuite/lib/libffi.exp
index 81eff7752d1..577c4d28183 100644
--- a/libffi/testsuite/lib/libffi.exp
+++ b/libffi/testsuite/lib/libffi.exp
@@ -15,12 +15,15 @@
 # <http://www.gnu.org/licenses/>.
 
 proc load_gcc_lib { filename } {
-    global srcdir
-    load_file $srcdir/lib/$filename
+    global srcdir loaded_libs
+    load_file $srcdir/../../gcc/testsuite/lib/$filename
+    set loaded_libs($filename) ""
 }
 
 load_lib dg.exp
 load_lib libgloss.exp
+load_gcc_lib target-supports.exp
+load_gcc_lib target-supports-dg.exp
 load_gcc_lib target-libpath.exp
 load_gcc_lib wrapper.exp
 
@@ -288,6 +291,7 @@ proc libffi-init { args } {
     global srcdir
     global blddirffi
     global objdir
+    global blddircxx
     global TOOL_OPTIONS
     global tool
     global libffi_include
@@ -296,13 +300,13 @@ proc libffi-init { args } {
     global ld_library_path
     global compiler_vendor
 
-    if ![info exists blddirffi] {
-        set blddirffi [pwd]/..
-    }
-
+    set blddirffi [lookfor_file [get_multilibs] libffi]
     verbose "libffi $blddirffi"
+    set blddircxx [lookfor_file [get_multilibs] libstdc++-v3]
+    verbose "libstdc++ $blddircxx"
+
+    set compiler_vendor "gnu"
 
-    # Which compiler are we building with?
     if { [string match $compiler_vendor "gnu"] } {
         set gccdir [lookfor_file $tool_root_dir gcc/libgcc.a]
         if {$gccdir != ""} {
@@ -331,6 +335,8 @@ proc libffi-init { args } {
 
     # add the library path for libffi.
     append ld_library_path ":${blddirffi}/.libs"
+    # add the library path for libstdc++ as well.
+    append ld_library_path ":${blddircxx}/src/.libs"
 
     verbose "ld_library_path: $ld_library_path"
 
@@ -342,7 +348,13 @@ proc libffi-init { args } {
     verbose "libffi_dir $libffi_dir"
     if { $libffi_dir != "" } {
         set libffi_dir [file dirname ${libffi_dir}]
-        set libffi_link_flags "-L ../.libs"
+       if [istarget *-*-darwin*] {
+           set libffi_link_flags "-B${libffi_dir}/.libs"
+           lappend libffi_link_flags "-B${blddircxx}/src/.libs"
+       } else {
+           set libffi_link_flags "-L${libffi_dir}/.libs"
+           lappend libffi_link_flags "-L${blddircxx}/src/.libs"
+       }
     }
 
     set_ld_library_path_env_vars
@@ -373,6 +385,13 @@ proc libffi_target_compile { source dest type options } {
         lappend options "ldflags=$wrap_flags"
     }
 
+    if { $blddirffi != "" } {
+       # If '--with-build-sysroot=[...]' was specified, use it for build-tree
+       # testing.
+       global SYSROOT_CFLAGS_FOR_TARGET
+       lappend options "additional_flags=${SYSROOT_CFLAGS_FOR_TARGET}"
+    }
+
     # TOOL_OPTIONS must come first, so that it doesn't override testcase
     # specific options.
     if [info exists TOOL_OPTIONS] {
@@ -415,16 +434,8 @@ proc libffi_target_compile { source dest type options } {
             }
         }
 
-        # this may be required for g++, but just confused clang.
         if { [string match "*.cc" $source] } {
-            lappend options "c++"
-            if { [string match "*-*-darwin*" $target_triplet] } {
-                if { [string match $compiler_vendor "gnu"] } {
-                    lappend options "libs= -lc++"
-                }
-            } elseif { [string match "*android*" $target_triplet] } {
-                lappend options "libs= -lc++"
-            }
+            lappend options "ldflags=-shared-libgcc -lstdc++"
         }
 
         if { [string match "arc*-*-linux*" $target_triplet] } {
-- 
2.43.0

Reply via email to