Fix #1457: Make --version exit immediately, -v continue linking#1521
Merged
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
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.
Fixes #1457
Problem
When running
clang -Wl,--version, Wild was printing the version but continuing to link, which caused failures when undefined symbols were present. Other linkers (GNU ld, LLD) print their version and exit immediately with code 0, even if there are linking errors.Solution
This PR separates the behavior of
-vand--versionflags to match GNU ld and LLD:Changes Made
Added
VersionModeenum with three states:None: Don't print versionVerbose: Print version and continue linking (for-vflag)ExitAfterPrint: Print version and exit immediately (for--versionflag)Separated flag handlers in
args.rs:--version→ SetsVersionMode::ExitAfterPrint-v→ SetsVersionMode::VerboseUpdated linker logic in
lib.rs:ExitAfterPrint→ Returns immediately after printing versionVerbose→ Prints version and continues with normal linkingNone→ No version outputUpdated tests to verify the new behavior
Behavior
Before:
After:
Testing
Manually tested:
wild --version - Prints version and exits with code 0 (no linking)
wild --version file.o - Ignores input files, exits immediately
wild -v file.o - Prints version and continues linking
clang -Wl,--version - Works correctly now
Compatibility
This implementation now matches the behavior of:
GNU ld (GNU Binutils)
LLD (LLVM linker)
Gold linker
This ensures Wild can be used as a drop-in replacement in build systems that query linker versions.