Skip to content

add asm_check tool and one-off asm test#23

Open
oliverlee wants to merge 1 commit into
asm-check-rulefrom
asm-check
Open

add asm_check tool and one-off asm test#23
oliverlee wants to merge 1 commit into
asm-check-rulefrom
asm-check

Conversation

@oliverlee

Copy link
Copy Markdown
Collaborator

Adds tools/asm_check, a Rust binary that checks assembly output against a TOML config file specifying per-function must_contain and must_not_contain regex patterns, with optional function exclude patterns.

Provies a one-off asm test using sh_binary and a manually generated TOML config for mod_layout.

Adds anyhow, clap, regex, serde, and toml to the tool_crates extension to support the new binary.

Adds `tools/asm_check`, a Rust binary that checks assembly output
against a TOML config file specifying per-function `must_contain` and
`must_not_contain` regex patterns, with optional function exclude
patterns.

Provies a one-off asm test using `sh_binary` and a manually generated
TOML config for `mod_layout`.

Adds `anyhow`, `clap`, `regex`, `serde`, and `toml` to the
`tool_crates` extension to support the new binary.
Comment on lines +23 to +37
write_file(
name = "mod_layout_asm_check_config",
out = "mod_layout_asm_check.toml",
content = [
"[[check]]",
"functions = [\"mod_layout::tests::test_layout_(right|left)_mapping_stride_out_of_bounds\"]",
"must_contain = [\"bl[[:space:]]+_core::panicking::panic_fmt\"]",
"",
"[[check]]",
"functions = [\"mod_layout::.*\"]",
"exclude = [\"mod_layout::tests::test_layout_(right|left)_mapping_stride_out_of_bounds\"]",
"must_not_contain = [\"bl[[:space:]]+_core::panicking::panic_fmt\"]",
"",
],
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curiosity: Why does this need to be written by bazel?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. We could create the file and check it in instead of generating it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay. Maybe it'll read better and get syntax highlighting if we materialize it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update this PR later and add the file.

Comment thread tools/asm_check/main.rs
Comment on lines +121 to +148
fn parse_functions<'a>(asm: &'a str) -> BTreeMap<&'a str, Vec<&'a str>> {
let mut chunks: Vec<Vec<&str>> = vec![];

for line in asm.lines() {
let is_label = line.ends_with(':') && !line.starts_with(|c: char| c.is_whitespace());

if is_label {
chunks.push(vec![line]);
} else if let Some(chunk) = chunks.last_mut() {
chunk.push(line);
}
}

for i in (1..chunks.len()).rev() {
if chunks[i][0].trim_end_matches(':').starts_with("Lloh") {
let lloh = chunks.remove(i);
chunks[i - 1].extend(lloh);
}
}

chunks
.into_iter()
.map(|mut chunk| {
let name = chunk.remove(0).trim_end_matches(':');
(name, chunk)
})
.collect()
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based this on the ASM on my machine. This will probably differ for Linux and bare-metal targets.

Comment thread tools/asm_check/main.rs
.cfi_endproc

.p2align 2
"#;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last function is copy/pasted from the asm on my machine. The ones above were generated by Claude.

@mickvangelderen can you add a function based on the output of your machine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants