Last active
August 24, 2018 15:19
-
-
Save kenkeiter/c2add8253ba10791566a2d13c42e6442 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | |
// file at the top-level directory of this distribution and at | |
// http://rust-lang.org/COPYRIGHT. | |
// | |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
// option. This file may not be copied, modified, or distributed | |
// except according to those terms. | |
// Targets the Cortex-R4F/R5F processor (ARMv7-R, little-endian) | |
use std::default::Default; | |
use spec::{LinkerFlavor, PanicStrategy, Target, TargetOptions, TargetResult}; | |
pub fn target() -> TargetResult { | |
Ok(Target { | |
llvm_target: "armv7r-none-eabihf".to_string(), | |
target_endian: "little".to_string(), | |
target_pointer_width: "32".to_string(), | |
target_c_int_width: "32".to_string(), | |
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | |
arch: "arm".to_string(), | |
target_os: "none".to_string(), | |
target_env: "".to_string(), | |
target_vendor: "".to_string(), | |
linker_flavor: LinkerFlavor::Gcc, | |
options: TargetOptions { | |
executables: true, | |
relocation_model: "static".to_string(), | |
panic_strategy: PanicStrategy::Abort, | |
features: "+v7,+armv7-r,+db,+dsp,+dsp,+hwdiv,+rclass,+r5,+ras,+vfp3,+d16,+slow-fp-brcc,+hwdiv-arm,+slowfpvmlx,+thumb2".to_string(), | |
max_atomic_width: Some(32), | |
abi_blacklist: super::arm_base::abi_blacklist(), | |
emit_debug_gdb_scripts: false, | |
.. Default::default() | |
}, | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<...elided...> | |
running: "arm-eabi-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-r" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-mfloat-abi=hard" "-fomit-frame-pointer" "-DVISIBILITY_HIDDEN" "-o" "/home/osboxes/rust/build/x86_64-unknown-linux-gnu/stage2-std/armv7r-none-eabihf/release/build/compiler_builtins-f47ee1d949f1c3ff/out/../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.o" "-c" "../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S" | |
cargo:warning=../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S: Assembler messages: | |
cargo:warning=../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S:26: Error: selected processor does not support `vmov d7,r0,r1' in ARM mode | |
cargo:warning=../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S:27: Error: selected processor does not support `vcvt.s32.f64 s15,d7' in ARM mode | |
cargo:warning=../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S:28: Error: selected processor does not support `vmov r0,s15' in ARM mode | |
exit code: 1 | |
--- stderr | |
thread 'main' panicked at ' | |
Internal error occurred: Command "arm-eabi-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-ffunction-sections" "-fdata-sections" "-fPIC" "-march=armv7-r" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-mfloat-abi=hard" "-fomit-frame-pointer" "-DVISIBILITY_HIDDEN" "-o" "/home/osboxes/rust/build/x86_64-unknown-linux-gnu/stage2-std/armv7r-none-eabihf/release/build/compiler_builtins-f47ee1d949f1c3ff/out/../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.o" "-c" "../../libcompiler_builtins/compiler-rt/lib/builtins/arm/fixdfsivfp.S" with args "arm-eabi-gcc" did not execute successfully (status code exit code: 1). | |
', /home/osboxes/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.18/src/lib.rs:2181:5 | |
note: Run with `RUST_BACKTRACE=1` for a backtrace. | |
warning: build failed, waiting for other jobs to finish... | |
xerror: build failed | |
command did not execute successfully: "/home/osboxes/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "armv7r-none-eabihf" "-j" "2" "--release" "--features" "c mem" "-p" "alloc" "-p" "compiler_builtins" "--manifest-path" "/home/osboxes/rust/src/rustc/compiler_builtins_shim/Cargo.toml" "--message-format" "json" | |
expected success, got: exit code: 101 | |
thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1119:9 | |
note: Run with `RUST_BACKTRACE=1` for a backtrace. | |
failed to run: /home/osboxes/rust/build/bootstrap/debug/bootstrap dist --target armv7r-none-eabihf | |
Build completed unsuccessfully in 0:50:21 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Alright – random question for someone that knows Rust's build setup better than I do: I'm working to add (little-endian) a new target for Cortex R5F MCUs using the suitable Linaro toolchain, similar to the approach taken here https://github.com/rust-lang/rust/pull/50813 | |
nagisa has left IRC (Client exited) | |
13:49 kenkeiter | |
I *think* I'm running into a weird issue with Rust's fork of compiler-rt. It appears that a patch has been added upstream to deal with specifics of -mfloat-abi=hard (see https://github.com/llvm-mirror/compiler-rt/blob/master/lib/builtins/arm/fixdfsivfp.S#L22-L25) that aren't in Rust's fork of compiler-rt (https://github.com/rust-lang/compiler-rt/blob/master/lib/arm/fixdfsivfp.S). | |
kenkeiter | |
When I build, I'm getting a few errors that correspond to these (https://github.com/rust-lang/compiler-rt/blob/master/lib/arm/fixdfsivfp.S#L22-L24) instructions, prefixed with "Error: selected processor does not support <...> in ARM mode" | |
lachlansneff has joined ([email protected]) | |
japaric | |
kenkeiter: rust-lang/rust is not using the master branch of rust-lang/compiler-rt | |
japaric | |
the version it's using does include the patch you mention. This is it https://github.com/rust-lang/compiler-rt/blob/8964c7a0c4d1dc8c45b5adee6fe5ae3db057ab98/lib/builtins/arm/fixdfsivfp.S | |
13:54 kenkeiter | |
Hmm, then I'm guessing that somehow COMPILER_RT_ARMHF_TARGET is not defined. | |
japaric | |
kenkeiter: what's the full error message? I'd like to see what instruction the compiler is rejecting | |
kenkeiter | |
Sure; I'll paste a couple things into a gist for you. Give me two seconds... | |
japaric | |
also I find odd that the other ARM targets are not running into this | |
japaric | |
kenkeiter: what's the name of the new target? | |
kenkeiter | |
Me too, but I was able to build https://github.com/paoloteti/ti-hercules-bsp successfully. | |
japaric | |
the build script in compiler-rt using the target triple to decide which .c / .s files to builds | |
japaric | |
to build** | |
kenkeiter | |
Right; and it should be able to build this one. The new target is called "armv7r-none-eabihf" | |
dustinm` is now known as ivan | |
japaric | |
kenkeiter: it could also be that the 'cc' crate needs to learn about the new target | |
japaric | |
the cc crate chooses which C flags to use based on the target name | |
japaric | |
kenkeiter: (also, if are working with Cortex-R devices you may want to say hello in this thread https://github.com/rust-embedded/wg/issues/183) | |
rgcottrell has left IRC (Quit: My MacBook has gone to sleep. ZZZzzz…) | |
kenkeiter | |
Ahhh interesting. One sec. Almost done with that gist. | |
kenkeiter | |
@japaric https://gist.github.com/kenkeiter/c2add8253ba10791566a2d13c42e6442 | |
kenkeiter | |
(yes, the LLVM features are a little verbose/redundant at the moment – I was running into issues earlier so I brought them in from the LLVM td) | |
kenkeiter | |
(just added the Dockerfile, as well) | |
japaric | |
kenkeiter: thanks, looking | |
kenkeiter | |
@japaric Thank you :) | |
kenkeiter | |
First attempt at digging into this layer of the Rust – so I apologize if something obvious is wrong. | |
raymondsiu has joined ([email protected]) | |
Arcaelyx_ has left IRC (Quit: Textual IRC Client: www.textualapp.com) | |
japaric | |
kenkeiter: hmm, weird. The armebv7r target which has been already commited doesn't work for me. The build also fails while compiling compiler-rt and with a similar error message | |
kenkeiter | |
I'm guessing you're using the Linaro toolchain? | |
japaric | |
kenkeiter: the one in the dockerfile | |
kenkeiter | |
Yeah, that's the right one... | |
japaric | |
the armeb-eabi linaro one | |
kenkeiter | |
Ah, you're trying to build the eb target? | |
kenkeiter | |
Sorry, I had misread. | |
japaric | |
yes, the eb one but it also fails | |
kenkeiter | |
That's strange – that one builds properly for me. | |
japaric | |
what I don't understand is how the ti-hercules-bsp does compile correctly | |
japaric | |
since I don't have the armeb toolchain in my PATH | |
kenkeiter | |
I added it to my PATH... | |
jperras has left IRC (Ping timeout: 121 seconds) | |
japaric | |
kenkeiter: interesting when you compile the ti-hercules-bsp repo you compile the compiler-builtins crate but the rlib doesn't contain the fixdfsivfp symbol which causes problem in the rust build system | |
kenkeiter | |
That is interesting... I'm not sure what a fix looks like for that, since I don't have enough familiarity there :-/ Happy to rubber-duck though... | |
japaric | |
kenkeiter: ah ok I see the difference. when using cargo-xbuild the compiler-builtins crate is compiled without the "c" Cargo feature so the .c / .s files never get compiled | |
japaric | |
otoh when using the rust build system that crate is compiled with the "c" feature enabled | |
japaric | |
so there are few things to fix here | |
japaric | |
first the cc crate needs to gain support for the armebv7r target and for your new target | |
japaric | |
then we'll probably need to tweak the compiler-builtins crate so that it build with the "c" feature enabled for both targets | |
japaric | |
I'm not familar with using gcc to compiler code for the cortex-r architecture though. What are some common flags one use in that case? other than -march=armv7-r | |
Douman has left IRC (Quit: ) | |
kenkeiter | |
japaric: I'm happy to try to dig into that, if you wish, with the caveat that I have almost no idea what I'm doing (: | |
kenkeiter | |
japaric: Probably specification of the float ABI that's in use (i.e. `-mfloat-abi=hard`) | |
kenkeiter | |
fpu specification, as well (i.e. `-mfpu=vfpv3-d16`) | |
japaric | |
kenkeiter: compare https://gist.github.com/japaric/3ef9723ef60c6f91115047e3770fadcd#file-armebv7r-none-eabihf-out-L25 and https://gist.github.com/japaric/3ef9723ef60c6f91115047e3770fadcd#file-thumbv7m-none-eabi-out-L27 | |
japaric | |
the armeb target is wrong; it's using cc when it should use an arm compiler | |
kenkeiter | |
So, for the eb target (at least, via its Dockerfile), there's an env var being set that points to the cc provided in the Linaro toolchain | |
kenkeiter | |
https://github.com/paoloteti/rust/blob/4897093cfd858fb10ce538e86f7b549cb199db13/src/ci/docker/disabled/dist-armebv7r-none-eabihf/Dockerfile | |
japaric | |
kenkeiter: the -march needs to be fixed around here https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L1245 | |
japaric | |
based on the target name | |
rgcottrell has joined ([email protected]) | |
kenkeiter | |
AH, yes, that would be a problem... | |
japaric | |
kenkeiter: the gist contains parts of a Cargo project. You can use it test a local checkout of the cc crate. See https://gist.github.com/japaric/3ef9723ef60c6f91115047e3770fadcd#file-cargo-toml-L12 | |
japaric | |
kenkeiter: the default compiler is set around here https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L1675-L1678 I think arm-none-eabi would be a good default since it's what most Linux distros provide and it can always be overridden | |
14:52 kenkeiter | |
Good hint! Okay. So I'm guessing the best approach here would be to modify cc-rs to include some new target matching for ARM (specifically, something that detects the "eabihf" suffix and adds the appropriate flag), and then attempt to build Rust using the modified cc crate. | |
kenkeiter | |
Right, makes sense. | |
rgcottrell has left IRC (Connection closed) | |
kenkeiter | |
Alright; I'll give that a shot! Thanks for your help. Generally haven't needed to dig this deep in the past, so the guidance is definitely appreciated. | |
kenkeiter | |
japaric: ^ | |
15:00 japaric | |
kenkeiter: yw. I don't know of a way to make the rust build system use a local checkout of a crate like cc so it may be better to test that the compiler-builtins crate builds by calling `cargo build` from its directory -- previous addition of [replace] to its Cargo.toml | |
japaric -> ZzZ | |
kenkeiter | |
Well, I probably could get it to work with a local crate, but I'm guessing it'd be a pretty violent and disturbing process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:16.04 | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
g++ \ | |
make \ | |
file \ | |
curl \ | |
ca-certificates \ | |
python2.7 \ | |
git \ | |
cmake \ | |
sudo \ | |
xz-utils \ | |
bzip2 \ | |
libssl-dev \ | |
pkg-config | |
COPY scripts/sccache.sh /scripts/ | |
RUN sh /scripts/sccache.sh | |
ENV BASE_URL=https://releases.linaro.org/components/toolchain/binaries/latest/arm-eabi/ | |
ENV GCC_LINARO=gcc-linaro-7.3.1-2018.05-x86_64_arm-eabi | |
RUN curl -sL $BASE_URL/$GCC_LINARO.tar.xz | tar -xJ | |
ENV PATH=$PATH:/$GCC_LINARO/bin | |
ENV TARGET=armv7r-none-eabihf | |
ENV CC_armv7r_none_eabihf=arm-eabi-gcc \ | |
CFLAGS_armv7r_none_eabihf="-march=armv7-r" | |
ENV RUST_CONFIGURE_ARGS --disable-docs | |
ENV SCRIPT python2.7 ../x.py dist --target $TARGET |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
features: "+v7,+armv7-r,+db,+dsp,+dsp,+hwdiv,+rclass,+r5,+ras,+vfp3,+d16,+slow-fp-brcc,+hwdiv-arm,+slowfpvmlx,+thumb2
There are redundant features here: for example
v7
is superfluous because part ofllvm_target
(the v7 in the triple name), the same forv7r
, alsothumb2
is already part of+v7
. +dsp and +hwdiv are superfluous too.BTW the idea is to provide only a set of minimal features for a give target and to override/extend features at command line.