Skip to content

fix: preserve link order#69

Open
kilyanni wants to merge 1 commit into
mainfrom
fix/preserve-link-order
Open

fix: preserve link order#69
kilyanni wants to merge 1 commit into
mainfrom
fix/preserve-link-order

Conversation

@kilyanni

@kilyanni kilyanni commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Right now, link inputs and link args get split apart and then appended after one-another.

This means that for order-sensitive args like --whole-archive libfoobar.a --no-whole-archive, it instead emits --whole-archive --no-whole-archive libfoobar.a, which means libfoobar gets dropped silently instead.

This PR makes it preserve ordering, as well as factoring out the argument building logic in order to make it testable.

Copilot AI review requested due to automatic review settings July 9, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kilyanni kilyanni force-pushed the fix/preserve-link-order branch from 1f1b186 to 1e33951 Compare July 9, 2026 11:47
@kilyanni kilyanni requested a review from Arshia001 July 9, 2026 11:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/compiler.rs
Comment on lines 530 to +533
let mut lib_arg = OsString::new();
lib_arg.push("-L");
lib_arg.push(&sysroot_lib_path);
command.arg(lib_arg);
lib_arg.push(sysroot_lib_path);
args.push(lib_arg);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is false, NLL drops it before we get to that point.

OsString::push should already be getting an OsStr via Paths AsRef impl

@Arshia001 Arshia001 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While the change is correct in principle, I'm not very fond of the implementation approach where we shuffle the link inputs with all the other flags and end up scanning through the list over and over again. Maybe we can do something like this:

enum LinkToken {
  Flag(String),
  Input(usize)
}

struct PrepatedArgs {
  // ...
  linker_flags: Vec<LinkToken>,
  linker_inputs: Vec<String>
}

so that we can maintain order when reconstructing the input to the final linker invocation, but also keep the inputs available separately for when we need them?

@kilyanni

kilyanni commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, that'd give two sources of truth, which I'm not too keen on. What do you think about having a helper method that just returns an iterator of the link inputs?

The performance impact should be negligible at this scale of array (and maybe trumped by the alloc costs of the two array version)

@Arshia001

Copy link
Copy Markdown
Contributor

Not exactly a second source of truth, no. The link tokens array will point into the inputs list (it stores usize for inputs). Either that or just have link_flags be this enum:

enum LinkInput {
  Flag(String),
  Input(String),
}

which at least saves us from looking at the raw strings over and over again.

@kilyanni

Copy link
Copy Markdown
Contributor Author

Wait but I already do this, don't I? Or do you mean to sort them apart in the first lexing pass?

@kilyanni kilyanni requested review from Arshia001 July 16, 2026 12:20
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