Skip to content

Commit 080915f

Browse files
bors[bot]robyoung
andauthored
Merge #70
70: Grammar fixes r=adamgreig a=robyoung Mostly minor grammar fixes and grammar consistency improvements. Co-authored-by: Rob Young <[email protected]>
2 parents 4dfdf69 + 355f0ca commit 080915f

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/main.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,12 @@ We also drop the `#![no_main]` attribute as it has no effect on library crates.
3636

3737
> There's an orthogonal question that arises at this stage: Should the `rt`
3838
> library provide a standard panicking behavior, or should it *not* provide a
39-
> `#[panic_handler]` function and leave the end user choose the panicking
39+
> `#[panic_handler]` function and leave the end user to choose the panicking
4040
> behavior? This document won't delve into that question and for simplicity will
4141
> leave the dummy `#[panic_handler]` function in the `rt` crate. However, we
4242
> wanted to inform the reader that there are other options.
4343
44-
The second change involves providing the linker script we wrote before to the application crate. You
45-
see the linker will search for linker scripts in the library search path (`-L`) and in the directory
44+
The second change involves providing the linker script we wrote before to the application crate. The linker will search for linker scripts in the library search path (`-L`) and in the directory
4645
from which it's invoked. The application crate shouldn't need to carry around a copy of `link.x` so
4746
we'll have the `rt` crate put the linker script in the library search path using a [build script].
4847

@@ -99,7 +98,7 @@ $ cargo objdump --bin app -- -d -no-show-raw-insn
9998

10099
## Making it type safe
101100

102-
The `main` interface works, but it's easy to get it wrong: For example, the user could write `main`
101+
The `main` interface works, but it's easy to get it wrong. For example, the user could write `main`
103102
as a non-divergent function, and they would get no compile time error and undefined behavior (the
104103
compiler will misoptimize the program).
105104

src/memory-layout.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ initializing the device.
1010
[LM3S6965]: http://www.ti.com/product/LM3S6965
1111

1212
Cortex-M devices require a [vector table] to be present at the start of their [code memory region].
13-
The vector table is an array of pointers; the first two pointers are required to boot the device;
14-
the rest of pointers are related to exceptions -- we'll ignore them for now.
13+
The vector table is an array of pointers; the first two pointers are required to boot the device,
14+
the rest of the pointers are related to exceptions. We'll ignore them for now.
1515

1616
[code memory region]: https://developer.arm.com/docs/dui0552/latest/the-cortex-m3-processor/memory-model
1717
[vector table]: https://developer.arm.com/docs/dui0552/latest/the-cortex-m3-processor/exception-model/vector-table
@@ -23,11 +23,11 @@ Symbols, in turn, can be data (a static variable), or instructions (a Rust funct
2323

2424
[linker scripts]: https://sourceware.org/binutils/docs/ld/Scripts.html
2525

26-
Every symbol has a name assigned by the compiler. As of Rust 1.28 , the Rust compiler assigns to
27-
symbols names of the form: `_ZN5krate6module8function17he1dfc17c86fe16daE`, which demangles to
26+
Every symbol has a name assigned by the compiler. As of Rust 1.28 , the names that the Rust compiler
27+
assigns to symbols are of the form: `_ZN5krate6module8function17he1dfc17c86fe16daE`, which demangles to
2828
`krate::module::function::he1dfc17c86fe16da` where `krate::module::function` is the path of the
2929
function or variable and `he1dfc17c86fe16da` is some sort of hash. The Rust compiler will place each
30-
symbol into its own and unique section; for example the symbol mentioned before will be placed in a
30+
symbol into its own unique section; for example the symbol mentioned before will be placed in a
3131
section named `.text._ZN5krate6module8function17he1dfc17c86fe16daE`.
3232

3333
These compiler generated symbol and section names are not guaranteed to remain constant across
@@ -43,7 +43,7 @@ With these attributes, we can expose a stable ABI of the program and use it in t
4343

4444
## The Rust side
4545

46-
Like mentioned before, for Cortex-M devices, we need to populate the first two entries of the
46+
As mentioned above, for Cortex-M devices, we need to populate the first two entries of the
4747
vector table. The first one, the initial value for the stack pointer, can be populated using
4848
only the linker script. The second one, the reset vector, needs to be created in Rust code
4949
and placed correctly using the linker script.
@@ -66,14 +66,14 @@ symbol name so we use `#[no_mangle]`. We need fine control over the location of
6666
place it in a known section, `.vector_table.reset_vector`. The exact location of the reset handler
6767
itself, `Reset`, is not important. We just stick to the default compiler generated section.
6868

69-
Also, the linker will ignore symbols with internal linkage, AKA internal symbols, while traversing
69+
The linker will ignore symbols with internal linkage (also known as internal symbols) while traversing
7070
the list of input object files, so we need our two symbols to have external linkage. The only way to
7171
make a symbol external in Rust is to make its corresponding item public (`pub`) and *reachable* (no
7272
private module between the item and the root of the crate).
7373

7474
## The linker script side
7575

76-
Below is shown a minimal linker script that places the vector table in the right location. Let's
76+
A minimal linker script that places the vector table in the correct location is shown below. Let's
7777
walk through it.
7878

7979
``` console
@@ -92,7 +92,7 @@ in the target. The values used here correspond to the LM3S6965 microcontroller.
9292

9393
### `ENTRY`
9494

95-
Here we indicate to the linker that the reset handler -- whose symbol name is `Reset` -- is the
95+
Here we indicate to the linker that the reset handler, whose symbol name is `Reset`, is the
9696
*entry point* of the program. Linkers aggressively discard unused sections. Linkers consider the
9797
entry point and functions called from it as *used* so they won't discard them. Without this line,
9898
the linker would discard the `Reset` function and all subsequent functions called from it.
@@ -107,21 +107,21 @@ you should use `EXTERN` in conjunction with `KEEP`.
107107

108108
### `SECTIONS`
109109

110-
This part describes how sections in the input object files, AKA *input sections*, are to be arranged
111-
in the sections of the output object file, AKA output sections; or if they should be discarded. Here
110+
This part describes how sections in the input object files (also known as *input sections*) are to be arranged
111+
in the sections of the output object file (also known as output sections) or if they should be discarded. Here
112112
we define two output sections:
113113

114114
``` text
115115
.vector_table ORIGIN(FLASH) : { /* .. */ } > FLASH
116116
```
117117

118-
`.vector_table`, which contains the vector table and is located at the start of `FLASH` memory,
118+
`.vector_table` contains the vector table and is located at the start of `FLASH` memory.
119119

120120
``` text
121121
.text : { /* .. */ } > FLASH
122122
```
123123

124-
and `.text`, which contains the program subroutines and is located somewhere in `FLASH`. Its start
124+
`.text` contains the program subroutines and is located somewhere in `FLASH`. Its start
125125
address is not specified, but the linker will place it after the previous output section,
126126
`.vector_table`.
127127

@@ -170,13 +170,15 @@ Now we can link the application. For reference, here's the complete Rust program
170170
{{#include ../ci/memory-layout/src/main.rs}}
171171
```
172172

173-
We have to tweak linker process to make it use our linker script. This is done
174-
passing the `-C link-arg` flag to `rustc` but there are two ways to do it: you
175-
can use the `cargo-rustc` subcommand instead of `cargo-build` as shown below:
173+
We have to tweak the linker process to make it use our linker script. This is done
174+
passing the `-C link-arg` flag to `rustc`. This can be done with `cargo-rustc` or
175+
`cargo-build`.
176176

177177
**IMPORTANT**: Make sure you have the `.cargo/config` file that was added at the
178178
end of the last section before running this command.
179179

180+
Using the `cargo-rustc` subcommand:
181+
180182
``` console
181183
$ cargo rustc -- -C link-arg=-Tlink.x
182184
```
@@ -199,7 +201,8 @@ when cross compiling to that target.
199201

200202
## Inspecting it
201203

202-
Now let's inspect the output binary to confirm the memory layout looks the way we want:
204+
Now let's inspect the output binary to confirm the memory layout looks the way we want
205+
(this requires [`cargo-binutils`](https://github.com/rust-embedded/cargo-binutils#readme)):
203206

204207
``` console
205208
$ cargo objdump --bin app -- -d -no-show-raw-insn

0 commit comments

Comments
 (0)