Skip to content

Commit 73ced50

Browse files
bors[bot]japaric
andcommitted
Merge #41
41: use LLD as the default linker r=therealprof a=japaric closes #39 I added instructions on how to switch to a different linker to .cargo/config but I don't think that's too visible. Beginners are unlikely to look into that file if they run into problems with the default linker. Any suggestions to improve the visibility of that information? Also, don't merge this until the default linker changes for the Cortex-M targets on nightly as this relies on that change. r? @rust-embedded/cortex-m Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 014dab6 + b89c76e commit 73ced50

File tree

9 files changed

+90
-77
lines changed

9 files changed

+90
-77
lines changed

.cargo/config

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
11
[target.thumbv6m-none-eabi]
22
runner = 'arm-none-eabi-gdb'
33
rustflags = [
4-
"-C", "link-arg=-Wl,-Tlink.x",
5-
"-C", "link-arg=-nostartfiles",
4+
# LLD (shipped with the Rust toolchain) is used as the default linker
5+
"-C", "link-arg=-Tlink.x",
6+
7+
# if you run into problems with LLD switch to the GNU linker by commenting out
8+
# this line
9+
# "-C", "linker=arm-none-eabi-ld",
10+
11+
# if you need to link to pre-compiled C libraries provided by a C toolchain
12+
# use GCC as the linker by commenting out both lines above and then
13+
# uncommenting the three lines below
14+
# "-C", "linker=arm-none-eabi-gcc",
15+
# "-C", "link-arg=-Wl,-Tlink.x",
16+
# "-C", "link-arg=-nostartfiles",
617
]
718

819
[target.thumbv7m-none-eabi]
920
runner = 'arm-none-eabi-gdb'
1021
rustflags = [
11-
"-C", "link-arg=-Wl,-Tlink.x",
12-
"-C", "link-arg=-nostartfiles",
22+
# the comments under `[target.thumbv6m-none-eabi]` also apply here
23+
"-C", "link-arg=-Tlink.x",
24+
25+
# "-C", "linker=arm-none-eabi-ld",
26+
27+
# "-C", "linker=arm-none-eabi-gcc",
28+
# "-C", "link-arg=-Wl,-Tlink.x",
29+
# "-C", "link-arg=-nostartfiles",
1330
]
1431

1532
[target.thumbv7em-none-eabi]
1633
runner = 'arm-none-eabi-gdb'
1734
rustflags = [
18-
"-C", "link-arg=-Wl,-Tlink.x",
19-
"-C", "link-arg=-nostartfiles",
35+
# the comments under `[target.thumbv6m-none-eabi]` also apply here
36+
"-C", "link-arg=-Tlink.x",
37+
38+
# "-C", "linker=arm-none-eabi-ld",
39+
40+
# "-C", "linker=arm-none-eabi-gcc",
41+
# "-C", "link-arg=-Wl,-Tlink.x",
42+
# "-C", "link-arg=-nostartfiles",
2043
]
2144

2245
[target.thumbv7em-none-eabihf]
2346
runner = 'arm-none-eabi-gdb'
2447
rustflags = [
25-
"-C", "link-arg=-Wl,-Tlink.x",
26-
"-C", "link-arg=-nostartfiles",
48+
# the comments under `[target.thumbv6m-none-eabi]` also apply here
49+
"-C", "link-arg=-Tlink.x",
50+
51+
# "-C", "linker=arm-none-eabi-ld",
52+
53+
# "-C", "linker=arm-none-eabi-gcc",
54+
# "-C", "link-arg=-Wl,-Tlink.x",
55+
# "-C", "link-arg=-nostartfiles",
2756
]

.travis.yml

+7-16
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,24 @@ language: rust
22

33
matrix:
44
include:
5+
- env: TARGET=x86_64-unknown-linux-gnu
6+
rust: nightly
7+
if: branch = master AND type != pull_request
8+
59
- env: TARGET=thumbv6m-none-eabi
610
rust: nightly
7-
addons:
8-
apt:
9-
packages:
10-
- gcc-arm-none-eabi
1111
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
1212

1313
- env: TARGET=thumbv7m-none-eabi
1414
rust: nightly
15-
addons:
16-
apt:
17-
packages:
18-
- gcc-arm-none-eabi
1915
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2016

2117
- env: TARGET=thumbv7em-none-eabi
2218
rust: nightly
23-
addons:
24-
apt:
25-
packages:
26-
- gcc-arm-none-eabi
2719
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2820

2921
- env: TARGET=thumbv7em-none-eabihf
3022
rust: nightly
31-
addons:
32-
apt:
33-
packages:
34-
- gcc-arm-none-eabi
3523
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
3624

3725
before_install: set -e
@@ -42,6 +30,9 @@ install:
4230
script:
4331
- bash ci/script.sh
4432

33+
after_success:
34+
- bash ci/after-success.sh
35+
4536
after_script: set +e
4637

4738
cache: cargo

Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
authors = ["Jorge Aparicio <[email protected]>"]
33
categories = ["embedded", "no-std"]
44
description = "A template for building applications for ARM Cortex-M microcontrollers"
5+
documentation = "https://rust-embedded.github.io/cortex-m-quickstart/cortex_m_quickstart"
56
keywords = ["arm", "cortex-m", "template"]
67
license = "MIT OR Apache-2.0"
78
name = "cortex-m-quickstart"
89
repository = "https://github.com/japaric/cortex-m-quickstart"
9-
version = "0.3.3"
10+
version = "0.3.4"
1011

1112
[dependencies]
12-
cortex-m = "0.5.0"
13-
cortex-m-rt = "0.5.0"
14-
cortex-m-semihosting = "0.3.0"
13+
cortex-m = "0.5.6"
14+
cortex-m-rt = "0.5.3"
15+
cortex-m-semihosting = "0.3.1"
1516
panic-semihosting = "0.3.0"
1617

1718
# Uncomment for the panic example.

ci/after-success.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
set -euxo pipefail
2+
3+
main() {
4+
cargo doc
5+
6+
mkdir ghp-import
7+
8+
curl -Ls https://github.com/davisp/ghp-import/archive/master.tar.gz |
9+
tar --strip-components 1 -C ghp-import -xz
10+
11+
./ghp-import/ghp_import.py target/doc
12+
13+
set +x
14+
git push -fq https://$GH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git gh-pages && echo OK
15+
}
16+
17+
# only publish on successful merges to master
18+
if [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && [ $TARGET = x86_64-unknown-linux-gnu ]; then
19+
main
20+
fi

ci/install.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
set -euxo pipefail
22

33
main() {
4-
rustup target add $TARGET
4+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
5+
rustup target add $TARGET
6+
fi
57
}
68

79
main

ci/script.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ EOF
6161
examples+=( $ex )
6262
fi
6363

64-
IFS=,;eval arm-none-eabi-size target/$TARGET/release/examples/"{${examples[*]}}"
64+
IFS=,;eval size target/$TARGET/release/examples/"{${examples[*]}}"
6565

6666
popd
6767
rm -rf $td
6868
}
6969

70-
main
70+
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
71+
main
72+
fi

examples/allocator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
#![feature(alloc)]
1313
#![feature(alloc_error_handler)]
14-
#![feature(global_allocator)]
1514
#![feature(lang_items)]
1615
#![no_main]
1716
#![no_std]
@@ -58,7 +57,7 @@ fn main() -> ! {
5857
// define what happens in an Out Of Memory (OOM) condition
5958
#[alloc_error_handler]
6059
#[no_mangle]
61-
pub fn alloc_error(layout: Layout) -> ! {
60+
pub fn alloc_error(_layout: Layout) -> ! {
6261
asm::bkpt();
6362

6463
loop {}

examples/minimal.rs

+1-24
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,19 @@
1515
//! define a panicking behavior is to link to a [panic handler crate][0]
1616
//!
1717
//! [0]: https://crates.io/keywords/panic-impl
18-
//!
19-
//! - Define the `HardFault` handler using the [`exception!`] macro. This handler (function) is
20-
//! called when a hard fault exception is raised by the hardware.
21-
//!
22-
//! [`exception!`]: https://docs.rs/cortex-m-rt/~0.5/cortex_m_rt/macro..html
23-
//!
24-
//! - Define a default handler using the [`exception!`] macro. This function will be used to handle
25-
//! all interrupts and exceptions which have not been assigned a specific handler.
2618
2719
#![no_main] // <- IMPORTANT!
2820
#![no_std]
2921

3022
extern crate cortex_m;
3123

32-
#[macro_use(entry, exception)]
24+
#[macro_use(entry)]
3325
extern crate cortex_m_rt as rt;
3426

3527
// makes `panic!` print messages to the host stderr using semihosting
3628
extern crate panic_semihosting;
3729

3830
use cortex_m::asm;
39-
use rt::ExceptionFrame;
4031

4132
// the program entry point is ...
4233
entry!(main);
@@ -47,17 +38,3 @@ fn main() -> ! {
4738
asm::bkpt();
4839
}
4940
}
50-
51-
// define the hard fault handler
52-
exception!(HardFault, hard_fault);
53-
54-
fn hard_fault(ef: &ExceptionFrame) -> ! {
55-
panic!("HardFault at {:#?}", ef);
56-
}
57-
58-
// define the default exception handler
59-
exception!(*, default_handler);
60-
61-
fn default_handler(irqn: i16) {
62-
panic!("Unhandled exception (IRQn = {})", irqn);
63-
}

src/lib.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//!
55
//! - Nightly Rust toolchain newer than `nightly-2018-04-08`: `rustup default nightly`
66
//! - Cargo `clone` subcommand: `cargo install cargo-clone`
7-
//! - ARM toolchain: `sudo apt-get install gcc-arm-none-eabi` (on Ubuntu)
87
//! - GDB: `sudo apt-get install gdb-arm-none-eabi` (on Ubuntu)
98
//! - OpenOCD: `sudo apt-get install OpenOCD` (on Ubuntu)
109
//! - [Optional] Cargo `add` subcommand: `cargo install cargo-edit`
@@ -179,11 +178,13 @@
179178
//! ``` text
180179
//! $ cargo build
181180
//! Compiling demo v0.1.0 (file:///home/japaric/tmp/demo)
182-
//! error: linking with `arm-none-eabi-ld` failed: exit code: 1
181+
//! error: linking with `rust-lld` failed: exit code: 1
183182
//! |
184-
//! = note: "arm-none-eabi-gcc" "-L" (..)
183+
//! = note: "rust-lld" "-flavor" "gnu" "-L" (..)
184+
//! (..)
185+
//! = note: rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by X bytes
186+
//! rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by Y bytes
185187
//! (..)
186-
//! (..)/ld: region `FLASH' overflowed by XXX bytes
187188
//! ```
188189
//!
189190
//! Solution: Specify your device memory layout in the `memory.x` linker script. See [Usage]
@@ -206,24 +207,15 @@
206207
//!
207208
//! ## Overwrote the original `.cargo/config` file
208209
//!
209-
//! Error message:
210+
//! You won't get an error message but the output binary will be empty
210211
//!
211212
//! ``` text
212-
//! error: linking with `arm-none-eabi-gcc` failed: exit code: 1
213-
//! |
214-
//! = note: (..)
215-
//! (..)
216-
//! (..)/crt0.o: In function `_start':
217-
//! (.text+0x90): undefined reference to `memset'
218-
//! (..)/crt0.o: In function `_start':
219-
//! (.text+0xd0): undefined reference to `atexit'
220-
//! (..)/crt0.o: In function `_start':
221-
//! (.text+0xd4): undefined reference to `__libc_init_array'
222-
//! (..)/crt0.o: In function `_start':
223-
//! (.text+0xe4): undefined reference to `exit'
224-
//! (..)/crt0.o: In function `_start':
225-
//! (.text+0x100): undefined reference to `__libc_fini_array'
226-
//! collect2: error: ld returned 1 exit status
213+
//! $ cargo build && echo OK
214+
//! OK
215+
//!
216+
//! $ size target/thumbv7m-none-eabi/debug/app
217+
//! text data bss dec hex filename
218+
//! 0 0 0 0 0 target/thumbv7m-none-eabi/debug/app
227219
//! ```
228220
//!
229221
//! Solution: You probably overwrote the original `.cargo/config` instead of appending the default

0 commit comments

Comments
 (0)