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

Commit

Permalink
add LLD support
Browse files Browse the repository at this point in the history
this commit adds LLD support by removing all INFO sections. LLD kind of supports INFO in the form of
NOLOAD but when the linker script contains NOLOAD sections LLD emits a binary with false `size`
information: for example, it reported a fake increase of 20KB in .text and a fake increase of 1KB in
.bss when compiling a program that only allocates a single Box.

As the INFO sections are gone we can no longer support the stack overflow protection added in #43 so
all the other related changes, like making _stack_start overridable, have been removed as well.
If you want to continue using stack overflow protection you can stick to v0.3.x.

As the .debug_gdb_scripts output section has been removed from the linker script these changes will
only reliably support both LD and LLD if/when rust-lang/rust#49728 lands.

closes #53
  • Loading branch information
japaric committed Apr 8, 2018
1 parent 032ca2a commit 401416a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "runtime", "startup"]
license = "MIT OR Apache-2.0"
name = "cortex-m-rt"
repository = "https://github.com/japaric/cortex-m-rt"
version = "0.3.15"
version = "0.4.0"

[dependencies]
cortex-m = "0.3.0"
Expand Down
42 changes: 3 additions & 39 deletions link.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EXTERN(EXCEPTIONS);
object file that's passed to the linker *before* this crate */
EXTERN(INTERRUPTS);

PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
_stack_start = ORIGIN(RAM) + LENGTH(RAM);

SECTIONS
{
Expand Down Expand Up @@ -48,20 +48,6 @@ SECTIONS
. = ALIGN(4);
} > FLASH

/* limits of the .stack region */
_estack = _stack_start;
/* HACK the `true` case indicates that two RAM regions are being used and
/* that the stack was placed in the second region. In that case we don't know
/* the size of the second RAM region, or its start address, so we just assume
/* its zero sized */
_sstack = _stack_start < ORIGIN(RAM)? _stack_start : ORIGIN(RAM);

/* fictitious region that represents the memory available for the stack */
.stack _sstack (INFO) : ALIGN(4)
{
. += (_estack - _sstack);
}

PROVIDE(_sbss = ORIGIN(RAM));
.bss _sbss : ALIGN(4)
{
Expand All @@ -81,15 +67,10 @@ SECTIONS

PROVIDE(_heap_size = 0);

/* The heap starts right after the .bss + .data section ends */
_sheap = _edata;
_eheap = _sheap + _heap_size;

/* fictitious region that represents the memory available for the heap */
.heap _sheap (INFO) : ALIGN(4)
{
. += _heap_size;
}

/* fake output .got section */
/* Dynamic relocations are unsupported. This section is only used to detect
relocatable code in the input files and raise an error if relocatable code
Expand All @@ -101,26 +82,9 @@ SECTIONS
_egot = .;
} > RAM AT > FLASH

/* The heap starts right after the .bss + .data section ends */
_sheap = _edata;

/* Due to an unfortunate combination of legacy concerns,
toolchain drawbacks, and insufficient attention to detail,
rustc has no choice but to mark .debug_gdb_scripts as allocatable.
We really do not want to upload it to our target, so we
remove the allocatable bit. Unfortunately, it appears
that the only way to do this in a linker script is
the extremely obscure "INFO" output section type specifier. */
/* a rustc hack will force the program to read the first byte of this section,
so we'll set the (fake) start address of this section to something we're
sure can be read at runtime: the start of the .text section */
.debug_gdb_scripts _stext (INFO) : {
KEEP(*(.debug_gdb_scripts))
}

/DISCARD/ :
{
*(.ARM.exidx.*)
*(.ARM.exidx.*);
}
}

Expand Down

0 comments on commit 401416a

Please sign in to comment.