Cross compiling with lld gives me entry point of 0x0

I want to compile a rust application for an embedded system featuring an armv5, which leads me to the following setup.

rustc --version
rustc 1.25.0-nightly (27a046e93 2018-02-18)

A freescale compiler toolchain which is the same as this one (gcc-4.1.2 with glibc-2.5)

/usr/lib/llvm-6.0/bin/ld.lld --version
LLD 6.0.0 (compatible with GNU linkers)

which is taken from the official llvm repo.

My file looks like this:

#![feature(global_allocator, allocator_api)]

use std::heap::System;

#[global_allocator]
static ALLOCATOR: System = System;

fn main() {
    println!("Hello World");
}

Which is the minimal example with the default allocator instead of jemalloc.

Now I try to compile the file with rustc

rustc --target armv5te-unknown-linux-gnueabi hello.rs -Z linker-flavor=ld -C linker=/usr/lib/llvm-6.0/bin/ld.lld -C link-args='-dynamic-linker /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/arm-none-linux-gnueabi/sysroot/lib/ld-linux.so.3 -L/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/arm-none-linux-gnueabi/sysroot/lib/ -L/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/arm-none-linux-gnueabi/sysroot/usr/lib/'

which succeeds and produces a valid binary. But trying to execute it on the remote platform gives me

./hello 
-sh: ./hello: not found

which is, I think, a result of this:

$ /opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-readelf hello -h
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          52 (bytes into file)
  Start of section headers:          1826276 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         22
  Section header string table index: 20

How is it possible, that lld cannot determine the entry point? Is there a way to get additional information (e.g. --verbose did not print any line so far).

Looks like the linker generated either a dud elf header or dud executable. Does the compiled binary look really small, as if it doesn't really contain any code?

You may want to check the target JSON file (if defining your own target) or linker script (if you are using one) to double check what the entry point is. I know there are ways to ask rustc to dump the full linker invitation and a bunch of other info, but I can't remember what the particular compiler arguments are.

The binary is quite big for that simple program (~2MB)
There is no specific json file, but the official armv5te target from rustup (nightly).
Does anybody know the compiler switch :confused: ?