This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Updated NPTL toolchain patch...


On Tue, 2005-04-05 at 10:41 +1000, Ryan.Oliver@pha.com.au wrote:
> 
> Jean-Christophe Dubois wrote:
> <SNIP>
> >Would anybody have a clue how to unleash the __thread support for my
> >bootstrap compiler on solaris/sparc (or is it at all possible)?
> >Looking
> >for clues on google and co has not been very helpful so far ...
> >
> >Thanks
> >
> >JC
> 
> One question, were you using a vanilla sunfreeware compiler to do the
> build with?

Yes, I am using some sunfreeware packages (binutils, gcc, wget, perl,
sed, grep , ...) to make my Solaris system behave more like an OSS
system (assuming I set the path correctly). You have to with all the
Linux/OSS specific stuff in there ... This seem a bit stupid but I am
required to work with Solaris (for now).

> If so, build a native sun-sparc-solaris2.x GNU binutils (2.15) and
> a native sun-sparc-solaris2.x gcc to the same prefix somewhere on your
> system (homedir) and use this toolchain to build your cross-toolchain.

Yes, I could try this. I am using the sunfreeware stuff for convenience
because I want to avoid to have to rebuild a full OSS environment all by
myself. 

However, it seems I found another way to have the overall crosstool.sh
script to succeed on my system. For all "gcc" configure phase (3 places
in the crosstool script), I am "forcing" the as/ld binaries to use the
following way (patch attached).

        --with-gnu-as \
        --with-as=${PREFIX}/bin/${TARGET}-as \
        --with-gnu-ld \
        --with-ld=${PREFIX}/bin/${TARGET}-ld \

Without this it looks like somewhere the wrong assembler or linker is
chosen (on solaris) by the generated cross-compilers. Does this look bad
or acceptable? How do you feel about it?

This allows the script to complete successfully on Solaris (and I guess
on any other platform). I still have to test the resulting tool chain
though.

JC

> This probably wont be your only issue, you will probably also want to
> build a few GNU utilities (sed, grep, gawk, some of coreutils) to use
> instead of the sun supplied ones...
> 
> HTH
>  Regards
> Ryan
> 
--- crosstool-0.30.org/crosstool.sh	2005-03-24 02:13:14.000000000 -0500
+++ crosstool-0.30/crosstool.sh	2005-04-05 05:34:06.480468000 -0400
@@ -48,23 +48,28 @@
 BUILD=${GCC_BUILD-`$TOP_DIR/config.guess`}
 
 if test -z "${GLIBC_ADDON_OPTIONS}"; then
-   echo "GLIBC_ADDON_OPTIONS not set, so guessing addons from GLIBCTHREADS_FILENAME and GLIBCCRYPT_FILENAME"
-   # this is lame, need to fix this for nptl later?
-   # (nptl is an addon, but it's shipped in the main tarball)
+   echo "GLIBC_ADDON_OPTIONS not set"
    GLIBC_ADDON_OPTIONS="="
-   case "${GLIBCTHREADS_FILENAME}" in
-     *linuxthreads*) GLIBC_ADDON_OPTIONS="${GLIBC_ADDON_OPTIONS}linuxthreads," ;;
-   esac
+   if test '!' -z ${GLIBC_ADDON_LINUXTHREADS}; then
+       GLIBC_ADDON_OPTIONS="${GLIBC_ADDON_OPTIONS}linuxthreads,"
+   elif test '!' -z ${GLIBC_ADDON_NPTL}; then
+       GLIBC_ADDON_OPTIONS="${GLIBC_ADDON_OPTIONS}nptl,"
+   fi
    # crypt is only an addon for glibc-2.1.x
    test -z "${GLIBCCRYPT_FILENAME}"   || GLIBC_ADDON_OPTIONS="${GLIBC_ADDON_OPTIONS}crypt,"
 fi
 
+if test '!' -z "${GLIBC_ADDON_NPTL}"; then
+    GLIBC_EXTRA_CONFIG="--with-tls --with-__thread ${GLIBC_EXTRA_CONFIG}"
+    GLIBC_MIN_KERNEL=2.6.4
+else
+    GLIBC_EXTRA_CONFIG="--without-tls --without-__thread ${GLIBC_EXTRA_CONFIG}"
+    GLIBC_MIN_KERNEL=2.4.3
+fi
+
 # One is forbidden
 test -z "${LD_LIBRARY_PATH}" || abort  "glibc refuses to build if LD_LIBRARY_PATH is set.  Please unset it before running this script."
 
-# And one is derived.
-GLIBCTHREADS_FILENAME=`echo $GLIBC_DIR | sed 's/glibc-/glibc-linuxthreads-/'`
-
 # Check for a few prerequisites that have tripped people up.
 awk '/x/' < /dev/null  || abort "You need awk to build a toolchain."
 test -z "${CFLAGS}"    || abort "Don't set CFLAGS, it screws up the build"
@@ -321,13 +326,42 @@
     # http://sources.redhat.com/ml/libc-alpha/2003-11/msg00045.html
     cp bits/stdio_lim.h $HEADERDIR/bits/stdio_lim.h
 
+    if test '!' -z "${GLIBC_ADDON_NPTL}"; then 
+        # To build gcc with thread support requires real pthread headers. These
+        # will have to manually be copied from under the tree of the desired
+        # target pthread implementation.
+        cp ${GLIBC_DIR}/nptl/sysdeps/pthread/pthread.h $HEADERDIR/pthread.h
+
+        case $TARGET in
+             powerpc* ) pthreadtypes_h=nptl/sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h ;;
+             * )        pthreadtypes_h=nptl/sysdeps/unix/sysv/linux/${ARCH}/bits/pthreadtypes.h ;;
+        esac
+
+        cp ${GLIBC_DIR}/${pthreadtypes_h} $HEADERDIR/bits/pthreadtypes.h
+
+        # On s390, powerpc and sparc we also require bits/wordsize.h.
+        case $TARGET in
+        sparc* | s390* | powerpc* )
+            case $TARGET in
+            sparc64* )   wordsize_h=sysdeps/sparc/sparc64/bits/wordsize.h ;;
+            sparc* )     wordsize_h=sysdeps/sparc/sparc32/bits/wordsize.h ;;
+            s390x* )     wordsize_h=sysdeps/s390/s390x/bits/wordsize.h ;;
+            s390* )      wordsize_h=sysdeps/s390/s390/bits/wordsize.h ;;
+            powerpc64* ) wordsize_h=sysdeps/powerpc/powerpc64/bits/wordsize.h ;;
+            powerpc* )   wordsize_h=sysdeps/powerpc/powerpc32/bits/wordsize.h ;;
+            esac
+            test ! -f $HEADERDIR/bits/wordsize.h && cp ${GLIBC_DIR}/${wordsize_h} $HEADERDIR/bits/wordsize.h
+	    ;;
+	esac
+    fi # GLIBC_ADDONS_NPTL
+
     cd ..
 fi
 
 #---------------------------------------------------------
-echo "Build gcc-core (just enough to build glibc)"
+echo "Build gcc-core w/o shared libgcc (just enough to build glibc starfiles)"
 
-mkdir -p build-gcc-core; cd build-gcc-core
+mkdir -p build-gcc-core-static; cd build-gcc-core-static
 
 # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
 
@@ -343,6 +377,10 @@
         --enable-symvers=gnu \
         --enable-__cxa_atexit \
         --enable-languages=c \
+        --with-gnu-as \
+	--with-as=${PREFIX}/bin/${TARGET}-as \
+        --with-gnu-ld \
+	--with-ld=${PREFIX}/bin/${TARGET}-ld \
         --disable-shared
 fi
 
@@ -354,8 +392,118 @@
 
 test -x ${PREFIX}/bin/${TARGET}-gcc${EXEEXT} || abort Build failed during gcc-core 
 
+# Following extra steps required for building an NPTL enabled glibc.
+if test '!' -z "${GLIBC_ADDON_NPTL}"; then
+    #---------------------------------------------------------
+    echo "Build glibc startfiles (required for shared libgcc)"
+
+    mkdir -p build-glibc-startfiles; cd build-glibc-startfiles
+
+    # sh4 really needs to set configparms as of gcc-3.4/glibc-2.3.2
+    # note: this is awkward, doesn't work well if you need more than one line in configparms
+    echo ${GLIBC_CONFIGPARMS} > configparms
+
+    echo "libc_cv_forced_unwind=yes" > config.cache
+    echo "libc_cv_c_cleanup=yes" >> config.cache
+    # this here is moot, currently you cannot build nptl for sparc64
+    case ${TARGET} in
+        sparc64* ) echo "libc_cv_sparc64_tls=yes" >> config.cache ;;
+    esac
+
+    if test '!' -f Makefile; then
+        # Configure with --prefix the way we want it on the target...
+        # There are a whole lot of settings here.  You'll probably want
+        # to read up on what they all mean, and customize a bit.
+        # e.g. I picked --enable-kernel=2.4.3 here just because it's the kernel Bill 
+        # used in his example gcc2.95.3 script.  That means some backwards compatibility 
+        # stuff is turned on in glibc that you may not need if you're using a newer kernel.
+        # Compare these options with the ones used when installing the glibc headers above - they're different.
+        # Adding "--without-gd" option to avoid error "memusagestat.c:36:16: gd.h: No such file or directory" 
+        # See also http://sources.redhat.com/ml/libc-alpha/2000-07/msg00024.html. 
+        # Set BUILD_CC, or you won't be able to build datafiles
+        # Set --build, else glibc-2.3.2 will think you're not cross-compiling, and try to run the test programs
+
+        BUILD_CC=gcc CFLAGS="$TARGET_CFLAGS" CC="${TARGET}-gcc $GLIBC_EXTRA_CC_ARGS" \
+        AR=${TARGET}-ar RANLIB=${TARGET}-ranlib \
+            ${GLIBC_DIR}/configure --prefix=/usr \
+	    --build=$BUILD --host=$TARGET \
+            ${GLIBC_EXTRA_CONFIG} \
+            --enable-kernel=${GLIBC_MIN_KERNEL} \
+            --without-cvs --disable-profile --disable-debug --without-gd \
+            $SHARED_MODE \
+            --enable-add-ons${GLIBC_ADDON_OPTIONS} --with-headers=$HEADERDIR \
+            --cache-file=config.cache
+    fi
+
+    #TODO: should check whether slibdir has been set in configparms to */lib64
+    #      and copy the startfiles into the appropriate libdir.
+    make csu/subdir_lib
+    
+    test -z "${USE_SYSROOT}" &&
+    cp -fp csu/crt[1in].o ${SYSROOT}/lib/ ||
+    cp -fp csu/crt[1in].o ${SYSROOT}/usr/lib/ 
+
+    cd ..
+
+    #---------------------------------------------------------
+    echo "Build gcc-core w shared libgcc"
+
+    mkdir -p build-gcc-core-shared; cd build-gcc-core-shared
+
+    # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
+
+    if test '!' -f Makefile; then
+        ${GCC_DIR}/configure $CANADIAN_BUILD --target=$TARGET --host=$GCC_HOST --prefix=$PREFIX \
+	    --with-local-prefix=${SYSROOT} \
+	    --disable-multilib \
+            ${GCC_EXTRA_CONFIG} \
+	    ${GCC_SYSROOT_ARG_CORE} \
+	    --disable-nls \
+	    --enable-symvers=gnu \
+	    --enable-__cxa_atexit \
+            --enable-languages=c \
+            --with-gnu-as \
+	    --with-as=${PREFIX}/bin/${TARGET}-as \
+            --with-gnu-ld \
+	    --with-ld=${PREFIX}/bin/${TARGET}-ld \
+            --enable-shared
+    fi
+
+    # HACK: we need to override SHLIB_LC from gcc/config/t-slibgcc-elf-ver or
+    #       gcc/config/t-libunwind so -lc is removed from the link for 
+    #       libgcc_s.so, as we do not have a target -lc yet.
+    #       This is not as ugly as it appears to be ;-) All symbols get resolved
+    #       during the glibc build, and we provide a proper libgcc_s.so for the
+    #       cross toolchain during the final gcc build.
+    #
+    #       As we cannot modify the source tree, nor override SHLIB_LC itself
+    #       during configure or make, we have to edit the resultant 
+    #       gcc/libgcc.mk itself to remove -lc from the link.
+    #       This causes us to have to jump through some hoops...
+    #
+    #       To produce libgcc.mk to edit we firstly require libiberty.a,
+    #       so we configure then build it.
+    #       Next we have to configure gcc, create libgcc.mk then edit it...
+    #       So much easier if we just edit the source tree, but hey...
+    make configure-libiberty
+    make -C libiberty libiberty.a
+    make configure-gcc
+    make -C gcc libgcc.mk
+
+    if test '!' -f gcc/libgcc.mk-ORIG ; then cp -p gcc/libgcc.mk gcc/libgcc.mk-ORIG; fi
+    sed 's@-lc@@g' < gcc/libgcc.mk-ORIG > gcc/libgcc.mk
+
+    test "$CANADIAN_BUILD" = "" || make $PARALLELMFLAGS all-build-libiberty || true
+    make $PARALLELMFLAGS all-gcc 
+    make install-gcc
+
+    cd ..
+
+    test -x ${PREFIX}/bin/${TARGET}-gcc || abort Build failed during gcc-core 
+
+fi # GLIBC_ADDON_NPTL
 #---------------------------------------------------------
-echo Build glibc and linuxthreads
+echo Build glibc
 
 mkdir -p build-glibc; cd build-glibc
 
@@ -363,6 +511,16 @@
 # note: this is awkward, doesn't work well if you need more than one line in configparms
 echo ${GLIBC_CONFIGPARMS} > configparms
 
+if test '!' -z "${GLIBC_ADDON_NPTL}"; then
+    # Following configure tests fail while cross-compiling
+    echo "libc_cv_forced_unwind=yes" > config.cache
+    echo "libc_cv_c_cleanup=yes" >> config.cache
+    # The following is moot, currently you cannot build nptl for sparc64
+    case ${TARGET} in
+        sparc64* ) echo "libc_cv_sparc64_tls=yes" >> config.cache ;;
+    esac
+fi # GLIBC_ADDON_NPTL
+
 if test '!' -f Makefile; then
     # Configure with --prefix the way we want it on the target...
     # There are a whole lot of settings here.  You'll probably want
@@ -381,11 +539,11 @@
         ${GLIBC_DIR}/configure --prefix=/usr \
         --build=$BUILD --host=$TARGET \
         ${GLIBC_EXTRA_CONFIG} \
-        --enable-kernel=2.4.3 \
+        --enable-kernel=${GLIBC_MIN_KERNEL} \
         --without-cvs --disable-profile --disable-debug --without-gd \
-        --without-tls --without-__thread \
         $SHARED_MODE \
-        --enable-add-ons${GLIBC_ADDON_OPTIONS} --with-headers=$HEADERDIR
+        --enable-add-ons${GLIBC_ADDON_OPTIONS} --with-headers=$HEADERDIR \
+	--cache-file=config.cache
 fi
 
 if grep -l '^install-lib-all:' ${GLIBC_DIR}/Makerules > /dev/null; then
@@ -464,6 +622,10 @@
         --enable-languages="$GCC_LANGUAGES" \
          $SHARED_MODE \
         --enable-c99 \
+        --with-gnu-as \
+	--with-as=${PREFIX}/bin/${TARGET}-as \
+        --with-gnu-ld \
+	--with-ld=${PREFIX}/bin/${TARGET}-ld \
         --enable-long-long
 fi
 

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]