From 9dece62800d69c72b538ca00b44d17bf7e449077 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 15:19:16 +0200 Subject: [PATCH 1/8] remove build dependency on arm-none-eabi-gcc Before this commit we used gcc to assemble external assembly files into object files that we linked into our Rust program. This commit drops the dependency on gcc by shipping the already assembled object files with this crate source code. --- .gitignore | 1 + Cargo.toml | 3 --- asm.s | 1 + assemble.sh | 17 +++++++++++++++++ bin/thumbv6m-none-eabi.a | Bin 0 -> 886 bytes bin/thumbv7em-none-eabi.a | Bin 0 -> 886 bytes bin/thumbv7em-none-eabihf.a | Bin 0 -> 886 bytes bin/thumbv7m-none-eabi.a | Bin 0 -> 886 bytes build.rs | 11 +++++++---- 9 files changed, 26 insertions(+), 7 deletions(-) create mode 100755 assemble.sh create mode 100644 bin/thumbv6m-none-eabi.a create mode 100644 bin/thumbv7em-none-eabi.a create mode 100644 bin/thumbv7em-none-eabihf.a create mode 100644 bin/thumbv7m-none-eabi.a diff --git a/.gitignore b/.gitignore index 6dc3db1a..9895bb1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **/*.rs.bk Cargo.lock +bin/*.o target/ diff --git a/Cargo.toml b/Cargo.toml index 988faa71..e8313207 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,6 @@ name = "cortex-m-rt" repository = "https://github.com/japaric/cortex-m-rt" version = "0.5.2" -[build-dependencies] -cc = "1.0.10" - [dependencies] r0 = "0.2.1" diff --git a/asm.s b/asm.s index 2937be84..c7133c07 100644 --- a/asm.s +++ b/asm.s @@ -1,3 +1,4 @@ + .section .text.HardFault .global HardFault .thumb_func HardFault: diff --git a/assemble.sh b/assemble.sh new file mode 100755 index 00000000..f2ee3fd9 --- /dev/null +++ b/assemble.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -euxo pipefail + +# cflags taken from cc 1.0.22 + +arm-none-eabi-as -march=armv6s-m asm.s -o bin/cortex-m-rt.o +ar crs bin/thumbv6m-none-eabi.a bin/cortex-m-rt.o + +arm-none-eabi-as -march=armv7-m asm.s -o bin/cortex-m-rt.o +ar crs bin/thumbv7m-none-eabi.a bin/cortex-m-rt.o + +arm-none-eabi-as -march=armv7e-m asm.s -o bin/cortex-m-rt.o +ar crs bin/thumbv7em-none-eabi.a bin/cortex-m-rt.o +ar crs bin/thumbv7em-none-eabihf.a bin/cortex-m-rt.o + +rm bin/cortex-m-rt.o diff --git a/bin/thumbv6m-none-eabi.a b/bin/thumbv6m-none-eabi.a new file mode 100644 index 0000000000000000000000000000000000000000..62ac3178dac91bba2eb2ab9bf24cfe9801437660 GIT binary patch literal 886 zcmah{OH0E*5T2Oy6+CFKdT2qg2eVcP)kBf?VDVr;eBrU1Hqb&#WwQl6=}+)ydh_7H zi&$rp4A};x6K3c2%{SRenq8?zlXLgDu`X>ROnvigG)~SKFmwUHLVdWDYCMq3nTF9q z>FC*;drFH1Qvb)+@%@D6)Mv!deZ9CESQZhcVnHjR=lCuymHZ^p0vBrV`Bi;eegCfd zdzh4w45wi2qFd_RdI6NTD?u$MWFo`bYZCx$*fOdV+lAOEbU1~28LF7!p>=TZ$z_M! z0}c0ar1Gsnf^n%)#4mF#L$q3@cETPmR)ZKzEkT5F3_?XSK}nG_iT+I>q}FO0E_D>= zgEx4zK6>YJhD&#xH}O`Q8IHG7#PPik5l7eAgllJf=3MGy;kiecsG;_3{LIVZ3RJh)k6n@JGkeB;yeu54jUdUh^Tnn>sHucWAge2^Q1q)pXtqm z2QT7G+J?RjMFV-sOTK)0Nn2}6H5{M2$KJX$jce+gr{|rVF<{^VfQ5Q@A=Ria7gG(x zxzf?HF>5F-=1Bb;+o|s-G%cSI1NW(S*|#hrOvQqFLeKY`G*$GIKpkADz}tKIdG+zN z>h57sMlzg$wTo`C)oTRcY?p${7T5n|?X?a7Hmt*KjF@6WVWXm8rV;Hx86!MJ74arw zhtLNaZsSPhTZ07SQlW?+XIh46wMy-nJzT5?F_Kz>2;&%pil%~sB4-la>p)1Y)g)Z# zD5h@z5?UX<*~!r9j`LF9N-e|jRyJ`w_aWkFoWF3*jL+;#bu8TX2m=+=PL}vYOSlp$ z?U$799aQZ3fF_YPp8J_khTlh)xhZ~+`hse5(zl|XJOjG$idrQn6Xv6T&cqckam66C GjQa-CicReR literal 0 HcmV?d00001 diff --git a/bin/thumbv7em-none-eabihf.a b/bin/thumbv7em-none-eabihf.a new file mode 100644 index 0000000000000000000000000000000000000000..ef9042ff8a177ac4c4e72309f498ffa708b01f02 GIT binary patch literal 886 zcma)4K}*9>3{LIVZ3RJh)k6n@JGkeB;yeu54jUdUh^Tnn>sHucWAge2^Q1q)pXtqm z2QT7G+J?RjMFV-sOTK)0Nn2}6H5{M2$KJX$jce+gr{|rVF<{^VfQ5Q@A=Ria7gG(x zxzf?HF>5F-=1Bb;+o|s-G%cSI1NW(S*|#hrOvQqFLeKY`G*$GIKpkADz}tKIdG+zN z>h57sMlzg$wTo`C)oTRcY?p${7T5n|?X?a7Hmt*KjF@6WVWXm8rV;Hx86!MJ74arw zhtLNaZsSPhTZ07SQlW?+XIh46wMy-nJzT5?F_Kz>2;&%pil%~sB4-la>p)1Y)g)Z# zD5h@z5?UX<*~!r9j`LF9N-e|jRyJ`w_aWkFoWF3*jL+;#bu8TX2m=+=PL}vYOSlp$ z?U$799aQZ3fF_YPp8J_khTlh)xhZ~+`hse5(zl|XJOjG$idrQn6Xv6T&cqckam66C GjQa-CicReR literal 0 HcmV?d00001 diff --git a/bin/thumbv7m-none-eabi.a b/bin/thumbv7m-none-eabi.a new file mode 100644 index 0000000000000000000000000000000000000000..b93dae7e22dd122d40513fd113b43040363ca0c4 GIT binary patch literal 886 zcma)3ze~eV5WblH%%mN4X+hAzJ}U(4P^29!4i-dI9Q)D+T4<>xub`9u3I3UG4h}A2 z{VvJT*P`gb<$itl-MdSzrK7><)H|%MO2Z0M-~LvsM<)X4dqm_wZ_jl!?CSZ%&|nss z@S#4fM@G#+{Tth{?FlEGI82y|L;DH6#Mfyl? zjie5BFeYacZoXOXQNb(r${W)Dqjgs%5V^F9cagEhrQBLa&MpI8pb|2&MFn^p!Ed8o zLpO04Ew4ri#^Xj6KTeGfU`>?Tk$5<)AvM%SlM3RPR1{7WC)JWkb*_3!8xxI#xd~&Q z_Al81ir-ww(CLkrt#XxGhLfwT<7DqW;CP+CaE*-5p38kAGWP(9GPIo)K4BSGgz|k^ zIc`HS^ByLV7QVcjh`f)jaC7Yr`U15%`Csu&*#R!SLM!ZKB79qjZCnn8O98 BO`-q* literal 0 HcmV?d00001 diff --git a/build.rs b/build.rs index fc53d79f..8166b1b0 100644 --- a/build.rs +++ b/build.rs @@ -1,18 +1,21 @@ -extern crate cc; - use std::env; -use std::fs::File; +use std::fs::{self, File}; use std::io::Write; use std::path::PathBuf; fn main() { let target = env::var("TARGET").unwrap(); + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); has_fpu(&target); let is_armv6m = is_armv6m(&target); if target.starts_with("thumbv") { - cc::Build::new().file("asm.s").compile("asm"); + fs::copy( + format!("bin/{}.a", target), + out_dir.join("libcortex-m-rt.a"), + ).unwrap(); + println!("cargo:rustc-link-lib=static=cortex-m-rt"); } // Put the linker script somewhere the linker can find it From 6c971db6ee3f7b16968a184c0118684943638840 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 15:31:06 +0200 Subject: [PATCH 2/8] refactor assemble.sh --- assemble.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/assemble.sh b/assemble.sh index f2ee3fd9..5d368a80 100755 --- a/assemble.sh +++ b/assemble.sh @@ -4,14 +4,16 @@ set -euxo pipefail # cflags taken from cc 1.0.22 -arm-none-eabi-as -march=armv6s-m asm.s -o bin/cortex-m-rt.o -ar crs bin/thumbv6m-none-eabi.a bin/cortex-m-rt.o +crate=cortex-m-rt -arm-none-eabi-as -march=armv7-m asm.s -o bin/cortex-m-rt.o -ar crs bin/thumbv7m-none-eabi.a bin/cortex-m-rt.o +arm-none-eabi-as -march=armv6s-m asm.s -o bin/$crate.o +ar crs bin/thumbv6m-none-eabi.a bin/$crate.o -arm-none-eabi-as -march=armv7e-m asm.s -o bin/cortex-m-rt.o -ar crs bin/thumbv7em-none-eabi.a bin/cortex-m-rt.o -ar crs bin/thumbv7em-none-eabihf.a bin/cortex-m-rt.o +arm-none-eabi-as -march=armv7-m asm.s -o bin/$crate.o +ar crs bin/thumbv7m-none-eabi.a bin/$crate.o -rm bin/cortex-m-rt.o +arm-none-eabi-as -march=armv7e-m asm.s -o bin/$crate.o +ar crs bin/thumbv7em-none-eabi.a bin/$crate.o +ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o + +rm bin/$crate.o From c5189e1807d0a7204343653b1513cc4dc03ada45 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 15:56:32 +0200 Subject: [PATCH 3/8] simplify CI we no longer need to test clang because this crate never invokes a compiler / assembler --- .travis.yml | 16 ---------------- ci/script.sh | 30 ++++++++++++------------------ 2 files changed, 12 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7381b734..ff66c360 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,34 +9,18 @@ matrix: rust: stable if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv6m-none-eabi CC=clang - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7m-none-eabi rust: stable if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7m-none-eabi CC=clang - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7em-none-eabi rust: stable if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7em-none-eabi CC=clang - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7em-none-eabihf rust: stable if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv7em-none-eabihf CC=clang - rust: stable - if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - - env: TARGET=thumbv6m-none-eabi rust: nightly if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) diff --git a/ci/script.sh b/ci/script.sh index 2e070bfc..1fa35358 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -20,63 +20,57 @@ main() { # linking with GNU LD for ex in "${examples[@]}"; do cargo rustc --target $TARGET --example $ex -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x cargo rustc --target $TARGET --example $ex --release -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x done for ex in "${fail_examples[@]}"; do ! cargo rustc --target $TARGET --example $ex -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x ! cargo rustc --target $TARGET --example $ex --release -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x done cargo rustc --target $TARGET --example device --features device -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x cargo rustc --target $TARGET --example device --features device --release -- \ - -C link-arg=-nostartfiles \ - -C link-arg=-Wl,-Tlink.x + -C linker=arm-none-eabi-ld \ + -C link-arg=-Tlink.x # linking with rustc's LLD for ex in "${examples[@]}"; do cargo rustc --target $TARGET --example $ex -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x cargo rustc --target $TARGET --example $ex --release -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x done for ex in "${fail_examples[@]}"; do ! cargo rustc --target $TARGET --example $ex -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x ! cargo rustc --target $TARGET --example $ex --release -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x done cargo rustc --target $TARGET --example device --features device -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x cargo rustc --target $TARGET --example device --features device --release -- \ -C linker=rust-lld \ - -Z linker-flavor=ld.lld \ -C link-arg=-Tlink.x fi } From 4c229ebfaf1c2eec68a9e5650bb8f75d9d821ee1 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 17:15:41 +0200 Subject: [PATCH 4/8] check that the blobs are up to date --- .gitignore | 2 ++ .travis.yml | 1 + check-blobs.sh | 21 +++++++++++++++++++++ ci/script.sh | 4 ++++ 4 files changed, 28 insertions(+) create mode 100755 check-blobs.sh diff --git a/.gitignore b/.gitignore index 9895bb1c..c71d6dbd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ **/*.rs.bk Cargo.lock +bin/*.after +bin/*.before bin/*.o target/ diff --git a/.travis.yml b/.travis.yml index ff66c360..caa29efb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: rust matrix: include: - env: TARGET=x86_64-unknown-linux-gnu + rust: stable if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master) - env: TARGET=thumbv6m-none-eabi diff --git a/check-blobs.sh b/check-blobs.sh new file mode 100755 index 00000000..e1d0d80e --- /dev/null +++ b/check-blobs.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Checks that the blobs are up to date with the committed assembly files + +set -euxo pipefail + +for lib in $(ls bin/*.a); do + filename=$(basename $lib) + arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.before +done + +./assemble.sh + +for lib in $(ls bin/*.a); do + filename=$(basename $lib) + arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.after +done + +for cksum in $(ls bin/*.after); do + diff -u $cksum ${cksum%.after}.before +done diff --git a/ci/script.sh b/ci/script.sh index 1fa35358..7d1cc677 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -73,6 +73,10 @@ main() { -C linker=rust-lld \ -C link-arg=-Tlink.x fi + + if [ $TARGET = x86_64-unknown-linux-gnu ]; then + ./check-blobs.sh + fi } main From c4a7e88624c5d28f6bb3723a38072f73a5ac2522 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 17:16:10 +0200 Subject: [PATCH 5/8] [TODO: UNDO] introduce an intentional error --- asm.s | 1 + 1 file changed, 1 insertion(+) diff --git a/asm.s b/asm.s index c7133c07..ffd0407c 100644 --- a/asm.s +++ b/asm.s @@ -3,4 +3,5 @@ .thumb_func HardFault: mrs r0, MSP + nop bl UserHardFault From 157a742fd129110d4742a5ed225fbfb4c9f3a28a Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 17:18:54 +0200 Subject: [PATCH 6/8] #!/bin/bash --- assemble.sh | 2 +- check-blobs.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/assemble.sh b/assemble.sh index 5d368a80..f9ec7d87 100755 --- a/assemble.sh +++ b/assemble.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -euxo pipefail diff --git a/check-blobs.sh b/check-blobs.sh index e1d0d80e..94fde420 100755 --- a/check-blobs.sh +++ b/check-blobs.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Checks that the blobs are up to date with the committed assembly files From fe7382e687684415bc242f0048b05f82e122f777 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 17:26:40 +0200 Subject: [PATCH 7/8] always install arm-none-eabi-gcc --- ci/install.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ci/install.sh b/ci/install.sh index f211207f..e63e8054 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -3,13 +3,11 @@ set -euxo pipefail main() { if [ $TARGET != x86_64-unknown-linux-gnu ]; then rustup target add $TARGET + fi - if [ ${CC:-gcc} = gcc ]; then - mkdir gcc + mkdir gcc - curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj - fi - fi + curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj } main From dd0c08a2a59dfdbd0bc9ae56130116f78a7b15cc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 25 Aug 2018 17:30:32 +0200 Subject: [PATCH 8/8] remove intentional error --- asm.s | 1 - 1 file changed, 1 deletion(-) diff --git a/asm.s b/asm.s index ffd0407c..c7133c07 100644 --- a/asm.s +++ b/asm.s @@ -3,5 +3,4 @@ .thumb_func HardFault: mrs r0, MSP - nop bl UserHardFault