This is the mail archive of the crossgcc@sourceware.org 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 6 of 6] cc/gcc: build bare-metal gcc statically


On Wed, Dec 8, 2010 at 3:59 PM, Yann E. MORIN
<yann.morin.1998@anciens.enib.fr> wrote:
> # HG changeset patch
> # User Bryan Hundven <bryanhundven@gmail.com>
> # Date 1287436323 -7200
> # Node ID 844af83f1a8fcc4275b120fbbcdb93af16d1a719
> # Parent Âc78e61daa6977913fe7a92d8bf6358f47c0d255c
> cc/gcc: build bare-metal gcc statically
>
> - add a new parameter to do_cc_core: build_statically=[yes|no]
> - pass build_statically=yes in core_pass_2 when doing bare_metal
> - fix handling the static / static libstdc++ / static complibs stuff
> - add a commment to keep both blocks (in core and final) in sync
>
> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
>
> diff --git a/scripts/build/cc/gcc.sh b/scripts/build/cc/gcc.sh
> --- a/scripts/build/cc/gcc.sh
> +++ b/scripts/build/cc/gcc.sh
> @@ -63,12 +63,19 @@
> Â Â # In any other case, build the static core gcc and, if using gcc-4.3+,
> Â Â # also build the target libgcc.
> Â Â case "${CT_BARE_METAL},${CT_CANADIAN},${CT_THREADS}" in
> - Â Â Â Ây,*,*) Âdo_cc_core mode=baremetal build_libgcc=yes build_libstdcxx=yes;;
> + Â Â Â Ây,*,*)
> + Â Â Â Â Â Âif [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
> + Â Â Â Â Â Â Â Âdo_cc_core mode=baremetal build_libgcc=yes build_libstdcxx=yes build_staticlinked=yes
> + Â Â Â Â Â Âelse
> + Â Â Â Â Â Â Â Âdo_cc_core mode=baremetal build_libgcc=yes build_libstdcxx=yes
> + Â Â Â Â Â Âfi
> + Â Â Â Â Â Â;;
> Â Â Â Â ,y,*) Â ;;
> Â Â Â Â ,,nptl)
> Â Â Â Â Â Â do_cc_core mode=shared build_libgcc=yes
> Â Â Â Â Â Â ;;
> - Â Â Â Â,,win32) do_cc_core mode=static build_libgcc=yes
> + Â Â Â Â,,win32)
> + Â Â Â Â Â Âdo_cc_core mode=static build_libgcc=yes
> Â Â Â Â Â Â ;;
> Â Â Â Â *) Âif [ "${CT_CC_GCC_4_3_or_later}" = "y" ]; then
> Â Â Â Â Â Â Â Â do_cc_core mode=static build_libgcc=yes
> @@ -84,18 +91,20 @@
> Â# This function is used to build both the static and the shared core C conpiler,
> Â# with or without the target libgcc. We need to know wether:
> Â# Â- we're building static, shared or bare metal: mode=[static|shared|baremetal]
> -# Â- we need to build libgcc or not       : build_libgcc=[yes|no]   (default: no)
> -# Â- we need to build libstdc++ or not     Â: build_libstdcxx=[yes|no] Â(default: no)
> -# Usage: do_cc_core_static mode=[static|shared|baremetal] build_libgcc=[yes|no]
> +# Â- we need to build libgcc or not       : build_libgcc=[yes|no]    (default: no)
> +# Â- we need to build libstdc++ or not     Â: build_libstdcxx=[yes|no]  Â(default: no)
> +# Â- we need to build statically linked or not Â: build_staticlinked=[yes|no] (default: no)
> +# Usage: do_cc_core mode=[static|shared|baremetal] build_libgcc=[yes|no] build_staticlinked=[yes|no]
> Âdo_cc_core() {
> Â Â local mode
> Â Â local build_libgcc=no
> Â Â local build_libstdcxx=no
> + Â Âlocal build_staticlinked=no
> Â Â local core_prefix_dir
> Â Â local lang_opt
> Â Â local tmp
> Â Â local -a extra_config
> - Â Âlocal core_LDFLAGS
> + Â Âlocal -a core_LDFLAGS
> Â Â local -a core_targets
>
> Â Â while [ $# -ne 0 ]; do
> @@ -158,13 +167,35 @@
> Â Â Â Â extra_config+=("--disable-__cxa_atexit")
> Â Â fi
>
> - Â Â# When companion libraries are build static (eg !shared),
> - Â Â# the libstdc++ is not pulled automatically, although it
> - Â Â# is needed. Shoe-horn it in our LDFLAGS
> - Â Â# Ditto libm on some Fedora boxen
> - Â Âif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
> - Â Â Â Âcore_LDFLAGS='-lstdc++ -lm'
> + Â Â# *** WARNING ! ***
> + Â Â# Keep this full if-else-if-elif-fi-fi block in sync
> + Â Â# with the same block in do_cc, below.
> + Â Âif [ "${build_staticlinked}" = "yes" ]; then
> + Â Â Â Âcore_LDFLAGS+=("-static")
> + Â Â Â Âextra_config+=("--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++ -lm")
> + Â Â Â Â# Companion libraries are build static (eg !shared), so
> + Â Â Â Â# the libstdc++ is not pulled automatically, although it
> + Â Â Â Â# is needed. Shoe-horn it in our LDFLAGS
> + Â Â Â Â# Ditto libm on some Fedora boxen
> + Â Â Â Âfinal_LDFLAGS+=("-lstdc++")
> + Â Â Â Âfinal_LDFLAGS+=("-lm")
> + Â Âelse
> + Â Â Â Âif [ "${CT_CC_STATIC_LIBSTDCXX}" = "y" ]; then
> + Â Â Â Â Â Â# this is from CodeSourcery arm-2010q1-202-arm-none-linux-gnueabi.src.tar.bz2
> + Â Â Â Â Â Â# build script
> + Â Â Â Â Â Â# FIXME: if the host gcc is gcc-4.5 then presumably we could use -static-libstdc++,
> + Â Â Â Â Â Â# see http://gcc.gnu.org/ml/gcc-patches/2009-06/msg01635.html
> + Â Â Â Â Â Âextra_config+=("--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm")
> + Â Â Â Âelif [ "${CT_COMPLIBS_SHARED}" != "y" ]; then
> + Â Â Â Â Â Â# When companion libraries are build static (eg !shared),
> + Â Â Â Â Â Â# the libstdc++ is not pulled automatically, although it
> + Â Â Â Â Â Â# is needed. Shoe-horn it in our LDFLAGS
> + Â Â Â Â Â Â# Ditto libm on some Fedora boxen
> + Â Â Â Â Â Âcore_LDFLAGS+=("-lstdc++")
> + Â Â Â Â Â Âcore_LDFLAGS+=("-lm")
> + Â Â Â Âfi
> Â Â fi
> +
> Â Â if [ "${CT_CC_GCC_USE_GMP_MPFR}" = "y" ]; then
> Â Â Â Â extra_config+=("--with-gmp=${CT_COMPLIBS_DIR}")
> Â Â Â Â extra_config+=("--with-mpfr=${CT_COMPLIBS_DIR}")
> @@ -202,7 +233,7 @@
> Â Â # Use --with-local-prefix so older gccs don't look in /usr/local (http://gcc.gnu.org/PR10532)
> Â Â CC_FOR_BUILD="${CT_BUILD}-gcc" Â Â Â Â Â Â Â Â Â\
> Â Â CFLAGS="${CT_CFLAGS_FOR_HOST}" Â Â Â Â Â Â Â Â Â\
> - Â ÂLDFLAGS="${core_LDFLAGS}" Â Â Â Â Â Â Â Â Â Â Â \
> + Â ÂLDFLAGS="${core_LDFLAGS[*]}" Â Â Â Â Â Â Â Â Â Â\
> Â Â CT_DoExecLog CFG Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â\
> Â Â "${CT_SRC_DIR}/gcc-${CT_CC_VERSION}/configure" Â\
> Â Â Â Â --build=${CT_BUILD} Â Â Â Â Â Â Â Â Â Â Â Â \
> @@ -373,6 +404,9 @@
> Â Â Â Â extra_config+=(--disable-libssp)
> Â Â fi
>
> + Â Â# *** WARNING ! ***
> + Â Â# Keep this full if-else-if-elif-fi-fi block in sync
> + Â Â# with the same block in do_cc_core, above.
> Â Â if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then
> Â Â Â Â final_LDFLAGS+=("-static")
> Â Â Â Â extra_config+=("--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++ -lm")
>

Ah, oh well. I guess I "didn't care" about bare-metal.
Thanks for fixing that!

As for the -lstdc++ stuff, -static-libstdc++ could be set by doing
something like:

------8<----8<------
if [ ! "${CT_CC_GCC_4_5_or_later}" = "y" ]; then
    extra_config+=("--with-host-libstdcxx=-static-libgcc
-Wl,-Bstatic,-lstdc++,-Bdynamic -lm")
else
    core_LDFLAGS+=("-static-libstdc++")
fi
------8<----8<------
?

If you don't want to do that, I can add it to my list of patches for
gcc/binutils snapshot support.

-Bryan

(P.S., I don't know who '-r' is, it was in the "To:" field of this email... ;) )

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


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