Skip to content

Commit 1c47247

Browse files
committed
layout: Improve development workflow
Right now, if layout.ld or target.json is changed, the firmware will not automatically relink when running "cargo xbuild". This can make working on layout.ld quite tedious, as you have to manually change the Rust code to get the firmware to rebuild. We solve this by adding a tiny build script which simply rebuilds the program if either layout.ld or target.json changes. We also stop using "-s" (aka "--strip-all") in the target options. Instead, we add a second /DISCARD/ section in the linker script. This puts all of our logic about sections in a single place. It also makes it easier for a developer to get the symbols (if they want them). Signed-off-by: Joe Richey <[email protected]>
1 parent e602ead commit 1c47247

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
println!("cargo:rerun-if-changed=target.json");
3+
println!("cargo:rerun-if-changed=layout.ld");
4+
}

layout.ld

+5
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ SECTIONS
5151
*(.comment)
5252
*(COMMON)
5353
}
54+
/* Strip symbols from the output binary (comment out to get symbols) */
55+
/DISCARD/ : {
56+
*(.symtab)
57+
*(.strtab)
58+
}
5459
}

target.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
"code-model": "small",
1717
"relocation-model": "static",
1818
"pre-link-args": {
19-
"ld.lld": [
20-
"-s",
21-
"--script=layout.ld"
22-
]
19+
"ld.lld": ["--script=layout.ld"]
2320
}
2421
}

0 commit comments

Comments
 (0)