Skip to content

Fix Response Files on Windows #22985

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
merged 1 commit into from
Mar 2, 2019
Merged

Conversation

gmittert
Copy link
Contributor

This prevents response files on Windows from being overridden after they
are read.

Note that this is #20885 but without the unicode changes. The patch upstream has been taking a while and response files would help a lot with building Foundation on Windows.

#ifdef _WIN32
// PROGRAM_START/InitLLVM overwrites the passed arguments with the unexpanded
// commandline arguments. Since we already handle getting utf-8 arguments, we
// overwrite the changed arguments again.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong for a few reasons:

  • the Swift-driver-written response files are going to be in UTF-8, aren't they?
  • the PrettyStackTraceProgram inside InitLLVM isn't going to have the expanded arguments, which we were very much trying to support
  • this is now doing redundant work

Maybe we shouldn't be using InitLLVM.

Copy link
Contributor Author

@gmittert gmittert Feb 28, 2019

Choose a reason for hiding this comment

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

  • The response files are expected to be in UTF-8. This converts the file name argument to UTF16 but leaves the expanded response files alone.
  • This does actually register the right arguments, you get the expanded arguments in "Program Arguments:". InitLLVM overwrites the arguments you pass it, but not the ones it registers with the StackPrinter. I'm unsure why.
  • Yup, it's completely redundant. Now that I think about it, it would be slightly better to make copies of the expanded arguments and pass those to InitLLVM. But alternatively, it wouldn't be difficult to have an InitSwift instead. Any preference?

Copy link
Contributor

Choose a reason for hiding this comment

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

The less we can diverge from LLVM the better, so if "just don't use the replacements InitLLVM gives us" is the right answer, we can just make extra Argc and Argv variables that we then throw away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems reasonable to me!

PROGRAM_START(ExpandedArgc, ExpandedArgv);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can make this even simpler by renaming ExpandedArgc/v to ThrowawayArgc/v, and then initializing the argv ArrayRef below from ExpandedArgs instead. It's a good comment, though.

Copy link
Contributor Author

@gmittert gmittert Feb 28, 2019

Choose a reason for hiding this comment

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

Good call, +1 to one less #ifdef _WIN32.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Code looks good! …and now I'm paying more attention to the tests and am curious.

@@ -0,0 +1,8 @@
// Windows returns a negative exit code from -debug-crash-immediately so not
// considers that to be a crash (requiring --crash) instead of an abnormal exit
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. The driver is supposed to be catching crashes when not doing an exec. Is it possible the decision of whether to exec or not is different on Windows vs. other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by catching crashes when not doing an exec?

Copy link
Contributor

Choose a reason for hiding this comment

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

The TaskQueue implementation has a callback for when a process crashes, and is supposed to exit with a normal error when that happens.

Copy link
Contributor Author

@gmittert gmittert Feb 28, 2019

Choose a reason for hiding this comment

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

From what I've seen, on Unix, if a process exits with an uncaught signal, the driver catches that and exits with a positive exit code (254 it seems).

On Windows, signals aren't really a thing, so the signal handler only gets called if llvm:sys::Wait fails due to say, a malformed argument. Otherwise, it simply bubbles up the return code to the driver and the driver exits with it. I think the closest Windows thing would be checking the high bits of the 32bit exit code. 10 is a warning, 11 is an error which llvm respects. However, that's not really a signal and I'm not sure if it makes too much sense to have that call the signalled callback.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the "signalled" callback really is supposed to be "crashed". It controls things like whether temporary files are cleaned up or left in place for debugging purposes.

// MERGE: -emit-module-doc-path [[PARTIAL_MODULE_B:[^ ]+]].swiftdoc
// MERGE: bin/swift{{c?}}
// MERGE: @{{[^ ]*}}arguments-{{[0-9a-zA-Z]+}}.resp # -frontend -merge-modules -emit-module [[PARTIAL_MODULE_A]].swiftmodule [[PARTIAL_MODULE_B]].swiftmodule
// MERGE: bin{{(/|\\\\)}}swift{{c?}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Personal opinion: {{[/\\]}} is a little easier to read.

Copy link
Contributor Author

@gmittert gmittert Feb 28, 2019

Choose a reason for hiding this comment

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

There are two backslashes here that need to be matched. ..Though the parens there are not needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, bah, I always forget that. Thanks.

@gmittert
Copy link
Contributor Author

gmittert commented Mar 2, 2019

With #23018 (comment), we don't need to have multiple tests anymore!

This prevents response files on Windows from being overridden after they
are read.
@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 24c10fe into swiftlang:master Mar 2, 2019
@gmittert gmittert deleted the PlsRespond branch March 11, 2019 23:40
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.

2 participants