japaric-archived / ruststrap

[SUPERSEDED] by https://github.com/warricksothr/RustBuild
MIT License
96 stars 17 forks source link

cargo #35

Open geraldstanje opened 9 years ago

geraldstanje commented 9 years ago

hi,

how did you install cargo? i build the rust cross compiler from source...

japaric commented 9 years ago

If you want to use the existing (old) cargo nightlies, I recommend using multirust

If you want a newer cargo, I recommend using an old ARM nightly to build a new one (in the ARM device). Use the normal configure && make procedure but pass the --local-cargo=/path/to/cargo to the configure script.

geraldstanje commented 9 years ago

or build it from source using (http://www.rust-lang.org/install.html): curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --prefix tmp ?

geraldstanje commented 9 years ago

do you talk about the configure script from here https://github.com/rust-lang/rust ?

japaric commented 9 years ago

You are trying to build a newer cargo on your ARM device, right? Because you mention that you already cross compiled a rust compiler to ARM, and you can install one of my older cargo nightlies with multirust. Then, something like this should work:

# On your ARM device
# `rustc` should already work
$ rustc -V
rustc 1.2.0-nightly (0cc99f9cc 2015-05-17) (built 2015-05-18)

# The old `cargo` too
$ cargo -V
cargo 0.2.0-nightly (e3a6425 2015-04-27) (built 2015-04-28)

# Get cargo source
$ git clone https://github.com/rust-lang/cargo

# configure
$ cd cargo
$ ./configure --enable-nightly --enable-optimize --local-cargo=/some/path/bin/cargo
(...)

# then make
$ make
(...)

# The output will be at target/arm-*/release
$ ls target/arm-unknown-linux-gnueabihf/release
(..)  cargo  (..)  libcargo-afd1dac7f2432d5a.rlib  (..)
Arnold1 commented 9 years ago

i installed the cross compiler on my ubuntu linux...

this is how i installed cargo for ubuntu:

curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --prefix=tmp

why shouldnt i use this way? i would like to use rust 1.0.0 (stable)

japaric commented 9 years ago

@Arnold1 The rustup.sh script installs a pre-compiled package that includes rust and cargo, and there are only precompiled packages for officially supported targets like linux, mac and windows on x86_64/i686. That script won't work on your ARM device, because the arm-linux-gnueabihf target is not officially supported.

Arnold1 commented 9 years ago

i dont run cargo on the arm! cargo is used on ubuntu (x86_64) together with rustc (cross compiler for arm)

japaric commented 9 years ago

@Arnold1 Can you clarify what you intend to do? I see that you have both rust and cargo on a x86_64 machine, what is the role of the ARM device? Do you want to cross compile a crate on the x86_64 machine, and run the produced binary on the ARM device?

Arnold1 commented 9 years ago

i use ubuntu (x86_64) to cross compile rust for ARM, scp the binary to my ARM device and execute it there.

i build the rust cross compiler for ARM on my ubuntu. and also installed cargo on ubuntu as mentioned before.

japaric commented 9 years ago

i use ubuntu (x86_64) to cross compile rust for ARM, scp the binary to my ARM device and execute it there.

Yes, that the main idea. You may also need some libraries in the ARM device as well. Calling ldd on the ARM binary in your x86_64 machine may tell you which libraries you'll need in the ARM device. I've written about cross compiling in this document.

@Arnold1 or @geraldstanje Could you tell me what specific problems are you encountering? A lot of things can go wrong when cross compiling, specially when C dependencies/libraries are involved.

Arnold1 commented 9 years ago

hi, i have some problem when i build my app with:

cargo build --target=arm-unknown-linux-gnueabihf --release

here my ldd output:

    libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0x36de6000)
    /lib/ld-linux-armhf.so.3 (0x36f18000)
    libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x36d79000)
    libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0x36d6e000)
    libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0x36d53000)
    libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0x36d32000)

i get a runtime error: illegal instruction

japaric commented 9 years ago

@Arnold1

i get a runtime error: illegal instruction

That may be caused because you compiled the rust program for armv7, or one of the C dependencies was compiled for armv7 but you are running the binary on an armv6 device.

Could you give me details about the device? Is an ARMv6 processor? Also what rustc/cargo version are you using? Did you download one of my unofficial tarballs, or did you compile it yourself from source?

Arnold1 commented 9 years ago

here some infos:

rustc:

rustc --version
rustc 1.0.0-dev (a59de37e9 2015-05-13) (built 2015-05-21)

cargo:

./cargo --version
cargo 0.2.0-nightly (efb482d 2015-04-30) (built 2015-04-30)

arm device:

armv7l

i built rustc (cross compiler for arm) using your instruction and cargo (with the install script from here: http://www.rust-lang.org/install.html) by myself.

japaric commented 9 years ago

i built rustc (cross compiler for arm) using your instruction

Here may be the problem. which gcc cross compiler did you use to cross compile the standard crates? The g++-arm-linux-gnueabihf package provided by Ubuntu? If so, which Ubuntu release are you using? And what's the output of arm-linux-gnueabihf-gcc -v?

Also what linux distribution are you running on the ARM device? Does your cargo crate have any C dependencies? Does a simple "Hello, world" program work fine on the ARM device?

By the way, I've uploaded new tarballs for 1.0.0 and the nightly channel, you may want to try those as well.

Arnold1 commented 9 years ago

i use the following linker for rust:

[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

my output of arm-linux-gnueabihf-gcc -v:

gcc version 4.8.2 (Ubuntu/Linaro 4.8.2-16ubuntu4)

my cargo dependencies:

[dependencies]
libc = "*"
mmap = "*"

yes, simple hello world works fine...

the vm with the rust cross compiler uses:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:    14.04
Codename:   trusty

the arm device runs:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:    14.04
Codename:   trusty

the ubuntu for the arm device is downloaded from here:

root_tar=ubuntu-core-14.04.2-core-armhf.tar.gz
root_url=http://cdimage.ubuntu.com/ubuntu-core/releases/14.04/release/$root_tar

i used valgrind to see if there are any leaks:

japaric commented 9 years ago

If "hello world" works and your crate doesn't, could you try to generate a minimal working example that reproduces the "illegal instruction" problem, and share that with me?

Arnold1 commented 9 years ago

crate also does work... but i implemented a function which doesnt work with --release. it works fine with debug.

here is the function: http://ideone.com/OjuSb9

when i do the following change the function works fine with --release: from:

(*self.chaMem)[i] = (*data)[i] as u32;

to:

(*self.chaMem)[i] = 12; // this is just some dummy value

chaMem is defined as:

chaMem: *mut [u32; n],

very strange...

here the strace output: http://paste.ubuntu.com/11482780/ i guess i need to run gdb?

Arnold1 commented 9 years ago

i took the original code of the function and put a #[inline(never)] before ... code runs fine :D

japaric commented 9 years ago

If it works in debug but not under release, that could indicate that you are relying on undefined behavior at some point.

from ... to ...

That sounds like data may have been freed/unmapped at that point in time. I'd check the memory region under gdb.

i took the original code of the function and put a #[inline(never)] before ... code runs fine :D

Oh well...

Arnold1 commented 9 years ago

bug fixed :D

the following loop needs to be changed to for the release build (it works fine in debug), otherwise the code will crash with illegal instruction, reason: wrong code optimization: stmiacs r3!, {r1, r12} ... it stores two 32-bit values at a time...

use:

for i in 0..n {
              volatile_store::<u32>(&mut (*self.chaMem)[i], (*data)[i] as u32);
}