Skip to content

Make DWARF debug flag behavior match Clang. #17087

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 4 commits into from
Jun 15, 2018

Conversation

allevato
Copy link
Member

Only write the compilation flags to debug info for Mach-O targets, and only
if the RC_DEBUG_OPTIONS environment variable is set.

This change improves hermeticity/reproducibility of Swift binaries/dSYMs by not encoding command line flags that might contain file system paths, since LLDB no longer needs them (except for -private-discriminator, which I've left in; it's invariant because it's computed only from the basename anyway).

@adrian-prantl

Only write the compilation flags to debug info for Mach-O targets, and only
if the RC_DEBUG_OPTIONS environment variable is set.
@adrian-prantl adrian-prantl self-assigned this Jun 10, 2018
Copy link
Contributor

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

This is going into the right direction, I added a suggestion for an alternate wording. Let's also hear if @jrose-apple has any opinions.

@@ -486,4 +486,7 @@ def disable_verify_exclusivity : Flag<["-"], "disable-verify-exclusivity">,
def enable_key_path_resilience : Flag<["-"], "enable-key-path-resilience">,
HelpText<"Enable key path resilience.">;

def use_dwarf_debug_flags : Flag<["-"], "use-dwarf-debug-flags">,
HelpText<"Write the compilation flags into the DWARF debug info.">;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps: -emit-debug-options: Emit the compiler invocation in the debug info.

Copy link
Member Author

Choose a reason for hiding this comment

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

That alternative seems fine; my only concern would be whether it would be easily confused with -serialize-debugging-options. Or do you think the symmetry between "serialize" and "emit" would intentionally work well and make it clear which one goes where?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love either name; it's not the "debug flags" or "debug options" that are being written. (It also doesn't seem DWARF-specific.) I'll toss another contribution in, -enable-invocation-in-debug-info, but that's getting fairly wordy.

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 it would be nice if the debug-info part came first for grouping and sorting.
-debug-info-(emit|store)-invocation, -debug-info-invocation=yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we're making it a driver flag based on the conversation below, should we prefix it with -g then (but not add it to the g_Group)? How do any of these sound:

  • -gcompiler-flags
  • -gcompiler-options
  • -gcompiler-invocation
  • -grecord-compiler-flags
  • -grecord-compiler-options
  • -grecord-compiler-invocation

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm fine with -debug-info; it's grouping a bunch of things under single letters that I don't like. To compare with GCC/Clang flags:

  • -f* - something to do with the language? Why -f?
  • -m* - something to do with code generation? Why -m?
  • -d* - something to do with dependencies? Or "defines"?
  • -i* - "includes", okay…but it led us to the horrible -iframework, meaning "system framework include path"

-g is at least consistently used for debugging things, but there's still no obvious link between "-g" and "debug info"; you just have to memorize it. -O, -W, and -X are pretty much the only flag families that stayed consistent, and -W is still weird around the edges.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we do have a man page! It just tells you to use -help. :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, given the feedback so far, if we exclude prefixed flags, I think -debug-info-store-invocation is the one that best balances conciseness while still getting across what the flag actually does. -enable-invocation-in-debug-info came close, but I agree that it's a bit verbose.

If that sounds good, I'll go ahead and update the PR to use that.

Copy link
Member

@compnerd compnerd Jun 13, 2018

Choose a reason for hiding this comment

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

@jrose-apple the prefixes actually have some level of consistency

-f: feature flags
-m: machine flags
-d: dump flags (used for the C Preprocessor)
-i: includes

Copy link
Contributor

Choose a reason for hiding this comment

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

Except that "feature flag" vs. "machine flag" doesn't make any sense to a normal user, and "-i", while consistent, has led to badness elsewhere.

@compnerd
Copy link
Member

Please don't limit this to Darwin. This is a spelling issue. -grecord-gcc-switches accomplishes the same thing (it records all of the CC1 flags).

@allevato
Copy link
Member Author

@compnerd This PR only changes the default behavior of the driver to match that of Clang, where on non-Darwin platforms it never emits the flags, and on Darwin it only emits them if that environment variable is set. The user can still force the frontend to emit them on other platforms by passing -Xfrontend -use-dwarf-debug-flags (or whatever we end up renaming it to).

Is that sufficient, or do you think we need a driver-level flag for this?

@jrose-apple
Copy link
Contributor

Definitely in favor of this direction! I've been after Adrian to remove/disable this feature for a while. :-) I'm inclined to make this a driver-level flag too; if it's useful on Darwin it could easily be useful elsewhere, and no one's supposed to use -Xfrontend options in production code (they're not supported or stable). And environment variables are terrible for controlling things like this.

@adrian-prantl
Copy link
Contributor

adrian-prantl commented Jun 11, 2018

And environment variables are terrible for controlling things like this.

The environment variable is (good design or not) necessary for uniformity with clang on Apple platforms.

I just wanted to point out that the intent of this feature is to help debugging build systems.
(Historically the flags were also used by LLDB during Swift bringup, but that use-case has since been superseded by information serialized in the .swiftmodule files.)

@compnerd
Copy link
Member

@allevato - I think as @jrose-apple points out, -Xfrontend options aren't as attractive

@allevato
Copy link
Member Author

I've updated the PR to use -debug-info-store-invocation, and renamed the toolchain method that lets it override the behavior if the flag isn't present (to preserve the Clang behavior under Darwin, as discussed above). PTAL.

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.

Looks reasonable to me! Adrian?

// Check that the sdk and resource dirs end up in the debug info if we build for
// a Darwin target and set the RC_DEBUG_OPTIONS environment variable. This
// matches the behavior found in Clang.
// RUN: %target-swiftc_driver %s -emit-ir -g -target x86_64-apple-macosx10.10 -o - | %FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

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

These can just be %swiftc_driver, since you're overriding the target anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 22ac700

if (!PD.empty())
IRGenOpts.DWARFDebugFlags += (" -private-discriminator " + PD.str()).str();
if (!PD.empty()) {
if (!IRGenOpts.DWARFDebugFlags.empty()) IRGenOpts.DWARFDebugFlags += " ";
Copy link
Contributor

Choose a reason for hiding this comment

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

clang-format would format this as:

if (!IRGenOpts.DWARFDebugFlags.empty())
   IRGenOpts.DWARFDebugFlags += " ";

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 22ac700

@allevato
Copy link
Member Author

Thanks all! Latest requested changes are pushed.

@adrian-prantl
Copy link
Contributor

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0acc73a

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 0acc73a

@jrose-apple
Copy link
Contributor

Oops, of course. By default, we can't compile for macOS on a non-macOS platform. Adding -parse-stdlib to that test should get around that by not trying to import Swift.

@allevato
Copy link
Member Author

Ah-ha, thanks for the tip! Updated.

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@jrose-apple jrose-apple self-assigned this Jun 13, 2018
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 88cffc1

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 88cffc1

@allevato
Copy link
Member Author

Hmm, I'm not sure why the test is crashing when emitting the debug info on Linux after the change adding -parse-stdlib. It looks similar to this IRGen/nominal-type-section.swift test, which works; the only meaningful difference I see is that it's invoking the frontend directly instead of the driver. Could that be the important difference here? (I only have a macOS machine to test locally with.)

@jrose-apple
Copy link
Contributor

All right, #17226 should have cleared it up. Let's try again.

@swift-ci Please test Linux

@jrose-apple
Copy link
Contributor

And to be sure nothing's changed since a few days ago.

@swift-ci Please smoke test macOS

@allevato
Copy link
Member Author

Excellent! Thanks for the related fix on the side.

@jrose-apple jrose-apple merged commit 8d43ec3 into swiftlang:master Jun 15, 2018
@allevato allevato deleted the dwarf-command-line-flags branch June 15, 2018 16:53
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.

5 participants