fix: preserve link order#69
Conversation
1f1b186 to
1e33951
Compare
1e33951 to
2f3837e
Compare
| 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); |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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?
|
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) |
|
Not exactly a second source of truth, no. The link tokens array will point into the inputs list (it stores enum LinkInput {
Flag(String),
Input(String),
}which at least saves us from looking at the raw strings over and over again. |
|
Wait but I already do this, don't I? Or do you mean to sort them apart in the first lexing pass? |
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 meanslibfoobargets dropped silently instead.This PR makes it preserve ordering, as well as factoring out the argument building logic in order to make it testable.