From febfac59d0e8a864370d0b4018b4e497ceec156d Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 29 Mar 2013 09:10:06 +0400
Subject: [PATCH] 64-bit multilib hack

GCC has internal multilib handling code but it assumes a very specific rigid directory
layout. The build system implementation of multilib layout is very generic and allows
complete customisation of the library directories.

This patch is a partial solution to allow any custom directories to be passed into gcc
and handled correctly. It forces gcc to use the base_libdir (which is the current
directory, "."). We need to do this for each multilib that is configured as we don't
know which compiler options may be being passed into the compiler. Since we have a compiler
per mulitlib at this point that isn't an issue.

The one problem is the target compiler is only going to work for the default multlilib at
this point. Ideally we'd figure out which multilibs were being enabled with which paths
and be able to patch these entries with a complete set of correct paths but this we
don't have such code at this point. This is something the target gcc recipe should do
and override these platform defaults in its build config.

Do same for riscv64, aarch64 & arc

RP 15/8/11

Upstream-Status: Inappropriate [OE-Specific]

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Elvis Dowson <elvis.dowson@gmail.com>
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Zang Ruochen <zangruochen@loongson.cn>
---
 gcc/config/aarch64/t-aarch64-linux |  8 ++++----
 gcc/config/arc/t-multilib-linux    |  4 ++--
 gcc/config/i386/t-linux64          |  6 ++----
 gcc/config/mips/t-linux64          | 28 ++--------------------------
 gcc/config/riscv/t-linux           |  4 ++--
 gcc/config/rs6000/t-linux64        |  5 ++---
 gcc/config/loongarch/t-linux       | 34 ++++++++++++++++++----------------
 7 files changed, 32 insertions(+), 57 deletions(-)

diff --git a/gcc/config/aarch64/t-aarch64-linux b/gcc/config/aarch64/t-aarch64-linux
index 57bf4100fcd..aaef5da8059 100644
--- a/gcc/config/aarch64/t-aarch64-linux
+++ b/gcc/config/aarch64/t-aarch64-linux
@@ -21,8 +21,8 @@
 LIB1ASMSRC   = aarch64/lib1funcs.asm
 LIB1ASMFUNCS = _aarch64_sync_cache_range
 
-AARCH_BE = $(if $(findstring TARGET_BIG_ENDIAN_DEFAULT=1, $(tm_defines)),_be)
-MULTILIB_OSDIRNAMES = mabi.lp64=../lib64$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu)
-MULTIARCH_DIRNAME = $(call if_multiarch,aarch64$(AARCH_BE)-linux-gnu)
+#AARCH_BE = $(if $(findstring TARGET_BIG_ENDIAN_DEFAULT=1, $(tm_defines)),_be)
+#MULTILIB_OSDIRNAMES = mabi.lp64=../lib64$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu)
+#MULTIARCH_DIRNAME = $(call if_multiarch,aarch64$(AARCH_BE)-linux-gnu)
 
-MULTILIB_OSDIRNAMES += mabi.ilp32=../libilp32$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu_ilp32)
+#MULTILIB_OSDIRNAMES += mabi.ilp32=../libilp32$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu_ilp32)
diff --git a/gcc/config/arc/t-multilib-linux b/gcc/config/arc/t-multilib-linux
index a839e4ea67c..f92664573a9 100644
--- a/gcc/config/arc/t-multilib-linux
+++ b/gcc/config/arc/t-multilib-linux
@@ -16,9 +16,9 @@
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-MULTILIB_OPTIONS = mcpu=hs/mcpu=archs/mcpu=hs38/mcpu=hs38_linux/mcpu=arc700/mcpu=nps400
+#MULTILIB_OPTIONS = mcpu=hs/mcpu=archs/mcpu=hs38/mcpu=hs38_linux/mcpu=arc700/mcpu=nps400
 
-MULTILIB_DIRNAMES = hs archs hs38 hs38_linux arc700 nps400
+#MULTILIB_DIRNAMES = hs archs hs38 hs38_linux arc700 nps400
 
 # Aliases:
 MULTILIB_MATCHES += mcpu?arc700=mA7
diff --git a/gcc/config/i386/t-linux64 b/gcc/config/i386/t-linux64
index 138956b0962..d6e0cdc4342 100644
--- a/gcc/config/i386/t-linux64
+++ b/gcc/config/i386/t-linux64
@@ -32,7 +32,5 @@
 #
 comma=,
 MULTILIB_OPTIONS    = $(subst $(comma),/,$(TM_MULTILIB_CONFIG))
-MULTILIB_DIRNAMES   = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS)))
-MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-linux-gnu)
-MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-linux-gnu)
-MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-linux-gnux32)
+MULTILIB_DIRNAMES = . .
+MULTILIB_OSDIRNAMES = ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir))
diff --git a/gcc/config/mips/t-linux64 b/gcc/config/mips/t-linux64
index 176091cabb6..8258ef40559 100644
--- a/gcc/config/mips/t-linux64
+++ b/gcc/config/mips/t-linux64
@@ -17,29 +17,5 @@
 # <http://www.gnu.org/licenses/>.
 
 MULTILIB_OPTIONS = mabi=n32/mabi=32/mabi=64
-MULTILIB_DIRNAMES = n32 32 64
-MIPS_EL = $(if $(filter %el, $(firstword $(subst -, ,$(target)))),el)
-MIPS_SOFT = $(if $(strip $(filter MASK_SOFT_FLOAT_ABI, $(target_cpu_default)) $(filter soft, $(with_float))),soft)
-ifeq (yes,$(enable_multiarch))
-  ifneq (,$(findstring gnuabi64,$(target)))
-    MULTILIB_OSDIRNAMES = \
-	../lib32$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabin32$(MIPS_SOFT)) \
-	../libo32$(call if_multiarch,:mips$(MIPS_EL)-linux-gnu$(MIPS_SOFT)) \
-	../lib$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabi64$(MIPS_SOFT))
-  else ifneq (,$(findstring gnuabin32,$(target)))
-    MULTILIB_OSDIRNAMES = \
-	../lib$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabin32$(MIPS_SOFT)) \
-	../libo32$(call if_multiarch,:mips$(MIPS_EL)-linux-gnu$(MIPS_SOFT)) \
-	../lib64$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabi64$(MIPS_SOFT))
-  else
-    MULTILIB_OSDIRNAMES = \
-	../lib32$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabin32$(MIPS_SOFT)) \
-	../lib$(call if_multiarch,:mips$(MIPS_EL)-linux-gnu$(MIPS_SOFT)) \
-	../lib64$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabi64$(MIPS_SOFT))
-  endif
-else
-  MULTILIB_OSDIRNAMES = \
-	../lib32$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabin32$(MIPS_SOFT)) \
-	../lib$(call if_multiarch,:mips$(MIPS_EL)-linux-gnu$(MIPS_SOFT)) \
-	../lib64$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabi64$(MIPS_SOFT))
-endif
+MULTILIB_DIRNAMES = . . .
+MULTILIB_OSDIRNAMES = ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir))
diff --git a/gcc/config/riscv/t-linux b/gcc/config/riscv/t-linux
index 216d2776a18..e3c520f4bf6 100644
--- a/gcc/config/riscv/t-linux
+++ b/gcc/config/riscv/t-linux
@@ -1,3 +1,3 @@
 # Only XLEN and ABI affect Linux multilib dir names, e.g. /lib32/ilp32d/
-MULTILIB_DIRNAMES := $(patsubst rv32%,lib32,$(patsubst rv64%,lib64,$(MULTILIB_DIRNAMES)))
-MULTILIB_OSDIRNAMES := $(patsubst lib%,../lib%,$(MULTILIB_DIRNAMES))
+#MULTILIB_DIRNAMES := $(patsubst rv32%,lib32,$(patsubst rv64%,lib64,$(MULTILIB_DIRNAMES)))
+#MULTILIB_OSDIRNAMES := $(patsubst lib%,../lib%,$(MULTILIB_DIRNAMES))
diff --git a/gcc/config/rs6000/t-linux64 b/gcc/config/rs6000/t-linux64
index 01a94242308..1429eceaebf 100644
--- a/gcc/config/rs6000/t-linux64
+++ b/gcc/config/rs6000/t-linux64
@@ -26,10 +26,9 @@
 # MULTILIB_OSDIRNAMES according to what is found on the target.
 
 MULTILIB_OPTIONS    := m64/m32
-MULTILIB_DIRNAMES   := 64 32
+MULTILIB_DIRNAMES   := . .
 MULTILIB_EXTRA_OPTS := 
-MULTILIB_OSDIRNAMES := m64=../lib64$(call if_multiarch,:powerpc64-linux-gnu)
-MULTILIB_OSDIRNAMES += m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:powerpc-linux-gnu)
+MULTILIB_OSDIRNAMES := ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir))
 
 rs6000-linux.o: $(srcdir)/config/rs6000/rs6000-linux.cc
 	$(COMPILE) $<
diff --git a/gcc/config/loongarch/t-linux b/gcc/config/loongarch/t-linux
index e40da1792..0c7ec9f8a 100644
--- a/gcc/config/loongarch/t-linux
+++ b/gcc/config/loongarch/t-linux
@@ -18,7 +18,9 @@

 # Multilib
 MULTILIB_OPTIONS = mabi=lp64d/mabi=lp64f/mabi=lp64s
-MULTILIB_DIRNAMES = base/lp64d base/lp64f base/lp64s
+#MULTILIB_DIRNAMES = base/lp64d base/lp64f base/lp64s
+MULTILIB_DIRNAMES = . . .
+MULTILIB_OSDIRNAMES = ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir)) ../$(shell basename $(base_libdir))

 # The GCC driver always gets all abi-related options on the command line.
 # (see loongarch-driver.c:driver_get_normalized_m_opts)
@@ -36,18 +38,18 @@ else
 endif

 # Don't define MULTILIB_OSDIRNAMES if multilib is disabled.
-ifeq ($(filter LA_DISABLE_MULTILIB,$(tm_defines)),)
-
-    MULTILIB_OSDIRNAMES = \
-      mabi.lp64d=../lib64$\
-      $(call if_multiarch,:loongarch64-linux-gnu)
-
-    MULTILIB_OSDIRNAMES += \
-      mabi.lp64f=../lib64/f32$\
-      $(call if_multiarch,:loongarch64-linux-gnuf32)
-
-    MULTILIB_OSDIRNAMES += \
-      mabi.lp64s=../lib64/sf$\
-      $(call if_multiarch,:loongarch64-linux-gnusf)
-
-endif
+#ifeq ($(filter LA_DISABLE_MULTILIB,$(tm_defines)),)
+#
+#    MULTILIB_OSDIRNAMES = \
+#      mabi.lp64d=../lib64$\
+#      $(call if_multiarch,:loongarch64-linux-gnu)
+#
+#    MULTILIB_OSDIRNAMES += \
+#      mabi.lp64f=../lib64/f32$\
+#      $(call if_multiarch,:loongarch64-linux-gnuf32)
+#
+#    MULTILIB_OSDIRNAMES += \
+#      mabi.lp64s=../lib64/sf$\
+#      $(call if_multiarch,:loongarch64-linux-gnusf)
+#
+#endif

