This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Explicitly set object format to COFF in CL mode
ClosedPublic

Authored by iid_iunknown on Aug 31 2017, 7:59 AM.

Details

Summary

Currently object format is taken from the default target triple. For toolchains with a non-COFF default target this may result in an object format inappropriate for pc-windows and lead to compilation issues.

For example, the default triple aarch64-linux-elf may produce something like aarch64-pc-windows-msvc19.0.24215-elf in CL mode. Clang creates MicrosoftARM64TargetInfo for such triple with data layout e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128. On the other hand, the AArch64 backend in computeDataLayout detects a non-COFF target and selects e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128 as data layout for little endian. Different layouts used by clang and the backend cause an error:

error: backend data layout 'e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128'
 does not match expected target description 'e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128'

This can be observed on the clang's Driver/cl-pch.c test with AArch64 as a default target.

This patch enforces COFF in CL mode.

Diff Detail

Repository
rL LLVM

Event Timeline

iid_iunknown created this revision.Aug 31 2017, 7:59 AM
hans edited edge metadata.Aug 31 2017, 8:52 AM

Seems reasonable, but should probably have a test.

This can be observed on the clang's Driver/cl-pch.c test with AArch64 as a default target.

But why isn't that failure showing on some buildbot, then?

In D37336#857802, @hans wrote:

But why isn't that failure showing on some buildbot, then?

The test needs system-windows to run:

// REQUIRES: system-windows

There is no windows buildbot that builds clang defaulted to the AArch64 target.

hans added a comment.Aug 31 2017, 9:29 AM
In D37336#857802, @hans wrote:

But why isn't that failure showing on some buildbot, then?

The test needs system-windows to run:

// REQUIRES: system-windows

There is no windows buildbot that builds clang defaulted to the AArch64 target.

I see.

Do you think you can write a test for your patch that will work on the buildbots we have?

Do you think you can write a test for your patch that will work on the buildbots we have?

I am afraid, this is not possible with the existing buildbots. --target does not affect the default triple. There is LLVM_TARGET_TRIPLE_ENV that allows to override the default triple at runtime, but LLVM must be configured to support it and none of the Windows buildbots do this. I see no other way to implement such a test, unfortunately.

hans accepted this revision.Aug 31 2017, 12:40 PM

lgtm

This revision is now accepted and ready to land.Aug 31 2017, 12:40 PM

Thanks for reviewing this!

iid_iunknown closed this revision.Aug 31 2017, 1:32 PM