-
Notifications
You must be signed in to change notification settings - Fork 36
[BUILD] Fail early if findsymbols fails #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mooinglemur
merged 1 commit into
X16Community:master
from
claui:findsymbols-guard-exit-code
Dec 2, 2025
Merged
[BUILD] Fail early if findsymbols fails #446
mooinglemur
merged 1 commit into
X16Community:master
from
claui:findsymbols-guard-exit-code
Dec 2, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If `findsymbols` fails, it prints a helpful usage message to standard output: > Usage: findsymbols file [-p prefix] symbol ... > file: > Symbol file created with the -Ln option in ld65 > -p prefix: > A prefix added to all returned symbol names > symbol: > Name of one or more symbols Unfortunately, the Makefile ignores the exit status of `findsymbols`. It then misinterprets the whole help text as legitimate output and rolls it all into the linker command line. Because the help text happens to contain the word `-Ln` and there’s another `-Ln` in the command line already, so the linker treats this duplication as an error and bails: > ld65: Error: Cannot use -Ln twice which was also reported in GitHub issue X16Community#363 [1]. To improve the error message and fix the leaky help text: 1. Add a conditional block that queries `.SHELLSTATUS`, a variable which was introduced in GNU Make v4.2, and if it is nonzero, error out early with the message "findsymbols failed with exit code $(.SHELLSTATUS)." 2. Additionally, improve `findsymbols` so it redirects the usage text to standard error and includes the file name in its "File not found" message. That way, the message can be seen by the user who ran `make`. It can also no longer be mistaken for machine-readable output. Example output of `make`: > File not found: build/x16/dos.sym > Usage: findsymbols file [-p prefix] symbol ... > file: > Symbol file created with the -Ln option in ld65 > -p prefix: > A prefix added to all returned symbol names > symbol: > Name of one or more symbols > Makefile:407: *** findsymbols failed with exit code 1. Stop. 3. To avoid peppering the whole Makefile with exit code guards, declare a `findsymbols` function that hides the complexity. 4. As an unwanted side effect, calling a function causes Make to misinterpret the `$` address prefixes that occur in the `findsymbols` output. To counteract that, escape every `$` with `$$`. 5. As a graceful fallback for users of GNU Make versions older than 4.2, default `.SHELLSTATUS` to 0. In that case, we have no early returns, but users still get a somewhat meaningful error message that says e.g., "Unresolved external 'skip_mask' referenced in: fat32/match.s", which is still much more helpful than "ld65: Error: Cannot use -Ln twice". [1]: X16Community#363
Contributor
Author
|
Output of BeforeAfter |
mooinglemur
approved these changes
Dec 2, 2025
Collaborator
mooinglemur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This definitely helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If
findsymbolsfails, it prints a helpful usage message to standard output:Unfortunately, the Makefile ignores the exit status of
findsymbols. It then misinterprets the whole help text as legitimate output and rolls it all into the linker command line.Because the help text happens to contain the word
-Lnand there’s another-Lnin the command line already, the linker treats this duplication as an error and bails with the error message from issue #363:This PR is to improve the error message and fix the leaky help text.
It redirects the help text to stderr (so the help text is no longer misinterpreted as legitimate output) and adds an exit status guard (so the build fails early with a more useful error message.)
See my commit message for more details.
Note that this PR does not fix the root cause of #363, which I think should be a separate PR.
@mooinglemur Review would be appreciated.