Skip to content

Commit 559f7e1

Browse files
committed
fix: strip comments before processing linker script
1 parent 0f3d7cf commit 559f7e1

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ evalexpr = "12"
1616
getrandom = "0.2"
1717
log = "0.4"
1818
object = { version = "0.35", default-features = false, features = ["read_core", "elf", "std"] }
19+
regex = "1.11"
1920

2021
[dev-dependencies]
2122
assert_cmd = "2.0"

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::{
1313

1414
use object::{elf, Object as _, ObjectSection, SectionFlags};
1515

16+
use regex::Regex;
17+
1618
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
1719

1820
const EXIT_CODE_FAILURE: i32 = 1;
@@ -299,6 +301,9 @@ fn get_includes_from_linker_script(linker_script: &str) -> Vec<&str> {
299301
/// Looks for "RAM : ORIGIN = $origin, LENGTH = $length"
300302
// FIXME this is a dumb line-by-line parser
301303
fn find_ram_in_linker_script(linker_script: &str) -> Option<MemoryEntry> {
304+
// strip any multiline comments in the linker script before processing
305+
let re = Regex::new(r"(?s)/\*.*?\*/").unwrap();
306+
let linker_script = re.replace_all(linker_script, "");
302307
for (index, mut line) in linker_script.lines().enumerate() {
303308
line = line.trim();
304309
line = eat!(line, "RAM");

0 commit comments

Comments
 (0)