feat: support matching based on linker script input filenames#1596
Conversation
|
How about adding test linker scripts to integration tests? |
|
@lapla-cogito |
00ef5b7 to
9a4855e
Compare
|
I intend the latter. Place the test code (in this case, likely a linker script and a C source file) under |
|
Is it okay now? Since it’s my first time, there might still be some changes needed. |
lapla-cogito
left a comment
There was a problem hiding this comment.
Thanks for working on this! I've added some comments. Also, CI seems to be failing checks for test code formatting and cargo-minimal-versions.
|
|
||
| /// Performs glob-style matching of `pattern` against `text`. Supports `*` (matches any sequence of | ||
| /// characters) and `?` (matches any single character). | ||
| fn glob_match_bytes(pattern: &[u8], text: &[u8]) -> bool { |
There was a problem hiding this comment.
Wild already has a dependency on the glob crate. It's used in version_script.rs. Can you look and see if that'd be suitable to use here? Probably call Pattern::new just once for each pattern, since I think that part of the process is slightly expensive, so it's good to not repeat it.
There was a problem hiding this comment.
Good suggestion! I've replaced the custom glob_match_bytes with glob::Pattern from the existing dependency. The pattern is now compiled once in SectionRule::new() and stored as Option, so the parsing cost isn't repeated on every match. The matches() method now delegates to pattern.matches() with a UTF-8 conversion of the filename.
|
Might be worthwhile installing typos so that you can run it before you upload the change. I have a script that gets run whenever I'm uploading a change. It runs typos, runs the tests in a few different modes etc. |
|
My script, in case you're wondering currently looks like the following. #!/usr/bin/bash
set -e
typos
cargo +nightly fmt --check
cargo clippy --all-targets --features mold_tests -- -D warnings
cargo clippy --no-default-features --all-targets -- -D warnings
cargo clippy --features plugins
cargo test --features plugins
if [ -z "$SKIP_MOLD_TESTS" ]; then
WILD_TEST_CROSS=aarch64 cargo nextest run -v --features mold_tests
fiOr at least that's the wild-specific part of the script. I also have other more generic scripts that grep the diff of changes for things like "DO NOT SUBMIT", notify me of any added files, etc. |
|
Where possible, it's good if you can make the title of the PR what will go into the release notes. If you prefix it with "feat:" then it'll go into the features section. I'll usually edit it when I'm merging the change if it doesn't seem quite right, but I sometimes forget. |
lapla-cogito
left a comment
There was a problem hiding this comment.
I've modified the PR title to clearly indicate it relates to linker scripts (since this is typically documented in release notes, I think the relevant section should be more obvious). Otherwise, LGTM.
This pull request adds support for matching input sections based on input file names (including glob patterns) in linker scripts. Now, section mapping rules can specify not only section name patterns but also which input files (or file patterns) they apply to, enabling more precise control over section placement. The implementation includes parsing, rule matching, and comprehensive tests for this new feature.
Enhancements to section rule matching:
input_file_patternfield toSectionRuleandMatcher, allowing rules to optionally specify a glob pattern for matching input filenames. IfNone, the rule matches all files.SectionRule::matchesmethod and section rule lookup logic to consider both section name and input file name, using a newglob_match_bytesfunction that supports*and?wildcards.Parsing and propagation of file patterns:
input_file_patternfield inMatcher.Integration and testing: