Greetings folks

In regards to previous conversations on this list and a desire to post something that is not considered "idle speculation" find attached a build recipe for creating a multilib cross-toolchain that neither misuses -B/foo/lib nor uses the untolerably
heinous and evil STARTFILE_PREFIX_SPEC.

This is only part 1, the initial cross-toolchain

Also note that I am using a combined gcc + binutils tree, more for fun than anything else ;)
I wouldn't personally use it in the book though...

I can provide alternative instructions (though basically just look at cross-lfs, add --with-sysroot=${CLFS} to binutils and gcc builds and run the gcc and binutils specific mods from the textfile in the apporpriate place)

The attached file would be the whole build except this build is using binutils 2.19, and due to that in an effort to skip one gcc build (ie the finalize cross-gcc step we have in cross-lfs which produces a cross-g++ and libstc++) I'm seeing if the combined gcc + binutils build tree is smart enough to build g++ before it is required by binutils (I'm not holding my breath)

For binutils 2.18 things are a lot easier and we of course dont have this problem... but if g++ is to become a dep we need to deal with it

The initial cross-toolchain build will (after some conversations) probably be folded into cross-lfs ( though probably not combined as it is here )

See what you think... more to follow later

Best Regards
[R]

P.S. also attached the glibc-2.9-libgcc_eh patch used within (more for clfs folks reading, you guys copy libgcc.a)
# Greetings folks
# Here is something that may interest you
#
# Ryan Oliver - 20081219
#
#================================================================================
# Sysroot based SANE multilib cross-compiler build for LFS style builds
#
# Part 1 
#================================================================================

# OK, for me BUILD_HOST today is i686-pc-linux-gnu (Old 2.4 based RH box)
#
# To ensure though that BUILD_HOST does not equal target throughout
# I am fudging it to be i686-build-linux-gnu
#
# This is primarily so glibc does not assume we are native compiling...
# Things get unhappy if you are building on a 2.4 kernel otherwise ;)
#
# We could just as easily fudge the targets to be x86_64-clfs-linux-gnu or
# i686-clfs-linux-gnu
#
# Change to however you want it to be

BUILD_HOST=i686-build-linux-gnu

mkdir ${LFS}/tools
ln -sf ${LFS}/tools /

# Tools linked against the host dont have to live under $LFS, can live in your 
home directory
# Here we just follow clfs.
# This keeps all our binaries/libs compiled and linked against the host outside 
of /tools
# It also means that they never get clobbered making it very easy to restart a 
build

mkdir ${LFS}/cross-tools
ln -sf ${LFS}/cross-tools /

# Kernel Headers
bzip2 -dc linux-2.6.27.9.tar.bz2
cd linux-2.6.27.9

install -dv /tools/include
make mrproper
make ARCH=x86_64 headers_check
make ARCH=x86_64 INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include

cd ../

#-----------------------------------------------------------------
# Sysrooted toolchain build

# OK this is probably too much, but I wanted to use binutils 2.19 for shits and 
giggles
# so I combined all gcc and binutils and let zlib come in from the gcc source 
tree
# ( not that it is an issue using the hosts zlib, the whole toolchain is linked 
against the host )
#
# Easy enough to break the build back into separate binutils and gcc

bzip2 -dc gcc-4.3.2.tar.bz2 | tar xf -
bzip2 -dc binutils-2.19.tar.bz2 | tar xf -
bzip2 -dc mfpr-2.3.2.tar.bz2 | tar xf -
bzip2 -dc gmp-4.2.4.tar.bz2 | tar xf -

# Binutils build framework is newer than gcc's

mkdir sysroot-toolchain
cd gcc-4.3.2; tar -c * | ( cd ../sysroot-toolchain ; tar xf - )
cd ../binutils-2.19; tar -c * | ( cd ../sysroot-toolchain ; tar xf - )
cd ../sysroot-toolchain
mv ../mfpr-2.3.2 ./mfpr
mv ../gmp-4.2.4 ./gmp

# Binutils patches
#--------------------
# The following patch makes genscripts process LIB_PATH ( --with-libpath) to 
provide
# multilib dirs in the linkers search path.
# Also removes anything specified by --libdir from the linker search path 
(keeps lib64 out of 32bit search paths)

patch -Np1 -i ../binutils-2.18-genscripts_multilib-1.patch

# GCC Patches
#--------------------
# Apply the gcc specs patch

patch -Np1 -i ../gcc-4.3.2-specs-1.patch

# For this sysrooted compiler we override STANDARD_STARTFILE_PREFIX{_1,_2} from
# /lib , /usr/lib to be /tools/lib only.
#
# This ensures by default the compiler will look in /tools/lib/../lib or 
/tools/lib/../lib64 as appropriate

echo "
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 \"/tools/lib/\"
#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> gcc/config/linux.h

# Next we ensure that only /tools/include will be used as the defined 
SYSTEM_HEADER_DIR
# We adjust CROSS_SYSTEM_HEADER_DIR in this case (not NATIVE_SYSTEM_HEADER_DIR)
# as this is a cross compiler

cp -v gcc/Makefile.in{,.orig}
sed -e "s...@\(^CROSS_SYSTEM_HEADER_DIR =\)....@\1 /tools/incl...@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in

# And to be anally retentive, nuke any mention of /usr/include out of 
cppdefault.c
cp -v gcc/cppdefault.c{,.orig}
sed -e '/#define STANDARD_INCLUDE_DIR/s@"/usr/include"@0...@g' \
    gcc/cppdefault.c.orig > gcc/cppdefault.c

mkdir ../sysroot-toolchain-build
cd ../sysroot-toolchain-build

# For this build we will have to inhibit_libc , so --with-newlib and 
--without-headers will be defined
# ( we could also just set -Dinhibit_libc)
#
# Alternatively, if the binutils/gcc build was split we could install glibc 
headers
# after the binutils build but before gcc and dispense with the above

AR=ar AS=as ../sysroot-toolchain/configure \
   --with-sysroot=${LFS} \
   --prefix=/host-tools \
   --target=x86_64-pc-linux-gnu \
   --with-local-prefix=/tools \
   --without-headers \
   --with-newlib \
   --disable-nls \
   --disable-shared \
   --disable-decimal-float \
   --disable-libgomp \
   --disable-libmudflap \
   --disable-libssp \
   --disable-threads \
   --enable-languages=c \
   --enable-64-bit-bfd \
   --with-lib-path=/tools/lib

make
make install

# OK, now we have a SANE multilib capable cross compiler
# Build glibc (here pretty much straight from cross-lfs)

export PATH=/cross-tools/bin:${PATH}

cd ../
bzip2 -dc glibc-2.9-20081215.tar.bz2 | tar xf -

mv glibc-2.9-20081215{,-32}
cd glibc-2.9-20081215-32

# Disable linking to libgcc_eh
patch -Np1 -i ../glibc-2.9-libgcc_eh-1.patch

mkdir ../glibc-build-32
cd ../glibc-build-32

echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_gnu89_inline=yes" >> config.cache

# OK , we should be able to use our new compiler as BUILD_CC (of course if on 
ix86 -m32 must be supplied)
# BUILD_CC is used to compile the tools glibc uses to build/configure 
components of itself with, these run
# on the host syatem and are not installed, so its probably just as safe to use 
the hosts gcc to avoid any
# potential issues
#
# Also BUILD_HOST should not equal the target, we may be running on a 2.4 
kernel, you never know

BUILD_CC="gcc" CC="x86_64-pc-linux-gnu-gcc -m32" \
    AR="x86_64-pc-linux-gnu-ar" RANLIB="x86_64-pc-linux-gnu-ranlib" \
    CFLAGS="-march=i686 -mtune=generic -g -O2" \
    ../glibc-2.9-20081215-32/configure --prefix=/tools \
    --host=i686-pc-linux-gnu --build=${BUILD_HOST} \
    --disable-profile --enable-add-ons \
    --with-tls --enable-kernel=2.6.0 --with-__thread \
    --with-binutils=/cross-tools/bin --with-headers=/tools/include \
    --cache-file=config.cache

make
make install

# Build 64-bit GLIBC
cd ../
bzip2 -dc glibc-2.9-20081215.tar.bz2 | tar xf -

mv glibc-2.9-20081215{,-64}
cd glibc-2.9-20081215-64

# Disable linking to libgcc_eh
patch -Np1 -i ../glibc-2.9-libgcc_eh-1.patch

mkdir ../glibc-build-64
cd ../glibc-build-64

echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_gnu89_inline=yes" >> config.cache

echo "slibdir=/tools/lib64" >> configparms

BUILD_CC="gcc" CC="x86_64-pc-linux-gnu-gcc -m64" \
    AR="x86_64-pc-linux-gnu-ar" \
    RANLIB="x86_64-pc-linux-gnu-ranlib" \
    CFLAGS="-march=i686 -mtune=generic -g -O2" \
    ../glibc-2.9-20081215-32/configure --prefix=/tools \
    --host=x86_64-pc-linux-gnu --build=${BUILD_HOST} \
    --libdir=/tools/lib64 \
    --disable-profile --enable-add-ons \
    --with-tls --enable-kernel=2.6.0 --with-__thread \
    --with-binutils=/cross-tools/bin --with-headers=/tools/include \
    --cache-file=config.cache

make
make install

# Allright, SANE self hosted multilib cross-toolchain
#
# Here in cross-lfs we would build our final cross-gcc which would supply the 
self hosted toolchain with libgcc_s.so
# and a cross c++ compiler + libstdc++ etc. This would allow us build 
binutils-2.19 in the next phase.
#
# But we are looking for any shortcut that may be possible (even if it is not 
sane ;) )
#
# MY personal recommendation would be to do a gcc-cross-final build, but 
suspect some folks
# would scream bloody murder (we cant have this being exactly cross-lfs now can 
we ;) )


# This is basically where I am in the build up to now... the following is what 
I am going to try to see if it is sane
# or not... will report back. If its not sane we need a fnother gcc build. 
Here's hoping I am rudely surprised

#--------------------------------------------------------------------------------------------------

cd ../

gzip -dc zlib-1.2.3.tar.gc | tar xf -
mv zlib-1.2.3 zlib-1.2.3-32

cd zlib-1.2.3-32
# Build zlib 32 bit
CC="x86_64-pc-linux-gnu-gcc -m32" \
   ./configure --prefix=/tools --shared --libdir=/tools/lib

make
make install

cd ../
gzip -dc zlib-1.2.3.tar.gc | tar xf -
mv zlib-1.2.3 zlib-1.2.3-64

cd zlib-1.2.3-64
# Build zlib 32 bit
CC="x86_64-pc-linux-gnu-gcc -m64" \
   ./configure --prefix=/tools --shared --libdir=/tools/lib

make
make install

cd ../

# In the interests of seeing if the combined build is smart enough to create a 
c++ compiler
# first to build c++ components we will forego that step... somehow I think it 
wont... but hey you never know

# We already unpacked gcc and binutils
# unpack mpfr and gmp again
bzip2 -dc mfpr-2.3.2.tar.bz2 | tar xf -
bzip2 -dc gmp-4.2.4.tar.bz2 | tar xf -

# Binutils build framework is newer than gcc's

mkdir native-toolchain
cd gcc-4.3.2; tar -c * | ( cd ../native-toolchain ; tar xf - )
cd ../binutils-2.19; tar -c * | ( cd ../native-toolchain ; tar xf - )
cd ../native-toolchain
mv ../mfpr-2.3.2 ./mfpr
mv ../gmp-4.2.4 ./gmp

# Binutils patches
#--------------------
# The following patch makes genscripts process LIB_PATH ( --with-libpath) to 
provide
# multilib dirs in the linkers search path.
# Also removes anything specified by --libdir from the linker search path 
(keeps lib64 out of 32bit search paths)

patch -Np1 -i ../binutils-2.18-genscripts_multilib-1.patch

# GCC Patches
#--------------------
# Apply the gcc specs patch

patch -Np1 -i ../gcc-4.3.2-specs-1.patch

# For this native compiler we override STANDARD_STARTFILE_PREFIX{_1,_2} from
# /lib , /usr/lib to be /tools/lib only.
#
# This ensures by default the compiler will look in /tools/lib/../lib or 
/tools/lib/../lib64 as appropriate

echo "
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 \"/tools/lib/\"
#define STANDARD_STARTFILE_PREFIX_2 \"\"" >> gcc/config/linux.h

# Next we ensure that only /tools/include will be used as the defined 
SYSTEM_HEADER_DIR
# We adjust NATIVE_SYSTEM_HEADER_DIR in this case (not CROSS_SYSTEM_HEADER_DIR)
# as this is a native compiler

cp -v gcc/Makefile.in{,.orig}
sed -e "s...@\(^NATIVE_SYSTEM_HEADER_DIR =\)....@\1 /tools/incl...@g" \
    gcc/Makefile.in.orig > gcc/Makefile.in

# And to be anally retentive, nuke any mention of /usr/include out of 
cppdefault.c
cp -v gcc/cppdefault.c{,.orig}
sed -e '/#define STANDARD_INCLUDE_DIR/s@"/usr/include"@0...@g' \
    gcc/cppdefault.c.orig > gcc/cppdefault.c

mkdir ../native-toolchain-build
cd ../native-toolchain-build

CC="x86_64-pc-linux-gnu-gcc" \
AR="x86_64-pc-linux-gnu-ar" \
AS="x86_64-pc-linux-gnu-as" \
RANLIB="x86_64-pc-linux-gnu-ranlib" \
../native-toolchain/configure \
   --prefix=/tools \
   --target=x86_64-pc-linux-gnu \
   --with-local-prefix=/tools \
   --disable-nls \
   --enable-shared \
   --enable-languages=c,c++ \
   --enable-__cxa_atexit \
   --enable-c99 \
   --enable-long-long \
   --enable-threads=posix \
   --enable-64-bit-bfd \
   --with-lib-path=/tools/lib

make
make install
Submitted By: Joe Ciccone <jcicc...@linuxfromscratch.org>
Date: 2006-11-09
Initial Package Version: 2.5
Origin: Joe Ciccone
Upstream Status: Unknown
Description: Checks to see if libgcc_eh has been provided by gcc. If it has
             the glibc will attempt to link to it.

             Rediffed for 2.7 by Jim Gifford
             Rediffed for 2.8 by Joe Ciccone
             Rediffed for 2.9 by Ryan Oliver


diff -uNr glibc-2.9-20081215-orig/configure.in glibc-2.9-20081215/configure.in
--- glibc-2.9-20081215-orig/configure.in        2008-11-11 20:50:11.000000000 
+1100
+++ glibc-2.9-20081215/configure.in     2008-12-19 16:59:30.000000000 +1100
@@ -1394,6 +1394,23 @@
     AC_DEFINE(HAVE_CC_WITH_LIBUNWIND)
   fi
 
+  AC_CACHE_CHECK(whether to link against libgcc_eh,
+                 libc_cv_cc_with_libgcc_eh, [
+    cat > conftest.c <<EOF
+int main (void) { return 0; }
+EOF
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \
+       conftest.c -v 2>&1 >/dev/null | grep -q " -lgcc_eh "; then
+      libc_cv_cc_with_libgcc_eh=yes
+    else
+      libc_cv_cc_with_libgcc_eh=no
+    fi
+    rm -f conftest*])
+  AC_SUBST(libc_cv_cc_with_libgcc_eh)
+  if test $libc_cv_cc_with_libgcc_eh = yes; then
+    AC_DEFINE(HAVE_CC_WITH_LIBGCC_EH)
+  fi
+
   AC_CACHE_CHECK(for -z nodelete option,
                 libc_cv_z_nodelete, [dnl
   cat > conftest.c <<EOF
diff -uNr glibc-2.9-20081215-orig/Makeconfig glibc-2.9-20081215/Makeconfig
--- glibc-2.9-20081215-orig/Makeconfig  2008-08-18 19:42:17.000000000 +1000
+++ glibc-2.9-20081215/Makeconfig       2008-12-19 16:59:30.000000000 +1100
@@ -525,12 +525,20 @@
   libunwind = -lunwind
 endif
 ifneq ($(have-as-needed),yes)
+ifneq ($(have-cc-with-libgcc_eh),yes)
+ libgcc_eh := $(libunwind)
+else
  libgcc_eh := -lgcc_eh $(libunwind)
+endif
 else
  libgcc_eh := -Wl,--as-needed -lgcc_s$(libgcc_s_suffix) $(libunwind) 
-Wl,--no-as-needed
 endif
 gnulib := -lgcc $(libgcc_eh)
-static-gnulib := -lgcc -lgcc_eh $(libunwind)
+ifneq ($(have-cc-with-libgcc_eh),yes)
+ static-gnulib := -lgcc $(libunwind)
+else
+ static-gnulib := -lgcc -lgcc_eh $(libunwind)
+endif
 libc.so-gnulib := -lgcc
 endif
 ifeq ($(elf),yes)
diff -uNr glibc-2.9-20081215-orig/config.make.in 
glibc-2.9-20081215/config.make.in
--- glibc-2.9-20081215-orig/config.make.in      2008-08-18 19:42:17.000000000 
+1000
+++ glibc-2.9-20081215/config.make.in   2008-12-19 16:59:30.000000000 +1100
@@ -60,6 +60,7 @@
 have-libaudit = @have_libaudit@
 have-libcap = @have_libcap@
 have-cc-with-libunwind = @libc_cv_cc_with_libunwind@
+have-cc-with-libgcc_eh = @libc_cv_cc_with_libgcc_eh@
 fno-unit-at-a-time = @fno_unit_at_a_time@
 bind-now = @bindnow@
 have-hash-style = @libc_cv_hashstyle@
diff -uNr glibc-2.9-20081215-orig/configure glibc-2.9-20081215/configure
--- glibc-2.9-20081215-orig/configure   2008-11-11 20:50:11.000000000 +1100
+++ glibc-2.9-20081215/configure        2008-12-19 17:04:17.000000000 +1100
@@ -716,6 +716,7 @@
 BISON
 VERSIONING
 libc_cv_cc_with_libunwind
+libc_cv_cc_with_libgcc_eh
 libc_cv_Bgroup
 libc_cv_libgcc_s_suffix
 libc_cv_as_needed
@@ -6053,6 +6054,33 @@
 
   fi
 
+  { echo "$as_me:$LINENO: checking whether to link against libgcc_eh" >&5
+echo $ECHO_N "checking whether to link against libgcc_eh... $ECHO_C" >&6; }
+if test "${libc_cv_cc_with_libgcc_eh+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+    cat > conftest.c <<EOF
+int main (void) { return 0; }
+EOF
+    if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \
+       conftest.c -v 2>&1 >/dev/null | grep -q " -lgcc_eh "; then
+      libc_cv_cc_with_libgcc_eh=yes
+    else
+      libc_cv_cc_with_libgcc_eh=no
+    fi
+    rm -f conftest*
+fi
+{ echo "$as_me:$LINENO: result: $libc_cv_cc_with_libgcc_eh" >&5
+echo "${ECHO_T}$libc_cv_cc_with_libgcc_eh" >&6; }
+
+  if test $libc_cv_cc_with_libgcc_eh = yes; then
+    cat >>confdefs.h <<\_ACEOF
+#define HAVE_CC_WITH_LIBGCC_EH 1
+_ACEOF
+
+  fi
+
   { echo "$as_me:$LINENO: checking for -z nodelete option" >&5
 echo $ECHO_N "checking for -z nodelete option... $ECHO_C" >&6; }
 if test "${libc_cv_z_nodelete+set}" = set; then
@@ -9282,6 +9310,7 @@
 BISON!$BISON$ac_delim
 VERSIONING!$VERSIONING$ac_delim
 libc_cv_cc_with_libunwind!$libc_cv_cc_with_libunwind$ac_delim
+libc_cv_cc_with_libgcc_eh!$libc_cv_cc_with_libgcc_eh$ac_delim
 libc_cv_Bgroup!$libc_cv_Bgroup$ac_delim
 libc_cv_libgcc_s_suffix!$libc_cv_libgcc_s_suffix$ac_delim
 libc_cv_as_needed!$libc_cv_as_needed$ac_delim
@@ -9335,7 +9364,7 @@
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 54; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 55; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to