elf2flt questions

Denys Vlasenko vda.linux at googlemail.com
Thu Jun 5 00:13:17 UTC 2008

Hi Mike.

A bit of a background of what I am doing here.

I was given a blackfin board (BF537).
I want to build and run busybox on it (for starters).
I never built or ran blackfin binaries,
and more broadly have no experience with flat binaries
for any architecture.

I want to do it in "Linux from scratch" style. This way,
I will get better understanding of the way it is done,
and possibly stumble upon rough edges in busybox,
uclubc, etc. This will lead to "itch scratching"
and bug fixing.

I managed to build uclibc as a static lib and busybox as a
static elf binary for bfin. Now I need to create a flat binary.
For one, the kernel on this board seems to be unable to run
elf binaries, it says "BINFMT_FLAT: bad magic/rev (0x1010100, need 0x5)".

It means that I am venturing into unexplored (by me) territory of elf2flt.

I took toolchain/trunk/elf2flt directory and built elf2flt:

# ./elf2flt
Usage: ./elf2flt [vrzd] [-p <abs-pic-file>] [-s stack-size] [-o <output-file>] <elf-file>
       -v              : verbose operation
       -r              : force load to RAM
       -k              : enable kernel trace on load (for debug)
       -z              : compress code/data/relocs
       -d              : compress data/relocs
       -a              : use existing symbol references
                         instead of recalculating from
                         relocation info
       -R reloc-file   : read relocations from a separate file
       -p abs-pic-file : GOT/PIC processing with files
       -s stacksize    : set application stack size
       -o output-file  : output file name
Compiled for bfin architecture

To be honest, building it was somewhat contrived - I copied the directory
into binutils' build dir and gave it all necessary configure parameters,
and it still could not find e.g. elf/bfin.h - had to add some include paths
by hand. (Do you want a more detailed report about this?)
If I did it incorrectly - well, there are no build instructions apart
from configure help.
Looking into ld-elf2flt makes me doubtful -
"LINKER="$0.real" # the original renamed-linker" - really? It will rename
my linker and replace it by itself? This script looks rather contrived,
will it really work correctly for all possible invocations of ld which
don't even want to do any elf2flt-ification?

This makes me reluctant to run "make install" blidly, I decided
to ask you instead for some directions.

In the order of importance:

Can you write up a small explanation what elf2flt does, how to produce
a flat executable with it? Let's say in my situation - I seem to have
correctly built static elf bfin busybox, can I make a flat one out of it?

What is this ld-elf2flt wrapper - what is it doing?

How elf2flt is added into binutils? Again, my situation - I built
bfin toolchain (binutils+gcc), it works, but it produces elf executables.
(Actually, I have two toolchains - bfin-linux-uclibc and bfin-uclinux.
Both produce elf executables). How to add elf2flt to the toolchain
so that it can produce flat executables? After that, how to instruct ld
to produce flat executable?


More information about the uClibc mailing list