Skip to content

Commit 5452a89

Browse files
authored
Merge pull request #64 from japaric/v4
v0.4.0: with LLD support
2 parents 718da40 + 7521c60 commit 5452a89

File tree

6 files changed

+47
-309
lines changed

6 files changed

+47
-309
lines changed

cortex-m-rt/CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.4.0] - 2018-04-09
11+
12+
### Added
13+
14+
- LLD support. The linker script provided by this crate has been tweaked to support both LLD and GNU
15+
LD. To use LLD as a linker change `.cargo/config` to look like this:
16+
17+
``` diff
18+
[target.thumbv7m-none-eabi]
19+
rustflags = [
20+
"-C", "link-arg=-Tlink.x",
21+
- "-C", "linker=arm-none-eabi-ld",
22+
- "-Z", "linker-flavor=ld",
23+
+ "-C", "linker=lld",
24+
+ "-Z", "linker-flavor=ld.lld",
25+
]
26+
```
27+
28+
### Removed
29+
30+
- [breaking-change] Stack overflow protection has been removed. Unfortunately, supporting this
31+
feature produces totally wrong `arm-none-eabi-size` reports when LLD is used to link the
32+
program. If you need the stack overflow protection feature you can continue to use version
33+
v0.3.13+.
34+
35+
- [breaking-change] The "abort-on-panic" Cargo feature, which provided a `panic_fmt` implementation,
36+
has been removed. If you were using this feature you can instead use a [panic implementation
37+
crate][panic-impl].
38+
39+
[panic-impl]: https://crates.io/keywords/panic-impl
40+
1041
## [v0.3.15] - 2018-04-08
1142

1243
### Fixed

cortex-m-rt/Cargo.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@ keywords = ["arm", "cortex-m", "runtime", "startup"]
77
license = "MIT OR Apache-2.0"
88
name = "cortex-m-rt"
99
repository = "https://github.com/japaric/cortex-m-rt"
10-
version = "0.3.15"
10+
version = "0.4.0"
1111

1212
[dependencies]
1313
cortex-m = "0.3.0"
14-
r0 = "0.2.1"
15-
16-
[features]
17-
# provides a panic_fmt implementation that calls the abort instruction (`udf 0xfe`)
18-
abort-on-panic = []
19-
20-
[build-dependencies]
21-
rustc_version = "0.2.1"
22-
chrono = "0.4.0"
14+
r0 = "0.2.1"

cortex-m-rt/build.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
1-
extern crate chrono;
2-
extern crate rustc_version;
3-
41
use std::env;
52
use std::fs::File;
63
use std::io::Write;
74
use std::path::PathBuf;
85

9-
use chrono::NaiveDate;
10-
116
fn main() {
12-
let meta = rustc_version::version_meta().unwrap();
13-
let commit_date = meta.commit_date.unwrap().parse::<NaiveDate>().unwrap();
14-
if meta.channel == rustc_version::Channel::Dev
15-
|| commit_date > NaiveDate::from_ymd(2017, 12, 26)
16-
{
17-
println!("cargo:rustc-cfg=has_termination_lang")
18-
}
19-
20-
// newest nightlies don't need 'extern crate compiler_builtins'
21-
if commit_date < NaiveDate::from_ymd(2018, 04, 07)
22-
{
23-
println!("cargo:rustc-cfg=needs_cb")
24-
}
25-
267
let target = env::var("TARGET").unwrap();
278

289
has_fpu(&target);

cortex-m-rt/link.x

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,16 @@ SECTIONS
4848
. = ALIGN(4);
4949
} > FLASH
5050

51-
/* limits of the .stack region */
52-
_estack = _stack_start;
53-
/* HACK the `true` case indicates that two RAM regions are being used and
54-
/* that the stack was placed in the second region. In that case we don't know
55-
/* the size of the second RAM region, or its start address, so we just assume
56-
/* its zero sized */
57-
_sstack = _stack_start < ORIGIN(RAM)? _stack_start : ORIGIN(RAM);
58-
59-
/* fictitious region that represents the memory available for the stack */
60-
.stack _sstack (INFO) : ALIGN(4)
61-
{
62-
. += (_estack - _sstack);
63-
}
64-
6551
PROVIDE(_sbss = ORIGIN(RAM));
6652
.bss _sbss : ALIGN(4)
6753
{
6854
*(.bss .bss.*);
6955
. = ALIGN(4);
7056
_ebss = .;
71-
} > RAM
57+
} > RAM AT > FLASH
58+
/* NOTE(AT > FLASH) without this LLD v6 produces a binary that crashes OpenOCD whereas LLD v7
59+
emits a ".rodata and .bss sections overlap" error ... This hacky workaround doesn't increase
60+
the binary size AFAICT */
7261

7362
.data : ALIGN(4)
7463
{
@@ -79,16 +68,8 @@ SECTIONS
7968
_edata = .;
8069
} > RAM AT > FLASH
8170

82-
PROVIDE(_heap_size = 0);
83-
71+
/* The heap starts right after the .bss + .data section ends */
8472
_sheap = _edata;
85-
_eheap = _sheap + _heap_size;
86-
87-
/* fictitious region that represents the memory available for the heap */
88-
.heap _sheap (INFO) : ALIGN(4)
89-
{
90-
. += _heap_size;
91-
}
9273

9374
/* fake output .got section */
9475
/* Dynamic relocations are unsupported. This section is only used to detect
@@ -101,26 +82,9 @@ SECTIONS
10182
_egot = .;
10283
} > RAM AT > FLASH
10384

104-
/* The heap starts right after the .bss + .data section ends */
105-
_sheap = _edata;
106-
107-
/* Due to an unfortunate combination of legacy concerns,
108-
toolchain drawbacks, and insufficient attention to detail,
109-
rustc has no choice but to mark .debug_gdb_scripts as allocatable.
110-
We really do not want to upload it to our target, so we
111-
remove the allocatable bit. Unfortunately, it appears
112-
that the only way to do this in a linker script is
113-
the extremely obscure "INFO" output section type specifier. */
114-
/* a rustc hack will force the program to read the first byte of this section,
115-
so we'll set the (fake) start address of this section to something we're
116-
sure can be read at runtime: the start of the .text section */
117-
.debug_gdb_scripts _stext (INFO) : {
118-
KEEP(*(.debug_gdb_scripts))
119-
}
120-
12185
/DISCARD/ :
12286
{
123-
*(.ARM.exidx.*)
87+
*(.ARM.exidx.*);
12488
}
12589
}
12690

cortex-m-rt/src/lang_items.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/// Default panic handler
2-
#[cfg(feature = "abort-on-panic")]
3-
#[lang = "panic_fmt"]
4-
unsafe extern "C" fn panic_fmt(_: ::core::fmt::Arguments, _: &'static str, _: u32, _: u32) -> ! {
5-
::core::intrinsics::abort()
6-
}
7-
81
// Lang item required to make the normal `main` work in applications
92
//
103
// This is how the `start` lang item works:
@@ -24,7 +17,6 @@ unsafe extern "C" fn panic_fmt(_: ::core::fmt::Arguments, _: &'static str, _: u3
2417
// The final piece is that the entry point of our program, the reset handler,
2518
// has to call `rustc_main`. That's covered by the `reset_handler` function in
2619
// root of this crate.
27-
#[cfg(has_termination_lang)]
2820
#[lang = "start"]
2921
extern "C" fn start<T>(main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize
3022
where
@@ -35,21 +27,11 @@ where
3527
0
3628
}
3729

38-
#[cfg(not(has_termination_lang))]
39-
#[lang = "start"]
40-
extern "C" fn start(main: fn(), _argc: isize, _argv: *const *const u8) -> isize {
41-
main();
42-
43-
0
44-
}
45-
4630
#[lang = "termination"]
47-
#[cfg(has_termination_lang)]
4831
pub trait Termination {
4932
fn report(self) -> i32;
5033
}
5134

52-
#[cfg(has_termination_lang)]
5335
impl Termination for () {
5436
fn report(self) -> i32 {
5537
0

0 commit comments

Comments
 (0)