Skip to content

linker_script: emit "unclosed comment" error for unterminated block comments#1674

Merged
davidlattimore merged 4 commits intowild-linker:mainfrom
plasmaDestroyer:fix-unclosed-comment-error
Mar 11, 2026
Merged

linker_script: emit "unclosed comment" error for unterminated block comments#1674
davidlattimore merged 4 commits intowild-linker:mainfrom
plasmaDestroyer:fix-unclosed-comment-error

Conversation

@plasmaDestroyer
Copy link
Contributor

When a linker script contains an unclosed /* comment, the parser previously returned a generic winnow parse error with no meaningful message.

This adds an UnclosedComment variant to LinkerScriptError and returns it when take_until("*/") fails due to EOF, producing an error message containing "unclosed comment".

Fixes the mold test linker-script-error.sh.

Copy link
Member

@mati865 mati865 left a comment

Choose a reason for hiding this comment

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

Please create a test (in addition to mold one) for it. You can let us know if you need help with that.

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LinkerScriptError::InvalidAlignment => write!(f, "Invalid alignment"),
LinkerScriptError::UnclosedComment => write!(f, "unclosed comment"),
Copy link
Member

Choose a reason for hiding this comment

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

Let's make the case consistent:

Suggested change
LinkerScriptError::UnclosedComment => write!(f, "unclosed comment"),
LinkerScriptError::UnclosedComment => write!(f, "Unclosed comment"),

Copy link
Member

Choose a reason for hiding this comment

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

I agree. The mold test can have a comment added next to it - "Different message formats". There's plenty of other tests that we do that for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

capitalized the error message, updated the integration test to match, and resolved the merge conflict.

@mati865
Copy link
Member

mati865 commented Mar 9, 2026

Fixes the mold test linker-script-error.sh.

Looks like this test was already passing before your changes.

@plasmaDestroyer
Copy link
Contributor Author

plasmaDestroyer commented Mar 9, 2026

Fixes the mold test linker-script-error.sh.

Looks like this test was already passing before your changes.

It seems the test is listed in mold_skip_tests.toml under skipped_groups.ignore with reason "We ignore these tests for some reasons", so it may have been getting skipped rather than passing. Running with WILD_IGNORE_SKIP=mold confirmed it failed before this fix.

Regarding the capitalization, the mold test greps for the exact string 'unclosed comment' in lowercase, so capitalizing it would cause the test to fail, that is why i kept it that way.

i will create and add the test you asked for shortly.

@plasmaDestroyer
Copy link
Contributor Author

plasmaDestroyer commented Mar 9, 2026

You can let us know if you need help with that.

hey, I've written a test based on the pattern of the tests i saw, but it doesn't seem to be getting discovered by the test runner. Could you help me with this?

@davidlattimore
Copy link
Member

You can let us know if you need help with that.

hey, I've written a test based on the pattern of the tests i saw, but it doesn't seem to be getting discovered by the test runner. Could you help me with this?

It doesn't look like you've pushed the change that includes the test, so it's hard to say, but at a guess, I'd say you might have not known to add the test to the list of tests in integration_tests.rs.

@plasmaDestroyer
Copy link
Contributor Author

plasmaDestroyer commented Mar 9, 2026

It doesn't look like you've pushed the change that includes the test, so it's hard to say, but at a guess, I'd say you might have not known to add the test to the list of tests in integration_tests.rs.

yeah i forgot to push that but got it now, thanks for the feedback.

Copy link
Member

@davidlattimore davidlattimore left a comment

Choose a reason for hiding this comment

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

Thanks :)

@davidlattimore davidlattimore merged commit d6e7f2e into wild-linker:main Mar 11, 2026
22 checks passed
@plasmaDestroyer plasmaDestroyer deleted the fix-unclosed-comment-error branch March 12, 2026 04:09
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.

3 participants