[LLVMdev] Targeting low level embedded

Eli Friedman eli.friedman at gmail.com
Fri Mar 12 22:13:59 PST 2010


On Fri, Mar 12, 2010 at 9:10 PM, Tom Hawkins <tomahawkins at gmail.com> wrote:
> I'm new to LLVM and I'm trying to set it up to target a low level
> embedded device with no OS.  Therefore the final program needs to
> perform variable initialization and be located at a certain address
> location.  Here is my basic flow:
>
> Compile C to bytecode:
> $ llvm-gcc -emit-llvm -c src1.c src2.c src3.c
>
> Consolidate to one bytecode file:
> $ llvm-link -o all.o src1.c src2.o src3.o
>
> Emit assembly code:
> $ llc -march=ppc32 -o all.s all.o
>
> Assemble to machine code:
> $ powerpc-eabi-as -o all.elf all.s
>
> Relocate sections to target specific addresses:
> $ powerpc-eabi-ld -T sections.ld -o relocated.elf all.elf
>
> ... then convert to an s-record and flash the device.
>
> A few questions...
>
> 1. Is this the right approach?

You're trying to shoehorn LLVM into an environment it isn't really set
up for; if you've compiled llvm-gcc as a cross-compiler targeting
ppc32, then it should work roughly as well as it would work with gcc.
If llvm-gcc is an x86 compiler, you're likely to run into issues; see
http://llvm.org/docs/FAQ.html#platformindependent .

> 2. Does llvm-gcc insert initialization code?  It doesn't look like it,
> but I may be missing something.

Initialization for what, exactly?  Is your toolchain not capable of
setting up writable data sections correctly?

> 3. What is the difference between llvm-link and llvm-ld?  Does
> llvm-link do inter module optimization?

If you want to break down the process into steps as small as possible,
just use llvm-link.  llvm-ld is a combination of llvm-link and opt
-std-link-opts and optionally llc+as+ld.

> 4. Can llvm-link or llvm-ld perform any memory placement, or does this
> fall on binutils ld?

What do you expect llc to output?  llvm-link is not a linker in the
same way that ld is.

-Eli




More information about the llvm-dev mailing list