Open japaric opened 8 years ago
@Bigomby
I don't know what I'm doing wrong.
The only thing that I think you could be doing wrong is compiling the binary for
MIPS (big endian) but running it on a MIPSel (little endian) device but then not
even the "Hello, world!" program that uses system_alloc
would work so I'm
going to discard that possibility.
I'd like to check a few things:
My guess, since C code is involved in all the crashes, is that we are building
our binary releases of std
with C compiler flags that generate instructions
that are not available on your device. We'll hopefully only need to tweak those
and then a new nightly release of std
should work for you.
If it's not the C side, then we may need to tweak our LLVM codegen options.
Or it could be a bad libc
definition.
I got this when running with gdb
#![feature(alloc_system)]
extern crate alloc_system;
use std::net::TcpStream;
fn main() {
TcpStream::connect("google.com:80").unwrap();
}
(gdb) r
Starting program: /root/kinton-yeelight
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Program received signal SIGILL, Illegal instruction.
0x5556269c in ?? ()
(gdb) bt
#0 0x5556269c in ?? ()
#1 0x55565fdc in _$LT$str$u20$as$u20$std..net..addr..ToSocketAddrs$GT$::to_socket_addrs::h7d1fe6bb64ce9c00 ()
#2 0x55560cec in _ftext ()
This is what happends when using jemalloc
fn main() {
println!("Hello world");
}
(gdb) r
Starting program: /root/hello_world
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
Program received signal SIGILL, Illegal instruction.
je_arena_mapbits_binind_get () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:801
801 /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h: No such file or directory.
(gdb) bt
#0 je_arena_mapbits_binind_get () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:801
#1 je_arena_salloc () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:1317
#2 je_isalloc () at include/jemalloc/internal/jemalloc_internal.h:924
#3 je_iallocztm () at include/jemalloc/internal/jemalloc_internal.h:937
#4 a0ialloc () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/jemalloc.c:321
#5 je_a0malloc () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/jemalloc.c:336
#6 je_arena_tdata_get_hard () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/jemalloc.c:519
#7 0x5558f7dc in je_arena_tdata_get () at include/jemalloc/internal/jemalloc_internal.h:818
#8 je_decay_ticker_get () at include/jemalloc/internal/jemalloc_internal.h:842
#9 je_arena_decay_ticks () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:1253
#10 je_arena_decay_tick () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:1264
#11 je_arena_malloc_large () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/arena.c:2476
#12 0x55590ad4 in je_arena_malloc () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/arena.h:1287
#13 je_arena_palloc () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/arena.c:2601
#14 0x555b2420 in je_ipallocztm () at include/jemalloc/internal/jemalloc_internal.h:982
#15 je_tcache_create () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/tcache.c:328
#16 0x555849b0 in je_tcache_get () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/include/jemalloc/internal/tcache.h:236
#17 je_imalloc () at include/jemalloc/internal/jemalloc_internal.h:954
#18 imallocx_no_prof () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/jemalloc.c:2135
#19 mallocx () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/src/jemalloc/src/jemalloc.c:2164
#20 0x5557bb30 in alloc_jemalloc::imp::__rust_allocate () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/liballoc_jemalloc/lib.rs:106
#21 0x5557aaa4 in alloc::heap::allocate () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/liballoc/heap.rs:59
#22 alloc::raw_vec::{{impl}}::with_capacity<u8> () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/liballoc/raw_vec.rs:96
#23 collections::vec::{{impl}}::with_capacity<u8> () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libcollections/vec.rs:356
#24 collections::slice::hack::to_vec<u8> () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libcollections/slice.rs:160
#25 collections::slice::{{impl}}::to_vec<u8> () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libcollections/slice.rs:1161
#26 collections::slice::{{impl}}::to_owned<u8> () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libcollections/slice.rs:1281
#27 collections::str::{{impl}}::to_owned () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libcollections/str.rs:167
#28 0x5556c934 in std::rt::lang_start () at /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-linux/build/obj/../src/libstd/rt.rs:50
#29 0x55561cd8 in main ()
warning: GDB can't find the start of the function at 0x77f78acf.
GDB is unable to find the start of the function at 0x77f78acf
and thus can't determine the size of that function's stack frame.
This means that GDB may be unable to access that stack frame, or
the frames below it.
This problem is most likely caused by an invalid program counter or
stack pointer.
However, if you think GDB should simply search farther back
from 0x77f78acf for code which looks like the beginning of a
function, you can increase the range of the search using the `set
heuristic-fence-post' command.
A SIGILL probably means that we're miscompiling jemalloc somehow (maybe some weird codegen option) but if it still faults with the system allocator then it's likely not exclusively a jemalloc problem.
I tried to run the program on an OM2P (MIPS device) and it's working fine, even with jemalloc. OM2P uses an Atheros AR7240 so the issue seems to be something more specific to Broadcom 6358.
UPDATE: It crashes also when using glibc instead musl on the Huawei EchoLife HG556a.
Interesting. Then this could be due to codegen options related to "architecture level" (-march) or CPU optimizations (-mcpu) in the sense that the current rustc options generate instructions that are not available on some of these devices. Unfortunately, I don't know the MIPS ISA well enough to confirm this.
This is probably due to the ISA level. The HG556a seems to use MIPS32r1 and the OM2P uses MIPS32r2. I think LLVM defaults to MIPS32r2 unless told otherwise. It would be interesting to get a disassembly at the SIGILL, then I could tell you for certain that this was the problem.
I'm experiencing this issue too (on a Broadcom chip, though).
The chip is BCM63168. I have a working OpenWRT toolchain for it. Using mips-unknown-linux-musl
as a target with rustc
\Cargo works for a simple hello world application, but for anything more complicated I get an illegal instruction.
I have suffered similar losses in the battle for Illegal Instructions on mips. My research so far and i hope this helps:
To save you some hours i describe the process how i build a hello world without
ending up with Illegal instruction
errors on the BCM7425B2 STB platform.
Target Specs
root@vuduo2:~# cat /proc/cpuinfo
system type : BCM7425B2 STB platform
machine : Unknown
processor : 0
cpu model : Broadcom BMIPS5000 V1.1 FPU V0.1
BogoMIPS : 864.25
cpu MHz : 1305.097
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
processor : 1
cpu model : Broadcom BMIPS5000 V1.1 FPU V0.1
BogoMIPS : 655.36
cpu MHz : 1305.097
wait instruction : yes
microsecond timers : yes
tlb_entries : 64
extra interrupt vector : yes
hardware watchpoint : no
isa : mips1 mips2 mips32r1
ASEs implemented :
shadow register sets : 1
kscratch registers : 0
core : 0
VCED exceptions : not available
VCEI exceptions : not available
To compile for the target i used Codescape GNU Tools 2018.09-03 Binaries
https://codescape.mips.com/components/toolchain/2018.09-03/downloads.html
installed in C:\Toolchain\MIPS\mips-2016.05
.
Rust components used:
E:\Projects\Rust\vuduo2\hello-vuduo>rustup show
Default host: x86_64-pc-windows-gnu
installed targets for active tool chain
--------------------------------------
mipsel-unknown-linux-gnu
x86_64-pc-windows-gnu
active tool chain
----------------
nightly-x86_64-pc-windows-gnu (default)
rustc 1.35.0-nightly (719b0d984 2019-03-13)
Install "The sysroot manager that lets you build and customize std
"
xargo.
cargo install xargo
Paths are specific to my setup and locations. This can vary in your case and you have to adjust them.
Add your cross-compiler to the search path
set PATH=C:\Toolchain\MIPS\mips-2016.05\bin;%PATH%
Specify the compiler setup to use:
set CC=mips-linux-gnu-gcc
set CFLAGS_mipsel-unknown-linux-gnu=-EL
set AR_mipsel-unknown-linux-gnu=mips-linux-gnu-ar
mipsel-linux-gnu-gcc
,
but in my case the compiler is mips-linux-gnu-gcc
and can output in both endianess. You
have to consider this when using a different tool chain.
To learn more about the capabilities of the compiler use mips-linux-gnu-gcc --target-help
.Any minimal Cargo.toml
. Nothing special:
[package]
name = "hello-vuduo"
version = "0.1.0"
authors = ["Jedzia <jed69@gmx.de>"]
edition = "2018"
Build file for Xargo Xargo.toml
:
[dependencies]
std = {features = ["panic_unwind"]}
[build]
target = "mipsel-linux-gnu-gcc"
Illegal instruction
errors on mips32r1 targets as the
upstream target from the Rust repository is built for mips32r2 with fpxx and
nooddspreg enabled. This change was done on Mar 15, 2018:
bump mipsel isa leval and enable fpxx #48874The [build] target specifies the default architecture to build. Can also be specified at the command-line with
cargo build --target=mipsel-unknown-linux-gnu
xargo build --target=my-unknown-system-dos
Local cargo configuration .cargo/config
:
[build]
target = "mipsel-unknown-linux-gnu"
[target.mipsel-unknown-linux-gnu]
rustflags = [
"-C", "link-arg=-EL",
"-C", "target-cpu=mips32",
"-C", "target-feature=+mips32,-mips32r2,-fpxx,-nooddspreg",
]
ar = "mips-linux-gnu-ar"
linker = "mips-linux-gnu-gcc"
runner = "run.bat"
rustc -C help
will list all options available. The default target specs for the current rustc
compiler can be listed with:
rustc -Z unstable-options --print target-spec-json --target mipsel-unknown-linux-gnu
.
The used options in detail:
rustc --print target-cpus
. We are building for mips so with our target:
rustc --target mipsel-unknown-linux-gnu --print target-cpus
.rustc --print target-features
or in our case:
rustc --target mipsel-unknown-linux-gnu -C target-cpu=mips32 -C target-feature=help
. I was able to successfully compile and run with the fpxx and nooddspreg options enabled (
"-C", "target-feature=+mips32,-mips32r2,+fpxx,+nooddspreg"
). Maybe they are not necessary for the VU+ Duo2. But i can't prove this as i only compile a little hello world with floating point arithmetic in it. When it fails you have to tweak it for your target. I have disabled these options as they are part of the #48874 change set (see above).
run
xargo build
or if you have set up a runner in .cargo/config
for remote execution
xargo run
to see it work.
and
cargo build
to see it fail again with illegal instruction as it is compiled against the Rust mipsel-unknown-linux-gnu target and not our custom one built by xargo.
I cant withstand not to add an example: https://github.com/Jedzia/RokerDepp
cc @Bigomby @alexcrichton
Originally reported as japaric/rust-cross#27
Original report below:
Hi, I'm trying to cross compile a Rust app for LEDE (fork of OpenWRT) but I'm stuck.
The application is just an
hello_world
example:These are the steps I performed:
mips-openwrt-linux-musl-gcc
).rustup add mips-unknown-linux-musl
.Create a
.cargo/config
file in my project with the following content:cargo build --release --target=mips-unknown-linux-musl
.scp
.Illegal instruction
On target
On host
Disabling jemalloc
If I use rust nightly and disable jemalloc as following:
Then it works! But as I keep adding code the application eventually crashes with another
Illegal instruction
. For example:Works
Does not work
I don't know what I'm doing wrong. Any help will be appreciated.