rustc, ELF, ld...
Julie Stamp (8365) 474 posts |
Hello, I had a go at trying to run rustc output (from Linux) on RISC OS.
produces an ELF file with correct code in (my test program has standard library and C runtime disabled, so it’s pure ARM), and everything looks ok to me using objdump. When I run it on RISC OS however the .text segment doesn’t end up in the right place. The error is “Undefined instruction at &20114”, which makes sense as I’m hoping someone who understands ELF and ld a bit better than me can help here?! In case anyone else wants a go, here is my main.rs:
Also to actually get the target to work I had to do
|
Paolo Fabio Zaino (28) 1882 posts |
Hummm sounds like something may not right with some PT_LOAD segment maybe? What readelf shows? Have you compared the header with what is generated by GCC when a module is compiled without SCL/UnixLib support? Also remember that in Rust: #![no_std] surely compile without std support, but it still uses core (which is kind of a subset of std), so it is possible that maybe core is causing some linking issues? |
Julie Stamp (8365) 474 posts |
This is what it looked like (linked with default, rust-lld)
I figured ld in the gccsdk cross-compiler knows how to produce the right arrangement, so I built using
(the -nostdlib is to stop it trying to put crt0.o in), but ld ((GCCSDK GCC 4.7.4 Release 5) 2.24) terminated with a segmentation fault. I put autobuilder to work on gcc8 which gave me an ld (GNU Binutils) 2.30, and using
I get an ELF looking like
which seems much more satisfactory. Getting a little excited now, I tried running it in RISC OS and it didn’t crash, and the memory at &8000 is just the ELF as expected. To prove it really worked, I modified the function h in main.rs to
and after running it *Memory 8000 shows
:D |
Paolo Fabio Zaino (28) 1882 posts |
nice work! :) |
Julie Stamp (8365) 474 posts |
Looking at the possibility of porting libstd to RISCOS, I tried compiling my test program with
which complained that librt, libdl and libutil were not available. I didn’t find those libraries in the gccsdk autobuilder (I satisified other dependencies that are provided by gccsdk by appending ‘-C link-args=“…”’). There was a step in the middle where I cross-compiled libstd, but I don’t remember the command now, I think it might be using rustup. I also used a custom json target file at some point:
So I think we’d need to either satisfy the above dependencies or somehow switch off those bits (It looks to me like they’re actually dependencies of rusts’s libc, studying the source code.) |
Paolo Fabio Zaino (28) 1882 posts |
Yes librt is the PSOIX.4 API for real time extensions. In rust it should be used by clock_gettime (and yes rust should not link to it by default, no idea why it does!), anyway, maybe it may be easy to replace? (guessing!) libdl is the dynamic linking library (it is used by dl_iterate_phdr and obviously by libloading.rs), it should be available, we just used it for RiscLua and it’s working fine. libutil, if not available, should be easy to port, there is already a tested armv7-none-eabi-* somewhere, I remember I have used it for another project… Few obvious questions:
JFYI, this guide is what I use when cross compiling with Rust, it may have some useful info: https://github.com/japaric/rust-cross |