Skip to content
This repository was archived by the owner on Jan 24, 2022. It is now read-only.

Commit 8eeedbe

Browse files
bors[bot]japaric
andcommitted
Merge #84
84: refactor the linker script r=therealprof a=japaric to make it more compatible with LLD. This commit contains no functional changes. fixes #70 Overview of changes: - Alignment checks are enabled now that rust-lld (LLD 7.0) supports the modulo operator. - Removed some private symbols (e.g. __foo) in favor of ADDR and SIZEOF. - Turned .got into a NOLOAD section now that rust-lld supports it. - Replaced `ABSOLUTE(.)` with `.` as an old LLD overlap bug seems to be gone and ABSOLUTE seems to cause problems, like #70, on bigger programs. - Made the linker assertion messages more uniform. - Extended test suite to check that linking works with both rust-lld and GNU LD. r? therealprof (chosen at random) Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 6c269f1 + 85c5d77 commit 8eeedbe

File tree

7 files changed

+156
-122
lines changed

7 files changed

+156
-122
lines changed

.travis.yml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ matrix:
77

88
- env: TARGET=thumbv6m-none-eabi
99
rust: stable
10-
addons:
11-
apt:
12-
packages:
13-
- gcc-arm-none-eabi
1410
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
1511

1612
- env: TARGET=thumbv6m-none-eabi CC=clang
@@ -19,10 +15,6 @@ matrix:
1915

2016
- env: TARGET=thumbv7m-none-eabi
2117
rust: stable
22-
addons:
23-
apt:
24-
packages:
25-
- gcc-arm-none-eabi
2618
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2719

2820
- env: TARGET=thumbv7m-none-eabi CC=clang
@@ -31,10 +23,6 @@ matrix:
3123

3224
- env: TARGET=thumbv7em-none-eabi
3325
rust: stable
34-
addons:
35-
apt:
36-
packages:
37-
- gcc-arm-none-eabi
3826
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
3927

4028
- env: TARGET=thumbv7em-none-eabi CC=clang
@@ -43,10 +31,6 @@ matrix:
4331

4432
- env: TARGET=thumbv7em-none-eabihf
4533
rust: stable
46-
addons:
47-
apt:
48-
packages:
49-
- gcc-arm-none-eabi
5034
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
5135

5236
- env: TARGET=thumbv7em-none-eabihf CC=clang
@@ -55,40 +39,25 @@ matrix:
5539

5640
- env: TARGET=thumbv6m-none-eabi
5741
rust: nightly
58-
addons:
59-
apt:
60-
packages:
61-
- gcc-arm-none-eabi
6242
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
6343

6444
- env: TARGET=thumbv7m-none-eabi
6545
rust: nightly
66-
addons:
67-
apt:
68-
packages:
69-
- gcc-arm-none-eabi
7046
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
7147

7248
- env: TARGET=thumbv7em-none-eabi
7349
rust: nightly
74-
addons:
75-
apt:
76-
packages:
77-
- gcc-arm-none-eabi
7850
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
7951

8052
- env: TARGET=thumbv7em-none-eabihf
8153
rust: nightly
82-
addons:
83-
apt:
84-
packages:
85-
- gcc-arm-none-eabi
8654
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
8755

8856
before_install: set -e
8957

9058
install:
9159
- bash ci/install.sh
60+
- export PATH="$PATH:$PWD/gcc/bin"
9261

9362
script:
9463
- bash ci/script.sh

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ r0 = "0.2.1"
1717

1818
[dev-dependencies]
1919
panic-semihosting = "0.3.0"
20+
panic-abort = "0.2.0"
2021

2122
[features]
2223
device = []

build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ INCLUDE device.x"#
4242
writeln!(
4343
f,
4444
r#"
45-
ASSERT(__einterrupts - __eexceptions <= 0x{:x}, "
46-
There can't be more than {} interrupt handlers. This may be a bug in
47-
your device crate, or you may have registered more than 240 interrupt
45+
ASSERT(SIZEOF(.vector_table) <= 0x{:x}, "
46+
There can't be more than {1} interrupt handlers. This may be a bug in
47+
your device crate, or you may have registered more than {1} interrupt
4848
handlers.");
4949
"#,
50-
max_int_handlers * 4,
50+
max_int_handlers * 4 + 0x40,
5151
max_int_handlers
5252
).unwrap();
5353

ci/install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ set -euxo pipefail
33
main() {
44
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
55
rustup target add $TARGET
6+
7+
if [ ${CC:-gcc} = gcc ]; then
8+
mkdir gcc
9+
10+
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
11+
fi
612
fi
713
}
814

ci/script.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ main() {
66
cargo check --target $TARGET --features device
77

88
local examples=(
9+
alignment
910
minimal
1011
main
1112
state
1213
)
1314
if [ $TRAVIS_RUST_VERSION = nightly ]; then
15+
# linking with GNU LD
1416
for ex in "${examples[@]}"; do
1517
cargo rustc --target $TARGET --example $ex -- \
1618
-C link-arg=-nostartfiles \
@@ -28,6 +30,29 @@ main() {
2830
cargo rustc --target $TARGET --example device --features device --release -- \
2931
-C link-arg=-nostartfiles \
3032
-C link-arg=-Wl,-Tlink.x
33+
34+
# linking with rustc's LLD
35+
for ex in "${examples[@]}"; do
36+
cargo rustc --target $TARGET --example $ex -- \
37+
-C linker=rust-lld \
38+
-Z linker-flavor=ld.lld \
39+
-C link-arg=-Tlink.x
40+
41+
cargo rustc --target $TARGET --example $ex --release -- \
42+
-C linker=rust-lld \
43+
-Z linker-flavor=ld.lld \
44+
-C link-arg=-Tlink.x
45+
done
46+
47+
cargo rustc --target $TARGET --example device --features device -- \
48+
-C linker=rust-lld \
49+
-Z linker-flavor=ld.lld \
50+
-C link-arg=-Tlink.x
51+
52+
cargo rustc --target $TARGET --example device --features device --release -- \
53+
-C linker=rust-lld \
54+
-Z linker-flavor=ld.lld \
55+
-C link-arg=-Tlink.x
3156
fi
3257
}
3358

examples/alignment.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! This is not an example; this is a link-pass test
2+
3+
#![deny(warnings)]
4+
#![no_main]
5+
#![no_std]
6+
7+
#[macro_use(entry, exception)]
8+
extern crate cortex_m_rt as rt;
9+
extern crate panic_abort;
10+
11+
use core::ptr;
12+
13+
use rt::ExceptionFrame;
14+
15+
entry!(main);
16+
17+
static mut BSS1: u16 = 0;
18+
static mut BSS2: u8 = 0;
19+
static mut DATA1: u8 = 1;
20+
static mut DATA2: u16 = 1;
21+
static RODATA1: &[u8; 3] = b"012";
22+
static RODATA2: &[u8; 2] = b"34";
23+
24+
fn main() -> ! {
25+
unsafe {
26+
let _bss1 = ptr::read_volatile(&BSS1);
27+
let _bss2 = ptr::read_volatile(&BSS2);
28+
let _data1 = ptr::read_volatile(&DATA1);
29+
let _data2 = ptr::read_volatile(&DATA2);
30+
let _rodata1 = ptr::read_volatile(&RODATA1);
31+
let _rodata2 = ptr::read_volatile(&RODATA2);
32+
}
33+
34+
loop {}
35+
}
36+
37+
exception!(HardFault, hard_fault);
38+
39+
fn hard_fault(_ef: &ExceptionFrame) -> ! {
40+
loop {}
41+
}
42+
43+
exception!(*, default_handler);
44+
45+
fn default_handler(_irqn: i16) {}

0 commit comments

Comments
 (0)