Skip to content

Commit

Permalink
fix: strip comments before processing linker script
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tdrn committed Feb 23, 2025
1 parent 0f3d7cf commit 559f7e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ evalexpr = "12"
getrandom = "0.2"
log = "0.4"
object = { version = "0.35", default-features = false, features = ["read_core", "elf", "std"] }
regex = "1.11"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use std::{

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

use regex::Regex;

type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;

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

0 comments on commit 559f7e1

Please sign in to comment.