]> granicus.if.org Git - clang/commitdiff
[clang-cl] Explicitly set object format to COFF in CL mode
authorOleg Ranevskyy <oranevskyy@accesssoftek.com>
Thu, 31 Aug 2017 20:31:30 +0000 (20:31 +0000)
committerOleg Ranevskyy <oranevskyy@accesssoftek.com>
Thu, 31 Aug 2017 20:31:30 +0000 (20:31 +0000)
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.

Reviewers: hans

Reviewed By: hans

Subscribers: cfe-commits, aemerson, asl, kristof.beyls

Differential Revision: https://reviews.llvm.org/D37336

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@312275 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp

index cf0962b2865f92c80203c6272c3e5750d654c71a..c6367409eb106bd5181fc51b13139b43d61dcf6d 100644 (file)
@@ -663,6 +663,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
     T.setOS(llvm::Triple::Win32);
     T.setVendor(llvm::Triple::PC);
     T.setEnvironment(llvm::Triple::MSVC);
+    T.setObjectFormat(llvm::Triple::COFF);
     DefaultTargetTriple = T.str();
   }
   if (const Arg *A = Args.getLastArg(options::OPT_target))