Subject: bug#39941: Disk-image size increase on core-updates.

From: Mathieu Othacehe <[email-masked]>
Date: Tue, 17 Mar 2020 12:28:25 +0100

Hey,

> Congrats on this, Mathieu!

Thank you :)

> Perhaps add “Fixes <https://bugs.gnu.org/39941>.”

Well I think it doesn't. In the bug report 39941, I reported a recent
increase of the cross-compiled disk-image on core-updates (1.5 -> 2.0
GiB), over the last two months. It is not resolved, and this patch fixes
something that has always been around I guess.

>> +     ;; TOOLDIR_BASE_PREFIX is erroneous when using a separate "lib"
>> +     ;; output. Specify it correctly, otherwise GCC won't find its shared
>> +     ;; libraries installed in the "lib" output.
>
> How erroneous is it?  Is there a bug report we could link to?

I didn't find any bug report related. The issue is that in
gcc/Makefile.in, when computing libsubdir_to_prefix:

--8<---------------cut here---------------start------------->8---
libsubdir_to_prefix := \
  $(unlibsubdir)/$(shell echo "$(libdir)" | \
    sed -e 's|^$(prefix)||' -e 's|/$$||' -e 's|^[^/]|/|' \
        -e 's|/[^/]*|../|g')
--8<---------------cut here---------------end--------------->8---

unlibsubdir is ../../../
libdir /gnu/store/xxx-gcc-cross-aarch64-linux-gnu-7.5.0-lib/lib
prefix is /gnu/store/yyy-gcc-cross-aarch64-linux-gnu-7.5.0

then,

libsubdir_to_prefix = ../../../../../..

Which then gives a search path that looks like:

/gnu/store/5qh73asm77554wj43z2wjdrkl3fjxxbp-gcc-cross-aarch64-linux-gnu-7.5.0-lib/lib/gcc/aarch64-linux-gnu/7.5.0/../../../../../../../aarch64-linux-gnu/lib/aarch64-linux-gnu/7.5.0/

So its just that this hack is completely broken for non FHS compliant
path I guess.

Note that on our native toolchain, we have the same issue. If you run:

--8<---------------cut here---------------start------------->8---
 `guix build -e '(@@ (gnu packages gcc) gcc-9)'|tail -1`/bin/gcc -print-search-dirs
--8<---------------cut here---------------end--------------->8---

You can see the same kind of wrong path:

--8<---------------cut here---------------start------------->8---
/gnu/store/347y0zr1a9s2f5pkcncgi3gd0r33qq81-gcc-9.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../../../../../x86_64-unknown-linux-gnu/lib/x86_64-unknown-linux-gnu/9.2.0/
--8<---------------cut here---------------end--------------->8---

and it still works, because of this snippet in GCC, disabled when
cross-compiling:

--8<---------------cut here---------------start------------->8---
      else if (*cross_compile == '0')
	{
	  add_prefix (&startfile_prefixes,
		      concat (gcc_exec_prefix
			      ? gcc_exec_prefix : standard_exec_prefix,
			      machine_suffix,
			      standard_startfile_prefix, NULL),
		      NULL, PREFIX_PRIORITY_LAST, 0, 1);
	}
--8<---------------cut here---------------end--------------->8---

that produces an extra search-path that looks like:

--8<---------------cut here---------------start------------->8---
/gnu/store/347y0zr1a9s2f5pkcncgi3gd0r33qq81-gcc-9.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/../../../
--8<---------------cut here---------------end--------------->8---

In short, quite a big mess...

> Apologies for suggesting some more tedious work, but I think it’ll be
> helpful!  :-)

Hehe no worries, here's an updated patch :)

Mathieu
>From 31402fc14126f04e175081ce851e9794cc3ab218 Mon Sep 17 00:00:00 2001
From: Mathieu Othacehe <[email-masked]>
Date: Sat, 14 Mar 2020 11:39:52 +0100
Subject: [PATCH] gnu: cross-gcc: Add a "lib" output.

Add a "lib" output to cross-gcc. This requires an upstream GCC patch adding
support for --with-toolexeclibdir configure option. This option allows to
install cross-built GCC libraries in a specific location.

This also fixes the computation of TOOLDIR_BASE_PREFIX, that fails when
/gnu/store/... directories are involved.

* gnu/packages/patches/gcc-7-cross-toolexeclibdir.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/cross-base.scm (cross-gcc)[source]: Apply it,
[outputs]: add a "lib" output,
(cross-gcc-snippet): fix TOOLDIR_BASE_PREFIX.
---
 gnu/local.mk                                  |    3 +-
 gnu/packages/cross-base.scm                   |   41 +-
 .../patches/gcc-7-cross-toolexeclibdir.patch  | 1677 +++++++++++++++++
 3 files changed, 1707 insertions(+), 14 deletions(-)
 create mode 100644 gnu/packages/patches/gcc-7-cross-toolexeclibdir.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 21a149c469..3af841efea 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -14,7 +14,7 @@
 # Copyright © 2016, 2017, 2018, 2019 Jan (janneke) Nieuwenhuizen <[email-masked]>
 # Copyright © 2017, 2018, 2019, 2020 Tobias Geerinckx-Rice <[email-masked]>
 # Copyright © 2017, 2018 Clément Lassieur <[email-masked]>
-# Copyright © 2017 Mathieu Othacehe <[email-masked]>
+# Copyright © 2017, 2020 Mathieu Othacehe <[email-masked]>
 # Copyright © 2017, 2018, 2019 Gábor Boskovits <[email-masked]>
 # Copyright © 2018 Amirouche Boubekki <[email-masked]>
 # Copyright © 2018, 2019, 2020 Oleg Pykhalov <[email-masked]>
@@ -911,6 +911,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/gcc-6-source-date-epoch-2.patch		\
   %D%/packages/patches/gcc-7-cross-mingw.patch			\
   %D%/packages/patches/gcc-7-cross-environment-variables.patch	\
+  %D%/packages/patches/gcc-7-cross-toolexeclibdir.patch		\
   %D%/packages/patches/gcc-8-cross-environment-variables.patch	\
   %D%/packages/patches/gcc-8-strmov-store-file-names.patch	\
   %D%/packages/patches/gcc-9-asan-fix-limits-include.patch	\
diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 667d1f786a..d373e522d5 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -6,6 +6,7 @@
 ;;; Copyright © 2018 Tobias Geerinckx-Rice <[email-masked]>
 ;;; Copyright © 2019, 2020 Marius Bakke <[email-masked]>
 ;;; Copyright © 2019 Carl Dong <[email-masked]>
+;;; Copyright © 2020 Mathieu Othacehe <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -162,6 +163,13 @@ base compiler and using LIBC (which may be either a libc package or #f.)"
                                "--disable-libsanitizer"
                                 ))
 
+                       ;; Install cross-built libraries such as libgcc_s.so in
+                       ;; the "lib" output.
+                       ,@(if libc
+                             `((string-append "--with-toolexeclibdir="
+                                              (assoc-ref %outputs "lib")
+                                              "/" ,target "/lib"))
+                             '())
                        ;; For a newlib (non-glibc) target
                        ,@(if (cross-newlib? target)
                              '("--with-newlib")
@@ -196,12 +204,18 @@ base compiler and using LIBC (which may be either a libc package or #f.)"
 
 (define (cross-gcc-snippet target)
   "Return GCC snippet needed for TARGET."
-  (cond ((target-mingw? target)
-         '(begin
-            (copy-recursively "libstdc++-v3/config/os/mingw32-w64"
-                              "libstdc++-v3/config/os/newlib")
-            #t))
-        (else #f)))
+  `(begin
+     ,@(if (target-mingw? target)
+           '((copy-recursively "libstdc++-v3/config/os/mingw32-w64"
+                               "libstdc++-v3/config/os/newlib"))
+           '())
+     ;; TOOLDIR_BASE_PREFIX is erroneous when using a separate "lib"
+     ;; output. Specify it correctly, otherwise GCC won't find its shared
+     ;; libraries installed in the "lib" output.
+     (substitute* "gcc/Makefile.in"
+       (("-DTOOLDIR_BASE_PREFIX=[^ ]*")
+        "-DTOOLDIR_BASE_PREFIX=\\\"../../../../\\\""))
+     #t))
 
 (define* (cross-gcc target
                     #:key
@@ -220,18 +234,19 @@ target that libc."
               (patches
                (append
                 (origin-patches (package-source xgcc))
-                (cons (cond
-                       ((version>=? (package-version xgcc) "8.0") (search-patch "gcc-8-cross-environment-variables.patch"))
-                       ((version>=? (package-version xgcc) "6.0") (search-patch "gcc-6-cross-environment-variables.patch"))
-                       (else  (search-patch "gcc-cross-environment-variables.patch")))
+                (append (cond
+                       ((version>=? (package-version xgcc) "8.0")
+                        (search-patches "gcc-8-cross-environment-variables.patch"))
+                       ((version>=? (package-version xgcc) "6.0")
+                        (search-patches "gcc-7-cross-toolexeclibdir.patch"
+                                        "gcc-6-cross-environment-variables.patch"))
+                       (else  (search-patches "gcc-cross-environment-variables.patch")))
                       (cross-gcc-patches xgcc target))))
               (modules '((guix build utils)))
               (snippet
                (cross-gcc-snippet target))))
 
-    ;; For simplicity, use a single output.  Otherwise libgcc_s & co. are not
-    ;; found by default, etc.
-    (outputs '("out"))
+    (outputs '("out" "lib"))
 
     (arguments
      `(#:implicit-inputs? #f
diff --git a/gnu/packages/patches/gcc-7-cross-toolexeclibdir.patch b/gnu/packages/patches/gcc-7-cross-toolexeclibdir.patch
new file mode 100644
index 0000000000..109e6f8b02
--- /dev/null
+++ b/gnu/packages/patches/gcc-7-cross-toolexeclibdir.patch
@@ -0,0 +1,1677 @@
+This patch taken from GCC upstream adds support for overriding cross-compiled
+shared libraries installation path.  This is needed to have a separate "lib"
+output containing those shared libraries.
+
+See:
+https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e8e66971cdc6d1390d47a227899e2e340ff44d66
+
+This commit has been stripped. Some modifications to Changelogs and
+configure.ac scripts were removed.
+
+From fe6b5640a52a6e75dddea834e357974c205c737c Mon Sep 17 00:00:00 2001
+From: "Maciej W. Rozycki" <[email-masked]>
+Date: Fri, 24 Jan 2020 11:24:25 +0000
+Subject: [PATCH] Add `--with-toolexeclibdir=' configuration option
+
+Provide means, in the form of a `--with-toolexeclibdir=' configuration
+option, to override the default installation directory for target
+libraries, otherwise known as $toolexeclibdir.  This is so that it is
+possible to get newly-built libraries, particularly the shared ones,
+installed in a common place, so that they can be readily used by the
+target system as their host libraries, possibly over NFS, without a need
+to manually copy them over from the currently hardcoded location they
+would otherwise be installed in.
+
+In the presence of the `--enable-version-specific-runtime-libs' option
+and for configurations building native GCC the option is ignored.
+
+diff --git a/config/toolexeclibdir.m4 b/config/toolexeclibdir.m4
+new file mode 100644
+index 00000000000..5dd89786219
+--- /dev/null
++++ b/config/toolexeclibdir.m4
+@@ -0,0 +1,31 @@
++dnl toolexeclibdir override support.
++dnl Copyright (C) 2020  Free Software Foundation, Inc.
++dnl
++dnl This program is free software; you can redistribute it and/or modify
++dnl it under the terms of the GNU General Public License as published by
++dnl the Free Software Foundation; either version 3, or (at your option)
++dnl any later version.
++dnl
++dnl This program is distributed in the hope that it will be useful,
++dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
++dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++dnl GNU General Public License for more details.
++dnl
++dnl You should have received a copy of the GNU General Public License
++dnl along with this program; see the file COPYING3.  If not see
++dnl <http://www.gnu.org/licenses/>.
++
++AC_DEFUN([GCC_WITH_TOOLEXECLIBDIR],
++[AC_ARG_WITH(toolexeclibdir,
++  [AS_HELP_STRING([--with-toolexeclibdir=DIR],
++		  [install libraries built with a cross compiler within DIR])],
++  [dnl
++case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac],
++  [with_toolexeclibdir=no])
++])
+diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
+index 77ba08d3f21..28cb6d88da8 100644
+--- a/gcc/doc/install.texi
++++ b/gcc/doc/install.texi
+@@ -2083,6 +2083,10 @@ shorthand for
+ The following options only apply to building cross compilers.
+ 
+ @table @code
++@item --with-toolexeclibdir=@var{dir}
++Specify the installation directory for libraries built with a cross compiler.
++The default is @option{$@{gcc_tooldir@}/lib}.
++
+ @item --with-sysroot
+ @itemx --with-sysroot=@var{dir}
+ Tells GCC to consider @var{dir} as the root of a tree that contains
+diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in
+index f6eeab312ea..86d7ba20c19 100644
+--- a/libatomic/Makefile.in
++++ b/libatomic/Makefile.in
+@@ -72,6 +72,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libatomic/aclocal.m4 b/libatomic/aclocal.m4
+index 1363e7b9cbc..f1a3f1dda26 100644
+--- a/libatomic/aclocal.m4
++++ b/libatomic/aclocal.m4
+@@ -1017,6 +1017,7 @@ m4_include([../config/lthostflags.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
+ m4_include([../config/stdint.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+ m4_include([../ltversion.m4])
+diff --git a/libatomic/configure b/libatomic/configure
+index 2ae9b8d40f3..0fa531ec4a3 100755
+--- a/libatomic/configure
++++ b/libatomic/configure
+@@ -755,6 +755,7 @@ enable_option_checking
+ enable_version_specific_runtime_libs
+ enable_generated_files_in_srcdir
+ enable_multilib
++with_toolexeclibdir
+ enable_dependency_tracking
+ enable_shared
+ enable_static
+@@ -1414,6 +1415,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -3185,6 +3189,22 @@ fi
+ ac_config_commands="$ac_config_commands default-1"
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${enable_version_specific_runtime_libs} in
+@@ -3200,7 +3220,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -11115,7 +11142,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11118 "configure"
++#line 11145 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11221,7 +11248,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11224 "configure"
++#line 11251 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libatomic/testsuite/Makefile.in b/libatomic/testsuite/Makefile.in
+index adfc231484a..a2a76e07502 100644
+--- a/libatomic/testsuite/Makefile.in
++++ b/libatomic/testsuite/Makefile.in
+@@ -61,6 +61,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libffi/Makefile.in b/libffi/Makefile.in
+index 8a99ee58b68..032dadf4c4a 100644
+--- a/libffi/Makefile.in
++++ b/libffi/Makefile.in
+@@ -72,6 +72,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
+diff --git a/libffi/aclocal.m4 b/libffi/aclocal.m4
+index 6d6207eb897..9cd050aaaf5 100644
+--- a/libffi/aclocal.m4
++++ b/libffi/aclocal.m4
+@@ -1051,6 +1051,7 @@ m4_include([../config/depstand.m4])
+ m4_include([../config/lead-dot.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../libtool.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+diff --git a/libffi/configure b/libffi/configure
+index 790a291011f..6e37039e84c 100755
+--- a/libffi/configure
++++ b/libffi/configure
+@@ -777,6 +777,7 @@ enable_debug
+ enable_structs
+ enable_raw_api
+ enable_purify_safety
++with_toolexeclibdir
+ enable_symvers
+ with_gcc_major_version_only
+ '
+@@ -1436,6 +1437,9 @@ Optional Packages:
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-gcc-major-version-only
+                           use only GCC major number in filesystem paths
+ 
+@@ -11390,7 +11394,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11393 "configure"
++#line 11397 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11496,7 +11500,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11499 "configure"
++#line 11507 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -16002,10 +16006,33 @@ $as_echo "#define USING_PURIFY 1" >>confdefs.h
+ fi
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ if test -n "$with_cross_host" &&
+    test x"$with_cross_host" != x"no"; then
+   toolexecdir='$(exec_prefix)/$(target_alias)'
+-  toolexeclibdir='$(toolexecdir)/lib'
++  case ${with_toolexeclibdir} in
++    no)
++      toolexeclibdir='$(toolexecdir)/lib'
++      ;;
++    *)
++      toolexeclibdir=${with_toolexeclibdir}
++      ;;
++  esac
+ else
+   toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+   toolexeclibdir='$(libdir)'
+diff --git a/libffi/include/Makefile.in b/libffi/include/Makefile.in
+index e0c75992327..3762e6c9b68 100644
+--- a/libffi/include/Makefile.in
++++ b/libffi/include/Makefile.in
+@@ -62,6 +62,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
+diff --git a/libffi/man/Makefile.in b/libffi/man/Makefile.in
+index 0243bdbedfa..12e61e485eb 100644
+--- a/libffi/man/Makefile.in
++++ b/libffi/man/Makefile.in
+@@ -60,6 +60,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
+diff --git a/libffi/testsuite/Makefile.in b/libffi/testsuite/Makefile.in
+index b7da4b0b3e7..469b251b17f 100644
+--- a/libffi/testsuite/Makefile.in
++++ b/libffi/testsuite/Makefile.in
+@@ -60,6 +60,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/acinclude.m4 \
+diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
+index a1a392de88d..3a94dab2fdd 100644
+--- a/libgcc/Makefile.in
++++ b/libgcc/Makefile.in
+@@ -163,6 +163,7 @@ AUTOCONF = autoconf
+ configure_deps = \
+ 	$(srcdir)/../config/enable.m4 \
+ 	$(srcdir)/../config/tls.m4 \
++	$(srcdir)/../config/toolexeclibdir.m4 \
+ 	$(srcdir)/../config/acx.m4 \
+ 	$(srcdir)/../config/no-executables.m4 \
+ 	$(srcdir)/../config/lib-ld.m4 \
+diff --git a/libgcc/configure b/libgcc/configure
+index 441601a1f76..976827dc57e 100644
+--- a/libgcc/configure
++++ b/libgcc/configure
+@@ -669,6 +669,7 @@ enable_shared
+ enable_vtable_verify
+ with_aix_soname
+ enable_version_specific_runtime_libs
++with_toolexeclibdir
+ with_slibdir
+ enable_maintainer_mode
+ with_build_libsubdir
+@@ -1329,6 +1330,9 @@ Optional Packages:
+   --with-aix-soname=aix|svr4|both
+                           shared library versioning (aka "SONAME") variant to
+                           provide on AIX
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-slibdir=DIR      shared libraries in DIR LIBDIR
+   --with-build-libsubdir=DIR  Directory where to find libraries for build system
+   --with-system-libunwind use installed libunwind
+@@ -2403,6 +2407,22 @@ fi
+ $as_echo "$version_specific_libs" >&6; }
+ 
+ 
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
++
+ # Check whether --with-slibdir was given.
+ if test "${with_slibdir+set}" = set; then :
+   withval=$with_slibdir; slibdir="$with_slibdir"
+@@ -2410,7 +2430,14 @@ else
+   if test "${version_specific_libs}" = yes; then
+   slibdir='$(libsubdir)'
+ elif test -n "$with_cross_host" && test x"$with_cross_host" != x"no"; then
+-  slibdir='$(exec_prefix)/$(host_noncanonical)/lib'
++  case ${with_toolexeclibdir} in
++    no)
++      slibdir='$(exec_prefix)/$(host_noncanonical)/lib'
++      ;;
++    *)
++      slibdir=${with_toolexeclibdir}
++      ;;
++  esac
+ else
+   slibdir='$(libdir)'
+ fi
+@@ -2640,7 +2667,14 @@ case ${version_specific_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_noncanonical)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_noncanonical)'
+       toolexeclibdir='$(libdir)'
+diff --git a/libgomp/Makefile.in b/libgomp/Makefile.in
+index 920d29d1c4c..9deafc4e0ce 100644
+--- a/libgomp/Makefile.in
++++ b/libgomp/Makefile.in
+@@ -101,6 +101,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lthostflags.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
+ 	$(top_srcdir)/../config/tls.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libgomp/aclocal.m4 b/libgomp/aclocal.m4
+index a1f51f27651..c244c2549e5 100644
+--- a/libgomp/aclocal.m4
++++ b/libgomp/aclocal.m4
+@@ -998,6 +998,7 @@ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
+ m4_include([../config/stdint.m4])
+ m4_include([../config/tls.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+ m4_include([../ltversion.m4])
+diff --git a/libgomp/configure b/libgomp/configure
+index 06166c66120..6b3beae0f63 100755
+--- a/libgomp/configure
++++ b/libgomp/configure
+@@ -782,6 +782,7 @@ enable_option_checking
+ enable_version_specific_runtime_libs
+ enable_generated_files_in_srcdir
+ enable_multilib
++with_toolexeclibdir
+ enable_dependency_tracking
+ enable_shared
+ enable_static
+@@ -1455,6 +1456,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -3338,6 +3342,22 @@ fi
+ ac_config_commands="$ac_config_commands default-1"
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${enable_version_specific_runtime_libs} in
+@@ -3353,7 +3373,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -11155,7 +11182,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11158 "configure"
++#line 11185 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11261,7 +11288,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11264 "configure"
++#line 11295 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libgomp/testsuite/Makefile.in b/libgomp/testsuite/Makefile.in
+index 6edb7ae7ade..0492e7788ab 100644
+--- a/libgomp/testsuite/Makefile.in
++++ b/libgomp/testsuite/Makefile.in
+@@ -63,6 +63,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lthostflags.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
+ 	$(top_srcdir)/../config/tls.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libhsail-rt/Makefile.in b/libhsail-rt/Makefile.in
+index 528cdb0b423..0b6596b79bc 100644
+--- a/libhsail-rt/Makefile.in
++++ b/libhsail-rt/Makefile.in
+@@ -106,6 +106,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/depstand.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+diff --git a/libhsail-rt/aclocal.m4 b/libhsail-rt/aclocal.m4
+index 505744c695a..05de587bda2 100644
+--- a/libhsail-rt/aclocal.m4
++++ b/libhsail-rt/aclocal.m4
+@@ -992,6 +992,7 @@ m4_include([../config/acx.m4])
+ m4_include([../config/depstand.m4])
+ m4_include([../config/lead-dot.m4])
+ m4_include([../config/override.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../libtool.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+diff --git a/libhsail-rt/configure b/libhsail-rt/configure
+index a4fcc10c1f9..1b4f2a953d0 100755
+--- a/libhsail-rt/configure
++++ b/libhsail-rt/configure
+@@ -737,6 +737,7 @@ enable_option_checking
+ enable_maintainer_mode
+ enable_dependency_tracking
+ enable_version_specific_runtime_libs
++with_toolexeclibdir
+ enable_shared
+ enable_static
+ with_pic
+@@ -1395,6 +1396,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -4418,6 +4422,22 @@ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_version_specific_runtime_libs" >&5
+ $as_echo "$enable_version_specific_runtime_libs" >&6; }
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${enable_version_specific_runtime_libs} in
+@@ -4433,7 +4453,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -10973,7 +11000,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10976 "configure"
++#line 11003 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11079,7 +11106,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11082 "configure"
++#line 11113 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libitm/Makefile.in b/libitm/Makefile.in
+index bd16ce0cfb8..851c6b37f0b 100644
+--- a/libitm/Makefile.in
++++ b/libitm/Makefile.in
+@@ -74,6 +74,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
+ 	$(top_srcdir)/../config/tls.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/weakref.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+diff --git a/libitm/aclocal.m4 b/libitm/aclocal.m4
+index 26de26b7808..3b67780342a 100644
+--- a/libitm/aclocal.m4
++++ b/libitm/aclocal.m4
+@@ -1022,6 +1022,7 @@ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
+ m4_include([../config/stdint.m4])
+ m4_include([../config/tls.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../config/weakref.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+diff --git a/libitm/configure b/libitm/configure
+index 96c494d4a3f..ed47fab3c83 100644
+--- a/libitm/configure
++++ b/libitm/configure
+@@ -766,6 +766,7 @@ enable_option_checking
+ enable_version_specific_runtime_libs
+ enable_generated_files_in_srcdir
+ enable_multilib
++with_toolexeclibdir
+ enable_dependency_tracking
+ enable_shared
+ enable_static
+@@ -1430,6 +1431,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -3371,6 +3375,22 @@ fi
+ ac_config_commands="$ac_config_commands default-1"
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${enable_version_specific_runtime_libs} in
+@@ -3386,7 +3406,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -11794,7 +11821,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11797 "configure"
++#line 11824 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11900,7 +11927,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11903 "configure"
++#line 11934 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libitm/testsuite/Makefile.in b/libitm/testsuite/Makefile.in
+index eb9e992279d..88d2120c156 100644
+--- a/libitm/testsuite/Makefile.in
++++ b/libitm/testsuite/Makefile.in
+@@ -66,6 +66,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
+ 	$(top_srcdir)/../config/tls.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/weakref.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+diff --git a/liboffloadmic/Makefile.in b/liboffloadmic/Makefile.in
+index f4470c6e4d4..d42745a49e0 100644
+--- a/liboffloadmic/Makefile.in
++++ b/liboffloadmic/Makefile.in
+@@ -94,6 +94,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/lead-dot.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+diff --git a/liboffloadmic/aclocal.m4 b/liboffloadmic/aclocal.m4
+index 4bb1d43a5e5..c62ed26f6b1 100644
+--- a/liboffloadmic/aclocal.m4
++++ b/liboffloadmic/aclocal.m4
+@@ -993,6 +993,7 @@ m4_include([../config/depstand.m4])
+ m4_include([../config/lead-dot.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../libtool.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+diff --git a/liboffloadmic/configure b/liboffloadmic/configure
+index f873716991b..6dfe9e37642 100644
+--- a/liboffloadmic/configure
++++ b/liboffloadmic/configure
+@@ -739,6 +739,7 @@ enable_maintainer_mode
+ enable_dependency_tracking
+ enable_multilib
+ enable_version_specific_runtime_libs
++with_toolexeclibdir
+ enable_shared
+ enable_static
+ with_pic
+@@ -1397,6 +1398,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -5003,6 +5007,22 @@ else
+ fi
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir.
+ # Also toolexecdir, though it's only used in toolexeclibdir.
+ case ${enable_version_specific_runtime_libs} in
+@@ -5018,7 +5038,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -11108,7 +11135,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11111 "configure"
++#line 11138 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11214,7 +11241,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11217 "configure"
++#line 11248 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/liboffloadmic/plugin/Makefile.in b/liboffloadmic/plugin/Makefile.in
+index 2a7c8d2ec6c..6e180f6a23c 100644
+--- a/liboffloadmic/plugin/Makefile.in
++++ b/liboffloadmic/plugin/Makefile.in
+@@ -90,6 +90,7 @@ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
+ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+ am__aclocal_m4_deps = $(top_srcdir)/../../config/acx.m4 \
+ 	$(top_srcdir)/../../config/depstand.m4 \
++	$(top_srcdir)/../../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../../config/lead-dot.m4 \
+ 	$(top_srcdir)/../../config/multi.m4 \
+ 	$(top_srcdir)/../../config/override.m4 \
+diff --git a/liboffloadmic/plugin/aclocal.m4 b/liboffloadmic/plugin/aclocal.m4
+index a4179ef40ac..6d90e5d6e16 100644
+--- a/liboffloadmic/plugin/aclocal.m4
++++ b/liboffloadmic/plugin/aclocal.m4
+@@ -990,6 +990,7 @@ AC_SUBST([am__untar])
+ 
+ m4_include([../../config/acx.m4])
+ m4_include([../../config/depstand.m4])
++m4_include([../../config/toolexeclibdir.m4])
+ m4_include([../../config/lead-dot.m4])
+ m4_include([../../config/multi.m4])
+ m4_include([../../config/override.m4])
+diff --git a/liboffloadmic/plugin/configure b/liboffloadmic/plugin/configure
+index c031eb3e7fa..570758344b4 100644
+--- a/liboffloadmic/plugin/configure
++++ b/liboffloadmic/plugin/configure
+@@ -735,6 +735,7 @@ enable_maintainer_mode
+ enable_dependency_tracking
+ enable_multilib
+ enable_version_specific_runtime_libs
++with_toolexeclibdir
+ enable_shared
+ enable_static
+ with_pic
+@@ -1394,6 +1395,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -4311,6 +4315,22 @@ fi
+ $as_echo "$enable_version_specific_runtime_libs" >&6; }
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir.
+ # Also toolexecdir, though it's only used in toolexeclibdir.
+ case ${enable_version_specific_runtime_libs} in
+@@ -4326,7 +4346,14 @@ case ${enable_version_specific_runtime_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -10815,7 +10842,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10818 "configure"
++#line 10845 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -10921,7 +10948,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10924 "configure"
++#line 10955 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libquadmath/Makefile.in b/libquadmath/Makefile.in
+index 428e0158aca..e5c7aba84b7 100644
+--- a/libquadmath/Makefile.in
++++ b/libquadmath/Makefile.in
+@@ -67,6 +67,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libquadmath/aclocal.m4 b/libquadmath/aclocal.m4
+index b9ebb8a9ed4..59009468a47 100644
+--- a/libquadmath/aclocal.m4
++++ b/libquadmath/aclocal.m4
+@@ -1030,6 +1030,7 @@ m4_include([../config/lthostflags.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/no-executables.m4])
+ m4_include([../config/override.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+ m4_include([../ltversion.m4])
+diff --git a/libquadmath/configure b/libquadmath/configure
+index 76a2c20b7e1..e887071aeb2 100755
+--- a/libquadmath/configure
++++ b/libquadmath/configure
+@@ -749,6 +749,7 @@ enable_fast_install
+ with_gnu_ld
+ enable_libtool_lock
+ enable_maintainer_mode
++with_toolexeclibdir
+ enable_symvers
+ enable_generated_files_in_srcdir
+ with_gcc_major_version_only
+@@ -1408,6 +1409,9 @@ Optional Packages:
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-gcc-major-version-only
+                           use only GCC major number in filesystem paths
+ 
+@@ -10572,7 +10576,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10575 "configure"
++#line 10579 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -10678,7 +10682,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10681 "configure"
++#line 10689 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11917,6 +11921,22 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
+ ac_compiler_gnu=$ac_cv_c_compiler_gnu
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${version_specific_libs} in
+@@ -11932,7 +11952,14 @@ case ${version_specific_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+diff --git a/libsanitizer/Makefile.in b/libsanitizer/Makefile.in
+index 1f4bb8cd6bb..fb533c253ea 100644
+--- a/libsanitizer/Makefile.in
++++ b/libsanitizer/Makefile.in
+@@ -71,6 +71,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/aclocal.m4 b/libsanitizer/aclocal.m4
+index 55e063530f6..f51347671e3 100644
+--- a/libsanitizer/aclocal.m4
++++ b/libsanitizer/aclocal.m4
+@@ -1017,6 +1017,7 @@ m4_include([../config/libstdc++-raw-cxx.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/override.m4])
+ m4_include([../config/stdint.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+ m4_include([../ltversion.m4])
+diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in
+index 4dad60ba1ae..f079e07f0da 100644
+--- a/libsanitizer/asan/Makefile.in
++++ b/libsanitizer/asan/Makefile.in
+@@ -66,6 +66,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/configure b/libsanitizer/configure
+index a3a08d635f4..5f4cdcad38d 100755
+--- a/libsanitizer/configure
++++ b/libsanitizer/configure
+@@ -767,6 +767,7 @@ enable_multilib
+ enable_version_specific_runtime_libs
+ enable_dependency_tracking
+ enable_maintainer_mode
++with_toolexeclibdir
+ enable_shared
+ enable_static
+ with_pic
+@@ -1425,6 +1426,9 @@ Optional Features:
+ Optional Packages:
+   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
+   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
+@@ -4773,6 +4777,22 @@ fi
+ 
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${version_specific_libs} in
+@@ -4788,7 +4808,14 @@ case ${version_specific_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+@@ -12032,7 +12059,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 12035 "configure"
++#line 12062 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -12138,7 +12165,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 12141 "configure"
++#line 12168 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in
+index c71fb57b8b8..ed9c996b5eb 100644
+--- a/libsanitizer/interception/Makefile.in
++++ b/libsanitizer/interception/Makefile.in
+@@ -62,6 +62,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/libbacktrace/Makefile.in b/libsanitizer/libbacktrace/Makefile.in
+index dff04cfa3ea..22655306594 100644
+--- a/libsanitizer/libbacktrace/Makefile.in
++++ b/libsanitizer/libbacktrace/Makefile.in
+@@ -94,6 +94,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in
+index baa8367cd40..efae691d3ef 100644
+--- a/libsanitizer/lsan/Makefile.in
++++ b/libsanitizer/lsan/Makefile.in
+@@ -63,6 +63,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in
+index c375f63a380..27c8b410ef7 100644
+--- a/libsanitizer/sanitizer_common/Makefile.in
++++ b/libsanitizer/sanitizer_common/Makefile.in
+@@ -68,6 +68,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in
+index 770c053e64f..a77cda3d0f3 100644
+--- a/libsanitizer/tsan/Makefile.in
++++ b/libsanitizer/tsan/Makefile.in
+@@ -65,6 +65,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in
+index 1664ce9497e..108505c3c67 100644
+--- a/libsanitizer/ubsan/Makefile.in
++++ b/libsanitizer/ubsan/Makefile.in
+@@ -64,6 +64,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ 	$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ 	$(top_srcdir)/acinclude.m4 $(top_srcdir)/../libtool.m4 \
+diff --git a/libssp/Makefile.in b/libssp/Makefile.in
+index 96b03ae1248..c119ef3e8a2 100644
+--- a/libssp/Makefile.in
++++ b/libssp/Makefile.in
+@@ -67,6 +67,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/multi.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ 	$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+diff --git a/libssp/aclocal.m4 b/libssp/aclocal.m4
+index 927988e5814..46585360592 100644
+--- a/libssp/aclocal.m4
++++ b/libssp/aclocal.m4
+@@ -995,6 +995,7 @@ m4_include([../config/lthostflags.m4])
+ m4_include([../config/multi.m4])
+ m4_include([../config/no-executables.m4])
+ m4_include([../config/override.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../libtool.m4])
+ m4_include([../ltoptions.m4])
+ m4_include([../ltsugar.m4])
+diff --git a/libssp/configure b/libssp/configure
+index ee1751d20db..3273cd40ab1 100755
+--- a/libssp/configure
++++ b/libssp/configure
+@@ -743,6 +743,7 @@ with_pic
+ enable_fast_install
+ with_gnu_ld
+ enable_libtool_lock
++with_toolexeclibdir
+ with_gcc_major_version_only
+ '
+       ac_precious_vars='build_alias
+@@ -1389,6 +1390,9 @@ Optional Packages:
+   --with-pic              try to use only PIC/non-PIC objects [default=use
+                           both]
+   --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-gcc-major-version-only
+                           use only GCC major number in filesystem paths
+ 
+@@ -10671,7 +10675,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10674 "configure"
++#line 10678 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -10777,7 +10781,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 10780 "configure"
++#line 10784 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11039,6 +11043,22 @@ esac
+ 
+ 
+ 
++
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
++
++
+ # Calculate toolexeclibdir
+ # Also toolexecdir, though it's only used in toolexeclibdir
+ case ${version_specific_libs} in
+@@ -11054,7 +11074,14 @@ case ${version_specific_libs} in
+        test x"$with_cross_host" != x"no"; then
+       # Install a library built with a cross compiler in tooldir, not libdir.
+       toolexecdir='$(exec_prefix)/$(target_alias)'
+-      toolexeclibdir='$(toolexecdir)/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  toolexeclibdir='$(toolexecdir)/lib'
++	  ;;
++	*)
++	  toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
+       toolexeclibdir='$(libdir)'
+diff --git a/libstdc++-v3/Makefile.in b/libstdc++-v3/Makefile.in
+index 85d56fb6a04..a4242569962 100644
+--- a/libstdc++-v3/Makefile.in
++++ b/libstdc++-v3/Makefile.in
+@@ -74,6 +74,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4
+index 08319dc5549..b97ff8db335 100644
+--- a/libstdc++-v3/acinclude.m4
++++ b/libstdc++-v3/acinclude.m4
+@@ -790,6 +790,8 @@ AC_DEFUN([GLIBCXX_EXPORT_INSTALL_INFO], [
+     [version_specific_libs=no])
+   AC_MSG_RESULT($version_specific_libs)
+ 
++  GCC_WITH_TOOLEXECLIBDIR
++
+   # Default case for install directory for include files.
+   if test $version_specific_libs = no && test $gxx_include_dir = no; then
+     gxx_include_dir='include/c++/${gcc_version}'
+@@ -820,7 +822,14 @@ AC_DEFUN([GLIBCXX_EXPORT_INSTALL_INFO], [
+     if test -n "$with_cross_host" &&
+        test x"$with_cross_host" != x"no"; then
+       glibcxx_toolexecdir='${exec_prefix}/${host_alias}'
+-      glibcxx_toolexeclibdir='${toolexecdir}/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  glibcxx_toolexeclibdir='${toolexecdir}/lib'
++	  ;;
++	*)
++	  glibcxx_toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
+       glibcxx_toolexeclibdir='${libdir}'
+diff --git a/libstdc++-v3/aclocal.m4 b/libstdc++-v3/aclocal.m4
+index 229d0354116..16c6e61cf7e 100644
+--- a/libstdc++-v3/aclocal.m4
++++ b/libstdc++-v3/aclocal.m4
+@@ -684,6 +684,7 @@ m4_include([../config/multi.m4])
+ m4_include([../config/no-executables.m4])
+ m4_include([../config/override.m4])
+ m4_include([../config/stdint.m4])
++m4_include([../config/toolexeclibdir.m4])
+ m4_include([../config/unwind_ipinfo.m4])
+ m4_include([../libtool.m4])
+ m4_include([../ltoptions.m4])
+diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
+index de8390703e2..88de3f728d4 100755
+--- a/libstdc++-v3/configure
++++ b/libstdc++-v3/configure
+@@ -903,6 +903,7 @@ enable_libstdcxx_threads
+ enable_libstdcxx_filesystem_ts
+ with_gxx_include_dir
+ enable_version_specific_runtime_libs
++with_toolexeclibdir
+ with_gcc_major_version_only
+ '
+       ac_precious_vars='build_alias
+@@ -1623,6 +1624,9 @@ Optional Packages:
+                           set the std::string ABI to use by default
+   --with-gxx-include-dir=DIR
+                           installation directory for include files
++  --with-toolexeclibdir=DIR
++                          install libraries built with a cross compiler within
++                          DIR
+   --with-gcc-major-version-only
+                           use only GCC major number in filesystem paths
+ 
+@@ -11606,7 +11610,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11609 "configure"
++#line 11613 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -11712,7 +11716,7 @@ else
+   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
+   lt_status=$lt_dlunknown
+   cat > conftest.$ac_ext <<_LT_EOF
+-#line 11715 "configure"
++#line 11723 "configure"
+ #include "confdefs.h"
+ 
+ #if HAVE_DLFCN_H
+@@ -15398,7 +15402,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; }
+   # Fake what AC_TRY_COMPILE does.
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15401 "configure"
++#line 15409 "configure"
+ int main()
+ {
+   typedef bool atomic_type;
+@@ -15433,7 +15437,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; }
+     rm -f conftest*
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15436 "configure"
++#line 15440 "configure"
+ int main()
+ {
+   typedef short atomic_type;
+@@ -15468,7 +15472,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; }
+     rm -f conftest*
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15471 "configure"
++#line 15475 "configure"
+ int main()
+ {
+   // NB: _Atomic_word not necessarily int.
+@@ -15504,7 +15508,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; }
+     rm -f conftest*
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15507 "configure"
++#line 15511 "configure"
+ int main()
+ {
+   typedef long long atomic_type;
+@@ -15585,7 +15589,7 @@ $as_echo "$as_me: WARNING: Performance of certain classes will degrade as a resu
+   # unnecessary for this test.
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15588 "configure"
++#line 15592 "configure"
+ int main()
+ {
+   _Decimal32 d1;
+@@ -15627,7 +15631,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+   # unnecessary for this test.
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15630 "configure"
++#line 15634 "configure"
+ template<typename T1, typename T2>
+   struct same
+   { typedef T2 type; };
+@@ -15661,7 +15665,7 @@ $as_echo "$enable_int128" >&6; }
+     rm -f conftest*
+ 
+     cat > conftest.$ac_ext << EOF
+-#line 15664 "configure"
++#line 15668 "configure"
+ template<typename T1, typename T2>
+   struct same
+   { typedef T2 type; };
+@@ -81674,6 +81678,19 @@ fi
+   { $as_echo "$as_me:${as_lineno-$LINENO}: result: $version_specific_libs" >&5
+ $as_echo "$version_specific_libs" >&6; }
+ 
++# Check whether --with-toolexeclibdir was given.
++if test "${with_toolexeclibdir+set}" = set; then :
++  withval=$with_toolexeclibdir; case ${with_toolexeclibdir} in
++  /)
++    ;;
++  */)
++    with_toolexeclibdir=`echo $with_toolexeclibdir | sed 's,/$,,'`
++    ;;
++esac
++else
++  with_toolexeclibdir=no
++fi
++
+   # Default case for install directory for include files.
+   if test $version_specific_libs = no && test $gxx_include_dir = no; then
+     gxx_include_dir='include/c++/${gcc_version}'
+@@ -81704,7 +81721,14 @@ $as_echo "$version_specific_libs" >&6; }
+     if test -n "$with_cross_host" &&
+        test x"$with_cross_host" != x"no"; then
+       glibcxx_toolexecdir='${exec_prefix}/${host_alias}'
+-      glibcxx_toolexeclibdir='${toolexecdir}/lib'
++      case ${with_toolexeclibdir} in
++	no)
++	  glibcxx_toolexeclibdir='${toolexecdir}/lib'
++	  ;;
++	*)
++	  glibcxx_toolexeclibdir=${with_toolexeclibdir}
++	  ;;
++      esac
+     else
+       glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
+       glibcxx_toolexeclibdir='${libdir}'
+diff --git a/libstdc++-v3/doc/Makefile.in b/libstdc++-v3/doc/Makefile.in
+index c98c42fce98..c61f0dc1aa0 100644
+--- a/libstdc++-v3/doc/Makefile.in
++++ b/libstdc++-v3/doc/Makefile.in
+@@ -69,6 +69,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in
+index 980cabb80e2..e57652bbda0 100644
+--- a/libstdc++-v3/include/Makefile.in
++++ b/libstdc++-v3/include/Makefile.in
+@@ -69,6 +69,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/libsupc++/Makefile.in b/libstdc++-v3/libsupc++/Makefile.in
+index 7386771d475..c0296d0a342 100644
+--- a/libstdc++-v3/libsupc++/Makefile.in
++++ b/libstdc++-v3/libsupc++/Makefile.in
+@@ -71,6 +71,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/po/Makefile.in b/libstdc++-v3/po/Makefile.in
+index d92d8b8ac6a..1166a4f55d1 100644
+--- a/libstdc++-v3/po/Makefile.in
++++ b/libstdc++-v3/po/Makefile.in
+@@ -69,6 +69,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/python/Makefile.in b/libstdc++-v3/python/Makefile.in
+index df8285226fa..188a3ab1a5d 100644
+--- a/libstdc++-v3/python/Makefile.in
++++ b/libstdc++-v3/python/Makefile.in
+@@ -70,6 +70,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
+index f0755f015a1..b168f992be8 100644
+--- a/libstdc++-v3/src/Makefile.in
++++ b/libstdc++-v3/src/Makefile.in
+@@ -70,6 +70,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/src/c++11/Makefile.in b/libstdc++-v3/src/c++11/Makefile.in
+index 73852e75c25..8dff9e75ab6 100644
+--- a/libstdc++-v3/src/c++11/Makefile.in
++++ b/libstdc++-v3/src/c++11/Makefile.in
+@@ -70,6 +70,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/src/c++17/Makefile.in b/libstdc++-v3/src/c++17/Makefile.in
+index 26a4713831d..07a88759fb2 100644
+--- a/libstdc++-v3/src/c++17/Makefile.in
++++ b/libstdc++-v3/src/c++17/Makefile.in
+@@ -105,6 +105,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/src/c++98/Makefile.in b/libstdc++-v3/src/c++98/Makefile.in
+index c0a55171935..1e168815777 100644
+--- a/libstdc++-v3/src/c++98/Makefile.in
++++ b/libstdc++-v3/src/c++98/Makefile.in
+@@ -70,6 +70,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/src/filesystem/Makefile.in b/libstdc++-v3/src/filesystem/Makefile.in
+index 3312d0306ca..bf32707c781 100644
+--- a/libstdc++-v3/src/filesystem/Makefile.in
++++ b/libstdc++-v3/src/filesystem/Makefile.in
+@@ -70,6 +70,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+diff --git a/libstdc++-v3/testsuite/Makefile.in b/libstdc++-v3/testsuite/Makefile.in
+index 5797a55b728..61cd1317a16 100644
+--- a/libstdc++-v3/testsuite/Makefile.in
++++ b/libstdc++-v3/testsuite/Makefile.in
+@@ -69,6 +69,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ 	$(top_srcdir)/../config/no-executables.m4 \
+ 	$(top_srcdir)/../config/override.m4 \
+ 	$(top_srcdir)/../config/stdint.m4 \
++	$(top_srcdir)/../config/toolexeclibdir.m4 \
+ 	$(top_srcdir)/../config/unwind_ipinfo.m4 \
+ 	$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ 	$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+-- 
+2.24.0
+
-- 
2.24.0