Skip to content

Fix #1457: Make --version exit immediately, -v continue linking#1521

Merged
davidlattimore merged 1 commit into
wild-linker:mainfrom
Blazearth:version-flag-debug
Feb 8, 2026
Merged

Fix #1457: Make --version exit immediately, -v continue linking#1521
davidlattimore merged 1 commit into
wild-linker:mainfrom
Blazearth:version-flag-debug

Conversation

@Blazearth

Copy link
Copy Markdown
Contributor

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 -v and --version flags to match GNU ld and LLD:

Changes Made

  • Added VersionMode enum with three states:

    • None: Don't print version
    • Verbose: Print version and continue linking (for -v flag)
    • ExitAfterPrint: Print version and exit immediately (for --version flag)
  • Separated flag handlers in args.rs:

    • --version → Sets VersionMode::ExitAfterPrint
    • -v → Sets VersionMode::Verbose
  • Updated linker logic in lib.rs:

    • ExitAfterPrint → Returns immediately after printing version
    • Verbose → Prints version and continues with normal linking
    • None → No version output
  • Updated tests to verify the new behavior

Behavior

Before:

$ clang -Wl,--version --ld-path=./wild
Wild version 0.8.0 ...
wild: error: Undefined symbol main
Exit code: 255 ❌

After:

$ clang -Wl,--version --ld-path=./wild
Wild version 0.8.0 ...
Exit code: 0 ✅

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.

@davidlattimore davidlattimore merged commit 218298b into wild-linker:main Feb 8, 2026
20 checks passed
@Blazearth Blazearth deleted the version-flag-debug branch February 10, 2026 15:06
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.

--version does not prevent link failure

2 participants