This is an archive of the discontinued LLVM Phabricator instance.

Emit proper CodeView even when not using the cl driver.
ClosedPublic

Authored by zturner on Feb 23 2018, 3:53 PM.

Details

Summary

Although the supported way of invoking clang on Windows is via the cl driver, some people may wish to use the g++ driver. and manually specify -gcodeview. This codepath is currently broken, as it will cause column information to be emitted, which causes debuggers to not work.

While we still don't claim to support clang on Windows without the cl driver, this is a straightforward patch to make things slightly better for people who want to go this route anyway.

Diff Detail

Repository
rC Clang

Event Timeline

zturner created this revision.Feb 23 2018, 3:53 PM

Seems good to me! I'll give it a test on my end.

One alternate implementation idea though, what if you defaulted EmitCodeView to the hasArg check instead of false, then removed the else *EmitCodeView = false; block on line 4999?

Seems good to me! I'll give it a test on my end.

One alternate implementation idea though, what if you defaulted EmitCodeView to the hasArg check instead of false, then removed the else *EmitCodeView = false; block on line 4999?

That would actually change the behavior of the cl driver, which I kind of don't want to do since it's not necessary. It would whitelist an additional clang option to be recognized by the cl driver. Specifically, you could then get debug info via the cl driver without specifying /Z7 or /Zi. It makes the possibilities more confusing, and someone will invariably try to do it and screw something up. We already whitelist some dash options so that the cl driver will recognize them, but it's on a case by case basis and only when there's a strong need for it.

Seems good to me! I'll give it a test on my end.

One alternate implementation idea though, what if you defaulted EmitCodeView to the hasArg check instead of false, then removed the else *EmitCodeView = false; block on line 4999?

That would actually change the behavior of the cl driver, which I kind of don't want to do since it's not necessary. It would whitelist an additional clang option to be recognized by the cl driver. Specifically, you could then get debug info via the cl driver without specifying /Z7 or /Zi. It makes the possibilities more confusing, and someone will invariably try to do it and screw something up. We already whitelist some dash options so that the cl driver will recognize them, but it's on a case by case basis and only when there's a strong need for it.

Good point, that's a pretty good reason not to.

Being a cross-compiler I think it's generally a good thing to have more combinations be less broken.
Note that PS4's compiler is hosted on Windows and uses the gcc-style driver; it's convenient sometimes to be able to target Windows without having to learn a new driver language. So thanks for doing this!

We were affected by this too. Thanks for fixing!

(We're actually using CodeView + DWARF, since we have a bunch of tooling built around DWARF. We use the gcc-style driver for legacy reasons.)

rnk accepted this revision.Feb 24 2018, 7:27 AM

Lgtm

We should go farther, IMO. clang -g should default to emitting codeview in an MSVC environment.

This revision is now accepted and ready to land.Feb 24 2018, 7:27 AM

Thanks for fixing this @zturner. I simply want to back-up what @probinson says above - most of the games we do at Ubisoft are currently using a different compilation toolchains for each platform (we ship at least 4-5 platforms for each top game). It can be clang or it can be MSVC; and most of the time it's different versions of clang. Our long-term goal is to preferably have only one toolchain for all our platforms & all our targets - that means one set of common g++ like flags, including Windows.

@rnk by "in an MSVC environment" do you mean "when -fms-compatibility is present"?

Thanks for fixing this @zturner. I simply want to back-up what @probinson says above - most of the games we do at Ubisoft are currently using a different compilation toolchains for each platform (we ship at least 4-5 platforms for each top game). It can be clang or it can be MSVC; and most of the time it's different versions of clang. Our long-term goal is to preferably have only one toolchain for all our platforms & all our targets - that means one set of common g++ like flags, including Windows.

+1, this is what we're going for on Lumberyard as well. Well put.

@rnk by "in an MSVC environment" do you mean "when -fms-compatibility is present"?

It looks like other places in this file are using Triple.isWindowsMSVCEnvironment(), which I think would make sense to use for this too. It's implemented as:

bool isWindowsMSVCEnvironment() const {
  return getOS() == Triple::Win32 &&
         (getEnvironment() == Triple::UnknownEnvironment ||
          getEnvironment() == Triple::MSVC);
}

This appears to default to true from a normal Windows cmd (on my Win10 machine, the default triple is x86_64-pc-windows-msvc).

The -g meaning -gcodeview for MSVC environments change should be a separate diff though, right?

The -g meaning -gcodeview for MSVC environments change should be a separate diff though, right?

Yes I'm not doing that in this patch. Just wanted to clarify what he meant. I'm writing a test for this right now and then I'll commit.

This revision was automatically updated to reflect the committed changes.

I had to revert this for now. It breaks the asan bots which expect column info. That fix is easy, but it also breaks a random linux bots which I don't have the ability to debug at the moment because my linux machine is not working. Hopefully I can get that resolved soon.