Thread: [Fremantle Maemo5] Running Rust programs on N900
View Single Post
Posts: 88 | Thanked: 411 times | Joined on Mar 2010 @ southern Italy
#1
I happen to love Rust programming language (already running my code on ARM targets like Jolla phone and Beagleboard).

I just found a way to cross-compile Rust programs to run on a N900.

Scenario:
- write/debug some Rust program on my Ubuntu PC
- cross-compile it for ARMv7 target (thanks, Rustup!)
- copy executable file on the N900 and execute it there.

On the N900:
- have a directory with updated libc/ldso/libgcc_s...
- use it:
Code:
LD_LIBRARY_PATH=/root/rust ./myrustprogram
Why this ugly solution:
- latest Rust releases require at least glibc 2.18 on the target N900
- (and glibc versions newer than 2.18 require kernel 2.6.32 or newer)
- I didn't want to try risky upgrades.

N900 preparation:
- grab a glibc 2.18 binary (I found one from OpenSUSE 13.1/ARM)
- grab the related libgcc_s binary (I found one from OpenSUSE 13.2/ARM)
- unpack them on your desktop PC, for example:
Code:
mkdir tmp
cd tmp
rpm2cpio glibc-2.18-4.44.1.armv7hl.rpm | cpio -idmv 
rpm2cpio libgcc_s1-4.8.3+r212056-2.2.1.armv7hl.rpm | cpio -idmv
- create a "rust" directory on the N900 in some place where executable bit is supported, for example:
Code:
ssh root@n900 mkdir /root/rust
- copy libraries (libc-2.18.so and so on) extracted from the glibc 2.18 and libgcc_s packages (will waste some 3.5 Mb of your precious disk space), for example:
Code:
rsync -ave ssh lib/* /root/rust/
- create a symbolic link to the new loader:
Code:
ssh root@n900 ln -s /root/rust/ld-linux-armhf.so.3 /lib
Typical workflow on desktop PC:
Code:
cargo new mytest --bin
cd mytest
vi src/main.rs
cargo build --quiet --release --target=armv7-unknown-linux-gnueabihf
cd target/armv7-unknown-linux-gnueabihf/release
arm-linux-gnueabihf-strip mytest
rsync -ave ssh mytest root@n900:/root/
And then, on the N900:
Code:
LD_LIBRARY_PATH=/root/rust /root/mytest
Note: you don't need to be root, as long as libraries are readable/executable.

Why did it work?
- Rust-compiled executables only require a few essential libraries (generally libc, libm, libpthread, libdl)
- Rust-compiled executables are happy with glibc 2.18 (this is why the same executable for N900 works on the Beagleboard and Jolla phones)
- I was lucky: N900 stock software uses legacy ld-linux.so.3 loader name instead of ld-linux-armhf.so.3

Note:
- a trick like this will work on any platform as long as it uses the legacy loader name and the kernel is not too old for the glibc "updated" version;
- some "updated" features may require extra fiddling (nsswitch, rpc, bindresvport; check the etc directory of the glibc package if you need them).

Mission: accomplished.
Attached Images
 
 

The Following 15 Users Say Thank You to alfmar For This Useful Post: