Patchwork [2,of,2] Rework binutils in order to provide soon binutils alternative

login
register
mail settings
Submitter Yann Diorcet
Date Nov. 19, 2012, 10:22 a.m.
Message ID <d3d1d51f399e6d2c1163.1353320546@macbook-smorlat.local>
Download mbox | patch
Permalink /patch/199971/
State Accepted
Commit 6a5946fbc728
Headers show

Comments

Yann Diorcet - Nov. 19, 2012, 10:22 a.m.
# HG changeset patch
# User Yann Diorcet (diorcet.yann@gmail.com)
# Date 1353320491 -3600
# Node ID d3d1d51f399e6d2c1163f2f3ace2e3cbc73b2324
# Parent  65c8bf534d0647ce52cdb319b52dab2f81da5017
Rework binutils in order to provide soon binutils alternative

config: now the binutils is choosen by a menu
script: elf2flt script is merged in binutils.sh

Signed-off-by: Yann Diorcet <diorcet.yann@gmail.com>


--
For unsubscribe information see http://sourceware.org/lists.html#faq
Yann E. MORIN - Nov. 19, 2012, 6:58 p.m.
Yann, All,

On Monday 19 November 2012 Yann Diorcet wrote:
> # HG changeset patch
> # User Yann Diorcet (diorcet.yann@gmail.com)
> # Date 1353320491 -3600
> # Node ID d3d1d51f399e6d2c1163f2f3ace2e3cbc73b2324
> # Parent  65c8bf534d0647ce52cdb319b52dab2f81da5017
> Rework binutils in order to provide soon binutils alternative
> 
> config: now the binutils is choosen by a menu
> script: elf2flt script is merged in binutils.sh
> 
> Signed-off-by: Yann Diorcet <diorcet.yann@gmail.com>

Here are my comments on that patch. I think it will be easier to follow
than what I said on IRC (which was quite hard to follow because of the
messages being inter-spersed).

Aside a few space-damage, here are my comments:

> diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils.in
> --- a/config/binutils.in	Mon Nov 19 11:19:54 2012 +0100
> +++ b/config/binutils.in	Mon Nov 19 11:21:31 2012 +0100
> @@ -21,11 +21,12 @@
>  
>  config ARCH_BINFMT_FLAT
>      bool
> +    depends on ! ARCH_USE_MMU

I like this change, but you're already in a "if ! MMU ... endif" block.
So this "depends on" is redundant. I'll fix here.

>      prompt "Flat"
>      help
>        This will build flat binaries, suitable for
>        MMU-less architectures.
> -
> +      

Space-damage.

>  config ARCH_BINFMT_FDPIC
>      bool
>      prompt "FD_PIC ELF"
> @@ -33,12 +34,14 @@
>        This will build FD_PIC ELF binaries, suitable for
>        MMU-less architectures that still require to use
>        shared libraries (FIXME).
> -

Space-damage.

>  endif # ! ARCH_USE_MMU
>  
>  endchoice
[--SNIP--]
> diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils/binutils.in
> --- a/config/binutils/binutils.in	Mon Nov 19 11:19:54 2012 +0100
> +++ b/config/binutils/binutils.in	Mon Nov 19 11:21:31 2012 +0100
> @@ -117,6 +117,8 @@
>  
>  config BINUTILS_GOLD_SUPPORTS_ARCH
>      bool
> +    default y if ARCH_arm
> +    default y if ARCH_x86
>  
>  config BINUTILS_HAS_PLUGINS
>      bool
> @@ -124,13 +126,6 @@
>  config BINUTILS_HAS_PKGVERSION_BUGURL
>      bool
>  
> -# Only these architectures have support in gold
> -config ARCH_arm
> -    select BINUTILS_GOLD_SUPPORTS_ARCH
> -
> -config ARCH_x86
> -    select BINUTILS_GOLD_SUPPORTS_ARCH
> -

Hmmm... When I wrote that code, I had in mind that it was the duty of
architectures to state if they supported binutils/gold or not.

Your change implies that it is binutils/gold that nows if it supports a
specific architecture. I think it makes much more sense this way. But
this should have been a separate patch.

Remember: one semantically autonomous change per patch. Here you're
mixing (at least) two semantic changes, and a cleanup change:
  - cleanup the ELF/FLAT/FDPIC choice dependencies on MMU/BARE_METAL
  - switch the way gold is available
  - introduce the multi-binutils infrastructure

Those three are unrelated, hence should be in different patches. That's
Ok, I'll do the split here. Next time, please try to better split your
changes.

BTW, when I said on IRC that you should submit those changes, I should have
been more explicit: I meant that these changes are an important foundation
of your Darwin port, but are unrelated to it, so you should get rid of
those changes as soon as possible by getting them upstreamed. What I was
not explicit enough about is that those changes should be reworked first.
Hence, I'll do the fixup here.

> diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils/binutils.in.2
> --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
> +++ b/config/binutils/binutils.in.2     Mon Nov 19 11:21:31 2012 +0100

Hmmm... Strange that Mercurial did not catch the file rename. The old
elf2flt.in is still around. Did you use 'hg mv' to do the rename, or
did you do it manually?

I'll fix here.

> diff -r 65c8bf534d06 -r d3d1d51f399e scripts/build/binutils/binutils.sh
> --- a/scripts/build/binutils/binutils.sh	Mon Nov 19 11:19:54 2012 +0100
> +++ b/scripts/build/binutils/binutils.sh	Mon Nov 19 11:21:31 2012 +0100
[--SNIP--]
> @@ -41,10 +54,21 @@
>      binutils_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
>      binutils_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
>      binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
> +    binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_HOST}" )
> +    binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )

The last two should be in the "if FLAT ... fi" block: ...

>      do_binutils_backend "${binutils_opts[@]}"
>  
>      CT_Popd
> +    
> +    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
> +        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-build-${CT_BUILD}"

... here.

> +        do_elf2flt_backend "${binutils_opts[@]}"
> +         
> +        CT_Popd
> +    fi
> +    
>      CT_EndStep
>  }
>  
> @@ -52,7 +76,7 @@
>  do_binutils_for_host() {
>      local -a binutils_tools
>      local -a binutils_opts
> -
> +    

Space-damage.

>      CT_DoStep INFO "Installing binutils for host"
>      CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}"
>  
> @@ -62,9 +86,20 @@
>      binutils_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
>      binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
>      binutils_opts+=( "build_manuals=${CT_BUILD_MANUALS}" )
> +    binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )

You forgot binutils_src
Ditto, should be in the "if FLAT ... fi" block, below...

>      do_binutils_backend "${binutils_opts[@]}"
>  
> +    CT_Popd
> +
> +    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
> +        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-host-${CT_HOST}"

... here.

> +        do_elf2flt_backend "${binutils_opts[@]}"
> +        
> +        CT_Popd
> +    fi
> +    
>      # Make those new tools available to the core C compilers to come.
>      # Note: some components want the ${TARGET}-{ar,as,ld,strip} commands as
>      # well. Create that.
> @@ -73,6 +108,9 @@
>      case "${CT_TOOLCHAIN_TYPE}" in
>          cross|native)
>              binutils_tools=( ar as ld strip )
> +            if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
> +                binutils_tools+=( elf2flt flthdr )
> +            fi

Exactly! :-)

>              case "${CT_BINUTILS_LINKERS_LIST}" in
>                  ld)         binutils_tools+=( ld.bfd ) ;;
>                  gold)       binutils_tools+=( ld.gold ) ;;
> @@ -218,6 +255,50 @@
>      fi
>  }
>  
> +# Build elf2flt for X -> target
> +#     Parameter     : description               : type      : default
> +#     host          : machine to run on         : tuple     : (none)
> +#     prefix        : prefix to install into    : dir       : (none)
> +#     static_build  : build statcially          : bool      : no
> +#     cflags        : cflags to use             : string    : (empty)
> +#     ldflags       : ldflags to use            : string    : (empty)

Also, binutils_src and binutils_bld.

[--SNIP--]

All in all, that's OK.
I'll do the split + misc fixes here. No need to resend.

Regards,
Yann E. MORIN.
Yann E. MORIN - Nov. 19, 2012, 11:49 p.m.
Yann, All,

Your patch:
    binutils: cleanup ELF/FLAT/FDPIC dependencies

has been applied as: #f32c0f8ffaa3
    http://crosstool-ng.org/hg/crosstool-ng/rev/f32c0f8ffaa3

Thank you!

Regards,
Yann E. MORIN.



--
For unsubscribe information see http://sourceware.org/lists.html#faq
Yann E. MORIN - Nov. 19, 2012, 11:49 p.m.
Yann, All,

Your patch:
    binutils/binutils: simplify gold dependencies

has been applied as: #5016315d88ba
    http://crosstool-ng.org/hg/crosstool-ng/rev/5016315d88ba

Thank you!

Regards,
Yann E. MORIN.



--
For unsubscribe information see http://sourceware.org/lists.html#faq
Yann E. MORIN - Nov. 19, 2012, 11:49 p.m.
Yann, All,

Your patch:
    binutils: introduce the infrastructure to support binutils alternatives

has been applied as: #6a5946fbc728
    http://crosstool-ng.org/hg/crosstool-ng/rev/6a5946fbc728

Thank you!

Regards,
Yann E. MORIN.



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

Patch

diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils.in
--- a/config/binutils.in	Mon Nov 19 11:19:54 2012 +0100
+++ b/config/binutils.in	Mon Nov 19 11:21:31 2012 +0100
@@ -21,11 +21,12 @@ 
 
 config ARCH_BINFMT_FLAT
     bool
+    depends on ! ARCH_USE_MMU
     prompt "Flat"
     help
       This will build flat binaries, suitable for
       MMU-less architectures.
-
+      
 config ARCH_BINFMT_FDPIC
     bool
     prompt "FD_PIC ELF"
@@ -33,12 +34,14 @@ 
       This will build FD_PIC ELF binaries, suitable for
       MMU-less architectures that still require to use
       shared libraries (FIXME).
-
 endif # ! ARCH_USE_MMU
 
 endchoice
 
-source "config/binutils/binutils.in"
-source "config/binutils/elf2flt.in"
+config BINUTILS
+    string
+
+source "config.gen/binutils.in"
+source "config.gen/binutils.in.2"
 
 endmenu
diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils/binutils.in
--- a/config/binutils/binutils.in	Mon Nov 19 11:19:54 2012 +0100
+++ b/config/binutils/binutils.in	Mon Nov 19 11:21:31 2012 +0100
@@ -117,6 +117,8 @@ 
 
 config BINUTILS_GOLD_SUPPORTS_ARCH
     bool
+    default y if ARCH_arm
+    default y if ARCH_x86
 
 config BINUTILS_HAS_PLUGINS
     bool
@@ -124,13 +126,6 @@ 
 config BINUTILS_HAS_PKGVERSION_BUGURL
     bool
 
-# Only these architectures have support in gold
-config ARCH_arm
-    select BINUTILS_GOLD_SUPPORTS_ARCH
-
-config ARCH_x86
-    select BINUTILS_GOLD_SUPPORTS_ARCH
-
 # Force using the BFD linker if needed
 # This is the case for some C libraries (eg. glibc and
 # eglibc at least) and affected components can select this
diff -r 65c8bf534d06 -r d3d1d51f399e config/binutils/binutils.in.2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config/binutils/binutils.in.2	Mon Nov 19 11:21:31 2012 +0100
@@ -0,0 +1,51 @@ 
+# elf2flt options
+
+if ARCH_BINFMT_FLAT
+
+comment "elf2flt"
+
+choice
+    bool
+    prompt "elf2flt version"
+# Don't remove next line
+# CT_INSERT_VERSION_BELOW
+
+config ELF2FLT_CVSHEAD
+    bool
+    prompt "CVS Head"
+    help
+      Grab the latest version of elf2flt from the CVS repository
+
+config ELF2FLT_CVS_SNAPSHOT
+    bool
+    prompt "CVS Snapshot"
+
+endchoice
+
+config ELF2FLT_CVS_SNAPSHOT_SPEC
+    string
+    depends on ELF2FLT_CVS_SNAPSHOT
+    default ""
+    prompt "CVS refspec for elf2flt"
+    help
+       What you enter here will be passed verbatim to the cvs checkout command
+       so be careful!
+
+config ELF2FLT_VERSION
+    string
+    default "head" if ELF2FLT_CVSHEAD
+# Don't remove next line
+# CT_INSERT_VERSION_STRING_BELOW
+
+config ELF2FLT_EXTRA_CONFIG_ARRAY
+    string
+    prompt "elf2flt extra config"
+    default ""
+    help
+      Extra flags passed onto ./configure when configuring
+      
+      You can enter multiple arguments here, and arguments can contain spaces
+      if they are properly quoted (or escaped, but prefer quotes). Eg.:
+          --with-foo="1st arg with 4 spaces" --with-bar=2nd-arg-without-space
+
+endif
diff -r 65c8bf534d06 -r d3d1d51f399e config/config.mk
--- a/config/config.mk	Mon Nov 19 11:19:54 2012 +0100
+++ b/config/config.mk	Mon Nov 19 11:21:31 2012 +0100
@@ -15,20 +15,23 @@ 
 $(STATIC_CONFIG_FILES): config
 
 # Build a list of per-component-type source config files
-ARCH_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in))
-ARCH_CONFIG_FILES_2   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in.2))
-KERNEL_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in))
-KERNEL_CONFIG_FILES_2 = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in.2))
-CC_CONFIG_FILES       = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in))
-CC_CONFIG_FILES_2     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in.2))
-LIBC_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in))
-LIBC_CONFIG_FILES_2   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in.2))
-DEBUG_CONFIG_FILES    = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/debug/*.in))
+ARCH_CONFIG_FILES       = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in))
+ARCH_CONFIG_FILES_2     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/arch/*.in.2))
+KERNEL_CONFIG_FILES     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in))
+KERNEL_CONFIG_FILES_2   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/kernel/*.in.2))
+CC_CONFIG_FILES         = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in))
+CC_CONFIG_FILES_2       = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/cc/*.in.2))
+BINUTILS_CONFIG_FILES   = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/binutils/*.in))
+BINUTILS_CONFIG_FILES_2 = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/binutils/*.in.2))
+LIBC_CONFIG_FILES       = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in))
+LIBC_CONFIG_FILES_2     = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/libc/*.in.2))
+DEBUG_CONFIG_FILES      = $(patsubst $(CT_LIB_DIR)/%,%,$(wildcard $(CT_LIB_DIR)/config/debug/*.in))
 
 # Build the list of generated config files
 GEN_CONFIG_FILES = config.gen/arch.in     \
                    config.gen/kernel.in   \
                    config.gen/cc.in       \
+                   config.gen/binutils.in \
                    config.gen/libc.in     \
                    config.gen/debug.in
 # ... and how to access them:
@@ -58,11 +61,12 @@ 
 #-----------------------------------------------------------
 # Build list of per-component-type items to easily build generated files
 
-ARCHS   = $(patsubst config/arch/%.in,%,$(ARCH_CONFIG_FILES))
-KERNELS = $(patsubst config/kernel/%.in,%,$(KERNEL_CONFIG_FILES))
-CCS     = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
-LIBCS   = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
-DEBUGS  = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
+ARCHS     = $(patsubst config/arch/%.in,%,$(ARCH_CONFIG_FILES))
+KERNELS   = $(patsubst config/kernel/%.in,%,$(KERNEL_CONFIG_FILES))
+CCS       = $(patsubst config/cc/%.in,%,$(CC_CONFIG_FILES))
+BINUTILSS = $(patsubst config/binutils/%.in,%,$(BINUTILS_CONFIG_FILES))
+LIBCS     = $(patsubst config/libc/%.in,%,$(LIBC_CONFIG_FILES))
+DEBUGS    = $(patsubst config/debug/%.in,%,$(DEBUG_CONFIG_FILES))
 
 #-----------------------------------------------------------
 # The rules for the generated config files
@@ -81,6 +85,10 @@ 
 	@$(ECHO) '  IN    $(@)'
 	$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C compiler" "CC" "config/cc" "N" $(CCS)
 
+config.gen/binutils.in: $(CC_BINUTILS_FILES) $(CC_BINUTILS_FILES_2)
+	@$(ECHO) '  IN    $(@)'
+	$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "Binutils" "BINUTILS" "config/binutils" "N" $(BINUTILSS)
+
 config.gen/libc.in: $(LIBC_CONFIG_FILES) $(LIBC_CONFIG_FILES_2)
 	@$(ECHO) '  IN    $(@)'
 	$(SILENT)$(CT_LIB_DIR)/scripts/gen_in_frags.sh choice "$@" "C library" "LIBC" "config/libc" "Y" $(LIBCS)
diff -r 65c8bf534d06 -r d3d1d51f399e scripts/build/binutils/binutils.sh
--- a/scripts/build/binutils/binutils.sh	Mon Nov 19 11:19:54 2012 +0100
+++ b/scripts/build/binutils/binutils.sh	Mon Nov 19 11:21:31 2012 +0100
@@ -12,6 +12,14 @@ 
                    {ftp,http}://{ftp.gnu.org/gnu,ftp.kernel.org/pub/linux/devel}/binutils   \
                    ftp://gcc.gnu.org/pub/binutils/{releases,snapshots}
     fi
+
+    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
+        CT_GetCVS "elf2flt-cvs-${CT_ELF2FLT_VERSION}"           \
+                  ":pserver:anonymous@cvs.uclinux.org:/var/cvs" \
+                  "elf2flt"                                     \
+                  ""                                            \
+                  "elf2flt-cvs-${CT_ELF2FLT_VERSION}"
+    fi
 }
 
 # Extract binutils
@@ -24,6 +32,11 @@ 
 
     CT_Extract "binutils-${CT_BINUTILS_VERSION}"
     CT_Patch "binutils" "${CT_BINUTILS_VERSION}"
+
+    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
+        CT_Extract "elf2flt-cvs-${CT_ELF2FLT_VERSION}"
+        CT_Patch "elf2flt-cvs" "${CT_ELF2FLT_VERSION}"
+    fi
 }
 
 # Build binutils for build -> target
@@ -41,10 +54,21 @@ 
     binutils_opts+=( "prefix=${CT_BUILDTOOLS_PREFIX_DIR}" )
     binutils_opts+=( "cflags=${CT_CFLAGS_FOR_BUILD}" )
     binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_BUILD}" )
+    binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-build-${CT_HOST}" )
+    binutils_opts+=( "binutils_src=${CT_SRC_DIR}/binutils-${CT_BINUTILS_VERSION}" )
 
     do_binutils_backend "${binutils_opts[@]}"
 
     CT_Popd
+    
+    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
+        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-build-${CT_BUILD}"
+        
+        do_elf2flt_backend "${binutils_opts[@]}"
+         
+        CT_Popd
+    fi
+    
     CT_EndStep
 }
 
@@ -52,7 +76,7 @@ 
 do_binutils_for_host() {
     local -a binutils_tools
     local -a binutils_opts
-
+    
     CT_DoStep INFO "Installing binutils for host"
     CT_mkdir_pushd "${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}"
 
@@ -62,9 +86,20 @@ 
     binutils_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" )
     binutils_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" )
     binutils_opts+=( "build_manuals=${CT_BUILD_MANUALS}" )
+    binutils_opts+=( "binutils_bld=${CT_BUILD_DIR}/build-binutils-host-${CT_HOST}" )
 
     do_binutils_backend "${binutils_opts[@]}"
 
+    CT_Popd
+
+    if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
+        CT_mkdir_pushd "${CT_BUILD_DIR}/build-elf2flt-host-${CT_HOST}"
+
+        do_elf2flt_backend "${binutils_opts[@]}"
+        
+        CT_Popd
+    fi
+    
     # Make those new tools available to the core C compilers to come.
     # Note: some components want the ${TARGET}-{ar,as,ld,strip} commands as
     # well. Create that.
@@ -73,6 +108,9 @@ 
     case "${CT_TOOLCHAIN_TYPE}" in
         cross|native)
             binutils_tools=( ar as ld strip )
+            if [ -n "${CT_ARCH_BINFMT_FLAT}" ]; then
+                binutils_tools+=( elf2flt flthdr )
+            fi
             case "${CT_BINUTILS_LINKERS_LIST}" in
                 ld)         binutils_tools+=( ld.bfd ) ;;
                 gold)       binutils_tools+=( ld.gold ) ;;
@@ -93,7 +131,6 @@ 
         *)  ;;
     esac
 
-    CT_Popd
     CT_EndStep
 }
 
@@ -218,6 +255,50 @@ 
     fi
 }
 
+# Build elf2flt for X -> target
+#     Parameter     : description               : type      : default
+#     host          : machine to run on         : tuple     : (none)
+#     prefix        : prefix to install into    : dir       : (none)
+#     static_build  : build statcially          : bool      : no
+#     cflags        : cflags to use             : string    : (empty)
+#     ldflags       : ldflags to use            : string    : (empty)
+do_elf2flt_backend() {
+    local host
+    local prefix
+    local static_build
+    local cflags
+    local ldflags
+    local binutils_bld
+    local binutils_src
+    local arg
+
+    for arg in "$@"; do
+        eval "${arg// /\\ }"
+    done
+
+    CT_DoLog EXTRA "Configuring elf2flt"
+    CT_DoExecLog CFG                                            \
+    CFLAGS="${cflags}"                                          \
+    LDFLAGS="${ldflags}"                                        \
+    "${CT_SRC_DIR}/elf2flt-cvs-${CT_ELF2FLT_VERSION}/configure" \
+        --build=${CT_BUILD}                                     \
+        --host=${host}                                          \
+        --target=${CT_TARGET}                                   \
+        --prefix=${prefix}                                      \
+        --with-bfd-include-dir=${binutils_bld}/bfd              \
+        --with-binutils-include-dir=${binutils_src}/include     \
+        --with-libbfd=${binutils_bld}/bfd/libbfd.a              \
+        --with-libiberty=${binutils_bld}/libiberty/libiberty.a  \
+        ${elf2flt_opts}                                         \
+        "${CT_ELF2FLT_EXTRA_CONFIG_ARRAY[@]}"
+
+    CT_DoLog EXTRA "Building elf2flt"
+    CT_DoExecLog ALL make ${JOBSFLAGS}
+
+    CT_DoLog EXTRA "Installing elf2flt"
+    CT_DoExecLog ALL make install
+}
+
 # Now on for the target libraries
 do_binutils_for_target() {
     local -a extra_config
diff -r 65c8bf534d06 -r d3d1d51f399e scripts/crosstool-NG.sh.in
--- a/scripts/crosstool-NG.sh.in	Mon Nov 19 11:19:54 2012 +0100
+++ b/scripts/crosstool-NG.sh.in	Mon Nov 19 11:21:31 2012 +0100
@@ -127,8 +127,7 @@ 
 . "${CT_LIB_DIR}/scripts/build/companion_tools.sh"
 . "${CT_LIB_DIR}/scripts/build/kernel/${CT_KERNEL}.sh"
 . "${CT_LIB_DIR}/scripts/build/companion_libs.sh"
-. "${CT_LIB_DIR}/scripts/build/binutils/binutils.sh"
-. "${CT_LIB_DIR}/scripts/build/binutils/elf2flt.sh"
+. "${CT_LIB_DIR}/scripts/build/binutils/${CT_BINUTILS}.sh"
 . "${CT_LIB_DIR}/scripts/build/libc/${CT_LIBC}.sh"
 . "${CT_LIB_DIR}/scripts/build/cc/${CT_CC}.sh"
 . "${CT_LIB_DIR}/scripts/build/debug.sh"
@@ -545,7 +544,6 @@ 
     do_kernel_get
     do_companion_libs_get
     do_binutils_get
-    do_elf2flt_get
     do_cc_get
     do_libc_get
     do_debug_get
@@ -569,7 +567,6 @@ 
         do_kernel_extract
         do_companion_libs_extract
         do_binutils_extract
-        do_elf2flt_extract
         do_cc_extract
         do_libc_extract
         do_debug_extract
diff -r 65c8bf534d06 -r d3d1d51f399e steps.mk
--- a/steps.mk	Mon Nov 19 11:19:54 2012 +0100
+++ b/steps.mk	Mon Nov 19 11:21:31 2012 +0100
@@ -21,10 +21,8 @@ 
 CT_STEPS := libc_check_config        \
             companion_libs_for_build \
             binutils_for_build       \
-            elf2flt_for_build        \
             companion_libs_for_host  \
             binutils_for_host        \
-            elf2flt_for_host         \
             cc_core_pass_1           \
             kernel_headers           \
             libc_start_files         \