public inbox for crossgcc@sourceware.org
 help / color / mirror / Atom feed
* simple multilib option
@ 2011-11-11 15:45 Konrad Eisele
  2011-11-12 16:26 ` Yann E. MORIN
  0 siblings, 1 reply; 13+ messages in thread
From: Konrad Eisele @ 2011-11-11 15:45 UTC (permalink / raw)
  To: crossgcc; +Cc: yann.morin.1998

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

Appended is a patch that adds simple glibc multilib capability.

 scripts/build/libc/glibc-eglibc.sh-common
  main part: do_libc_backend_multilib():
   calls "do_libc_backend" multilib-times with 2 options
   extra_dir="/${dir}" extra_flags="${flags}"
   at the end do_libc_backend_rearrange is called to rearange
   the sysroot directories.
 config/cc/gcc.in.2
   Add CC_MULTILIB option
 patches/gcc/4.6.0/200-sparc-leon.patch
   Multilibbed sparc-leon compile. The multilibbed gcc is
   compiled with Vendor set to "leon3"
 patches/glibc/2.14/400-sparc-leon.patch
   Some fixes to get glibc-2.14 compiled with soft-float
 patches/glibc/2.14/401-s_fma_f.patch
   Some fixes to get glibc-2.14 compiled with soft-float
 scripts/build/binutils/binutils.sh
   add multilib
 scripts/build/cc/gcc.sh
   add multilib

-- Konrad

[-- Attachment #2: multilib.patch --]
[-- Type: text/x-patch, Size: 21718 bytes --]

From 4852e498b05e4c68f8a2170939a0572bdd45cd6b Mon Sep 17 00:00:00 2001
From: Konrad Eisele <konrad@gaisler.com>
Date: Thu, 10 Nov 2011 15:01:45 +0100
Subject: [PATCH] add multilib option

---

diff --git a/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common b/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common
index 2af3a9a..3218656 100644
--- a/scripts/build/libc/glibc-eglibc.sh-common
+++ b/scripts/build/libc/glibc-eglibc.sh-common
@@ -57,18 +57,99 @@ do_libc_extract() {
 do_libc_start_files() {
     # Start files and Headers should be configured the same way as the
     # final libc, but built and installed differently.
-    do_libc_backend libc_mode=startfiles
+    do_libc_backend_multilib libc_mode=startfiles
 }
 
 # This function builds and install the full C library
 do_libc() {
-    do_libc_backend libc_mode=final
+    do_libc_backend_multilib libc_mode=final
 }
 
+# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
+# to reflect the runtime setting.
+do_libc_backend_rearrange() {
+
+    local libc_mode=final
+    
+    while [ $# -ne 0 ]; do
+        eval "${1// /\\ }"
+        shift
+    done
+    
+    if [ "${libc_mode}" = "final" ]; then
+        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+            dir=`echo $i | sed -e 's/;.*$//'`; 
+           bdir=`echo ${dir} | sed -e 's/\//\\\\\//g'`
+           if [ "${dir}" = "." ]; then 
+               true; 
+           else 
+               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
+               CT_DoStep INFO "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
+               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
+               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
+           
+               # recreate the symbolic links for multilib 
+               find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1 > ${CT_SYSROOT_DIR}/usr/lib/${dir}/links
+               for f in `cat ${CT_SYSROOT_DIR}/usr/lib/${dir}/links`; do
+                   fn=`basename $f`
+                   ln=`readlink $f`
+                   ln=`basename $ln`
+                   pre=`echo ${dir} | awk '{r="";c=split($0,b,"/");for(i=0;i<c;i++){if(i!=0){r=r "/";}r=r "..";}; printf("%s",r); }'`
+                   (cd ${CT_SYSROOT_DIR}/usr/lib/${dir}/; ln -sf ../../${pre}/lib/${dir}/$ln $fn)
+               done
+
+                # rewrite the library multiplexers
+               for l in libc libpthread libgcc_s; do
+                   for d in lib/${dir} usr/lib/${dir}; do
+                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
+                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
+                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
+                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | sed -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
+                           fi
+                       fi
+                   done
+               done
+               CT_EndStep
+           fi
+        done;
+    fi
+}
+
+# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
+do_libc_backend_multilib() {
+    local flags=""; local i; local dir;
+    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+    if [ "${CT_CC_MULTILIB}" = "y" ]; then
+       CT_DoStep INFO "C Library with multilib"
+       CT_DoStep INFO "C Library with multilib. Flags: \"\" Dir: \"\""
+       # first create <non-multilib> to create ${CT_HEADERS_DIR} dir
+       do_libc_backend "$@"
+       CT_EndStep
+       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir=`echo $i | sed -e 's/;.*$//'`; 
+           if [ "${dir}" = "." ]; then 
+               true; 
+           else 
+               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
+               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
+               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}" 
+               CT_EndStep
+           fi
+       done;
+       do_libc_backend_rearrange
+       CT_EndStep
+    else
+       do_libc_backend "$@"
+    fi
+}		       
+
 do_libc_backend() {
     local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
     local libc_mode=final
     local extra_cc_args
+    local extra_dir=""; local extra_dir_p;
+    local extra_flags=""
     local -a extra_config
     local -a extra_make_args
     local glibc_cflags
@@ -77,15 +158,16 @@ do_libc_backend() {
         eval "${1// /\\ }"
         shift
     done
-
+    extra_dir_p=`echo ${extra_dir} | sed -e 's/\///g'`
+	
     if [ "${libc_mode}" = "startfiles" ]; then
         CT_DoStep INFO "Installing C library headers & start files"
-        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
-        cd "${CT_BUILD_DIR}/build-libc-start-files"
+        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
     else # libc_mode = final
         CT_DoStep INFO "Installing C library"
-        mkdir -p "${CT_BUILD_DIR}/build-libc"
-        cd "${CT_BUILD_DIR}/build-libc"
+        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
     fi
 
     CT_DoLog EXTRA "Configuring C library"
@@ -133,7 +215,13 @@ do_libc_backend() {
     esac
 
     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
-        y,) extra_config+=("--with-fp");;
+        y,) # if it is a <multilib> build then check if -msoft-float is given
+	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
+	    	extra_config+=("--with-fp=no");
+	    else
+	    	extra_config+=("--with-fp");
+	    fi
+	    ;;
         ,y) extra_config+=("--without-fp");;
     esac
 
@@ -173,7 +261,7 @@ do_libc_backend() {
     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
 
-    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"
+    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE} ${extra_flags}"
     case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
         y)  ;;
         *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
@@ -236,7 +324,7 @@ do_libc_backend() {
         # use the 'install-headers' makefile target to install the
         # headers
         CT_DoExecLog ALL make ${JOBSFLAGS}              \
-                         install_root=${CT_SYSROOT_DIR} \
+                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
                          install-bootstrap-headers=yes  \
                          "${extra_make_args[@]}"        \
                          install-headers
@@ -273,12 +361,12 @@ do_libc_backend() {
 
             # there are a few object files needed to link shared libraries,
             # which we build and install by hand
-            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
+            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
             CT_DoExecLog ALL make ${JOBSFLAGS}  \
                         "${extra_make_args[@]}" \
                         csu/subdir_lib
             CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
-                                "${CT_SYSROOT_DIR}/usr/lib"
+                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
 
             # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
             # However, since we will never actually execute its code,
@@ -288,9 +376,13 @@ do_libc_backend() {
                                            -nostartfiles    \
                                            -shared          \
                                            -x c /dev/null   \
-                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
+                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
         fi # threads == nptl
     else # libc_mode = final
+        CT_DoLog EXTRA "Prepare C library"
+        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
+                              "${extra_make_args[@]}"           \
+                              clean
         CT_DoLog EXTRA "Building C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
@@ -299,7 +391,7 @@ do_libc_backend() {
         CT_DoLog EXTRA "Installing C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
-                              install_root="${CT_SYSROOT_DIR}"  \
+                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
                               install
 
         if [ "${CT_LIBC_LOCALES}" = "y" ]; then
diff --git a/config/cc/gcc.in.2 b/config/cc/gcc.in.2
index 35a1070..8fe3a2e 100644
--- a/config/cc/gcc.in.2
+++ b/config/cc/gcc.in.2
@@ -1,4 +1,10 @@
 # gcc configuration options
+config CC_MULTILIB
+    bool
+    prompt "enable multilib"
+    default n
+    help
+      Enable multilib build of libc
 
 config CC_ENABLE_CXX_FLAGS
     string
@@ -11,6 +17,7 @@ config CC_ENABLE_CXX_FLAGS
       Note: just pass in the option _value_, that is only the part that goes
       after the '=' sign.
 
+      
 config CC_CORE_EXTRA_CONFIG_ARRAY
     string
     prompt "Core gcc extra config"
diff --git a/patches/gcc/4.6.0/200-sparc-leon.patch b/patches/gcc/4.6.0/200-sparc-leon.patch
index 5a92838..1d97105 100644
--- a/patches/gcc/4.6.0/200-sparc-leon.patch
+++ b/patches/gcc/4.6.0/200-sparc-leon.patch
@@ -105,10 +105,10 @@ index 1c2ba93..5aadff6 100644
      { TARGET_CPU_ultrasparc3, "ultrasparc3" },
      { TARGET_CPU_niagara, "niagara" },
      { TARGET_CPU_niagara2, "niagara2" },
-+    { TARGET_CPU_sparchfleon, "sparchfleon" },
-+    { TARGET_CPU_sparchfleonv8, "sparchfleonv8" },
-+    { TARGET_CPU_sparcsfleon, "sparcsfleon" },
-+    { TARGET_CPU_sparcsfleonv8, "sparcsfleonv8" },
++    { TARGET_CPU_sparchfleon, "hfleon" },
++    { TARGET_CPU_sparchfleonv8, "hfleonv8" },
++    { TARGET_CPU_sparcsfleon, "sfleon" },
++    { TARGET_CPU_sparcsfleonv8, "sfleonv8" },
      { 0, 0 }
    };
    const struct cpu_default *def;
@@ -119,10 +119,10 @@ index 1c2ba93..5aadff6 100644
 -    { "leon",       PROCESSOR_LEON, MASK_ISA, MASK_V8|MASK_FPU },
 +    { "leon",       PROCESSOR_LEON, MASK_ISA, MASK_FPU },
      { "sparclite",  PROCESSOR_SPARCLITE, MASK_ISA, MASK_SPARCLITE },
-+    { "sparchfleon",   PROCESSOR_LEON, MASK_ISA, MASK_FPU },
-+    { "sparchfleonv8", PROCESSOR_LEON, MASK_ISA & ~(MASK_V8), MASK_V8|MASK_FPU },
-+    { "sparcsfleon",   PROCESSOR_LEON, MASK_ISA | MASK_FPU, 0 },
-+    { "sparcsfleonv8", PROCESSOR_LEON, (MASK_ISA | MASK_FPU) & ~(MASK_V8), MASK_V8 },
++    { "hfleon",   PROCESSOR_LEON, MASK_ISA, MASK_FPU },
++    { "hfleonv8", PROCESSOR_LEON, MASK_ISA & ~(MASK_V8), MASK_V8|MASK_FPU },
++    { "sfleon",   PROCESSOR_LEON, MASK_ISA | MASK_FPU, 0 },
++    { "sfleonv8", PROCESSOR_LEON, (MASK_ISA | MASK_FPU) & ~(MASK_V8), MASK_V8 },
      /* The Fujitsu MB86930 is the original sparclite chip, with no FPU.  */
      { "f930",       PROCESSOR_F930, MASK_ISA|MASK_FPU, MASK_SPARCLITE },
      /* The Fujitsu MB86934 is the recent sparclite chip, with an FPU.  */
@@ -197,10 +197,10 @@ index 297844f..5e28646 100644
  %{mcpu=ultrasparc3:-D__sparc_v9__} \
  %{mcpu=niagara:-D__sparc_v9__} \
  %{mcpu=niagara2:-D__sparc_v9__} \
-+%{mcpu=sparchfleon:-D__leon__} \
-+%{mcpu=sparchfleonv8:-D__leon__ -D__sparc_v8__} \
-+%{mcpu=sparcsfleon:-D__leon__ -D_SOFT_FLOAT} \
-+%{mcpu=sparcsfleonv8:-D__leon__ -D_SOFT_FLOAT -D__sparc_v8__} \
++%{mcpu=hfleon:-D__leon__} \
++%{mcpu=hfleonv8:-D__leon__ -D__sparc_v8__} \
++%{mcpu=sfleon:-D__leon__ -D_SOFT_FLOAT} \
++%{mcpu=sfleonv8:-D__leon__ -D_SOFT_FLOAT -D__sparc_v8__} \
  %{!mcpu*:%(cpp_cpu_default)} \
  "
  #define CPP_ARCH32_SPEC ""
@@ -209,10 +209,10 @@ index 297844f..5e28646 100644
  %{mcpu=f930:-Asparclite} %{mcpu=f934:-Asparclite} \
  %{mv8plus:-Av8plus} \
 +%{mcpu=leon:-Aleon} \
-+%{mcpu=sparchfleon:-Aleon} \
-+%{mcpu=sparchfleonv8:-Aleon} \
-+%{mcpu=sparcsfleon:-Aleon} \
-+%{mcpu=sparcsfleonv8:-Aleon} \
++%{mcpu=hfleon:-Aleon} \
++%{mcpu=hfleonv8:-Aleon} \
++%{mcpu=sfleon:-Aleon} \
++%{mcpu=sfleonv8:-Aleon} \
  %{mcpu=v9:-Av9} \
  %{mcpu=ultrasparc:%{!mv8plus:-Av9a}} \
  %{mcpu=ultrasparc3:%{!mv8plus:-Av9b}} \
diff --git a/patches/glibc/2.14/400-sparc-leon.patch b/patches/glibc/2.14/400-sparc-leon.patch
new file mode 100644
index 0000000..dcf8219
--- /dev/null
+++ b/patches/glibc/2.14/400-sparc-leon.patch
@@ -0,0 +1,85 @@
+diff -Naur glibc-2.14.ori/math/math.h glibc-2.14.p2/math/math.h
+--- glibc-2.14.ori/math/math.h	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/math/math.h	2011-11-10 17:03:08.000000000 +0100
+@@ -396,7 +396,7 @@
+ # define __NO_MATH_INLINES	1
+ #endif
+ 
+-#if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
++#if (!(defined(__sparc__) &&  defined(_SOFT_FLOAT))) && defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
+ /* ISO C99 defines some macros to compare number while taking care for
+    unordered numbers.  Many FPUs provide special instructions to support
+    these operations.  Generic support in GCC for these as builtins went
+diff -Naur glibc-2.14.ori/sysdeps/sparc/fpu/bits/mathinline.h glibc-2.14.p2/sysdeps/sparc/fpu/bits/mathinline.h
+--- glibc-2.14.ori/sysdeps/sparc/fpu/bits/mathinline.h	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/fpu/bits/mathinline.h	2011-11-10 17:03:35.000000000 +0100
+@@ -232,6 +232,9 @@
+ 
+ /* This code is used internally in the GNU libc.  */
+ #  ifdef __LIBC_INTERNAL_MATH_INLINES
++
++#ifndef _SOFT_FLOAT
++
+ __MATH_INLINE double
+ __ieee754_sqrt (double __x)
+ {
+@@ -248,6 +251,8 @@
+   return __r;
+ }
+ 
++#endif
++
+ #   if __WORDSIZE == 64
+ __MATH_INLINE long double
+ __ieee754_sqrtl (long double __x)
+diff -Naur glibc-2.14.ori/sysdeps/sparc/fpu/fraiseexcpt.c glibc-2.14.p2/sysdeps/sparc/fpu/fraiseexcpt.c
+--- glibc-2.14.ori/sysdeps/sparc/fpu/fraiseexcpt.c	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/fpu/fraiseexcpt.c	2011-11-10 17:03:58.000000000 +0100
+@@ -32,6 +32,10 @@
+   };
+   double d;
+ 
++#ifdef _SOFT_FLOAT
++#define __asm(...)
++#endif
++  
+   /* Raise exceptions represented by EXPECTS.  But we must raise only
+      one signal at a time.  It is important the if the overflow/underflow
+      exception and the inexact exception are given at the same time,
+diff -Naur glibc-2.14.ori/sysdeps/sparc/sparc32/Makefile glibc-2.14.p2/sysdeps/sparc/sparc32/Makefile
+--- glibc-2.14.ori/sysdeps/sparc/sparc32/Makefile	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/sparc32/Makefile	2011-11-10 17:04:56.000000000 +0100
+@@ -24,6 +24,11 @@
+ CFLAGS-initfini.s += -mcpu=v7
+ endif
+ 
++ifeq ($(with-fp),no)
+++cflags += -msoft-float -D_SOFT_FLOAT
++sysdep-LDFLAGS += -msoft-float
++endif
++
+ # We distribute these files, even though they are generated,
+ # so as to avoid the need for a functioning m4 to build the library.
+ divrem := sdiv udiv rem urem
+diff -Naur glibc-2.14.ori/sysdeps/sparc/sparc32/e_sqrt.c glibc-2.14.p2/sysdeps/sparc/sparc32/e_sqrt.c
+--- glibc-2.14.ori/sysdeps/sparc/sparc32/e_sqrt.c	2011-05-31 06:12:33.000000000 +0200
++++ glibc-2.14.p2/sysdeps/sparc/sparc32/e_sqrt.c	2011-11-10 17:04:24.000000000 +0100
+@@ -23,6 +23,8 @@
+   #error This file uses GNU C extensions; you must compile with GCC.
+ #endif
+ 
++#ifndef _SOFT_FLOAT
++
+ /* Return the square root of X.  */
+ double
+ __ieee754_sqrt (x)
+@@ -32,3 +34,9 @@
+   asm ("fsqrtd %1, %0" : "=f" (result) : "f" (x));
+   return result;
+ }
++#else 
++
++#include <sysdeps/ieee754/dbl-64/e_sqrt.c>
++
++#endif
++
diff --git a/patches/glibc/2.14/401-s_fma_f.patch b/patches/glibc/2.14/401-s_fma_f.patch
new file mode 100644
index 0000000..071dd9c
--- /dev/null
+++ b/patches/glibc/2.14/401-s_fma_f.patch
@@ -0,0 +1,52 @@
+diff -Naur glibc-2.14.base/sysdeps/ieee754/dbl-64/s_fmaf.c glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c
+--- glibc-2.14.base/sysdeps/ieee754/dbl-64/s_fmaf.c	2011-11-11 09:48:40.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/dbl-64/s_fmaf.c	2011-11-11 10:03:51.000000000 +0100
+@@ -18,6 +18,10 @@
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+ 
++#ifdef _SOFT_FLOAT
++#include <math/s_fmaf.c>
++#else
++
+ #include <math.h>
+ #include <fenv.h>
+ #include <ieee754.h>
+@@ -48,3 +52,4 @@
+ #ifndef __fmaf
+ weak_alias (__fmaf, fmaf)
+ #endif
++#endif
+diff -Naur glibc-2.14.base/sysdeps/ieee754/ldbl-opt/s_fma.c glibc-2.14/sysdeps/ieee754/ldbl-opt/s_fma.c
+--- glibc-2.14.base/sysdeps/ieee754/ldbl-opt/s_fma.c	2011-11-11 09:48:40.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/ldbl-opt/s_fma.c	2011-11-11 10:00:13.000000000 +0100
+@@ -1,5 +1,9 @@
+ #include <math_ldbl_opt.h>
++#ifdef _SOFT_FLOAT
++#include <math/s_fma.c>
++#else
+ #include <sysdeps/ieee754/dbl-64/s_fma.c>
++#endif
+ #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
+ compat_symbol (libm, __fma, fmal, GLIBC_2_1);
+ #endif
+diff -Naur glibc-2.14.ori/sysdeps/ieee754/ldbl-128/s_fmal.c glibc-2.14/sysdeps/ieee754/ldbl-128/s_fmal.c
+--- glibc-2.14.ori/sysdeps/ieee754/ldbl-128/s_fmal.c    2011-11-11 11:03:30.000000000 +0100
++++ glibc-2.14/sysdeps/ieee754/ldbl-128/s_fmal.c        2011-11-11 11:07:32.000000000 +0100
+@@ -18,6 +18,10 @@
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+
++#ifdef _SOFT_FLOAT
++#include <math/s_fmal.c>
++#else
++
+ #include <float.h>
+ #include <math.h>
+ #include <fenv.h>
+@@ -221,3 +225,5 @@
+     }
+ }
+ weak_alias (__fmal, fmal)
++
++#endif
diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh
index e082590..7969b13 100644
--- a/scripts/build/binutils/binutils.sh
+++ b/scripts/build/binutils/binutils.sh
@@ -60,6 +60,12 @@ do_binutils() {
         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
     fi
 
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+    
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
     CT_DoExecLog CFG                                            \
@@ -71,7 +77,6 @@ do_binutils() {
         --target=${CT_TARGET}                                   \
         --prefix=${CT_PREFIX_DIR}                               \
         --disable-nls                                           \
-        --disable-multilib                                      \
         --disable-werror                                        \
         "${extra_config[@]}"                                    \
         ${CT_ARCH_WITH_FLOAT}                                   \
@@ -151,7 +156,13 @@ do_binutils_target() {
             extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
             [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
         fi
-
+	
+	if [ "${CT_CC_MULTILIB}" = "n" ]; then
+            extra_config+=("--disable-multilib")
+	else
+            extra_config+=("--enable-multilib")
+	fi
+    
         CT_DoExecLog CFG                                            \
         "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
             --build=${CT_BUILD}                                     \
@@ -162,7 +173,6 @@ do_binutils_target() {
             --enable-shared                                         \
             --enable-static                                         \
             --disable-nls                                           \
-            --disable-multilib                                      \
             "${extra_config[@]}"                                    \
             ${CT_ARCH_WITH_FLOAT}                                   \
             "${CT_BINUTILS_EXTRA_CONFIG[@]}"
diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh
index 05df729..e496803 100644
--- a/scripts/build/cc/gcc.sh
+++ b/scripts/build/cc/gcc.sh
@@ -288,6 +288,12 @@ do_cc_core() {
     extra_config+=(--disable-libgomp)
     extra_config+=(--disable-libmudflap)
 
+   if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+     
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
@@ -301,7 +307,6 @@ do_cc_core() {
         --target=${CT_TARGET}                       \
         --prefix="${core_prefix_dir}"               \
         --with-local-prefix="${CT_SYSROOT_DIR}"     \
-        --disable-multilib                          \
         --disable-libmudflap                        \
         ${CC_CORE_SYSROOT_ARG}                      \
         "${extra_config[@]}"                        \
@@ -424,7 +429,13 @@ do_cc() {
     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
 
     extra_config+=("--enable-languages=${lang_opt}")
-    extra_config+=("--disable-multilib")
+    
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+ 
     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
         eval tmp="\${CT_ARCH_WITH_${tmp}}"
         if [ -n "${tmp}" ]; then
-- 
1.6.5.4



[-- Attachment #3: Type: text/plain, Size: 71 bytes --]

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: simple multilib option
  2011-11-11 15:45 simple multilib option Konrad Eisele
@ 2011-11-12 16:26 ` Yann E. MORIN
  2011-11-14 10:38   ` Konrad Eisele
  0 siblings, 1 reply; 13+ messages in thread
From: Yann E. MORIN @ 2011-11-12 16:26 UTC (permalink / raw)
  To: crossgcc; +Cc: Konrad Eisele

Konrad, All,

On Friday 11 November 2011 16:38:17 Konrad Eisele wrote:
> Appended is a patch that adds simple glibc multilib capability.

Hehe! Very nice!

>  scripts/build/libc/glibc-eglibc.sh-common
>   main part: do_libc_backend_multilib():
>    calls "do_libc_backend" multilib-times with 2 options
>    extra_dir="/${dir}" extra_flags="${flags}"
>    at the end do_libc_backend_rearrange is called to rearange
>    the sysroot directories.
>  config/cc/gcc.in.2
>    Add CC_MULTILIB option
>  patches/gcc/4.6.0/200-sparc-leon.patch
>    Multilibbed sparc-leon compile. The multilibbed gcc is
>    compiled with Vendor set to "leon3"
>  patches/glibc/2.14/400-sparc-leon.patch
>    Some fixes to get glibc-2.14 compiled with soft-float
>  patches/glibc/2.14/401-s_fma_f.patch
>    Some fixes to get glibc-2.14 compiled with soft-float
>  scripts/build/binutils/binutils.sh
>    add multilib
>  scripts/build/cc/gcc.sh
>    add multilib

Next time, could you send in the body rather in attachement, it's easier to
review and comment...

First, the patch addresses different unrelated changes. For example, the
Leon changes should go in a separate patch.

Then, the multi-lib change is huge. I believe it could be split in a few,
smaller incremental patches.

Globally, avoid lines longer than 80 chars. I know there already are some
(very) long lines in the code, but try not to add more...


> diff --git a/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common b/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common
> index 2af3a9a..3218656 100644
> --- a/scripts/build/libc/glibc-eglibc.sh-common
> +++ b/scripts/build/libc/glibc-eglibc.sh-common
> @@ -57,18 +57,99 @@ do_libc_extract() {
> 
>  do_libc_start_files() {
>      # Start files and Headers should be configured the same way as the
>      # final libc, but built and installed differently.
> -    do_libc_backend libc_mode=startfiles
> +    do_libc_backend_multilib libc_mode=startfiles
> 
>  }
>  
>  # This function builds and install the full C library
>  do_libc() {
> -    do_libc_backend libc_mode=final
> +    do_libc_backend_multilib libc_mode=final
>  }
> 
> +# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
> +# to reflect the runtime setting.
> +do_libc_backend_rearrange() {
> +

No empty line at start of function.

> +    local libc_mode=final

No default.
The 'libc_mode' is not optional, so every caller has to pass it.

But are you sure that it makes sense to pass the libc_mode when
calling rearrange?

> +    while [ $# -ne 0 ]; do
> +        eval "${1// /\\ }"
> +        shift
> +    done
> +
> +    if [ "${libc_mode}" = "final" ]; then
> +        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
> +        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
> +            dir=`echo $i | sed -e 's/;.*$//'`;

dir="${i%%;*}"
Also, no trailing semi-column, it's useless in shell scripts
( this is not C! ;-) )

> +           bdir=`echo ${dir} | sed -e 's/\//\\\\\//g'`

Why do you need to double-escape the '/' ?
And for readability:
  sed -e 's:/:\\\\/:g'

Also, use ${sed} for portability reasons (eg. on MacOS-X, this is gsed,
not sed, and this is detected by ./configure).

And then, use the '-r' option to sed:
  ${sed} -r -e 's:/:\\\\/:g'

> +           if [ "${dir}" = "." ]; then
> +               true;
> +           else

if [ "${dir}" != "." ]; then

> +               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
> +               CT_DoStep INFO "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"

It does not belong to the 'INFO' log-level, but rather to 'EXTRA' or even
better yet, to 'DEBUG'.

> +               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
> +               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
> +
> +               # recreate the symbolic links for multilib
> +               find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1 > ${CT_SYSROOT_DIR}/usr/lib/${dir}/links
> +               for f in `cat ${CT_SYSROOT_DIR}/usr/lib/${dir}/links`; do

You could use an array variable, if you really want two lines:
    links=( $(find blabla       \
                   -type l      \
                   -maxdepth 1  ) )
    for f in "${links[@]}"; do

But you could also use a single call:
    for f in $(find blabla      \
                   -type l      \
                   -maxdepth 1  )
    do
        [...]
    done

> +                   fn=`basename $f`
> +                   ln=`readlink $f`
> +                   ln=`basename $ln`
> +                   pre=`echo ${dir} | awk '{r="";c=split($0,b,"/");for(i=0;i<c;i++){if(i!=0){r=r "/";}r=r "..";}; printf("%s",r); }'`

Explain what you're doing here. Basically, you want to turn
    foo/bar
into
    ../..

Also, try to get a shorter line, and use $(...) as everywhere else:
    pre=$( echo ${dir}  \
           |awk '{ r="";
                   c=split($0, b, "/");
                   for( i=0; i<c; i++ ) {
                       if( i!=0 ) {
                           r=r "/";
                       }
                       r = r "..";
                   }
                   printf("%s",r);
                 }' )

> +                   (cd ${CT_SYSROOT_DIR}/usr/lib/${dir}/; ln -sf ../../${pre}/lib/${dir}/$ln $fn)

I'm not fan of having a sub-shell here.
    CT_Pushd "blabla"
    ln -sf blabla blabla
    CT_Popd

> +               done
> +
> +                # rewrite the library multiplexers
> +               for l in libc libpthread libgcc_s; do
> +                   for d in lib/${dir} usr/lib/${dir}; do
> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then

What if the the _ori_i file already exist?
Surely, it should not happen, and if it does, we should consider this
as an error.

> +                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | sed -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
> +                           fi

Transform that whole if..fi into:
    ${sed} -r -i        \
           -e "blabla"  \
           foo.so

> +                       fi
> +                   done
> +               done
> +               CT_EndStep
> +           fi
> +        done;
> +    fi
> +}
> +
> +# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
> +do_libc_backend_multilib() {
> +    local flags=""; local i; local dir;
> +    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
> +    if [ "${CT_CC_MULTILIB}" = "y" ]; then
> +       CT_DoStep INFO "C Library with multilib"
> +       CT_DoStep INFO "C Library with multilib. Flags: \"\" Dir: \"\""

Redundant log line.
Missing flags and dir.

> +       # first create <non-multilib> to create ${CT_HEADERS_DIR} dir
> +       do_libc_backend "$@"
> +       CT_EndStep
> +       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
> +           dir=`echo $i | sed -e 's/;.*$//'`;

dir="${i%%;*}"

> +           if [ "${dir}" = "." ]; then
> +               true;
> +           else

if [ "${dir}" != "." ]; then

> +               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
> +               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
> +               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}"
> +               CT_EndStep
> +           fi
> +       done;
> +       do_libc_backend_rearrange

Missing the libc_mode.

> +       CT_EndStep
> +    else
> +       do_libc_backend "$@"
> +    fi
> +}

This will install headers multiple times, right? Is this expected/wanted?

Also, I'd do something like:

    do_libc_backend_multilib() {
        # We need to call the backend at least once,
        # with all settings set to the defaults
        do_libc_backend "$@"
        if [ "${CT_CC_MULTILIB}" = "y" ]; then
            for i in $( "${cross_cc}" --print-multi-lib 2>/dev/null ); do
                dir="${i%%;*}"
                if [ "${dir}" != "." ]; then
                    flags="${i#*;}"; flags="${flags//@/ -}"
                    CT_DoStep INFO "C Library with multilib. Flags: '${flags}' Dir: '${dir}'"
                    do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}"
                    CT_EndStep
                fi
            done
        fi
    }

>  do_libc_backend() {
>      local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
>      local libc_mode=final
>      local extra_cc_args
> +    local extra_dir=""; local extra_dir_p;

On two lines, no trailing semi-column.

> +    local extra_flags=""
>      local -a extra_config
>      local -a extra_make_args
>      local glibc_cflags
> 
> @@ -77,15 +158,16 @@ do_libc_backend() {
>          eval "${1// /\\ }"
>          shift
>      done
> -
> +    extra_dir_p=`echo ${extra_dir} | sed -e 's/\///g'`

Use $(...) instead of `...`, as everywhere else in the code.
Also, do not forget to quote strings:

    extra_dir_p="$( echo "${extra_dir}" | sed -e 's/\///g' )"

> +
>      if [ "${libc_mode}" = "startfiles" ]; then
>          CT_DoStep INFO "Installing C library headers & start files"
> -        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
> -        cd "${CT_BUILD_DIR}/build-libc-start-files"
> +        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
> +        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
>      else # libc_mode = final
>          CT_DoStep INFO "Installing C library"
> -        mkdir -p "${CT_BUILD_DIR}/build-libc"
> -        cd "${CT_BUILD_DIR}/build-libc"
> +        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
> +        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
>      fi

I would prefer that there is only one 'top-level' build dir. Also, we
could replace this whole fi..else.fi block with a single construct.
Something like:

    mkdir -p "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"
    cd "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"

>      CT_DoLog EXTRA "Configuring C library"
> @@ -133,7 +215,13 @@ do_libc_backend() {
>      esac
>      
>      case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
> -        y,) extra_config+=("--with-fp");;
> +        y,) # if it is a <multilib> build then check if -msoft-float is given
> +           if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
> +               extra_config+=("--with-fp=no");
> +           else
> +               extra_config+=("--with-fp");
> +           fi
> +           ;;
>          ,y) extra_config+=("--without-fp");;
>      esac

The hunk above no longer applies to the tree. The soft/hard float selection
now uses a string, because there might be a bunch of possibilities, not only
'soft' and 'hard', but also 'softfp' now.

[--SNIP--]
> @@ -288,9 +376,13 @@ do_libc_backend() {
>                                             -nostartfiles    \
>                                             -shared          \
>                                             -x c /dev/null   \
> -                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
> +                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
>          fi # threads == nptl
>      else # libc_mode = final
> +        CT_DoLog EXTRA "Prepare C library"
> +        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
> +                              "${extra_make_args[@]}"           \
> +                              clean

Why do you need to clean here?
The build dir should be brand new, as we just mkdir it a few lines above.
In any way, do not reuse any existing dir.

>          CT_DoLog EXTRA "Building C library"
>          CT_DoExecLog ALL make ${JOBSFLAGS}                      \
>                                "${extra_make_args[@]}"           \

[--SNIP--]
> diff --git a/config/cc/gcc.in.2 b/config/cc/gcc.in.2
> index 35a1070..8fe3a2e 100644
> --- a/config/cc/gcc.in.2
> +++ b/config/cc/gcc.in.2
> @@ -1,4 +1,10 @@
>  # gcc configuration options
> +config CC_MULTILIB
> +    bool
> +    prompt "enable multilib"
> +    default n
> +    help
> +      Enable multilib build of libc

We need to find a place where to put that option, but I think the gcc
sub-menu is not the proper place.

Multi-lib is a property of the toolchain, that is implemented by many
components, and gcc is only one of those. binutils also plays a role in
multilib.

So, it makes more sense to put the option in a more global sub-menu, such
as in the toolchain options sub-menu.

>  config CC_ENABLE_CXX_FLAGS
>      string
> @@ -11,6 +17,7 @@ config CC_ENABLE_CXX_FLAGS
>        Note: just pass in the option _value_, that is only the part that
>        goes after the '=' sign.
> 
> +

Spurious empty line.

>  config CC_CORE_EXTRA_CONFIG_ARRAY
>      string
>      prompt "Core gcc extra config"

[--SNIP leon patches--]

> diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh
> index e082590..7969b13 100644
> --- a/scripts/build/binutils/binutils.sh
> +++ b/scripts/build/binutils/binutils.sh
[--SNIP--]
> @@ -151,7 +156,13 @@ do_binutils_target() {
>              extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
>              [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
>          fi
> -
> +

Spurious empty-line change: space damage.

> +       if [ "${CT_CC_MULTILIB}" = "n" ]; then
> +            extra_config+=("--disable-multilib")
> +       else
> +            extra_config+=("--enable-multilib")
> +       fi
> +
>          CT_DoExecLog CFG                                            \
>          "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
>              --build=${CT_BUILD}                                     \
> @@ -162,7 +173,6 @@ do_binutils_target() {
>              --enable-shared                                         \
>              --enable-static                                         \
>              --disable-nls                                           \
> -            --disable-multilib                                      \
>              "${extra_config[@]}"                                    \
>              ${CT_ARCH_WITH_FLOAT}                                   \
>              "${CT_BINUTILS_EXTRA_CONFIG[@]}"

Be careful with binutils for target. It only installs a pair of libraries,
not the whole binutils. So, is it necessary to enable multilib for the
target binutils?

[--SNIP gcc changes (OK)--]

Globally, I am very happy to see this patch coming in!
There are a bunch of issues, but that's expected with such core changes.

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: simple multilib option
  2011-11-12 16:26 ` Yann E. MORIN
@ 2011-11-14 10:38   ` Konrad Eisele
  2011-11-14 10:55     ` [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele
  2011-11-14 23:25     ` simple multilib option Yann E. MORIN
  0 siblings, 2 replies; 13+ messages in thread
From: Konrad Eisele @ 2011-11-14 10:38 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc

I'll send revised patches as reply to this one, in the
meantime here are the comment-comments:

> Next time, could you send in the body rather in attachement, it's easier to
> review and comment...
> 
> First, the patch addresses different unrelated changes. For example, the
> Leon changes should go in a separate patch.
> 

I'll send the Multilib-patches only. I also skip the CC_MULTILIB option definition,
as for you have to decide where to put it.
The gcc-4.6 and glibc sparcleon toolchain patch I'll send some other time in the
future.
To get the multilib patches in would be nice as for without them none
of our toolchains can be built with crosstools.

> 
> 
>> diff --git a/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common b/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-common
>> index 2af3a9a..3218656 100644
>> --- a/scripts/build/libc/glibc-eglibc.sh-common
>> +++ b/scripts/build/libc/glibc-eglibc.sh-common
>> @@ -57,18 +57,99 @@ do_libc_extract() {
>>
>>  do_libc_start_files() {
>>      # Start files and Headers should be configured the same way as the
>>      # final libc, but built and installed differently.
>> -    do_libc_backend libc_mode=startfiles
>> +    do_libc_backend_multilib libc_mode=startfiles
>>
>>  }
>>  
>>  # This function builds and install the full C library
>>  do_libc() {
>> -    do_libc_backend libc_mode=final
>> +    do_libc_backend_multilib libc_mode=final
>>  }
>>
>> +# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
>> +# to reflect the runtime setting.
>> +do_libc_backend_rearrange() {
>> +
> 
> No empty line at start of function.

Done

> 
>> +    local libc_mode=final
> 
> No default.
> The 'libc_mode' is not optional, so every caller has to pass it.
> 
> But are you sure that it makes sense to pass the libc_mode when
> calling rearrange?

Because I use "$@" in do_libc_backend_multilib I think it the easiest way to let
do_libc_backend_rearrange check libc_mode.

> 
>> +    while [ $# -ne 0 ]; do
>> +        eval "${1// /\\ }"
>> +        shift
>> +    done
>> +
>> +    if [ "${libc_mode}" = "final" ]; then
>> +        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
>> +        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
>> +            dir=`echo $i | sed -e 's/;.*$//'`;
> 
> dir="${i%%;*}"
> Also, no trailing semi-column, it's useless in shell scripts
> ( this is not C! ;-) )

Done

> 
>> +           bdir=`echo ${dir} | sed -e 's/\//\\\\\//g'`
> 
> Why do you need to double-escape the '/' ?
> And for readability:
>   sed -e 's:/:\\\\/:g'

I use $bdir in a sed expression below: "s/\/lib\/$l/\/lib\/$bdir\/$l/g", so I have to
doublequote to get quotes.


> 
> Also, use ${sed} for portability reasons (eg. on MacOS-X, this is gsed,
> not sed, and this is detected by ./configure).
> 

Done

> And then, use the '-r' option to sed:
>   ${sed} -r -e 's:/:\\\\/:g'
> 
>> +           if [ "${dir}" = "." ]; then
>> +               true;
>> +           else
> 
> if [ "${dir}" != "." ]; then

Done

> 
>> +               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
>> +               CT_DoStep INFO "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
> 
> It does not belong to the 'INFO' log-level, but rather to 'EXTRA' or even
> better yet, to 'DEBUG'.

changed to DEBUG

> 
>> +               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
>> +               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
>> +
>> +               # recreate the symbolic links for multilib
>> +               find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1 > ${CT_SYSROOT_DIR}/usr/lib/${dir}/links
>> +               for f in `cat ${CT_SYSROOT_DIR}/usr/lib/${dir}/links`; do
> 
> You could use an array variable, if you really want two lines:
>     links=( $(find blabla       \
>                    -type l      \
>                    -maxdepth 1  ) )
>     for f in "${links[@]}"; do
> 

Done.

> But you could also use a single call:
>     for f in $(find blabla      \
>                    -type l      \
>                    -maxdepth 1  )
>     do
>         [...]
>     done
> 
>> +                   fn=`basename $f`
>> +                   ln=`readlink $f`
>> +                   ln=`basename $ln`
>> +                   pre=`echo ${dir} | awk '{r="";c=split($0,b,"/");for(i=0;i<c;i++){if(i!=0){r=r "/";}r=r "..";}; printf("%s",r); }'`
> 
> Explain what you're doing here. Basically, you want to turn
>     foo/bar
> into
>     ../..
> 
> Also, try to get a shorter line, and use $(...) as everywhere else:
>     pre=$( echo ${dir}  \
>            |awk '{ r="";
>                    c=split($0, b, "/");
>                    for( i=0; i<c; i++ ) {
>                        if( i!=0 ) {
>                            r=r "/";
>                        }
>                        r = r "..";
>                    }
>                    printf("%s",r);
>                  }' )

Done

> 
>> +                   (cd ${CT_SYSROOT_DIR}/usr/lib/${dir}/; ln -sf ../../${pre}/lib/${dir}/$ln $fn)
> 
> I'm not fan of having a sub-shell here.
>     CT_Pushd "blabla"
>     ln -sf blabla blabla
>     CT_Popd
> 

Done

>> +               done
>> +
>> +                # rewrite the library multiplexers
>> +               for l in libc libpthread libgcc_s; do
>> +                   for d in lib/${dir} usr/lib/${dir}; do
>> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
>> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
> 
> What if the the _ori_i file already exist?
> Surely, it should not happen, and if it does, we should consider this
> as an error.

I emit a Warning. If _iri_i exist it will already have been patched.

> 
>> +                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
>> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | sed -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
>> +                           fi
> 
> Transform that whole if..fi into:
>     ${sed} -r -i        \
>            -e "blabla"  \
>            foo.so
> 
>> +                       fi
>> +                   done
>> +               done
>> +               CT_EndStep
>> +           fi
>> +        done;
>> +    fi
>> +}
>> +
>> +# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
>> +do_libc_backend_multilib() {
>> +    local flags=""; local i; local dir;
>> +    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
>> +    if [ "${CT_CC_MULTILIB}" = "y" ]; then
>> +       CT_DoStep INFO "C Library with multilib"
>> +       CT_DoStep INFO "C Library with multilib. Flags: \"\" Dir: \"\""
> 
> Redundant log line.
> Missing flags and dir.

Done

> 
>> +       # first create <non-multilib> to create ${CT_HEADERS_DIR} dir
>> +       do_libc_backend "$@"
>> +       CT_EndStep
>> +       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
>> +           dir=`echo $i | sed -e 's/;.*$//'`;
> 
> dir="${i%%;*}"

Done

> 
>> +           if [ "${dir}" = "." ]; then
>> +               true;
>> +           else
> 
> if [ "${dir}" != "." ]; then

Done

> 
>> +               flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
>> +               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
>> +               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}"
>> +               CT_EndStep
>> +           fi
>> +       done;
>> +       do_libc_backend_rearrange
> 
> Missing the libc_mode.

Added "$@"

> 
>> +       CT_EndStep
>> +    else
>> +       do_libc_backend "$@"
>> +    fi
>> +}
> 
> This will install headers multiple times, right? Is this expected/wanted?

I do it for precaution.

> 
> Also, I'd do something like:
> 
>     do_libc_backend_multilib() {
>         # We need to call the backend at least once,
>         # with all settings set to the defaults
>         do_libc_backend "$@"
>         if [ "${CT_CC_MULTILIB}" = "y" ]; then
>             for i in $( "${cross_cc}" --print-multi-lib 2>/dev/null ); do
>                 dir="${i%%;*}"
>                 if [ "${dir}" != "." ]; then
>                     flags="${i#*;}"; flags="${flags//@/ -}"
>                     CT_DoStep INFO "C Library with multilib. Flags: '${flags}' Dir: '${dir}'"
>                     do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}"
>                     CT_EndStep
>                 fi
>             done
>         fi
>     }

Done.

> 
>>  do_libc_backend() {
>>      local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
>>      local libc_mode=final
>>      local extra_cc_args
>> +    local extra_dir=""; local extra_dir_p;
> 
> On two lines, no trailing semi-column.

Done

> 
>> +    local extra_flags=""
>>      local -a extra_config
>>      local -a extra_make_args
>>      local glibc_cflags
>>
>> @@ -77,15 +158,16 @@ do_libc_backend() {
>>          eval "${1// /\\ }"
>>          shift
>>      done
>> -
>> +    extra_dir_p=`echo ${extra_dir} | sed -e 's/\///g'`
> 
> Use $(...) instead of `...`, as everywhere else in the code.
> Also, do not forget to quote strings:
> 
>     extra_dir_p="$( echo "${extra_dir}" | sed -e 's/\///g' )"
> 
>> +
>>      if [ "${libc_mode}" = "startfiles" ]; then
>>          CT_DoStep INFO "Installing C library headers & start files"
>> -        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
>> -        cd "${CT_BUILD_DIR}/build-libc-start-files"
>> +        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
>> +        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
>>      else # libc_mode = final
>>          CT_DoStep INFO "Installing C library"
>> -        mkdir -p "${CT_BUILD_DIR}/build-libc"
>> -        cd "${CT_BUILD_DIR}/build-libc"
>> +        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
>> +        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
>>      fi
> 
> I would prefer that there is only one 'top-level' build dir. Also, we
> could replace this whole fi..else.fi block with a single construct.
> Something like:
> 
>     mkdir -p "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"
>     cd "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"
> 

I'm not shure how to do it. Please decide yourself and change...


>>      CT_DoLog EXTRA "Configuring C library"
>> @@ -133,7 +215,13 @@ do_libc_backend() {
>>      esac
>>      
>>      case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
>> -        y,) extra_config+=("--with-fp");;
>> +        y,) # if it is a <multilib> build then check if -msoft-float is given
>> +           if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
>> +               extra_config+=("--with-fp=no");
>> +           else
>> +               extra_config+=("--with-fp");
>> +           fi
>> +           ;;
>>          ,y) extra_config+=("--without-fp");;
>>      esac
> 
> The hunk above no longer applies to the tree. The soft/hard float selection
> now uses a string, because there might be a bunch of possibilities, not only
> 'soft' and 'hard', but also 'softfp' now.

Sorry, cant handle this. The scenario is modeled so that if multilib
issues "-msoft-float" then glibc is given "--with-fp=no". In fact I'm not shure
weather --with-fp=no is the same as --without-fp. In the
glibc Makefile snippet I use "ifeq ($(with-fp),no)", maybe the
configure is smart enough to define with-fp=no for "--without-fp"...

> 
> [--SNIP--]
>> @@ -288,9 +376,13 @@ do_libc_backend() {
>>                                             -nostartfiles    \
>>                                             -shared          \
>>                                             -x c /dev/null   \
>> -                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
>> +                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
>>          fi # threads == nptl
>>      else # libc_mode = final
>> +        CT_DoLog EXTRA "Prepare C library"
>> +        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
>> +                              "${extra_make_args[@]}"           \
>> +                              clean
> 
> Why do you need to clean here?
> The build dir should be brand new, as we just mkdir it a few lines above.
> In any way, do not reuse any existing dir.

I remember that it didnt proceed compiling without it when using the "RESTART, STOP" option,
maybe it can be removed, on the other hand it doesnt hurt.

> 
>>          CT_DoLog EXTRA "Building C library"
>>          CT_DoExecLog ALL make ${JOBSFLAGS}                      \
>>                                "${extra_make_args[@]}"           \
> 
> [--SNIP--]
>> diff --git a/config/cc/gcc.in.2 b/config/cc/gcc.in.2
>> index 35a1070..8fe3a2e 100644
>> --- a/config/cc/gcc.in.2
>> +++ b/config/cc/gcc.in.2
>> @@ -1,4 +1,10 @@
>>  # gcc configuration options
>> +config CC_MULTILIB
>> +    bool
>> +    prompt "enable multilib"
>> +    default n
>> +    help
>> +      Enable multilib build of libc
> 
> We need to find a place where to put that option, but I think the gcc
> sub-menu is not the proper place.

I didnt add this to the patchset this time. I think you have
to decide where to place CC_MULTILIB ...

> 
> Multi-lib is a property of the toolchain, that is implemented by many
> components, and gcc is only one of those. binutils also plays a role in
> multilib.
> 
> So, it makes more sense to put the option in a more global sub-menu, such
> as in the toolchain options sub-menu.
> 
>>  config CC_ENABLE_CXX_FLAGS
>>      string
>> @@ -11,6 +17,7 @@ config CC_ENABLE_CXX_FLAGS
>>        Note: just pass in the option _value_, that is only the part that
>>        goes after the '=' sign.
>>
>> +
> 
> Spurious empty line.
> 
>>  config CC_CORE_EXTRA_CONFIG_ARRAY
>>      string
>>      prompt "Core gcc extra config"
> 
> [--SNIP leon patches--]
> 
>> diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh
>> index e082590..7969b13 100644
>> --- a/scripts/build/binutils/binutils.sh
>> +++ b/scripts/build/binutils/binutils.sh
> [--SNIP--]
>> @@ -151,7 +156,13 @@ do_binutils_target() {
>>              extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
>>              [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
>>          fi
>> -
>> +
> 
> Spurious empty-line change: space damage.
> 

Done

>> +       if [ "${CT_CC_MULTILIB}" = "n" ]; then
>> +            extra_config+=("--disable-multilib")
>> +       else
>> +            extra_config+=("--enable-multilib")
>> +       fi
>> +
>>          CT_DoExecLog CFG                                            \
>>          "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
>>              --build=${CT_BUILD}                                     \
>> @@ -162,7 +173,6 @@ do_binutils_target() {
>>              --enable-shared                                         \
>>              --enable-static                                         \
>>              --disable-nls                                           \
>> -            --disable-multilib                                      \
>>              "${extra_config[@]}"                                    \
>>              ${CT_ARCH_WITH_FLOAT}                                   \
>>              "${CT_BINUTILS_EXTRA_CONFIG[@]}"
> 
> Be careful with binutils for target. It only installs a pair of libraries,
> not the whole binutils. So, is it necessary to enable multilib for the
> target binutils?
> 
> [--SNIP gcc changes (OK)--]
> 
> Globally, I am very happy to see this patch coming in!
> There are a bunch of issues, but that's expected with such core changes.
> 
> Regards,
> Yann E. MORIN.
> 


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-11-14 10:38   ` Konrad Eisele
@ 2011-11-14 10:55     ` Konrad Eisele
  2011-11-14 23:25     ` simple multilib option Yann E. MORIN
  1 sibling, 0 replies; 13+ messages in thread
From: Konrad Eisele @ 2011-11-14 10:55 UTC (permalink / raw)
  To: crossgcc; +Cc: yann.morin.1998, konrad

---
 scripts/build/binutils/binutils.sh        |   14 +++-
 scripts/build/cc/gcc.sh                   |   15 +++-
 scripts/build/libc/glibc-eglibc.sh-common |  124 +++++++++++++++++++++++++---
 3 files changed, 134 insertions(+), 19 deletions(-)

diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh
index e082590..9c51a3d 100644
--- a/scripts/build/binutils/binutils.sh
+++ b/scripts/build/binutils/binutils.sh
@@ -59,6 +59,11 @@ do_binutils() {
         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
     fi
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
 
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
@@ -71,7 +76,6 @@ do_binutils() {
         --target=${CT_TARGET}                                   \
         --prefix=${CT_PREFIX_DIR}                               \
         --disable-nls                                           \
-        --disable-multilib                                      \
         --disable-werror                                        \
         "${extra_config[@]}"                                    \
         ${CT_ARCH_WITH_FLOAT}                                   \
@@ -151,7 +155,12 @@ do_binutils_target() {
             extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
             [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
         fi
-
+	if [ "${CT_CC_MULTILIB}" = "n" ]; then
+            extra_config+=("--disable-multilib")
+	else
+            extra_config+=("--enable-multilib")
+	fi
+    
         CT_DoExecLog CFG                                            \
         "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
             --build=${CT_BUILD}                                     \
@@ -162,7 +171,6 @@ do_binutils_target() {
             --enable-shared                                         \
             --enable-static                                         \
             --disable-nls                                           \
-            --disable-multilib                                      \
             "${extra_config[@]}"                                    \
             ${CT_ARCH_WITH_FLOAT}                                   \
             "${CT_BINUTILS_EXTRA_CONFIG[@]}"
diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh
index 05df729..8804e85 100644
--- a/scripts/build/cc/gcc.sh
+++ b/scripts/build/cc/gcc.sh
@@ -288,6 +288,12 @@ do_cc_core() {
     extra_config+=(--disable-libgomp)
     extra_config+=(--disable-libmudflap)
 
+   if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
@@ -301,7 +307,6 @@ do_cc_core() {
         --target=${CT_TARGET}                       \
         --prefix="${core_prefix_dir}"               \
         --with-local-prefix="${CT_SYSROOT_DIR}"     \
-        --disable-multilib                          \
         --disable-libmudflap                        \
         ${CC_CORE_SYSROOT_ARG}                      \
         "${extra_config[@]}"                        \
@@ -424,7 +429,13 @@ do_cc() {
     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
 
     extra_config+=("--enable-languages=${lang_opt}")
-    extra_config+=("--disable-multilib")
+    
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+ 
     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
         eval tmp="\${CT_ARCH_WITH_${tmp}}"
         if [ -n "${tmp}" ]; then
diff --git a/scripts/build/libc/glibc-eglibc.sh-common b/scripts/build/libc/glibc-eglibc.sh-common
index 2af3a9a..2c77fbf 100644
--- a/scripts/build/libc/glibc-eglibc.sh-common
+++ b/scripts/build/libc/glibc-eglibc.sh-common
@@ -57,18 +57,103 @@ do_libc_extract() {
 do_libc_start_files() {
     # Start files and Headers should be configured the same way as the
     # final libc, but built and installed differently.
-    do_libc_backend libc_mode=startfiles
+    do_libc_backend_multilib libc_mode=startfiles
 }
 
 # This function builds and install the full C library
 do_libc() {
-    do_libc_backend libc_mode=final
+    do_libc_backend_multilib libc_mode=final
 }
 
+# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
+# to reflect the runtime setting.
+do_libc_backend_rearrange() {
+    local libc_mode
+    
+    while [ $# -ne 0 ]; do
+        eval "${1// /\\ }"
+        shift
+    done
+    
+    if [ "${libc_mode}" = "final" ]; then
+        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+	   bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
+               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
+               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
+
+               # recreate the symbolic links for multilib 
+               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do
+                   fn=`basename $f`
+                   ln=`readlink $f`
+                   ln=`basename $ln`
+		   # go toward root. Count the numer of "/" and asseble a "../.." prefix 
+                   pre=$( echo ${dir} | awk '{r="";
+		       c=split($0,b,"/");
+		       for(i=0;i<c;i++){
+		           if(i!=0){r=r "/";}
+			   r=r "..";
+		       };
+		       printf("%s",r);
+		   }')
+		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
+                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
+		   CT_Popd
+               done
+
+               # rewrite the library multiplexers
+               for l in libc libpthread libgcc_s; do
+                   for d in lib/${dir} usr/lib/${dir}; do
+                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
+                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
+                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
+                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
+			   else
+			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
+                           fi
+                       fi
+                   done
+               done
+               CT_EndStep
+           fi
+        done;
+    fi
+}
+
+# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
+do_libc_backend_multilib() {
+    local flags=""
+    local i
+    local dir
+    # We need to call the backend at least once,
+    # with all settings set to the defaults
+    do_libc_backend "$@"
+    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+    if [ "${CT_CC_MULTILIB}" = "y" ]; then
+       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
+               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}" 
+               CT_EndStep
+           fi
+       done;
+       do_libc_backend_rearrange
+    fi
+}		       
+
 do_libc_backend() {
     local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
     local libc_mode=final
     local extra_cc_args
+    local extra_dir=""
+    local extra_dir_p
+    local extra_flags=""
     local -a extra_config
     local -a extra_make_args
     local glibc_cflags
@@ -77,15 +162,16 @@ do_libc_backend() {
         eval "${1// /\\ }"
         shift
     done
-
+    extra_dir_p="$(echo ${extra_dir} | ${sed} -r -e 's/\///g')"
+	
     if [ "${libc_mode}" = "startfiles" ]; then
         CT_DoStep INFO "Installing C library headers & start files"
-        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
-        cd "${CT_BUILD_DIR}/build-libc-start-files"
+        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
     else # libc_mode = final
         CT_DoStep INFO "Installing C library"
-        mkdir -p "${CT_BUILD_DIR}/build-libc"
-        cd "${CT_BUILD_DIR}/build-libc"
+        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
     fi
 
     CT_DoLog EXTRA "Configuring C library"
@@ -133,7 +219,13 @@ do_libc_backend() {
     esac
 
     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
-        y,) extra_config+=("--with-fp");;
+        y,) # if it is a <multilib> build then check if -msoft-float is given
+	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
+	    	extra_config+=("--with-fp=no");
+	    else
+	    	extra_config+=("--with-fp");
+	    fi
+	    ;;
         ,y) extra_config+=("--without-fp");;
     esac
 
@@ -173,7 +265,7 @@ do_libc_backend() {
     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
 
-    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"
+    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE} ${extra_flags}"
     case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
         y)  ;;
         *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
@@ -236,7 +328,7 @@ do_libc_backend() {
         # use the 'install-headers' makefile target to install the
         # headers
         CT_DoExecLog ALL make ${JOBSFLAGS}              \
-                         install_root=${CT_SYSROOT_DIR} \
+                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
                          install-bootstrap-headers=yes  \
                          "${extra_make_args[@]}"        \
                          install-headers
@@ -273,12 +365,12 @@ do_libc_backend() {
 
             # there are a few object files needed to link shared libraries,
             # which we build and install by hand
-            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
+            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
             CT_DoExecLog ALL make ${JOBSFLAGS}  \
                         "${extra_make_args[@]}" \
                         csu/subdir_lib
             CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
-                                "${CT_SYSROOT_DIR}/usr/lib"
+                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
 
             # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
             # However, since we will never actually execute its code,
@@ -288,9 +380,13 @@ do_libc_backend() {
                                            -nostartfiles    \
                                            -shared          \
                                            -x c /dev/null   \
-                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
+                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
         fi # threads == nptl
     else # libc_mode = final
+        CT_DoLog EXTRA "Prepare C library"
+        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
+                              "${extra_make_args[@]}"           \
+                              clean
         CT_DoLog EXTRA "Building C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
@@ -299,7 +395,7 @@ do_libc_backend() {
         CT_DoLog EXTRA "Installing C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
-                              install_root="${CT_SYSROOT_DIR}"  \
+                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
                               install
 
         if [ "${CT_LIBC_LOCALES}" = "y" ]; then
-- 
1.6.4.1


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: simple multilib option
  2011-11-14 10:38   ` Konrad Eisele
  2011-11-14 10:55     ` [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele
@ 2011-11-14 23:25     ` Yann E. MORIN
  2011-11-15 10:32       ` Konrad Eisele
  1 sibling, 1 reply; 13+ messages in thread
From: Yann E. MORIN @ 2011-11-14 23:25 UTC (permalink / raw)
  To: crossgcc; +Cc: Konrad Eisele

Konrad, All,

On Monday 14 November 2011 11:30:54 Konrad Eisele wrote:
> I'll send revised patches as reply to this one, in the
> meantime here are the comment-comments:

OK, I saw your updated patch. I'll have a look tomorow, it's a bit late
for me here for now, and I could not get to review it this evening...
Sorry for the delay this implies... :-(

> I'll send the Multilib-patches only. I also skip the CC_MULTILIB
> option definition, as for you have to decide where to put it.

Sorry I was not explicit. My opinion is it should go into the toolchain
sub-menu. If you think of a better place, feel free to suggest it. :-)

> The gcc-4.6 and glibc sparcleon toolchain patch I'll send some other
> time in the future.

OK, good!

> To get the multilib patches in would be nice as for without them none
> of our toolchains can be built with crosstools.

Yes, I am very much interested in this patch! I just want to make it as
good as possible before it gets in. Once the code is in, it tends to be
more difficult to change it than before inclusion.

> >> diff --git a/build/lib/ct-ng-/scripts/build/libc/glibc-eglibc.sh-com
> >> +           bdir=`echo ${dir} | sed -e 's/\//\\\\\//g'`
> > 
> > Why do you need to double-escape the '/' ?
> > And for readability:
> >   sed -e 's:/:\\\\/:g'
> 
> I use $bdir in a sed expression below: "s/\/lib\/$l/\/lib\/$bdir\/$l/g",
> so I have to doublequote to get quotes.

Yes, I saw it afterwards, and forgot to remove my comment.
OK.

> >> +               done
> >> +
> >> +                # rewrite the library multiplexers
> >> +               for l in libc libpthread libgcc_s; do
> >> +                   for d in lib/${dir} usr/lib/${dir}; do
> >> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
> >> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
> > 
> > What if the the _ori_i file already exist?
> > Surely, it should not happen, and if it does, we should consider this
> > as an error.
> 
> I emit a Warning. If _iri_i exist it will already have been patched.

But why would a file, that we _just_installed_, be already patched?

> >> +
> >>      if [ "${libc_mode}" = "startfiles" ]; then
> >>          CT_DoStep INFO "Installing C library headers & start files"
> >> -        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
> >> -        cd "${CT_BUILD_DIR}/build-libc-start-files"
> >> +        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
> >> +        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
> >>      else # libc_mode = final
> >>          CT_DoStep INFO "Installing C library"
> >> -        mkdir -p "${CT_BUILD_DIR}/build-libc"
> >> -        cd "${CT_BUILD_DIR}/build-libc"
> >> +        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
> >> +        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
> >>      fi
> > 
> > I would prefer that there is only one 'top-level' build dir. Also, we
> > could replace this whole fi..else.fi block with a single construct.
> > Something like:
> > 
> >     mkdir -p "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"
> >     cd "${CT_BUILD_DIR}/build-libc-${libc_mode}/${extra_dir_p:-base}"
> > 
> 
> I'm not shure how to do it. Please decide yourself and change...

OK, I'll do it here.

> >>      CT_DoLog EXTRA "Configuring C library"
> >> @@ -133,7 +215,13 @@ do_libc_backend() {
> >>      esac
> >>      
> >>      case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
> >> -        y,) extra_config+=("--with-fp");;
> >> +        y,) # if it is a <multilib> build then check if -msoft-float is given
> >> +           if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
> >> +               extra_config+=("--with-fp=no");
> >> +           else
> >> +               extra_config+=("--with-fp");
> >> +           fi
> >> +           ;;
> >>          ,y) extra_config+=("--without-fp");;
> >>      esac
> > 
> > The hunk above no longer applies to the tree. The soft/hard float selection
> > now uses a string, because there might be a bunch of possibilities, not only
> > 'soft' and 'hard', but also 'softfp' now.
> 
> Sorry, cant handle this. The scenario is modeled so that if multilib
> issues "-msoft-float" then glibc is given "--with-fp=no". In fact I'm not shure
> weather --with-fp=no is the same as --without-fp. In the
> glibc Makefile snippet I use "ifeq ($(with-fp),no)", maybe the
> configure is smart enough to define with-fp=no for "--without-fp"...

What I meant was:
 - instead of writing:
    case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
      y,) blabla;;
      ,y) blibli;;
    esac

 - we now write:
    case "${CT_ARCH_FLOAT}" in
      hard) blabla;;
      soft) blibli;;
    esac

That's why the hunk does not apply. It does not change the fact that the
case..esac is needed, it's just the way it is written now. It's easier to
read, and we now have a third case: softfp (which is hard float using
integer registers, but only for archs that support it, such as ARM).

I will adapt that part to the new construct, don't worry.

> >> +        CT_DoLog EXTRA "Prepare C library"
> >> +        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
> >> +                              "${extra_make_args[@]}"           \
> >> +                              clean
> > 
> > Why do you need to clean here?
> > The build dir should be brand new, as we just mkdir it a few lines above.
> > In any way, do not reuse any existing dir.
> 
> I remember that it didnt proceed compiling without it when using the
> "RESTART, STOP" option, maybe it can be removed, on the other hand it
> doesnt hurt.

OK. But I would prefer to really understand why it breaks, so we get to
fix it rather than have a workaround...

> > We need to find a place where to put that option, but I think the gcc
> > sub-menu is not the proper place.
> 
> I didnt add this to the patchset this time. I think you have
> to decide where to place CC_MULTILIB ...
> 
> > Multi-lib is a property of the toolchain, that is implemented by many
> > components, and gcc is only one of those. binutils also plays a role in
> > multilib.
> > 
> > So, it makes more sense to put the option in a more global sub-menu, such
> > as in the toolchain options sub-menu.

And here I said where to put it. ;-)

Thanks for the efforts you are putting in that feature. It's much
appreciated!

As I said above (it was about 1h ago for me!), I'll review the new patch
tomorrow.

Going to sleep for now... (eyes, stay open for a few more minutes, please)...

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: simple multilib option
  2011-11-14 23:25     ` simple multilib option Yann E. MORIN
@ 2011-11-15 10:32       ` Konrad Eisele
  0 siblings, 0 replies; 13+ messages in thread
From: Konrad Eisele @ 2011-11-15 10:32 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc

Yann E. MORIN wrote:
> Konrad, All,
> 
> On Monday 14 November 2011 11:30:54 Konrad Eisele wrote:
>> I'll send revised patches as reply to this one, in the
>> meantime here are the comment-comments:
> 
> OK, I saw your updated patch. I'll have a look tomorow, it's a bit late
> for me here for now, and I could not get to review it this evening...
> Sorry for the delay this implies... :-(
> 
>> I'll send the Multilib-patches only. I also skip the CC_MULTILIB
>> option definition, as for you have to decide where to put it.
> 
> Sorry I was not explicit. My opinion is it should go into the toolchain
> sub-menu. If you think of a better place, feel free to suggest it. :-)

You should decide.

>>>> +               done
>>>> +
>>>> +                # rewrite the library multiplexers
>>>> +               for l in libc libpthread libgcc_s; do
>>>> +                   for d in lib/${dir} usr/lib/${dir}; do
>>>> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
>>>> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
>>>
>>> What if the the _ori_i file already exist?
>>> Surely, it should not happen, and if it does, we should consider this
>>> as an error.
>>
>> I emit a Warning. If _iri_i exist it will already have been patched.
> 
> But why would a file, that we _just_installed_, be already patched?

Yes you are right, the
"if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then"  ...
can be removed.

> 
>>>> +
> 
>>>> +        CT_DoLog EXTRA "Prepare C library"
>>>> +        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
>>>> +                              "${extra_make_args[@]}"           \
>>>> +                              clean
>>>
>>> Why do you need to clean here?
>>> The build dir should be brand new, as we just mkdir it a few lines above.
>>> In any way, do not reuse any existing dir.
>>
>> I remember that it didnt proceed compiling without it when using the
>> "RESTART, STOP" option, maybe it can be removed, on the other hand it
>> doesnt hurt.
> 
> OK. But I would prefer to really understand why it breaks, so we get to
> fix it rather than have a workaround...
> 

I tried again with the "clean" rule removed. I built the whole chain
and also did a "RESTART=libc STOP=libc" and it still built. So again:
You are right and the "clean" rule can be removed.


>>> We need to find a place where to put that option, but I think the gcc
>>> sub-menu is not the proper place.
>>
>> I didnt add this to the patchset this time. I think you have
>> to decide where to place CC_MULTILIB ...
>>
>>> Multi-lib is a property of the toolchain, that is implemented by many
>>> components, and gcc is only one of those. binutils also plays a role in
>>> multilib.
>>>
>>> So, it makes more sense to put the option in a more global sub-menu, such
>>> as in the toolchain options sub-menu.
> 
> And here I said where to put it. ;-)
> 
> Thanks for the efforts you are putting in that feature. It's much
> appreciated!
> 
> As I said above (it was about 1h ago for me!), I'll review the new patch
> tomorrow.
> 
> Going to sleep for now... (eyes, stay open for a few more minutes, please)...

:-)

> 
> Regards,
> Yann E. MORIN.
> 


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-12-26 19:03       ` konrad.gaisler
@ 2011-12-26 21:30         ` Yann E. MORIN
  0 siblings, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2011-12-26 21:30 UTC (permalink / raw)
  To: crossgcc; +Cc: konrad.gaisler

Konrad, All,

On Monday 26 December 2011 20:04:19 konrad.gaisler wrote:
> On 12/26/2011 05:56 PM, Yann E. MORIN wrote:
> > That is something we'll have to check later: is it possible to have more
> > than one multilib running on the target? I believe that would need some
> > non-trivial hackery to work properly...
> No, not multiple multilibs, but one of the multilibs subdirs. For example
> for the leon-sparc toolchain, the toolchain would have 4 subdirs: ./ 
> msoft-float/
> mv8 and mv8/msoft-float.
> on hardware without fpu but mv8 you would  only copy and use the
> mv8/msoft-float multilib-subdir  at /usr/lib, the others will not be used.

So, it is not possible to have (hypthetical setup for ARM with neon):

 - the basic system (eg. /bin/busybox ;-)) using the default multilib
   from "sysroot/lib" and "sysroot/usr/lib" (resp as "/lib" and "/usr/lib"
   at runtime)

 - some 'optimised' components (eg. mp3 player) using the float-optimised
   multilib from "sysroot/neon/lib" and "sysroot/usr/lib/neon" (resp as
   "/lib/neon" and "/usr/lib/neon" at runtime)

That would require that:
 - the linker 'ld' sets the proper path to the dynamic linker, at _built-time_
 - the dynamic linker looks in the proper search-path

Sounds like it's not too easy... :-/

But I agree with you, the most common setup would probably be to use only
one variant on the target, either everything from the defaults /lib and
/usr/lib, or everything from a sub-dir (eg. /lib/neon and usr/lib/neon)
and not a mix... Let's make that work first! ;-)

Thanks again!

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-12-26 16:57     ` Yann E. MORIN
@ 2011-12-26 19:03       ` konrad.gaisler
  2011-12-26 21:30         ` Yann E. MORIN
  0 siblings, 1 reply; 13+ messages in thread
From: konrad.gaisler @ 2011-12-26 19:03 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc

On 12/26/2011 05:56 PM, Yann E. MORIN wrote:
> Konrad, All,
>
> On Saturday 24 December 2011 22:11:43 konrad.gaisler wrote:
> [--SNIP--]
>> Is it possible that I missed something here? I think the
>> first patch I sent included this lines:
>>
>> do_libc_start_files() {
> [--SNIP--]
>> }
> Indeed, this was missing in your first and second patches:
>      http://sourceware.org/ml/crossgcc/2011-11/msg00029.html
>      http://sourceware.org/ml/crossgcc/2011-11/msg00040.html
>
> I now have a better understanding of what is required, and where it is.
> Thanks!
>
>> The point here is that glibc's install process adds the /lib at the
>> end, however the multilib structure must have /lib before:
>> /lib/<multilib>. Adding these symlinks before makes the
>> libraries end up in the right place. The "rearrange" stage
>> then fixes up the wrong paths.
>> Hope that makes it more clear.
> That I understood, the part that was misleading was the missing hunk
> in do_libc_start_files.
>
> [--SNIP--]
>>>> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g">   ${CT_SYSROOT_DIR}/${d}/${l}.so
>>> With this sed expression, you are not rewriting the dynamic linker path,
>>> which means a multilib variant still uses the default "ld.so".
>> You might be right. My particular toolchain doesnt care as for the
>> ld.so probably doesnt differ. It is also so that in the final running
>> embedded-system, there is only one libc set, that is copied back
>> to /usr/lib.
> That is something we'll have to check later: is it possible to have more
> than one multilib running on the target? I believe that would need some
> non-trivial hackery to work properly...
No, not multiple multilibs, but one of the multilibs subdirs. For example
for the leon-sparc toolchain, the toolchain would have 4 subdirs: ./ 
msoft-float/
mv8 and mv8/msoft-float.
on hardware without fpu but mv8 you would  only copy and use the
mv8/msoft-float multilib-subdir  at /usr/lib, the others will not be used.
-- Konrad

>
> [--SNIP--]
>>> In the end, it leaves everything in "sysroot/${dir}".
>>> It would make much more sense to carefully move the libs in their correct
>>> place, that is:
>>>    - move everything from "sysroot/${dir}/lib"     ->   "sysroot/lib/${dir}"
>>>                       and "sysroot/${dir}/usr/lib" ->   "sysroot/usr/lib/${dir}"
>>>    - get rid of "sysroot/${dir}" alltogether
>>>
>>> That's because gcc will search for things in "sysroot/{usr/,}lib/${dir}/",
>>> not in "sysroot/${dir}/{usr/,}lib/"
>> I'm not an insider to glibc, but maybe there is a option to
>> glibc's configure that create the right multilib structure.
>> Then all the hustle with moving and or creating symbolic
>> links  would be unneeded.
> Anyway, with the missing part you added above, it is more clear what you
> were trying to achieve.
>
> [--SNIP--]
>>> Floats are not the only thing we have to account for. For example, some
>>> archs can define big/little multilib. And most probably other stuff
>>> as well...
>> Sorry, I dont really know the requirements for other archs, I
>> come up with this because I require for sparc glibc the --with-fp=no.
> Yep, I was just saying ;-)
>
> Regards,
> Yann E. MORIN.
>


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-12-24 21:10   ` konrad.gaisler
  2011-12-26 16:57     ` Yann E. MORIN
@ 2011-12-26 17:29     ` Yann E. MORIN
  1 sibling, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2011-12-26 17:29 UTC (permalink / raw)
  To: crossgcc; +Cc: konrad.gaisler

Konrad, All,

On Saturday 24 December 2011 22:11:43 konrad.gaisler wrote:
[--SNIP--]
> > With this sed expression, you are not rewriting the dynamic linker path,
> > which means a multilib variant still uses the default "ld.so".
> You might be right. My particular toolchain doesnt care as for the
> ld.so probably doesnt differ.

The toolchain that I built (yours, minus the Leon patches) has the
following multilibs:
    # sparc-leon3-linux-gnu-gcc -print-multi-lib
    .;
    soft;@msoft-float

And the dynamic linkers are different:
    # ls -l sysroot/lib/ld-2.14.so \
            sysroot/soft/lib/ld-2.14.so
    -rwxr-xr-x 1 ymorin ymorin 816566 Dec 23 21:46 sysroot/lib/ld-2.14.so
    -rwxr-xr-x 1 ymorin ymorin 816110 Dec 23 21:51 sysroot/soft/lib/ld-2.14.so

The 'soft' one is 456 bytes smaller than the default one.

FWIW...

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-12-24 21:10   ` konrad.gaisler
@ 2011-12-26 16:57     ` Yann E. MORIN
  2011-12-26 19:03       ` konrad.gaisler
  2011-12-26 17:29     ` Yann E. MORIN
  1 sibling, 1 reply; 13+ messages in thread
From: Yann E. MORIN @ 2011-12-26 16:57 UTC (permalink / raw)
  To: crossgcc; +Cc: konrad.gaisler

Konrad, All,

On Saturday 24 December 2011 22:11:43 konrad.gaisler wrote:
[--SNIP--]
> Is it possible that I missed something here? I think the
> first patch I sent included this lines:
> 
> do_libc_start_files() {
[--SNIP--]
> }

Indeed, this was missing in your first and second patches:
    http://sourceware.org/ml/crossgcc/2011-11/msg00029.html
    http://sourceware.org/ml/crossgcc/2011-11/msg00040.html

I now have a better understanding of what is required, and where it is.
Thanks!

> The point here is that glibc's install process adds the /lib at the
> end, however the multilib structure must have /lib before:
> /lib/<multilib>. Adding these symlinks before makes the
> libraries end up in the right place. The "rearrange" stage
> then fixes up the wrong paths.
> Hope that makes it more clear.

That I understood, the part that was misleading was the missing hunk
in do_libc_start_files.

[--SNIP--]
> >> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g">  ${CT_SYSROOT_DIR}/${d}/${l}.so
> > With this sed expression, you are not rewriting the dynamic linker path,
> > which means a multilib variant still uses the default "ld.so".
> You might be right. My particular toolchain doesnt care as for the
> ld.so probably doesnt differ. It is also so that in the final running
> embedded-system, there is only one libc set, that is copied back
> to /usr/lib.

That is something we'll have to check later: is it possible to have more
than one multilib running on the target? I believe that would need some
non-trivial hackery to work properly...

[--SNIP--]
> > In the end, it leaves everything in "sysroot/${dir}".
> > It would make much more sense to carefully move the libs in their correct
> > place, that is:
> >   - move everything from "sysroot/${dir}/lib"     ->  "sysroot/lib/${dir}"
> >                      and "sysroot/${dir}/usr/lib" ->  "sysroot/usr/lib/${dir}"
> >   - get rid of "sysroot/${dir}" alltogether
> >
> > That's because gcc will search for things in "sysroot/{usr/,}lib/${dir}/",
> > not in "sysroot/${dir}/{usr/,}lib/"
> I'm not an insider to glibc, but maybe there is a option to
> glibc's configure that create the right multilib structure.
> Then all the hustle with moving and or creating symbolic
> links  would be unneeded.

Anyway, with the missing part you added above, it is more clear what you
were trying to achieve.

[--SNIP--]
> > Floats are not the only thing we have to account for. For example, some
> > archs can define big/little multilib. And most probably other stuff
> > as well...
> Sorry, I dont really know the requirements for other archs, I
> come up with this because I require for sparc glibc the --with-fp=no.

Yep, I was just saying ;-)

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-12-23 23:22 ` Yann E. MORIN
@ 2011-12-24 21:10   ` konrad.gaisler
  2011-12-26 16:57     ` Yann E. MORIN
  2011-12-26 17:29     ` Yann E. MORIN
  0 siblings, 2 replies; 13+ messages in thread
From: konrad.gaisler @ 2011-12-24 21:10 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: crossgcc

 >From what I see it does absolutely nothing, because ...
>> +           dir="${i%%;*}"
>> +          bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
>> +           if [ "${dir}" != "." ]; then
>> +               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
>> +               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
>> +               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
>> +               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
>> +
>> +               # recreate the symbolic links for multilib
>> +               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do
> ... of the 'find' here, that scans two newly-created directories (just
> above), so they are empty.
>
> Did you mean to scan "${dir}/usr/lib" and not "usr/lib/${dir}" ?
>
> And what about "${dir}/lib" ?

Is it possible that I missed something here? I think the
first patch I sent included this lines:

do_libc_start_files() {
     cross_cc=$(CT_Which "${CT_TARGET}-gcc")
     if [ "${CT_CC_MULTILIB}" = "y" ]; then
     for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
             dir=`echo $i | sed -e 's/;.*$//'`;
         if [ "${dir}" = "." ]; then
         true;
         else
         if [ "${CT_USE_SYSROOT}" = "y" ]; then
             # prepare installation redirects
             mkdir -p ${CT_SYSROOT_DIR}/${dir}/usr
             mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
             mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
             ln -sf ${CT_SYSROOT_DIR}/usr/lib/${dir} 
${CT_SYSROOT_DIR}/${dir}/usr/lib
             ln -sf ${CT_SYSROOT_DIR}/lib/${dir} 
${CT_SYSROOT_DIR}/${dir}/lib
             fi
         flags=`echo $i | sed -e 's/^[^;]*;//' -e 's/@/ -/g'`;
         CT_DoStep INFO "Installing C library start files multilibbed. 
Flags: ${flags} Dir: ${dir}"
         do_single_libc_start_files "/${dir}" "${flags}"
         CT_EndStep
         fi
     done;
     fi
     do_single_libc_start_files
}

These symlinks that are installed before the glibc
installs make that
${CT_SYSROOT_DIR}/${dir}/usr/lib
end up in
${CT_SYSROOT_DIR}/usr/lib/${dir}
and
${CT_SYSROOT_DIR}/${dir}/lib
end up in
${CT_SYSROOT_DIR}/lib/${dir}

The point here is that glibc's install process adds the /lib at the
end, however the multilib structure must have /lib before:
/lib/<multilib>. Adding these symlinks before makes the
libraries end up in the right place. The "rearrange" stage
then fixes up the wrong paths.
Hope that makes it more clear.

The whole thing might have to be rewritten, I think
you might come up with a solution that is easier.


>
> Besides, the options ordering to the 'find' command is wrong, and 'find'
> complains loudly. No problem, fixed here.
>
>> +                   fn=`basename $f`
>> +                   ln=`readlink $f`
>> +                   ln=`basename $ln`
>> +		   # go toward root. Count the numer of "/" and asseble a "../.." prefix
>> +                   pre=$( echo ${dir} | awk '{r="";
>> +		       c=split($0,b,"/");
>> +		       for(i=0;i<c;i++){
>> +		           if(i!=0){r=r "/";}
>> +			   r=r "..";
>> +		       };
>> +		       printf("%s",r);
>> +		   }')
>> +		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
>> +                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
>> +		   CT_Popd
>> +               done
>> +
>> +               # rewrite the library multiplexers
>> +               for l in libc libpthread libgcc_s; do
>> +                   for d in lib/${dir} usr/lib/${dir}; do
>> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
>> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
>> +                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
>> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g">  ${CT_SYSROOT_DIR}/${d}/${l}.so
> With this sed expression, you are not rewriting the dynamic linker path,
> which means a multilib variant still uses the default "ld.so".
You might be right. My particular toolchain doesnt care as for the
ld.so probably doesnt differ. It is also so that in the final running
embedded-system, there is only one libc set, that is copied back
to /usr/lib. I think buildroot needs a patch to copy the right set
of libc though.

>
> I think the following sed-expr does the trick (and does not require
> the '/' mangling done above):
>      "s:/lib/:/lib/${dir}/:g;"
>
> (mangling ':' in ${dir} is not needed, the dirname can not contain a ':',
> as ':' is the multilib separator in "gcc -print-multi-lib").
>
>> +			   else
>> +			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
>> +                           fi
>> +                       fi
>> +                   done
>> +               done
>> +               CT_EndStep
>> +           fi
>> +        done;
> In the end, it leaves everything in "sysroot/${dir}".
> It would make much more sense to carefully move the libs in their correct
> place, that is:
>   - move everything from "sysroot/${dir}/lib"     ->  "sysroot/lib/${dir}"
>                      and "sysroot/${dir}/usr/lib" ->  "sysroot/usr/lib/${dir}"
>   - get rid of "sysroot/${dir}" alltogether
>
> That's because gcc will search for things in "sysroot/{usr/,}lib/${dir}/",
> not in "sysroot/${dir}/{usr/,}lib/"
I'm not an insider to glibc, but maybe there is a option to
glibc's configure that create the right multilib structure.
Then all the hustle with moving and or creating symbolic
links  would be unneeded.

>
> Of course, we can go with the symlinks first; once that works, we can look
> into doing the move and clean-up.
>
> [--SNIP--]
>>       case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
>> -        y,) extra_config+=("--with-fp");;
>> +        y,) # if it is a<multilib>  build then check if -msoft-float is given
>> +	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
>> +	    	extra_config+=("--with-fp=no");
>> +	    else
>> +	    	extra_config+=("--with-fp");
>> +	    fi
>> +	    ;;
>>           ,y) extra_config+=("--without-fp");;
>>       esac
> Floats are not the only thing we have to account for. For example, some
> archs can define big/little multilib. And most probably other stuff
> as well...
Sorry, I dont really know the requirements for other archs, I
come up with this because I require for sparc glibc the --with-fp=no.

>
> Well... Time for some rejoicing !
> Merry X-Mas to All, and a Happy New Year! Cheers !

Merry XMas back. It just has passed.
-- Konrad
>
> Regards,
> Yann E. MORIN.
>


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* Re: [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
  2011-11-14 10:45 [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele
@ 2011-12-23 23:22 ` Yann E. MORIN
  2011-12-24 21:10   ` konrad.gaisler
  0 siblings, 1 reply; 13+ messages in thread
From: Yann E. MORIN @ 2011-12-23 23:22 UTC (permalink / raw)
  To: crossgcc; +Cc: Konrad Eisele

Konrad, All,

I am slowly and not-so-smoothly coming up with a sane situation wrt the
multilib patch, but there are still a few quirks I don't get right.

First, I split the code so it is more manageable. You can check it with:

    hg qclone -p http://crosstool-ng.org/hg/crosstool-ng/ct-ng.multilib  \
                 http://crosstool-ng.org/hg/crosstool-ng                 \
                 ct-ng.multilib
    cd ct-ng.multilib
    hg qpush -a

Note, this is a WIP:
 - the last patch is just testing fixes, and is not applied (it's guarded);
 - the penultimate patch (the last one applied) is not clean yet, and I may
   split it further to ease testing.

Second, I have some difficulties understanding the do_libc_backend_rearrange
function. See below.

On Monday 14 November 2011 11:37:59 Konrad Eisele wrote:
[--SNIP--]
> diff --git a/scripts/build/libc/glibc-eglibc.sh-common b/scripts/build/libc/glibc-eglibc.sh-common
> index 2af3a9a..2c77fbf 100644
> --- a/scripts/build/libc/glibc-eglibc.sh-common
> +++ b/scripts/build/libc/glibc-eglibc.sh-common
[--SNIP--]
> +# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
> +# to reflect the runtime setting.
> +do_libc_backend_rearrange() {
> +    local libc_mode
> +    
> +    while [ $# -ne 0 ]; do
> +        eval "${1// /\\ }"
> +        shift
> +    done
> +    
> +    if [ "${libc_mode}" = "final" ]; then
> +        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
> +        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do

Can you elaborate what you are trying to achieve with this big loop?
I mean, I can read the code, and I could probably end up making it work,
but could you explain in human-readable form the idea behind this code?

From what I see it does absolutely nothing, because ...

> +           dir="${i%%;*}"
> +          bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
> +           if [ "${dir}" != "." ]; then 
> +               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
> +               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
> +               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
> +               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
> +
> +               # recreate the symbolic links for multilib 
> +               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do

... of the 'find' here, that scans two newly-created directories (just
above), so they are empty.

Did you mean to scan "${dir}/usr/lib" and not "usr/lib/${dir}" ?

And what about "${dir}/lib" ?

Besides, the options ordering to the 'find' command is wrong, and 'find'
complains loudly. No problem, fixed here.

> +                   fn=`basename $f`
> +                   ln=`readlink $f`
> +                   ln=`basename $ln`
> +		   # go toward root. Count the numer of "/" and asseble a "../.." prefix 
> +                   pre=$( echo ${dir} | awk '{r="";
> +		       c=split($0,b,"/");
> +		       for(i=0;i<c;i++){
> +		           if(i!=0){r=r "/";}
> +			   r=r "..";
> +		       };
> +		       printf("%s",r);
> +		   }')
> +		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
> +                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
> +		   CT_Popd
> +               done
> +
> +               # rewrite the library multiplexers
> +               for l in libc libpthread libgcc_s; do
> +                   for d in lib/${dir} usr/lib/${dir}; do
> +                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
> +                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
> +                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
> +                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so

With this sed expression, you are not rewriting the dynamic linker path,
which means a multilib variant still uses the default "ld.so".

I think the following sed-expr does the trick (and does not require
the '/' mangling done above):
    "s:/lib/:/lib/${dir}/:g;"

(mangling ':' in ${dir} is not needed, the dirname can not contain a ':',
as ':' is the multilib separator in "gcc -print-multi-lib").

> +			   else
> +			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
> +                           fi
> +                       fi
> +                   done
> +               done
> +               CT_EndStep
> +           fi
> +        done;

In the end, it leaves everything in "sysroot/${dir}".
It would make much more sense to carefully move the libs in their correct
place, that is:
 - move everything from "sysroot/${dir}/lib"     -> "sysroot/lib/${dir}"
                    and "sysroot/${dir}/usr/lib" -> "sysroot/usr/lib/${dir}"
 - get rid of "sysroot/${dir}" alltogether

That's because gcc will search for things in "sysroot/{usr/,}lib/${dir}/",
not in "sysroot/${dir}/{usr/,}lib/"

Of course, we can go with the symlinks first; once that works, we can look
into doing the move and clean-up.

[--SNIP--]
>      case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
> -        y,) extra_config+=("--with-fp");;
> +        y,) # if it is a <multilib> build then check if -msoft-float is given
> +	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
> +	    	extra_config+=("--with-fp=no");
> +	    else
> +	    	extra_config+=("--with-fp");
> +	    fi
> +	    ;;
>          ,y) extra_config+=("--without-fp");;
>      esac

Floats are not the only thing we have to account for. For example, some
archs can define big/little multilib. And most probably other stuff
as well...

Well... Time for some rejoicing !
Merry X-Mas to All, and a Happy New Year! Cheers !

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

* [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure.
@ 2011-11-14 10:45 Konrad Eisele
  2011-12-23 23:22 ` Yann E. MORIN
  0 siblings, 1 reply; 13+ messages in thread
From: Konrad Eisele @ 2011-11-14 10:45 UTC (permalink / raw)
  To: crossgcc; +Cc: yann.morin.1998, konrad

---
 scripts/build/binutils/binutils.sh        |   14 +++-
 scripts/build/cc/gcc.sh                   |   15 +++-
 scripts/build/libc/glibc-eglibc.sh-common |  124 +++++++++++++++++++++++++---
 3 files changed, 134 insertions(+), 19 deletions(-)

diff --git a/scripts/build/binutils/binutils.sh b/scripts/build/binutils/binutils.sh
index e082590..9c51a3d 100644
--- a/scripts/build/binutils/binutils.sh
+++ b/scripts/build/binutils/binutils.sh
@@ -59,6 +59,11 @@ do_binutils() {
         extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
         [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
     fi
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
 
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
@@ -71,7 +76,6 @@ do_binutils() {
         --target=${CT_TARGET}                                   \
         --prefix=${CT_PREFIX_DIR}                               \
         --disable-nls                                           \
-        --disable-multilib                                      \
         --disable-werror                                        \
         "${extra_config[@]}"                                    \
         ${CT_ARCH_WITH_FLOAT}                                   \
@@ -151,7 +155,12 @@ do_binutils_target() {
             extra_config+=("--with-pkgversion=${CT_PKGVERSION}")
             [ -n "${CT_TOOLCHAIN_BUGURL}" ] && extra_config+=("--with-bugurl=${CT_TOOLCHAIN_BUGURL}")
         fi
-
+	if [ "${CT_CC_MULTILIB}" = "n" ]; then
+            extra_config+=("--disable-multilib")
+	else
+            extra_config+=("--enable-multilib")
+	fi
+    
         CT_DoExecLog CFG                                            \
         "${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}/configure"   \
             --build=${CT_BUILD}                                     \
@@ -162,7 +171,6 @@ do_binutils_target() {
             --enable-shared                                         \
             --enable-static                                         \
             --disable-nls                                           \
-            --disable-multilib                                      \
             "${extra_config[@]}"                                    \
             ${CT_ARCH_WITH_FLOAT}                                   \
             "${CT_BINUTILS_EXTRA_CONFIG[@]}"
diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh
index 05df729..8804e85 100644
--- a/scripts/build/cc/gcc.sh
+++ b/scripts/build/cc/gcc.sh
@@ -288,6 +288,12 @@ do_cc_core() {
     extra_config+=(--disable-libgomp)
     extra_config+=(--disable-libmudflap)
 
+   if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+
     CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'"
 
     # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
@@ -301,7 +307,6 @@ do_cc_core() {
         --target=${CT_TARGET}                       \
         --prefix="${core_prefix_dir}"               \
         --with-local-prefix="${CT_SYSROOT_DIR}"     \
-        --disable-multilib                          \
         --disable-libmudflap                        \
         ${CC_CORE_SYSROOT_ARG}                      \
         "${extra_config[@]}"                        \
@@ -424,7 +429,13 @@ do_cc() {
     lang_opt=$(echo "${lang_opt},${CT_CC_LANG_OTHERS}" |sed -r -e 's/,+/,/g; s/,*$//;')
 
     extra_config+=("--enable-languages=${lang_opt}")
-    extra_config+=("--disable-multilib")
+    
+    if [ "${CT_CC_MULTILIB}" = "n" ]; then
+        extra_config+=("--disable-multilib")
+    else
+        extra_config+=("--enable-multilib")
+    fi
+ 
     for tmp in ARCH ABI CPU TUNE FPU FLOAT; do
         eval tmp="\${CT_ARCH_WITH_${tmp}}"
         if [ -n "${tmp}" ]; then
diff --git a/scripts/build/libc/glibc-eglibc.sh-common b/scripts/build/libc/glibc-eglibc.sh-common
index 2af3a9a..2c77fbf 100644
--- a/scripts/build/libc/glibc-eglibc.sh-common
+++ b/scripts/build/libc/glibc-eglibc.sh-common
@@ -57,18 +57,103 @@ do_libc_extract() {
 do_libc_start_files() {
     # Start files and Headers should be configured the same way as the
     # final libc, but built and installed differently.
-    do_libc_backend libc_mode=startfiles
+    do_libc_backend_multilib libc_mode=startfiles
 }
 
 # This function builds and install the full C library
 do_libc() {
-    do_libc_backend libc_mode=final
+    do_libc_backend_multilib libc_mode=final
 }
 
+# installation is done into ${CT_SYSROOT_DIR}/${dir}. The multilib prefix has to be included
+# to reflect the runtime setting.
+do_libc_backend_rearrange() {
+    local libc_mode
+    
+    while [ $# -ne 0 ]; do
+        eval "${1// /\\ }"
+        shift
+    done
+    
+    if [ "${libc_mode}" = "final" ]; then
+        cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+        for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+	   bdir="$(echo ${dir} | ${sed} -r -e 's:/:\\\\/:g')"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep DEBUG "Fixing up multilib location ${CT_SYSROOT_DIR}/${dir}/lib to ${CT_SYSROOT_DIR}/lib/${dir}"
+               mkdir -p ${CT_SYSROOT_DIR}/lib/${dir}
+               mkdir -p ${CT_SYSROOT_DIR}/usr/lib/${dir}
+
+               # recreate the symbolic links for multilib 
+               for f in $(find ${CT_SYSROOT_DIR}/usr/lib/${dir}/ -type l -maxdepth 1); do
+                   fn=`basename $f`
+                   ln=`readlink $f`
+                   ln=`basename $ln`
+		   # go toward root. Count the numer of "/" and asseble a "../.." prefix 
+                   pre=$( echo ${dir} | awk '{r="";
+		       c=split($0,b,"/");
+		       for(i=0;i<c;i++){
+		           if(i!=0){r=r "/";}
+			   r=r "..";
+		       };
+		       printf("%s",r);
+		   }')
+		   CT_Pushd "${CT_SYSROOT_DIR}/usr/lib/${dir}/"
+                   ln -sf ../../${pre}/lib/${dir}/$ln $fn
+		   CT_Popd
+               done
+
+               # rewrite the library multiplexers
+               for l in libc libpthread libgcc_s; do
+                   for d in lib/${dir} usr/lib/${dir}; do
+                       if [ -f "${CT_SYSROOT_DIR}/${d}/${l}.so" -a ! -L ${CT_SYSROOT_DIR}/${d}/${l}.so ]; then
+                           if [ ! -f "${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i" ]; then
+                               cp ${CT_SYSROOT_DIR}/${d}/${l}.so ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i
+                               cat ${CT_SYSROOT_DIR}/${d}/${l}.so_ori_i | ${sed} -r -e "s/\/lib\/$l/\/lib\/$bdir\/$l/g" > ${CT_SYSROOT_DIR}/${d}/${l}.so
+			   else
+			       CT_DoLog WARN "${CT_SYSROOT_DIR}/${d}/${l}.so has already been patched, skipping"
+                           fi
+                       fi
+                   done
+               done
+               CT_EndStep
+           fi
+        done;
+    fi
+}
+
+# call do_libc_backend <multilib> times with varying <extra_dir> and <extra_flags> options
+do_libc_backend_multilib() {
+    local flags=""
+    local i
+    local dir
+    # We need to call the backend at least once,
+    # with all settings set to the defaults
+    do_libc_backend "$@"
+    cross_cc=$(CT_Which "${CT_TARGET}-gcc")
+    if [ "${CT_CC_MULTILIB}" = "y" ]; then
+       for i in `${cross_cc} --print-multi-lib 2>/dev/null`; do
+           dir="${i%%;*}"
+           if [ "${dir}" != "." ]; then 
+               flags="$(echo $i | ${sed} -r -e 's/^[^;]*;//' -e 's/@/ -/g')";
+               CT_DoStep INFO "C Library with multilib. Flags: \"${flags}\" Dir: \"${dir}\""
+               do_libc_backend "$@" extra_dir="/${dir}" extra_flags="${flags}" 
+               CT_EndStep
+           fi
+       done;
+       do_libc_backend_rearrange
+    fi
+}		       
+
 do_libc_backend() {
     local src_dir="${CT_SRC_DIR}/${CT_LIBC}-${CT_LIBC_VERSION}"
     local libc_mode=final
     local extra_cc_args
+    local extra_dir=""
+    local extra_dir_p
+    local extra_flags=""
     local -a extra_config
     local -a extra_make_args
     local glibc_cflags
@@ -77,15 +162,16 @@ do_libc_backend() {
         eval "${1// /\\ }"
         shift
     done
-
+    extra_dir_p="$(echo ${extra_dir} | ${sed} -r -e 's/\///g')"
+	
     if [ "${libc_mode}" = "startfiles" ]; then
         CT_DoStep INFO "Installing C library headers & start files"
-        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files"
-        cd "${CT_BUILD_DIR}/build-libc-start-files"
+        mkdir -p "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc-start-files${extra_dir_p}"
     else # libc_mode = final
         CT_DoStep INFO "Installing C library"
-        mkdir -p "${CT_BUILD_DIR}/build-libc"
-        cd "${CT_BUILD_DIR}/build-libc"
+        mkdir -p "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
+        cd "${CT_BUILD_DIR}/build-libc${extra_dir_p}"
     fi
 
     CT_DoLog EXTRA "Configuring C library"
@@ -133,7 +219,13 @@ do_libc_backend() {
     esac
 
     case "${CT_ARCH_FLOAT_HW},${CT_ARCH_FLOAT_SW}" in
-        y,) extra_config+=("--with-fp");;
+        y,) # if it is a <multilib> build then check if -msoft-float is given
+	    if [ "x`expr "${extra_flags}" : '.*-msoft-float.*'`" != "x0" ]; then
+	    	extra_config+=("--with-fp=no");
+	    else
+	    	extra_config+=("--with-fp");
+	    fi
+	    ;;
         ,y) extra_config+=("--without-fp");;
     esac
 
@@ -173,7 +265,7 @@ do_libc_backend() {
     CT_DoLog DEBUG "Extra config args passed: '${extra_config[*]}'"
     CT_DoLog DEBUG "Extra CC args passed    : '${extra_cc_args}'"
 
-    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE}"
+    glibc_cflags="${CT_TARGET_CFLAGS} ${CT_LIBC_GLIBC_EXTRA_CFLAGS} ${OPTIMIZE} ${extra_flags}"
     case "${CT_LIBC_ENABLE_FORTIFIED_BUILD}" in
         y)  ;;
         *)  glibc_cflags+=" -U_FORTIFY_SOURCE";;
@@ -236,7 +328,7 @@ do_libc_backend() {
         # use the 'install-headers' makefile target to install the
         # headers
         CT_DoExecLog ALL make ${JOBSFLAGS}              \
-                         install_root=${CT_SYSROOT_DIR} \
+                         install_root=${CT_SYSROOT_DIR}${extra_dir} \
                          install-bootstrap-headers=yes  \
                          "${extra_make_args[@]}"        \
                          install-headers
@@ -273,12 +365,12 @@ do_libc_backend() {
 
             # there are a few object files needed to link shared libraries,
             # which we build and install by hand
-            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}/usr/lib"
+            CT_DoExecLog ALL mkdir -p "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
             CT_DoExecLog ALL make ${JOBSFLAGS}  \
                         "${extra_make_args[@]}" \
                         csu/subdir_lib
             CT_DoExecLog ALL cp csu/crt1.o csu/crti.o csu/crtn.o \
-                                "${CT_SYSROOT_DIR}/usr/lib"
+                                "${CT_SYSROOT_DIR}${extra_dir}/usr/lib"
 
             # Finally, 'libgcc_s.so' requires a 'libc.so' to link against.
             # However, since we will never actually execute its code,
@@ -288,9 +380,13 @@ do_libc_backend() {
                                            -nostartfiles    \
                                            -shared          \
                                            -x c /dev/null   \
-                                           -o "${CT_SYSROOT_DIR}/usr/lib/libc.so"
+                                           -o "${CT_SYSROOT_DIR}${extra_dir}/usr/lib/libc.so"
         fi # threads == nptl
     else # libc_mode = final
+        CT_DoLog EXTRA "Prepare C library"
+        CT_DoExecLog ALL make ${JOBSFLAGS}                      \
+                              "${extra_make_args[@]}"           \
+                              clean
         CT_DoLog EXTRA "Building C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
@@ -299,7 +395,7 @@ do_libc_backend() {
         CT_DoLog EXTRA "Installing C library"
         CT_DoExecLog ALL make ${JOBSFLAGS}                      \
                               "${extra_make_args[@]}"           \
-                              install_root="${CT_SYSROOT_DIR}"  \
+                              install_root="${CT_SYSROOT_DIR}${extra_dir}"  \
                               install
 
         if [ "${CT_LIBC_LOCALES}" = "y" ]; then
-- 
1.6.4.1


--
For unsubscribe information see http://sourceware.org/lists.html#faq

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

end of thread, other threads:[~2011-12-26 21:30 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-11 15:45 simple multilib option Konrad Eisele
2011-11-12 16:26 ` Yann E. MORIN
2011-11-14 10:38   ` Konrad Eisele
2011-11-14 10:55     ` [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele
2011-11-14 23:25     ` simple multilib option Yann E. MORIN
2011-11-15 10:32       ` Konrad Eisele
2011-11-14 10:45 [PATCH 1/1] Add multilib build support for libc target. Libc is build <multilib>-times in seperate sysroot directories. In a last step links are created to reflect the expected multilib structure Konrad Eisele
2011-12-23 23:22 ` Yann E. MORIN
2011-12-24 21:10   ` konrad.gaisler
2011-12-26 16:57     ` Yann E. MORIN
2011-12-26 19:03       ` konrad.gaisler
2011-12-26 21:30         ` Yann E. MORIN
2011-12-26 17:29     ` Yann E. MORIN

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