Skip to content

use LLD as the default linker #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
[target.thumbv6m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",
# LLD (shipped with the Rust toolchain) is used as the default linker
"-C", "link-arg=-Tlink.x",

# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
# "-C", "linker=arm-none-eabi-ld",

# if you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then
# uncommenting the three lines below
# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
]

[target.thumbv7m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",
# the comments under `[target.thumbv6m-none-eabi]` also apply here
"-C", "link-arg=-Tlink.x",

# "-C", "linker=arm-none-eabi-ld",

# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
]

[target.thumbv7em-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",
# the comments under `[target.thumbv6m-none-eabi]` also apply here
"-C", "link-arg=-Tlink.x",

# "-C", "linker=arm-none-eabi-ld",

# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
]

[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'
rustflags = [
"-C", "link-arg=-Wl,-Tlink.x",
"-C", "link-arg=-nostartfiles",
# the comments under `[target.thumbv6m-none-eabi]` also apply here
"-C", "link-arg=-Tlink.x",

# "-C", "linker=arm-none-eabi-ld",

# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
]
23 changes: 7 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,24 @@ language: rust

matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly
if: branch = master AND type != pull_request

- env: TARGET=thumbv6m-none-eabi
rust: nightly
addons:
apt:
packages:
- gcc-arm-none-eabi
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7m-none-eabi
rust: nightly
addons:
apt:
packages:
- gcc-arm-none-eabi
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7em-none-eabi
rust: nightly
addons:
apt:
packages:
- gcc-arm-none-eabi
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7em-none-eabihf
rust: nightly
addons:
apt:
packages:
- gcc-arm-none-eabi
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

before_install: set -e
Expand All @@ -42,6 +30,9 @@ install:
script:
- bash ci/script.sh

after_success:
- bash ci/after-success.sh

after_script: set +e

cache: cargo
Expand Down
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
authors = ["Jorge Aparicio <[email protected]>"]
categories = ["embedded", "no-std"]
description = "A template for building applications for ARM Cortex-M microcontrollers"
documentation = "https://rust-embedded.github.io/cortex-m-quickstart/cortex_m_quickstart"
keywords = ["arm", "cortex-m", "template"]
license = "MIT OR Apache-2.0"
name = "cortex-m-quickstart"
repository = "https://github.com/japaric/cortex-m-quickstart"
version = "0.3.3"
version = "0.3.4"

[dependencies]
cortex-m = "0.5.0"
cortex-m-rt = "0.5.0"
cortex-m-semihosting = "0.3.0"
cortex-m = "0.5.6"
cortex-m-rt = "0.5.3"
cortex-m-semihosting = "0.3.1"
panic-semihosting = "0.3.0"

# Uncomment for the panic example.
Expand Down
20 changes: 20 additions & 0 deletions ci/after-success.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
set -euxo pipefail

main() {
cargo doc

mkdir ghp-import

curl -Ls https://github.com/davisp/ghp-import/archive/master.tar.gz |
tar --strip-components 1 -C ghp-import -xz

./ghp-import/ghp_import.py target/doc

set +x
git push -fq https://[email protected]/$TRAVIS_REPO_SLUG.git gh-pages && echo OK
}

# only publish on successful merges to master
if [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && [ $TARGET = x86_64-unknown-linux-gnu ]; then
main
fi
4 changes: 3 additions & 1 deletion ci/install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
set -euxo pipefail

main() {
rustup target add $TARGET
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
rustup target add $TARGET
fi
}

main
4 changes: 3 additions & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ EOF
rm -rf $td
}

main
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
main
fi
22 changes: 0 additions & 22 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
//! define a panicking behavior is to link to a [panic handler crate][0]
//!
//! [0]: https://crates.io/keywords/panic-impl
//!
//! - Define the `HardFault` handler using the [`exception!`] macro. This handler (function) is
//! called when a hard fault exception is raised by the hardware.
//!
//! [`exception!`]: https://docs.rs/cortex-m-rt/~0.5/cortex_m_rt/macro..html
//!
//! - Define a default handler using the [`exception!`] macro. This function will be used to handle
//! all interrupts and exceptions which have not been assigned a specific handler.

#![no_main] // <- IMPORTANT!
#![no_std]
Expand All @@ -47,17 +39,3 @@ fn main() -> ! {
asm::bkpt();
}
}

// define the hard fault handler
exception!(HardFault, hard_fault);

fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}

// define the default exception handler
exception!(*, default_handler);

fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}
32 changes: 12 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//!
//! - Nightly Rust toolchain newer than `nightly-2018-04-08`: `rustup default nightly`
//! - Cargo `clone` subcommand: `cargo install cargo-clone`
//! - ARM toolchain: `sudo apt-get install gcc-arm-none-eabi` (on Ubuntu)
//! - GDB: `sudo apt-get install gdb-arm-none-eabi` (on Ubuntu)
//! - OpenOCD: `sudo apt-get install OpenOCD` (on Ubuntu)
//! - [Optional] Cargo `add` subcommand: `cargo install cargo-edit`
Expand Down Expand Up @@ -179,11 +178,13 @@
//! ``` text
//! $ cargo build
//! Compiling demo v0.1.0 (file:///home/japaric/tmp/demo)
//! error: linking with `arm-none-eabi-ld` failed: exit code: 1
//! error: linking with `rust-lld` failed: exit code: 1
//! |
//! = note: "arm-none-eabi-gcc" "-L" (..)
//! = note: "rust-lld" "-flavor" "gnu" "-L" (..)
//! (..)
//! = note: rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by X bytes
//! rust-lld: error: section '.vector_table' will not fit in region 'FLASH': overflowed by Y bytes
//! (..)
//! (..)/ld: region `FLASH' overflowed by XXX bytes
//! ```
//!
//! Solution: Specify your device memory layout in the `memory.x` linker script. See [Usage]
Expand All @@ -206,24 +207,15 @@
//!
//! ## Overwrote the original `.cargo/config` file
//!
//! Error message:
//! You won't get an error message but the output binary will be empty
//!
//! ``` text
//! error: linking with `arm-none-eabi-gcc` failed: exit code: 1
//! |
//! = note: (..)
//! (..)
//! (..)/crt0.o: In function `_start':
//! (.text+0x90): undefined reference to `memset'
//! (..)/crt0.o: In function `_start':
//! (.text+0xd0): undefined reference to `atexit'
//! (..)/crt0.o: In function `_start':
//! (.text+0xd4): undefined reference to `__libc_init_array'
//! (..)/crt0.o: In function `_start':
//! (.text+0xe4): undefined reference to `exit'
//! (..)/crt0.o: In function `_start':
//! (.text+0x100): undefined reference to `__libc_fini_array'
//! collect2: error: ld returned 1 exit status
//! $ cargo build && echo OK
//! OK
//!
//! $ size target/thumbv7m-none-eabi/debug/app
//! text data bss dec hex filename
//! 0 0 0 0 0 target/thumbv7m-none-eabi/debug/app
//! ```
//!
//! Solution: You probably overwrote the original `.cargo/config` instead of appending the default
Expand Down